IbcAlpha / IBC

Automation of Interactive Brokers TWS. You can download the latest release here: https://github.com/ibcalpha/ibc/releases/latest
GNU General Public License v3.0
1.02k stars 178 forks source link

Adding Watchdog (Porting Watchdog from ib_insync) #56

Closed bantu closed 4 years ago

bantu commented 5 years ago

I propose adding functionality similar or exacly like the Watchdog from ib_insync:

The idea is to wait until there is no traffic coming from the app for a certain amount of time (the appTimeout parameter). This triggers a historical request to be placed just to see if the app is still alive and well. If yes, then continue, if no then restart the whole app and reconnect. Restarting will also occur directly on error 1100.

https://github.com/erdewit/ib_insync/blob/master/ib_insync/ibcontroller.py#L327-L331

The problems addressed by ib_insync's watchdog apply to TWS/IBG in general and are not limited to the Python API. As such I'd argue that the functionality better fits IBC rather than ib_insync.

We have little hope that the software quality of TWS/IBG is going to improve to a level at which it is acceptably usable for API projects on its own. As of this writing, we are seeing one major connectivity issue (TWS unable to obtain data from IB including NLV) using TWS (v976.2k) and another (potentially https://groups.io/g/twsapi/topic/8151520?p=Created,,,20,2,0,0) using IBG (v976.2k). To work around these issues, a watchdog would be very useful.

rlktradewright commented 5 years ago

I think perhaps you are misunderstanding how IBC works. It is NOT the case that IBC is a separate process controlling TWS/Gateway. IBC loads TWS/Gateway into the very same process (which is the only way that it can make use of the UI hooks provided by Java, on which it depends).

So when TWS or Gateway dies, IBC goes with it. Therefore there is no way IBC can 'restart' TWS/Gateway.

In any case, I entirely disagree that IBC would be the right place to build this functionality. By all means if people want some kind of watchdog, they can certainly use IBC as a component within that: run it to start TWS/Gateway, and send it a STOP command to terminate it. But that is a completely separate project from IBC.

Personally I see no need for such functionality. Contrary to your assertion, my systems run all day every trading day, in general without problems. I run four data collection programs on two different systems (starting on Sunday evening and closing on Friday evening), an autotrading system that runs from 06:50 to 17:30 GMT (trading the FTSE futures on the paper-trading account), and various other client programs as required. Yes there are occasional problems with TWS/Gateway, but they are rare and it's never clear to me that the kind of monitoring and restarting you're suggesting would be helpful.

In particular, I see absolutely no reason to restart TWS/Gateway on receiving an 1100: I find the 1100, 1101 and 1102 sequence to be entirely robust.

But maybe I've just been lucky since I ran my first autotrading system starting in October 2003...

bantu commented 5 years ago

In any case, I entirely disagree that IBC would be the right place to build this functionality. By all means if people want some kind of watchdog, they can certainly use IBC as a component within that: run it to start TWS/Gateway, and send it a STOP command to terminate it. But that is a completely separate project from IBC.

All right. We will make this an extra project then.

Personally I see no need for such functionality. Contrary to your assertion, my systems run all day every trading day, in general without problems. I run four data collection programs on two different systems (starting on Sunday evening and closing on Friday evening), an autotrading system that runs from 06:50 to 17:30 GMT (trading the FTSE futures on the paper-trading account), and various other client programs as required. Yes there are occasional problems with TWS/Gateway, but they are rare and it's never clear to me that the kind of monitoring and restarting you're suggesting would be helpful.

Out of curiosity, which platform and TWS/IBG versions are you using?

rlktradewright commented 5 years ago

I'm currently using TWS 972 for the live account, and TWS or Gateway 976 for the paper account. (As a matter of policy I always use the stable version for live. I chop and change quite a bit with the paper account as I have to try to ensure IBC works with all current versions.)

The platform I use is my own, which I have developed over the past 16 years. You can find it on Github here: https://github.com/rlktradewright/tradebuild-platform. If you have any queries about it, it would be best to raise them there, or email me directly.

rlktradewright commented 5 years ago

Having mentioned my platform above, I realised today that the latest release (2.7.232) was published with incorrect release files - they were for a different project. The correct files have now been included.