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
|
IB's New automated trading system questionnaire
9
I logged on to my account and found a must complete questionnaire about how I'm monitoring my automated api. It wanted to know 1) Did I write it or is it commercial and if so the vendor? 2) Is the API completely automated? If not to what extent it is manual? 3) How are critical errors handled (audible alert, email, text)? 4) Is it constantly monitored? 5) and more Apparently it is now being required by regulators. Given that, can anyone point to code that will allow me to send email/texts now that Google and Yahoo are requiring two factor authentication? I used to send emails and texts when single factor was good enough. Frank
|
reqMktData callbacks are missing data with gateway 10.30 and 10.31 sporadically, works fine with 10.19 and older gateways/TWS
28
Dear Twsapi experts, Since 10.30 gateway/tws looks like reqMktData cannot be relied upon and I am often not getting the data I am asking for. And I am talking about basic bid/ask/last etc data for popular contracts with high volume of trading on Nasdaq/NYSE (like MSFT, GOOG etc) nothing exotic. It happens so often that it makes it impossible to use reqMktData in practice (up to 10% call failure rate). Yet I've been using reqMktData for 5+ years both in test and live trading, it was pretty reliable for me, no complains so far (it was slow, sure, but reliable :) ). Moreover for gateway/tws 10.19 it works as expected still today just 10.30+ drops data. Making me believe that something got broken in 10.30 and newer software. The issue, as I will describe below seems to be related to resource usage/management of 10.30+ software, which makes me wonder what else tws is dropping once it gets somehow pushed. I could imagine that IB is loosing some data here which used to be perfect/fine it might as well drop other api call/callback (like drooping sending an order or dropping some order status data would be really bad). Thus making it more urgent to fix it. I of course reported the issue to IB with logs clearly showing that the gateway didn't provide the data it was asked. Moreover, I shipped them this test app which I will share below which (for me) 100% repeats the issue. And IB went silent for 10+ days. I have no idea atm if they confirm the issue and busy fixing or it just ended up at the bottom of the backlog. Thus really appreciate the help of the community here. Maybe I am not alone experiencing this issue. My ask for community is to run the test app provided (I did one in python and one in java. both languages experience the issue more strongly pointing towards IB software issue) if more can repeat the issue (and there is no issues in the my test code :) ) maybe it will help IB to rise the urgency for fixing the issue. I am using IBAPI 1030.01. It works for connecting to any gateway/TWS versions. I have not tested it with other IBAPI SDK version. in this api there is folder \samples\Python\Testbed extract provided python.zip in that folder (details for Java are later). Then, run Program_get_bid.py -f symbols.csv -m REALTIME --data-lines 75 --loops 5 --port 4001 this will read symbols (about 1200 stocks from big, liquid companies on Nasdaq/NYSE), connect to your gateway (maybe you use a different port). will ask for REALTIME data (if you don't have subscription to US stocks + realtime addon, FROZEN, DELAYED seem to be experience the same issue). Test also will make sure that we don't ask for more that 75 contract simultaneously and run this operation 5 loops The trick with this bug is that it is doesn't happen for a specific contract or specific order of API calls. In my experience it happens "randomly" after the gateway was used for some time. So this test app asks for data using self.reqMktData(self.nextValidOrderId, contract, "", False, False, []) and monitors callbacks if it receives the following data ["bid", "ask", "last", "volume", "last_timestamp", "high", "low"]. it waits for 20 seconds for this data to appear and if doesn't appear (this is the bug I am talking about) it declares this call as failed and prints out as TIMEOUT. Some runs will experience more issues than others. Some will have zero issues. The important bit that in my setup 5 loops of 1200 contracts always causes some failures if connected 10.30+ gateway/TWS and zero issues on 10.19. It is true for both Linux and Windows. A fragment of output All failed symbols are printed during the run and summarized with info received at the end. Also reqId is printed, so one can go into gateway log and search for this ID. All the searches I did in the gateway's log it was clear that gateway really didn't send the info the app is missing (i.e. it is not the test app which missed it somehow but the gateway didn't even send it) Notes Program_get_bid.py is based on Program.py. One can easily compare the differences to the "official" sample. It is really minimal differ
|
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
|
reqIds hangs when recereating IBClient - EWrapper
2
I have IBClient that implements EWrapper that I copied from C# samples from official TWS repository. When some event happens, I would like to destroy existing client and create new instance. This is the method I use to create this client. void Create() { var signal = new EReaderMonitorSignal(); _client = new IBClient(signal); _client.ClientSocket.SetConnectOptions("+PACEAPI"); _client.ClientSocket.eConnect(Host, Port, 0); var reader = new EReader(_client.ClientSocket, signal); var process = new Thread(() => { while (_client.ClientSocket.IsConnected()) { signal.waitForSignal(); reader.processMsgs(); } }); process.Start(); reader.Start(); } After that, I'm waiting for the next valid ID. async Task Register() { var source = new TaskCompletionSource(); void subscribe(int o) { _client.NextValidId -= subscribe; source.TrySetResult(); } _client.NextValidId += subscribe; _client.ClientSocket.reqIds(-1); await source.Task; } Then use method to destroy client. void Destroy() { _client?.ClientSocket?.eDisconnect(); } The first time everything works fine. When I try to call these 3 methods next time, "reqIds" hangs and I never receive response for "NextValidId". Is it some known limitation that only one client can connect to TWS only once or am I missing something?
|
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?
|
1 - 20 з 12923