
A docker image to run Interactive Brokers Gateway and TWS without any human interaction on a docker container
It includes:
10.26.1h10.19.2g-stable and 10.25.1o-latest or greater.live and paper trading mode.10.29.1e, stable 10.19.2m or greater)10.37.1l/10.39.1eImages are provided for [IB gateway][1] and [TWS][2]. With the following tags:
| Image | Channel | IB Gateway Version | IBC Version | Docker Tags |
|---|---|---|---|---|
| [ib-gateway][1] | latest |
10.51.1e |
3.24.2 |
latest 10.51 10.51.1e |
| [ib-gateway][1] | stable |
10.50.1f |
3.24.2 |
stable 10.50 10.50.1f |
| [tws-rdesktop][2] | latest |
10.51.1e |
3.24.2 |
latest 10.51 10.51.1e |
| [tws-rdesktop][2] | stable |
10.50.1f |
3.24.2 |
stable 10.50 10.50.1f |
All tags are available in the container repository for [ib-gateway][1] and [tws-rdesktop][2]. IB Gateway and TWS share the same version numbers and tags.
Create a docker-compose.yml file (or include ib-gateway services on your existing
one). The sample files provided can be used as starting point,
ib-gateway-compose and
tws-rdesktop-compose.
name: algo-trader
services:
ib-gateway:
restart: always
build:
context: ./stable
tags:
- "ghcr.io/gnzsnz/ib-gateway:stable"
image: ghcr.io/gnzsnz/ib-gateway:stable
environment:
TWS_USERID: ${TWS_USERID}
TWS_PASSWORD: ${TWS_PASSWORD}
TWS_PASSWORD_FILE: ${TWS_PASSWORD_FILE}
TRADING_MODE: ${TRADING_MODE:-paper}
TWS_SETTINGS_PATH: ${TWS_SETTINGS_PATH:-}
TWS_ACCEPT_INCOMING: ${TWS_ACCEPT_INCOMING:-}
TWS_MASTER_CLIENT_ID: ${TWS_MASTER_CLIENT_ID:-}
READ_ONLY_API: ${READ_ONLY_API:-}
VNC_SERVER_PASSWORD: ${VNC_SERVER_PASSWORD:-}
TWOFA_TIMEOUT_ACTION: ${TWOFA_TIMEOUT_ACTION:-exit}
BYPASS_WARNING: ${BYPASS_WARNING:-}
AUTO_RESTART_TIME: ${AUTO_RESTART_TIME:-}
AUTO_LOGOFF_TIME: ${AUTO_LOGOFF_TIME:-}
TWS_COLD_RESTART: ${TWS_COLD_RESTART:-}
SAVE_TWS_SETTINGS: ${SAVE_TWS_SETTINGS:-}
RELOGIN_AFTER_TWOFA_TIMEOUT: ${RELOGIN_AFTER_TWOFA_TIMEOUT:-no}
TWOFA_EXIT_INTERVAL: ${TWOFA_EXIT_INTERVAL:-60}
TWOFA_DEVICE: ${TWOFA_DEVICE:-}
EXISTING_SESSION_DETECTED_ACTION: ${EXISTING_SESSION_DETECTED_ACTION:-primary}
ALLOW_BLIND_TRADING: ${ALLOW_BLIND_TRADING:-no}
TIME_ZONE: ${TIME_ZONE:-Etc/UTC}
TZ: ${TIME_ZONE:-Etc/UTC}
CUSTOM_CONFIG: ${CUSTOM_CONFIG:-NO}
JAVA_HEAP_SIZE: ${JAVA_HEAP_SIZE:-}
SSH_TUNNEL: ${SSH_TUNNEL:-}
SSH_OPTIONS: ${SSH_OPTIONS:-}
SSH_ALIVE_INTERVAL: ${SSH_ALIVE_INTERVAL:-}
SSH_ALIVE_COUNT: ${SSH_ALIVE_COUNT:-}
SSH_PASSPHRASE: ${SSH_PASSPHRASE:-}
SSH_REMOTE_PORT: ${SSH_REMOTE_PORT:-}
SSH_USER_TUNNEL: ${SSH_USER_TUNNEL:-}
SSH_RESTART: ${SSH_RESTART:-}
SSH_VNC_PORT: ${SSH_VNC_PORT:-}
START_SCRIPTS: ${START_SCRIPTS:-}
X_SCRIPTS: ${X_SCRIPTS:-}
IBC_SCRIPTS: ${IBC_SCRIPTS:-}
# volumes:
# - ${PWD}/jts.ini:/home/ibgateway/Jts/jts.ini
# - ${PWD}/config.ini:/home/ibgateway/ibc/config.ini
# - ${PWD}/tws_settings/:${TWS_SETTINGS_PATH:-/home/ibgateway/tws_settings}
# - ${PWD}/ssh/:/home/ibgateway/.ssh
# - ${PWD}/init-scripts:/home/ibgateway/init-scripts
ports:
- "127.0.0.1:4001:4003"
- "127.0.0.1:4002:4004"
- "127.0.0.1:5900:5900"
Create an .env on root directory. You can use the provided .env-dist as a starting point. Example .env file:
TWS_USERID=myTwsAccountName
TWS_PASSWORD=myTwsPassword
# see credentials section
#TWS_PASSWORD_FILE
#TWS_USERID_PAPER=
#TWS_PASSWORD_PAPER=
#TWS_PASSWORD_PAPER_FILE=
# ib-gateway
#TWS_SETTINGS_PATH=/home/ibgateway/tws_settings
# tws
#TWS_SETTINGS_PATH=/config/tws_settings
TWS_SETTINGS_PATH=
TWS_ACCEPT_INCOMING=
TRADING_MODE=paper
READ_ONLY_API=no
VNC_SERVER_PASSWORD=myVncPassword
TWOFA_TIMEOUT_ACTION=restart
TWOFA_DEVICE=
BYPASS_WARNING=
AUTO_RESTART_TIME=11:59 PM
AUTO_LOGOFF_TIME=
TWS_COLD_RESTART=
SAVE_TWS_SETTINGS=
RELOGIN_AFTER_TWOFA_TIMEOUT=yes
EXISTING_SESSION_DETECTED_ACTION=primary
ALLOW_BLIND_TRADING=no
TIME_ZONE=Europe/Zurich
CUSTOM_CONFIG=
SSH_TUNNEL=
SSH_OPTIONS=
SSH_ALIVE_INTERVAL=
SSH_ALIVE_COUNT=
SSH_PASSPHRASE=
SSH_REMOTE_PORT=
SSH_USER_TUNNEL=
SSH_RESTART=
SSH_VNC_PORT=
#START_SCRIPTS=init-scripts/start_scripts
#X_SCRIPTS=init-scripts/x_scripts
#IBC_SCRIPTS=init-scripts/ibc_scripts
Once docker-compose.yml and .env are in place you can start the container with:
docker compose up
To get a GUI you can use vnc for ib-gateway or RDP for TWS.
Looking for help? Please keep reading below, or go to discussion section for common problems and solutions. If you have problems please go through the troubleshooting guide
All environment variables are common between ibgateway and TWS image, unless specifically stated. The container can be configured with the following environment variables:
| Variable | Description | Default |
|---|---|---|
TWS_USERID |
The TWS username. | |
TWS_PASSWORD |
The TWS password. | |
TWS_PASSWORD_FILE |
The file containing TWS password. See credentials section. | |
TRADING_MODE |
live or paper. From 10.26.1k it supports both which will start ib-gateway or TWS in live AND paper mode in parallel within the container. |
paper |
TWS_USERID_PAPER |
If TRADING_MODE=both, then this is required to pass paper account user |
not defined |
TWS_PASSWORD_PAPER |
If TRADING_MODE=both, then this is required to pass paper account password |
not defined |
TWS_PASSWORD_PAPER_FILE |
If TRADING_MODE=both, then this is required to pass paper account password. See credentials section. |
not defined |
READ_ONLY_API |
yes or no. See IBC documentation | not defined |
VNC_SERVER_PASSWORD |
VNC server password. If not defined, then VNC server will NOT start. Specific to ibgateway, ignored by TWS. See credentials section. | not defined (VNC disabled) |
VNC_SERVER_PASSWORD_FILE |
VNC server password. If not defined, then VNC server will NOT start. Specific to ibgateway, ignored by TWS. | not defined (VNC disabled) |
TWOFA_TIMEOUT_ACTION |
'exit' or 'restart', set to 'restart if you set AUTO_RESTART_TIME. See IBC documentation |
exit |
TWOFA_DEVICE |
second factor authentication device. See IBC documentation | not defined |
TWOFA_EXIT_INTERVAL |
It controls how long (in seconds) IBC waits for login to complete after the user acknowledges the second factor authentication. See IBC documentation | 60 seconds |
BYPASS_WARNING |
Settings relate to the corresponding 'Precautions' checkboxes in the API section of the Global Configuration dialog. Accepted values yes, no if not set, the existing TWS/Gateway configuration is unchanged |
not defined |
AUTO_RESTART_TIME |
time to restart IB Gateway, does not require daily 2FA validation. format hh:mm AM/PM. See IBC documentation | not defined |
AUTO_LOGOFF_TIME |
Auto-Logoff: at a specified time, TWS shuts down tidily, without restarting | not defined |
TWS_COLD_RESTART |
IBC > |
| 日期 | 榜单 | 排名 | 周期新增 | 总 STAR |
|---|