开云体育

ctrl + shift + ? for shortcuts
© 2025 开云体育

Re: Best practice for cancelmktdata


 

开云体育

I think that given the large number of market data streams you have running, this might just be caused by your application not keeping up with the market data events. If you’re processing several hundred market data streams, you could easily be handling several thousand API callbacks per second at busy times

?

As API messages are read from the socket, they are placed in a queue. A separate thread (the reader thread) takes items off that queue, parses the message and calls the appropriate callback function, then proceeds to the next item. If the processing in the callbacks (which happens on the same reader thread) is such that new items are arriving on the queue faster than the reader thread and the callback function can process them, then the queue will just keep growing. So you could end up with potentially thousands of items on the queue wating to be processed. If you now cancel a ticker, the cancel message will be immediately sent to TWS and it won’t send you any more data for that ticker. But there may already be several, or tens, or hundreds of items for that ticker waiting in the queue, and they will just be processed when the reader thread gets to them, which could be long after the cancel was sent. This is because the cancelMktData method does nothing except send a cancel API message to TWS: it doesn’t attempt to remove any unprocessed messages for that ticker from the queue. This means that the API client program has to simply ignore any market data callbacks for a ticker after it has been cancelled.

?

It’s actually very easy to see this using IBKRs C# sample APP. If you start a number of very active market data streams, such as the ES, NQ, YM and DAX futures, and the major forex pairs (EUR.USD, GBP.USD, JPY.USD, etc) and add some market depth streams (ES, YM, NQ), and tick-by-tick etc, and make sure the busiest ones appear in the various grids, then run it at the US market open, the application will eventually get bogged down. Stop the tickers, and the data grid will continue to update for a while. DISCLAIMER: it’s a long time since I last did this, so it’s possible IBKR have enhanced the program to make it more efficient, but it certainly wasn’t originally written for efficiency (nor was the C# API itself, but that has certainly been improved enormously over the years.)

?

Perhaps you could give a summary of what processing you do for each tick?

?

Richard

?

?

?

From: [email protected] <[email protected]> On Behalf Of H Liu via groups.io
Sent: 24 November 2024 19:01
To: [email protected]
Subject: Re: [TWS API] Best practice for cancelmktdata

?

interesting, In my case I need the cancelmktdata in case I run to Error 300, too many instruments subscribed. My experience is that in lag between cancelmktdata and IBKR cancelling the mktdata is that IBKR PACE doesn't actually cancel the first request, for example if I sent ticker ID 1-300 to be cancelled, I could sometimes get ticker id 245 cancelled before ticker 45,? (I continue getting ticker id 45 callbacks a long time before ticker 245, (which i confirm is cancelled by getting error Can't find EId) has anyone else had this?

Join [email protected] to automatically receive all group messages.