
The Interactive Brokers IB Gateway is a powerful trading platform that allows users to access a wide range of markets and instruments. It's a must-have for serious traders and investors.
The IB Gateway is a downloadable application that can be installed on your computer, allowing you to trade on the Interactive Brokers platform with a high level of precision and control. It's free to download and use, with no hidden fees or charges.
With the IB Gateway, you can access a vast array of markets, including stocks, options, futures, forex, and more. You can also use the platform to manage your account, view real-time market data, and place trades with ease.
You might enjoy: Moneybookers Payment Gateway
Installation
To install the IB Gateway, you'll need to download the installation files. These files are stored on the project's GitHub releases, not directly from the IB homepage.
The project's Dockerfile doesn't download the files from the IB homepage because IB only provides download links for the latest or stable version, and doesn't offer an archive of older versions.
You can specify a particular Gateway version by using the IB_GATEWAY_VERSION variable in the installation command. For example, you can use the command "RUN curl -sSL https://download2.interactivebrokers.com/installers/ibgateway/stable-standalone/ibgateway-stable-standalone-linux-x64.sh --output ibgateway-${IB_GATEWAY_VERSION}-standalone-linux-x64.sh" to download the current stable version from the IB homepage.
Consider reading: Sumup Payment Gateway
Installation Instructions
To start the installation, click the "Run" button to initiate the download of the IB Gateway.
You'll need to use the Setup Wizard to complete the installation. This is a straightforward process that will guide you through the necessary steps.
The installation will add an API icon to your desktop once it's complete. You can find this icon and access the API settings from there.
For Linux users, the installation process is a bit more involved. You'll need to install desktop services and a VNC server to enable remote desktop access.
You can use xfce and TightVNC as examples, and execute the following commands in the terminal to install:
Please set a highly secure password, as the maximum length for the password during installation is 8 characters.
The default startup port for the first session is 5901. You can log in by entering the password at the default address, vnc://IP Address:5901.
For another approach, see: What Stock Broker Should I Use

To download the IB Gateway, visit the download page at https://www.interactivebrokers.com/en/trading/ibgateway-stable.php. You can use a tool similar to wget for downloading, or download a VNC client for Windows.
Once you're logged in, you can manually run the installation directory directly by running ./ibgateway. After installation, log in and find the API option to configure the exchange correctly.
Installation Files
The IB Gateway installation files are downloaded from the project's github-releases rather than the IB homepage.
This is because the project allows for rebuilding the image with a specific Gateway version, but IB only provides download links for the latest or stable version.
The installer files stored on releases have been downloaded from the IB homepage and renamed to reflect the version.
For example, you can change the RUN command to use the current stable version from the IB homepage by modifying the line to ibgateway-${IB_GATEWAY_VERSION}-standalone-linux-x64.sh.
Broaden your view: Xfi Gateway Offline
Configuration
The IB Gateway offers several configuration options to suit different needs. The default setup is available to localhost, making it suitable for testing purposes.
You can also configure the IB Gateway to be available to the host network, but this is not recommended due to security concerns. This setup exposes the API ports to the host network, which can be a risk if not handled properly.
The most secure configuration option is to make the IB Gateway available to other services in the same Docker network. This can be achieved by uncommenting the port mappings in the docker-compose.yml file. For example, you can uncomment the lines that map port 4001 to 4003, port 4002 to 4004, and port 5900 to 5900.
Here are the main configuration options:
- Available to localhost (suitable for testing)
- Available to the host network (not recommended)
- Available for other services in the same Docker network (secure setup)
- SSH Tunnel (secure option if utilized correctly)
Core API Port Configurations
Core API Port Configurations are crucial for accessing your IB Gateway. The default setup provided in docker-compose.yml makes the API port available to localhost, suitable for testing, but doesn't expose it to the host network.
There are four possible IB API port configurations to consider. You can expose the API port to the host network, but this is an unsecure configuration suitable for short tests in a secure network. It's not recommended.

Alternatively, you can make the API port available for other services in the same docker network. This is a secure setup, but the host should still be trusted. Services with access to the trader network can access the IB Gateway through the hostname ib-gateway.
Here are the key port configurations to keep in mind:
The TWS image uses different port configurations, including ports 7498 and 7499 for live and paper accounts, respectively. Port 3389 is used for the RDP server.
What Is It?
This configuration is a Docker image that runs Interactive Brokers Gateway and TWS without any human interaction on a Docker container.
It includes several key components, such as IB Gateway, Trader Workstation TWS, and IBC, which simulates user input.
The image also includes Xvfb, a virtual framebuffer to run IB Gateway without graphics hardware, and x11vnc, a VNC server for interacting with the IB Gateway user interface.
Optional features include remote SSH tunnel support and secrets support, which are available in certain versions of the image.

