开云体育

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

Re: Best practice for cancelmktdata


 

I think JG is correct. You are likely bumping at the 50 requests/sec API limit when you cancel 300 market data feeds.

Traditionally, TWS/IBGW did reject requests at rates of more them 50/sec with an error callback. But there was always the "PACEAPI" connection option that, when specified during your connection requests, would instruct TWS.IBGW to perform request throttling instead of rejecting requests. More recent TWS/IBGW versions now enable throttling by default and you'd have to use an API configuration field in TWS/IBGW to disable it.

I have been using TWS/IBGW throttling for years (first with the PACEAPI option and now just by default) and found it works very well. In the few occasions where I did exceed the 50 requests/sec limit, TWS/IBGW newer throttled below that rate and for short peaks allowed a few more than 50. So I think it is just fine to send requests without implementing any delays on your client side. And should IBKR increase the rate at some time in the future (they tend to relax limits over time), your clients would immediately take advantage of the higher rate.

Keep in mind, that the 50 requests/sec is the cumulative limit for all clients connected to TWS/IBGW at any point in time. To implement throttling on the client side, you'd have to coordinate all of your clients should there be more than one.

But coming back to your question. We don't know all of your requirements, but I can see a three basic approaches (assuming you indeed need to cancel all these feeds simultaneously):

  • You could continue with what you are doing now and simply ignore any data callbacks after you submitted the cancel request for a feed to hide the additional data from your application. But TWS API would be unable to accept additional requests for up to 300/50 = 6 seconds until all cancel requests have been satisfied. But that may be fine.
  • You could simply keep the subscriptions active all the time and never cancel them since there is no limit on the number of messages TWS/IBGW send to your client.
  • Or you could have two connections with TWS/IBGW.
    • One for general requests (such as order placement etc) that you keep established for the entire lifetime of your client
    • One for these temporary market data feeds that you establish when you start the subscriptions and disconnect (instead of calling cancel requests for all data feeds) when you are done with the market data. Closing the connection will cancel all outstanding data feeds. But there may be unintended consequences when closing the connection without cancelling the data feeds (there was a bug in TWS/IBGW in the past that made it important that feeds were cancelled before disconnect) and you'd have to experiment with that.

I assume you also experience a delay when you establish the 300 market data feeds, right? So it might take up to six seconds for the first market data callbacks for the last instrument on the list to arrive. So the best approach depends on the the balance of all of your requirements.

闯ü谤驳别苍

?
On Sun, Nov 24, 2024 at 01:21 AM, J G wrote:

It used to be the case that you can send a maximum of 50 messages per second via the API. So you would need to include some waiting time if you need to send more messages. However, latest versions of the API have a pacing function built-in. So it would not help if you include any waiting time when you send your messages. In my case: even though the pacing function is there, I still include some waiting time in case I send a batch of messages that is longer than 50 messages.

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