If you trade with Interactive Brokers using a script or bot that goes through the API (Python, Java, C#…), you need a connection to IB that stays open all the time. That is what IB Gateway is for. Installing it on a VPS keeps everything running when your computer goes to sleep. Here is how to do it, and the pitfalls specific to IB.
IB Gateway or TWS?
Interactive Brokers offers two programs that give access to the API: Trader Workstation (TWS), the full platform with charts, and IB Gateway, a lighter version with no trading interface. For a bot running on its own, IB Gateway is the better fit: it uses fewer resources and stays more stable over time.
Windows or Linux?
IB Gateway runs on both. On a Windows VPS, you install and configure it as on your PC, from remote desktop: that is the simplest. On a Linux VPS, you need a virtual display (such as Xvfb) because the software has a login window; it is more technical, but lighter.
API ports
Your script connects to IB Gateway on a local port. By default: 4001 for a live account and 4002 for a paper account (with TWS, they are 7496 and 7497). In the API settings, enable ActiveX and socket clients, and leave "Trusted IPs" on 127.0.0.1 if your script runs on the same VPS.
Daily restart and weekly authentication
This is the Interactive Brokers quirk. IB Gateway closes or restarts once a day: in the settings, choose automatic restart rather than exit, at a time when your strategy is not trading. IB also asks you to re-authenticate regularly, at least once a week, with two-factor authentication. Plan that moment into your routine.
To automate login and restarts, many users rely on IBC, a dedicated open-source tool. It does not replace two-factor approval when IB asks for it.
Securing the VPS
- Never expose the API port to the Internet: your script should connect locally, or through a VPN.
- Protect access to the VPS: strong password, and on Windows a restricted remote desktop access.
- Keep Windows and IB Gateway up to date, outside your trading hours.
Which VPS for IB Gateway?
IB Gateway alone needs little: 2 to 4 GB of memory is usually enough, more if your script loads a lot of data or you run several connections. Stability and network proximity matter more than raw power. Our VPS are in Paris, at Equinix PAR6, with Anti-DDoS included, and come with no commitment.










