About python threading
for example i want create one client, and request two or more contract history data, this is wrong way? ``` app = Client() app.connect('127.0.0.1', 7497, 0) threading.Thread(target=app.run).start() time.sleep(1) for row in ['AAPL','GOOG']: app.reqHistoricalData(....) app.disconnect() ``` the app can not disconnect so i write like this: ``` for row in ['AAPL','GOOG']: app = Client() app.connect('127.0.0.1', 7497, 0) threading.Thread(target=app.run).start() app.reqHistoricalData(args) ``` then i disconnect on historicalDataEnd function, then it is work fine. so my question is, one client only can do one thing?
|
reqMktData subscription is not continuous
5
Trying to subscribe to live Bid / Ask prices for ES futures using "reqMktData". var contract = new Contract { Symbol = "ES", Exchange = "CME", ConId = 495512563, LastTradeDateOrContractMonth = "20251219" }; _client.TickPrice += o => Console.WriteLine(JsonSerializer.Serialize(o)); _client.ClientSocket.reqMktData(id, contract, string.Empty, false, false, null); As a result, I receive one round of messages below, and then notifications stop. {"Attribs":{"CanAutoExecute":true,"PastLimit":true,"PreOpen":false,"Unreported":false,"BidPastLow":false,"AskPastHigh":false},"Value":5801,"Data":5801,"RequestId":3,"Field":1} {"Attribs":null,"Value":1,"Data":1,"RequestId":3,"Field":0} {"Attribs":{"CanAutoExecute":true,"PastLimit":false,"PreOpen":false,"Unreported":false,"BidPastLow":false,"AskPastHigh":false},"Value":6300,"Data":6300,"RequestId":3,"Field":2} {"Attribs":null,"Value":1,"Data":1,"RequestId":3,"Field":3} {"Attribs":null,"Value":1,"Data":1,"RequestId":3,"Field":0} {"Attribs":null,"Value":1,"Data":1,"RequestId":3,"Field":3} {"Attribs":null,"Value":0,"Data":0,"RequestId":3,"Field":5} {"Attribs":{"CanAutoExecute":false,"PastLimit":false,"PreOpen":false,"Unreported":false,"BidPastLow":false,"AskPastHigh":false},"Value":6274,"Data":6274,"RequestId":3,"Field":9} {"Attribs":{"CanAutoExecute":false,"PastLimit":false,"PreOpen":false,"Unreported":false,"BidPastLow":false,"AskPastHigh":false},"Value":6050.5,"Data":6050.5,"RequestId":3,"Field":14} Are there any settings, like "Return only snapshots instead of continuous subscriptions"? Why notifications stop after receiving only one quote?
|
Question on nextValidId function
5
Hi All, one question on the orderId and the necessity of nextValidId function. From the documentation (https://www.interactivebrokers.com/campus/ibkr-api-page/twsapi-doc/#receive-news-articles) it is stated that ¡°if there are multiple client applications connected to one account, it is necessary to use an order ID with new orders which is greater than all previous order IDs returned to the client application in openOrder or orderStatus callbacks ¡±. so I expect that the nextValidId function is needed in case of multiple clients for one account. However i have created a program in python that handles orderIds internally without relying on the nextvalidid function. By launching multiple instances of it (each with different client id) I see no problems in handling orders (each client autonomously updating its orderId). What am I missing? Is nextValidId really needed? thanks, Marco
|
reqExecution failed to get executions
I have a Java program using TWS API to get market data and place orders. After it made a trade, it gets "ExecDetails" and "CommissionReport" callbacks. But after I restarted the Java program and called "clientSocket.reqExecutions(reqId, new ExecutionFilter());", it only gets "ExecDetailsEnd" message without any executions that were done before the restart. I tried to set the "clientID" and "time" field to start of the today in the ExecutionFilter object but no use. Do I miss anything in the TWS setting? Could anyone shed some light?
|
NQ Futures Security Definition
2
When I try to place an order on NQ futures, I have defined the contract the following way, but i get the following error: Error: 32 200 No security definition has been found for the request contract = Contract() contract.symbol = 'NQ' contract.secType = 'FUT' contract.exchange = 'CME' contract.currency = 'USD' contract.lastTradeDateOrContractMonth = "202412"
|
Entry that triggers OCO with TP and SL
10
Would anyone have a template for the following order: Entry that triggers OCO for Take Profit and Stop Loss? Regards, Javed
|
No definition for SPX option using LocalSymbol
6
Could somebody advise why I'm getting "No security definition" error for a contract with this local symbol : C SPX 20241218 5945 W Security: SPX index Strike: 5945 Side: Call Expiration: 2024-12-18 Type: Weekly Trying to send order to buy and sell SPX index options. When I set separate contract properties such as strike, symbol, expiration, currency, and exchange, place order request returns error "ambiguous definition" because API returns the same expiration date for monthly and weekly options. There are several ways to make contract definition for option unique, e.g. using TradingClass or LocalSymbol properties. When I try to use LocalSymbol I get error "No security definition found" Example of local symbol that I used : C SPX 20241218 5945 W Format mentioned in the docs : TWS API: Basic Contracts
|
-1 negative VOLUME in Futures BID_ASK historical request
I see the same. It looks like you only get VOLUME or BARCOUNT if you ask for TRADES. That doesn¡¯t seem unreasonable to me. Richard
|
API dev available
Hello, all, I am available for API dev work if anyone needs an extra hand
|
Best Practices for Pulling Stock Data Efficiently with APIs
6
Hi everyone, I¡¯m working on a project that requires pulling historical data on hundreds of stocks using the Interactive Brokers TWS API. The data includes daily OHLC (Open, High, Low, Close) values and trading volume. My current method involves sequential API calls in a loop, which is slow and not efficient for a large dataset. Here¡¯s my current setup: Sending requests for individual stocks sequentially using the TWS API. Saving the returned data locally after each request for further analysis. I¡¯d like to optimize this process to handle large batches of stocks more efficiently.I¡¯m interested in advice on: Batch Requests: Does the TWS API support batch requests, and if so, how can I implement them? API Limitations: Are there known rate limits or best practices with the TWS API to avoid throttling or data loss? Caching Strategies: Are there effective ways to cache or save data to avoid redundant requests during retries or updates? If anyone has experience optimizing the Interactive Brokers API or similar APIs for high-volume data retrieval, I¡¯d appreciate your insights. Also, if this topic has been covered before, I¡¯d be grateful if you could point me to the relevant discussions in the archives. Thanks in advance!
|
IB Gateway freezes sometimes.
15
Not sure if this is the right place to ask the question, but since I can't find anywhere else looking for help for those kinds of questions, I suppose I might just post it here or someone could probably redirect me to the right place. So I'm basically running the IB Gateway(the linux stable version) on a linux virtual machine, and sometimes the application just freezes, and when I try to click anything, it doesn't respond, and the api client connected to the gateway receiving data feeds also can't receive any data. when I try to connect new client, it also fails, I have to manually kill the process and restart the application. So looks like an issue related to the IB Gateway itself? Checking the api log doesn't give any useful information, just some normal messages. I'm wondering if anyone experience the same issue before or any bug report related to this kind of scenario? Any suggestions what I can do?
|
Generic ticks
Hi, there are several Market Data column types available in TWS for which I don't see corresponding generic tick types. Are the tick types supported by the API only a subset of the TWS types? The data points I am trying to request are Market Cap and 1 Wk Change. Thanks.
|
Retrieving last trade quotation side from api
I am trying to subscribe to the following last trade information from the API. - last price - last size - last timestamp - last quotation side I have only managed to receive the first 3 information from the callbacks as shown in logs: Tick Price. Ticker Id: 1013, Field: 68, Price: 42.35, CanAutoExecute: 0, PastLimit: 0, PreOpen: 0 // Delayed last Tick Size. Ticker Id: 1013, Field: 71, Size: 500 // Delayed last size Tick String. Ticker Id: 1013, Type: 88, Value: 1734076776 // Delayed last timestamp Is there any way of subscribing to the quotation side of last trade from the API?
|
No Security definition has been found for the request when running cpp sample code
7
Hi, I'been trying to run the cpp sample code to reqRealTimeBars for some contract. but the ib server returns no security defintionn found even though I was using the sample contract.
|
Discrepancies between real-time and historical market data
2
Attached are the logs from my subscription to real-time and historical bar data yesterday. As you can see, there are discrepancies between the 'high' and 'Wap' values in the two datasets. I'm wondering if anyone can explain why this might be occurring. Any insights would be helpful. RealTimeBars: JD,Time:1733404940,Open:36.28,High:36.28,Low:36.28,Close:36.28,Volume:500000000000,Wap:36280000000,Count:1 HistoricalBars: JD,BarData(date=datetime.datetime(2024, 12, 5, 8, 22, 20, tzinfo=backports.zoneinfo.ZoneInfo(key='US/Eastern')), open=36.28, high=36.29, low=36.28, close=36.28, volume=500.0, average=36.282, barCount=1) Thanks xb
|
what time EST is it safe to assume that IB have printed the final close for all symbols EOD
5
Hi all In the groups experience what is the earliest time , eastern standard time, when it's reasonable to say that IB have printed ( immutable) the close for all symbols that will be the number of record in perpetuity. So market close at 16:00 but there's going to be a period where the numbers are still being populated. I'm certain that someone has figured out what that "indeterminate" period is to a margin of safety. I asked IB sometime back but the support desk has never responded, I asked 3 time. thank you for any help OR thoughts. cp
|
Multiple strategies in one account
4
Hello, I need to run several strategies in one account. How do I best keep them apart, unknowing of each other? I can tag orders using the orderRef field, but as of now, all I can think of is to keep a local database with all information (and maybe reconcile it with IB now and then). How else can I know which position belongs to which strategy? Do you have any best practices, or tips, to share? Thanks, Peter
|
reqRealTimeBars: data stops receiving for after-hour session
4
isn't this exactly what useRTH=False supposed to mean?
|
Purebasic and TWS
20
Hi, I am looking for Purebasic source code that uses TWS API. I am a begineer in Purebasic and TWS but not in programming but dont really know where to start. For example do I have to: 1 - Load a DLL such as TWSAPI.DLL or TWSLib.dll or something else, and then call the included functions? 2 - Open a windows socket connection and then send command strings ? I tryed to find out exploring source code in other languages, but nothing appeared clearly to me. My feeling is that Purebasic is a good language for this use as it generates a very compact and efficient executable file with no depencies. I just need to get started, then I can manage the rest. However if I could find Purebasic source code I might save a lot of time. Thanking you in advance for any help.
|
TWS API - TICK Historical Candles issue AFTER November 25th
Hi, I am trying to retrieve historical price data of a few FOREX currency pairs: mainly AUDCAD, EURUSD and EURGBP. Since November 25th, I am unable to retrieve historical TICK data via API. Before that date, I was able to download any price even going back to 2022. When trying to download TICK data, I am getting the following error: Historical Market Data Service error message:HMDS query returned no data: <SYMBOL@TYPE OF PRICE> I get the error regardles if it's: CASH or CFD IDEAPRO or SMART ASK BID BID_ASK_MIDPOINT price What I tried: 1. I tried and I CAN download 30 SEC candles meaning that it is not a problem with the code, connection or ports. 2. I used another account and another IP. 3. I tried different DATE formats, e.g. yyyyMMdd-HH:mm:ss I am running out of options. Can you please help me understand what might be the problem?
|