The approach you describe sounds reasonable and seems to have worked for you for a while. But there are a few details that come to mind that make the process more robust and tolerant of changes by IBKR. Not sure whether any of these fix your problem, but I am sure they will prevent issues in the future.
We have a data monitor that subscribes to all available reqMktData ticks for about 80 instruments plus 15 TickByTick streams (TickByTickLast, TickByTickBidAsk, and TickByTickMid each for five instruments) plus three Level II market book streams and is rock stable.
During startup, we use to retrieve a contract object for each instrument instead of making our own contract objects. This way you get the most up-to-date instrument details and a contract object that has all fields initialized. You also get the trading hours for the next few days including short-notice changes caused by holidays or issues at the exchange. And any contract related errors (such as de-listed instruments, exchange changes, expired futures contracts, ...) are flagged well before you subscribe to market data.
The loop that runs the reqMktData subscription calls needs to make sure that it does not cause API pacing violations (more than 50 requests per second). Pacing violations will cause disconnects by TWS/IBGW.
For TWS/IBGW versions before V10 you have two options:
- Manage appropriate delays between back-to-back reqMktData calls
- Set the "+PACEAPI" connection option so that TWS/IBGW handle pacing for you
TWS/IBGW V10 have "+PACEAPI" enabled by default so this is less of an issue, but make sure the API global configuration "Reject messages above maximum allowed message rate" in TWS/IBGW is not selected.
And finally, make sure you catch all error callbacks and, at a minimum, log them to aid in troubleshooting. Errors our monitor has encountered while subscribing to the various market data streams include:
- 309??? Max number (3) of market depth requests has been reached
- 321??? Error validating request.-'bX' : cause - Incorrect generic tick list ...
- 354??? Requested market data is not subscribed.Delayed market data is available.
- 2117??? Requested top market data is not subscribed.
- 10090??? Part of requested market data is not subscribed. Subscription-independent ticks are still active.
- 10168??? Requested market data is not subscribed. Delayed market data is not enabled
- 10189??? Failed to request tick-by-tick data:No market data permissions for ...
- 10190??? Max number of tick-by-tick requests has been reached
- 10197??? No market data during competing live session
- 10225??? Bust event occurred, current subscription is deactivated. Please resubscribe real-time bars immediately.
There is a lot that can change without notice or go wrong.
Hope this helps,
´³¨¹°ù²µ±ð²Ô