medovarszki / ibkrfacade

Interactive Brokers API wrapper and trading toolbox
22 stars 9 forks source link

How to re-establish market data subscriptions after connection to TWS/Gateway lost #10

Open clisztian opened 1 month ago

clisztian commented 1 month ago

I guess this is more of a general question in the direction of the API itself, but suppose that the TWS /Gateway connection is lost (internet outage, TWS crash, whatever), and by some automatic means the TWS is restarted and reinstated. How does one go about regaining the market subscription after reconnect? The obvious approach of clientSocket.eConnect(....) and then calling after successful connection (clientSocket.isConnected() is true) clientSocket.reqRealTimeBars(...) with a new id does not work. Connection is successful, but it seems any api calls are inactive/dead. I also tried instantiating a new reader = new EReader(clientSocket..) but that does nothing either. Would you happen to have any insights on this? Thanks for you help!

medovarszki commented 1 month ago

Hi @clisztian! In cases like this, I would restart the whole application instead of handling the issue programmatically. The outage itself is an infrastructure issue, so I would handle it like that and create some kind of monitoring tool which restarts the service when the connection is reestablished.