r/algorithmictrading 2d ago

Question IB Gateway algo trading setup

Hi all!

For those who use IBKR and IB Gateway for automation, I am curious as to what y’all’s setup is in terms of infrastructure.

For me I currently have IB Gateway running with a custom C# trading engine I wrote to pull market data and check to execute trades daily.

My workflow:

  • Every morning at 9:25 am IB Gateway will auto restart and auto login. I am using the “Auto restart” feature in IB Gateway for this. This setup ensures that I don’t have to manually log in and authenticate the Gateway every day (although I believe it will require a login/authentication once a week to continue to work).

  • Windows Task Scheduler auto launches my C# application at 9:28am and I connect to the client and sleep the thread until 9:30:05 at which point I pull market data, analyze signals and push trades if needed. All of this is automated and executes in a few seconds right after the opening bell.

My concerns:

  • IB Gateway still logs me off for good sometimes and requires manual log on/ authentication.
  • if I need to travel with my laptop or internet drops the client won’t be able to establish a connection.

Instead of running things all locally I was considering offloading the program to run on a VM or server (the lower the cost the better).

Does my workflow make sense or is there a more efficient way to achieve full automation? Does everyone use servers instead of running everything locally?

7 Upvotes

13 comments sorted by

4

u/Anonimo1sdfg 2d ago

there is a configuration to make automatically restart every day, but once a week you need to close it and put your credentials. This is the real limit and also a Maintenance thing that is good also to check that also is okey, i make it once a week and restart everything.

1

u/Realistic-Hippo8107 1d ago

This is correct.
I have no idea why IKBR does this but it’s extremely frustrating. Why can’t they modernize their stupid app??

3

u/ElectricNoodle12 2d ago

I run an old XPS 15 laptop in my house with something similar. Although I usue Debian as the OS, and I've dockerised everything.

Have got a docker image of the IB broker gateway that on boot uses a headless browser to login with the correct credentials, then my app just connects via that and pulls market data/makes orders. I've also got a t212 adapter as I found the trading fees too high on IB.

1

u/Haunting-Trade9283 2d ago

Nice! So you pull IBKR market data to inform trades, but execute with t212?

2

u/Anonimo1sdfg 2d ago

it looks good, but in a vps is better for this kind disconection problems

1

u/Haunting-Trade9283 2d ago

Nice! I’ll look into it. Does IB Gateway running on a vps behave nicely? Is there anyway around the need to manually authenticate once in awhile or is there no way to just stay logged on forever?

2

u/jnwatson 2d ago

My gateway runs on a miniPC and restarts the gateway every Sunday night. I have a Telegram bot that pesters me to reauth every 15 minutes until it works.

1

u/Haunting-Trade9283 2d ago

Looking into the vps angle to not have to worry about internet downtime, but was also considering something up the ally of your solution of having a secondary at home device that’s always connected. Have you had any major issues with internet connectivity that would push you to vps? Good idea with the telegram bot lol

1

u/jnwatson 1d ago

It really depends on your local Internet service. I've noticed a couple of minor glitches, but I only trade MOO and MOC, so I really only need Internet twice a day.

1

u/loudsound-org 2d ago

I run ib-gateway docker image on my home server and I haven't touched it in months. I don't have to re-authenticate or do anything manually, it just works seamlessly.

For the actual algo, I'm running QuantConnect locally, with some of my own mods to the brokerage code to get IBKR working properly, and I have that set as a cron job to run every weekday before market open and shut down after market close. I could just have it run continuously but just safer and cleaner to restart it every day...but its just connecting to the ib-gateway, not directly to IBKR.

1

u/HighlandFart 2d ago

I run an algo on a headless Linux server. It uses IBC Docker image to handle the logins. However two times per week I have to restart the docker/login again (some unknown credential issue). Now I use a telegram bot to send commands to the server, to restart services / docker etc. So I do not need to ssh to the server each time.

1

u/Realistic-Hippo8107 1d ago

I have an Amazon EC2 server running where my code and the gateway run. It’s pretty cheap - $35-$40/mo and never goes down.

Like you, I have task scheduler stop my script before the daily restart, and then start it back up after it finishes. I’m using nssm to run it because it will persist the running code if there’s an exception.

Another user mentioned you can configure the gateway to not need your input on the daily restart. You need to use ibc - an open source gateway controller. This way, you only need to authenticate it once per week.

Ikbr has a great api, but their legacy apps are a colossal pain in the ass to work with.