I always try to write code that is portable like using
boost instead of calling native APIs or in the case of algo trading using C# which runs on most operating systems with Mono. Lately, I’ve been having so many issues with Windows or hardware that I’ve decided to just move it all to Linux so I don’t have to worry about it not starting when the market is open.
My main issues with Windows:
- Random Windows updates or doing updates then it decides to reboot in the middle of the night.
- Hardware or driver issues causing system instablity that take forever to diagnose.
I use Linux and docker for almost everything now so it only makes sense to move it to containers. I created containers for TWS and IB Gateway a few months ago but never got around to actually setting it up with the algos.
This is what my old setup was like: (for futures, otherwise just start at 9:25 AM on weekdays)
- Start TWS at 12:50 AM on weekdays using Windows scheduler.
- Start TWS at 5:55 PM on Sunday.
- Start the algo application 5 minutes after TWS opens.
I replicated the same process under Linux using cron and containers. I just setup the cronjobs so do not rely on them working as they have not been tested, yet.
I do not use a service here because I want to control it with cron. If you decide to do this make sure the docker IP has been whitelisted inside TWS (
172.17.0.1 in my case).
You’d be surprised how responsive it is with VNC. Oh, and do not run this over the internet without some additional security like an SSH tunnel or a VPN.
I use a simple systemd service that does not auto restart on exit.
I decided to move TWS from cron to systemd services so it’s easier to restart things if needed. This has been tested more thoroughly.
I use TWS instead of IB Gateway because I want to be able to more easily monitor trades, and trades rarely occur during the IB restart times so it’s been fine so far.
I have been using this method of starting TWS and my algo app for a few weeks and it has been working perfectly. I never have to worry about it not starting at the appropriate time due to Windows.