erdewit / ib_insync

Python sync/async framework for Interactive Brokers API
BSD 2-Clause "Simplified" License
2.85k stars 772 forks source link

Handling disconnection with reqHistoricalData(keepUpToDate=True) stream #699

Open kkotsche1 opened 8 months ago

kkotsche1 commented 8 months ago

I have been attempting to solve this issue for quite a while now, to no avail unfortunately. Maybe I can find some pointers/insights here as I am close to giving up on this.

I am using the keepUpToDate flag to run my trading logic where I am checking for certain conditions on each new bar received.

I have been attempting to deal with the case where Interactive Brokers loses connection (which happens every now and then, regardless of my internet connections stability), leading to interruption of the bar stream and subsequent death of my programs ability to do anything. However, I am unable to figure out any way in which I can get this thing spun back up after a loss of connection to restart the stream and continue on with the trading logic.

Is there a best practice way to handle this?

I am able to re-establish a connection, but the data stream doesn't continue. I am currently running my trading logic in a seperate function which I tag on to the updateEvent associated with the reqHistoricalData

I have previously tried to handle/solve this using the ib.errorEvent. However, I have been unable to get my reqHistoricalData stream back up and running after reconnection

jlixfeld commented 8 months ago

I don't use keepUpToDate so I don't know if this question has an obvious answers, but as you are able to re-establish a connection, are you able to just run reqHistoricalData again?

FWIW there is reqRealTimeBars. Or, maybe you could just run reqHistoricalData in a loop at some interval instead of KeepUpToDate?