Here are some of the key features of this configuration:
- IB Gateway (stable or latest)
- Trader Workstation TWS (stable or latest), from 10.26.1h
- IBC - to control TWS/IB Gateway
- Xvfb - a X11 virtual framebuffer
- x11vnc - a VNC server
- socat - to accept TCP connections from non-localhost
- Optional remote SSH tunnel
- Secrets support (latest 10.29.1e, stable 10.19.2m or greater)
This configuration can be used with other Docker images, such as Jupyter Quant, and supports parallel execution of live and paper trading mode.
Performance
Performance is crucial for a smooth experience with the Interactive Brokers IB Gateway. To optimize performance, it's essential to consider the recommended settings for TWS.
The recommended settings for TWS include setting /dev/dri:/dev/dri, which is a crucial step to ensure optimal performance.
To achieve this, you'll need to update the tws-docker-compose.yml file. Specifically, you'll want to add the following lines: set /dev/dri:/dev/drishm_size: "1gb"seccomp:unconfinedJAVA_HEAP_SIZE, depending your TWS you might need to increase it. See Increase Memory Size for TWSVolumes, set a volume for /tmp. ex tws_tmp:/tmpVolumes, set a volume for /config
Disabling xfce compositing during startup is also recommended, as it can have a significant impact on performance.
Using IB Gateway
IB Gateway is a free trading platform that allows you to connect to Interactive Brokers' servers. It's a great way to access your account and trade from the comfort of your own home.
You can download and install IB Gateway on your computer, and it's available for both Windows and Mac operating systems. The installation process is straightforward and shouldn't take more than a few minutes.
IB Gateway is a powerful platform that allows you to trade in over 100 markets worldwide, including stocks, options, futures, and forex.
Ports
Using the IB Gateway requires a good understanding of the ports it uses. The IB Gateway container and docker host have several ports available for usage.
The IB Gateway container exposes ports 4003, 4004, and 5900 for TWS API, paper accounts, and VNC server respectively. These ports are mapped to internal ports 4001, 4002, and 5900 through socat.
The TWS image uses ports 7498, 7499, and 3389 for TWS API, paper accounts, and RDP server respectively. These ports are mapped to internal ports 7496, 7497, and 3389 through socat.
Here's a summary of the available ports for the IB Gateway and TWS image:
It's worth noting that these ports are only exposed to the docker host by default, and not to the host network. To expose them to the host network, you'll need to modify the port mappings accordingly.
Using TWS

Using TWS in a container is now possible from version 10.26.1h. This allows you to run TWS in a more flexible and isolated environment.
The TWS-rdesktop image provides a desktop environment that enables you to use TWS in a container.
2 Answers
The IB Gateway lacks the GUI of the TWS, but provides the same API functionality.
It's essentially a stripped-down version of TWS, designed to use approximately 40% fewer system resources than TWS.
You can use the gateway if you don't need the full GUI of the TWS, making it ideal for developing or deploying applications.
The gateway will try to maintain a connection to IB for much longer than 24 hours, unlike TWS which requires a restart every 24 hours.
According to tech support, if you need to manually place orders, view charts, and work with the TWS, you should use TWS. If you only need the API, you can use the Gateway or the TWS.
For your interest: Why Use Mortgage Broker
Here are the key differences between the Gateway and TWS:
- Performance: Gateway uses 40% fewer system resources than TWS.
- Automatic logout: Gateway maintains a connection to IB for much longer than 24 hours.
- GUI: Gateway lacks the GUI of TWS.
- Restart requirement: TWS requires a restart every 24 hours, while Gateway can run indefinitely.
For all kinds of TWS API related questions, I suggest having a look at the IB TWS API Yahoo Group, and "Dmitry’s TWS API FAQ".
Docker
You can run ib-gateway-docker with a sidecar ssh bastion and a jupyter-quant, which provides a fully working algorithmic trading environment.
The ib-gateway-docker container does not run an SSH server, but rather creates a remote tunnel using the ssh client.
To set up an SSH tunnel, you can set SSH_TUNNEL to yes, which will start an SSH tunnel but not start socat.
You'll also need to pass SSH_USER_TUNNEL, which should be in the form user@server, and optionally SSH_PASSPHRASE, which will start ssh-agent and add ssh keys to agent.
Here's a minimal ssh tunnel setup:
- SSH_TUNNEL: set it to yes
- SSH_USER_TUNNEL: The user name that ssh should use, in the form user@server
- SSH_PASSPHRASE: Not mandatory, but strongly recommended, if set it will start ssh-agent and add ssh keys to agent
To pass ssh keys to the ib-gateway-docker container, you'll need to mount a volume and store the keys on /config/.ssh.
Frequently Asked Questions
What is the difference between TWS and IB gateway?
IB Gateway is a smaller, resource-efficient application focused on API functionality, unlike TWS which offers a GUI for account access. This key difference affects how you interact with your account and trade.
How do I set up IB Gateway?
To set up IB Gateway, open the ibg-.dmg file in your Downloads folder and follow the installation prompts. Click "Open" to confirm and start the installation process.
Sources
- https://www.interactivebrokers.com/en/trading/ibgateway-stable.php
- https://stackoverflow.com/questions/32778954/interactive-brokers-api-trader-workstation-tws-vs-ib-gateway
- https://medium.com/@FMZQuant/instructions-for-installing-interactive-brokers-ib-gateway-in-linux-bash-feca03350844
- https://github.com/gnzsnz/ib-gateway-docker
- https://datawookie.dev/blog/2022/04/setting-up-interactive-brokers-gateway/
Featured Images: pexels.com