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

Restart command (without requiring 2FA) from Linux #198

Closed leebailey88 closed 1 year ago

leebailey88 commented 1 year ago

Hi,

Thanks for making such an awesome software. I've run into several problems since December when IB decided to randomly start forcing all accounts to use 2FA for trading. I trade futures 23/5, and I sleep and go on holiday frequently when I either don't have access to my phone or don't have service to perform the 2FA. Even in the best case scenario, the 2FA is required once per week which means my bots are down when I'm not around which costs me money.

However, the best case is far from the realistic case that I've experienced over the past few months since the unfortunate decision from IB was made. IB Gateway is a poorly built and unstable piece of software. It frequently has problems such as:

I've been running my bots for 3+ years and before the 2FA requirement, this was no problem, as when I detected these problems in my scripts, I simply restarted the entire Docker container that hosts IB Gateway and the problems would go away. Now I obviously can't do that or else I would not be able to re-launch since I may not be able to respond to the 2FA.

The daily auto-restarts have helped some, and I've counted exactly one week since the 2FA decision when the Gateway has been stable enough to only require 2FA during the intended once per week on Sunday use case. On average, I've found I need to restart the Docker container every 2 days which has led to downtime because it's often when I'm asleep.

I see that in the latest version of IBC, you added a RESTART command and some .bat scripts to trigger it, which as far as my understanding goes, updates the auto-restart time to be within the next couple of minutes so that when you detect a problem, you can restart the IB Gateway (without restarting the surrounding Docker container) and this sort of restart should not require 2FA. I'm hoping this solution could answer some more of my problems so that I can try for this softer restart rather than Docker restart when I detect IB Gateway problems and hopefully lead to less downtime.

However, I use Ubuntu. Are you planning to add versions of SEND_COMMAND.bat and RESTART.bat in .sh files for linux users?

Thanks! Lee

rlktradewright commented 1 year ago

I haven’t provided a script for Linux because it’s easy to script telnet on Linux, as it reads input from stdin. This is not the case for Windows, hence the klunky mix of batch and vbs.

For example on Linux:

(echo restart; sleep 1; echo "quit" ) | telnet 10.252.0.7 7462

In this example, 10.252.0.7 is the IP address of my server that runs TWS/Gateway, and 7462 is the port for the IBC command server configured in config.ini.

I probably ought to add something about this to the User Guide.

Note that you might need to add a rule to any firewall that's in the network path to the host machine, to allow the relevant port number in.

leebailey88 commented 1 year ago

thank you so much! I have confirmed this is working perfectly in 3.16!