Skip to content

Commit 63fca7f

Browse files
committed
Signed-off-by: gnzsnz <[email protected]>
1 parent 03b2b03 commit 63fca7f

File tree

14 files changed

+137
-43
lines changed

14 files changed

+137
-43
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/.env
22
tws_settings/
33
ssh/
4-
config/
4+
/config/
55
.python-version

Dockerfile.tws.template

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,9 @@ ARG DEBIAN_FRONTEND=noninteractive
3434
RUN \
3535
apt-get update -y && \
3636
apt-get install --no-install-recommends --yes socat sshpass gettext-base \
37-
libnspr4 libnss3 libasound2 libatk-bridge2.0-0 libatk1.0-0 libatspi2.0-0 \
38-
libc6 libcairo2 libcrypto++8 libcups2 libdbus-1-3 libdrm2 libexpat1 \
39-
libfontconfig1 libgbm1 libgcc-s1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 \
40-
libpango-1.0-0 libpulse0 libx11-6 libxcb1 libxcomposite1 libxdamage1 \
41-
libxext6 libxfixes3 libxkbcommon0 libxrandr2 libxshmfence1 libxtst6 \
42-
xdg-utils && \
37+
libnspr4 libnss3 libcrypto++8 xdg-utils xfce4-cpugraph-plugin \
38+
xfce4-netload-plugin xfce4-taskmanager xfce4-xkb-plugin xfce4-notes \
39+
gvfs gvfs-backends gvfs-fuse && \
4340
apt-get clean && \
4441
rm -rf /var/lib/apt/lists/* # end
4542

README.md

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,26 @@ It includes:
1414
- [x11vnc](https://wiki.archlinux.org/title/x11vnc) - a VNC server to interact with the IB Gateway user interface (optional, for development / maintenance purpose).
1515
- [socat](https://manpages.ubuntu.com/manpages/jammy/en/man1/socat.1.html) a tool to accept TCP connection from non-localhost and relay it to IB Gateway from localhost (IB Gateway restricts connections to container's 127.0.0.1 by default).
1616
- Optional remote [SSH tunnel](https://manpages.ubuntu.com/manpages/jammy/en/man1/ssh.1.html) to provide secure connections for both IB Gateway and VNC. Only available for `10.19.2g-stable` and `10.25.1o-latest` or greater.
17+
- As of `10.26.1h` it includes a **beta** container image with TWS and a minimal desktop environment(build on top of [linuxserver/rdesktop](https://github.com/linuxserver/docker-rdesktop/)). Available on github's [container repository](https://github.com/gnzsnz/ib-gateway-docker/pkgs/container/tws-rdesktop).
1718
- Works well together with [Jupyter Quant](https://github.com/gnzsnz/jupyter-quant) docker image.
1819

1920
## Supported Tags
2021

2122
| Channel | IB Gateway Version | IBC Version | Docker Tags |
2223
| -------- | ------------------ | ----------- | --------------------------- |
23-
| `latest` | `10.26.1g` | `3.18.0` | `latest` `10.26` `10.26.1g` |
24+
| `latest` | `10.26.1h` | `3.18.0` | `latest` `10.26` `10.26.1h` |
2425
| `stable` | `10.19.2g` | `3.18.0` | `stable` `10.19` `10.19.2g` |
2526

26-
All [tags](https://github.com/gnzsnz/ib-gateway-docker/pkgs/container/ib-gateway/) are available in the container repository.
27+
All [tags](https://github.com/gnzsnz/ib-gateway-docker/pkgs/container/ib-gateway/) are available in the container repository. IB Gateway and TWS share the same version numers and tags, TWS tags are available on it's [container repository](https://github.com/gnzsnz/ib-gateway-docker/pkgs/container/tws-rdesktop).
2728

28-
## How to use?
29+
## How to use it?
2930

3031
Create a `docker-compose.yml` (or include ib-gateway services on your existing one)
3132

3233
```yaml
3334
version: "3.4"
3435

36+
name: algo-trader
3537
services:
3638
ib-gateway:
3739
restart: always
@@ -48,10 +50,14 @@ services:
4850
READ_ONLY_API: ${READ_ONLY_API:-}
4951
VNC_SERVER_PASSWORD: ${VNC_SERVER_PASSWORD:-}
5052
TWOFA_TIMEOUT_ACTION: ${TWOFA_TIMEOUT_ACTION:-exit}
53+
BYPASS_WARNING: ${BYPASS_WARNING:-}
5154
AUTO_RESTART_TIME: ${AUTO_RESTART_TIME:-}
55+
AUTO_LOGOFF_TIME: ${AUTO_LOGOFF_TIME:-}
56+
SAVE_TWS_SETTINGS: ${SAVE_TWS_SETTINGS:-}
5257
RELOGIN_AFTER_TWOFA_TIMEOUT: ${RELOGIN_AFTER_TWOFA_TIMEOUT:-no}
5358
TWOFA_EXIT_INTERVAL: ${TWOFA_EXIT_INTERVAL:-60}
5459
TIME_ZONE: ${TIME_ZONE:-Etc/UTC}
60+
TZ: ${TIME_ZONE:-Etc/UTC}
5561
CUSTOM_CONFIG: ${CUSTOM_CONFIG:-NO}
5662
SSH_TUNNEL: ${SSH_TUNNEL:-}
5763
SSH_OPTIONS: ${SSH_OPTIONS:-}
@@ -74,42 +80,55 @@ services:
7480

7581
```
7682

77-
The image can be configured with the following environment variables:
83+
For TWS there is a sample compose file [available](https://github.com/gnzsnz/ib-gateway-docker/blob/master/tws-docker-compose.yml).
84+
85+
All environment variables are common between ibgateway and TWS image, unless specifically stated. The image can be configured with the following environment variables:
7886

7987
| Variable | Description | Default |
8088
| -------- | ----------- | -------- |
8189
| `TWS_USERID` | The TWS **username**. | |
8290
| `TWS_PASSWORD` | The TWS **password**. | |
8391
| `TRADING_MODE` | **live** or **paper** | **paper** |
8492
| `READ_ONLY_API` | **yes** or **no**. [See IBC documentation](https://github.com/IbcAlpha/IBC/blob/master/userguide.md) | **not defined** |
85-
| `VNC_SERVER_PASSWORD` | VNC server password. If not defined, then VNC server will NOT start. | **not defined** (VNC disabled)|
93+
| `VNC_SERVER_PASSWORD` | VNC server password. If not defined, then VNC server will NOT start. Specific to ibgateway, ignored by TWS. | **not defined** (VNC disabled)|
8694
| `TWOFA_TIMEOUT_ACTION` | 'exit' or 'restart', set to 'restart if you set `AUTO_RESTART_TIME`. See IBC [documentation](https://github.com/IbcAlpha/IBC/blob/master/userguide.md#second-factor-authentication) | 'exit' |
95+
| `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** |
8796
| `AUTO_RESTART_TIME` | time to restart IB Gateway, does not require daily 2FA validation. format hh:mm AM/PM. See IBC [documentation](https://github.com/IbcAlpha/IBC/blob/master/userguide.md#ibc-user-guide) | **not defined** |
97+
| `AUTO_LOGOFF_TIME` | Auto-Logoff: at a specified time, TWS shuts down tidily, without restarting | **not defined** |
98+
| `SAVE_TWS_SETTINGS` | automatically save its settings on a schedule of your choosing. You can specify one or more specific times, ex `SaveTwsSettingsAt=08:00 12:30 17:30` | **not defined** |
8899
| `RELOGIN_AFTER_2FA_TIMEOUT` | support relogin after timeout. See IBC [documentation](https://github.com/IbcAlpha/IBC/blob/master/userguide.md#second-factor-authentication) | 'no' |
89100
| `TIME_ZONE` | Support for timezone, see your TWS jts.ini file for [valid values](https://ibkrguides.com/tws/usersguidebook/configuretws/configgeneral.htm) on a [tz database](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones). This sets time zone for IB Gateway. If jts.ini exists it will not be set. if `TWS_SETTINGS_PATH` is set and stored in a volume, jts.ini will already exists so this will not be used. Examples `Europe/Paris`, `America/New_York`, `Asia/Tokyo`| "Etc/UTC" |
90101
| `TWS_SETTINGS_PATH` | Settings path used by IBC's parameter `--tws_settings_path`. Use with a volume to preserve settings in the volume. | |
91102
| `CUSTOM_CONFIG` | If set to `yes`, then `run.sh` will not generate config files using env variables. You should mount config files. Use with care and only if you know what you are doing. | NO |
92-
| `SSH_TUNNEL` | If set to `yes` then `socat` won't start and a remote ssh tunnel is started. SSH keys should be provided to container through ~/.ssh volume. | **not defined** |
103+
| `SSH_TUNNEL` | If set to `yes` then `socat` won't start, instead a remote ssh tunnel is started. SSH keys should be provided to container through ~/.ssh volume. | **not defined** |
93104
| `SSH_OPTIONS` | additional options for [ssh](https://manpages.ubuntu.com/manpages/jammy/en/man1/ssh.1.html) client | **not defined** |
94105
| `SSH_ALIVE_INTERVAL` | [ssh](https://manpages.ubuntu.com/manpages/jammy/en/man1/ssh.1.html) `ServerAliveInterval` setting. Don't set it in `SSH_OPTIONS` as this behavior is undefined. | 20 |
95106
| `SSH_ALIVE_COUNT` | [ssh](https://manpages.ubuntu.com/manpages/jammy/en/man1/ssh.1.html) `ServerAliveCountMax` setting. Don't set it in `SSH_OPTIONS` as this behavior is undefined. | 3 |
96107
| `SSH_PASSPHRASE` | passphrase for ssh keys. If set the container will start ssh-agent and add ssh keys | **not defined** |
97108
| `SSH_REMOTE_PORT` | Remote port for ssh tunnel. | Same port than IB gateway 4001/4002 |
98109
| `SSH_USER_TUNNEL` | `user@server` to connect to | **not defined** |
99110
| `SSH_RESTART` | Number of seconds to wait before restarting tunnel in case of disconnection. | 5 |
100-
| `SSH_VNC_PORT` | If set, then a remote ssh tunnel will be created with remote port equal to `SSH_VNC_PORT` | **not defined** |
111+
| `SSH_VNC_PORT` | If set, then a remote ssh tunnel will be created with remote port equal to `SSH_VNC_PORT`. Specific to ibgateway, ignored by TWS. | **not defined** |
112+
| `SSH_DRP_PORT` | If set, then a remote ssh tunnel will be created with remote port equal to `SSH_DRP_PORT`. Specific to TWS, ignored by ibgateway. | **not defined** |
113+
| `PUID` | User `uid` for user `abc` (linuxserver default user name). Specific to TWS, ignored by ibgateway. | 1000 |
114+
| `PGID` | User `gid` for user `abc` (linuxserver default user name). Specific to TWS, ignored by ibgateway. | 1000 |
115+
| `PASSWD` | Password for user `abc` (linuxserver default user name). Specific to TWS, ignored by ibgateway. | abc |
101116

102117
Create an .env on root directory. Example .env file:
103118

104-
```text
119+
```bash
105120
TWS_USERID=myTwsAccountName
106121
TWS_PASSWORD=myTwsPassword
122+
#TWS_SETTINGS_PATH=/home/ibgateway/Jts
107123
TWS_SETTINGS_PATH=
108124
TRADING_MODE=paper
109125
READ_ONLY_API=no
110126
VNC_SERVER_PASSWORD=myVncPassword
111127
TWOFA_TIMEOUT_ACTION=restart
128+
BYPASS_WARNING=
112129
AUTO_RESTART_TIME=11:59 PM
130+
AUTO_LOGOFF_TIME=
131+
SAVE_TWS_SETTINGS=
113132
RELOGIN_AFTER_2FA_TIMEOUT=yes
114133
TIME_ZONE=Europe/Lisbon
115134
CUSTOM_CONFIG=
@@ -138,6 +157,14 @@ After image is downloaded, container is started + 30s, the following ports will
138157
| 4004 | TWS API port for paper accounts. Through socat, internal TWS API port 4002. Mapped **externally** to 4002 in sample `docker-compose.yml`. |
139158
| 5900 | When `VNC_SERVER_PASSWORD` was defined, the VNC server port. |
140159

160+
TWS image uses the following ports
161+
162+
| Port | Description |
163+
| ---- | ---------------------------------- |
164+
| 7498 | TWS API port for live accounts. Through socat, internal TWS API port 4001. Mapped **externally** to 7497 in sample `tws-docker-compose.yml`. |
165+
| 7499 | TWS API port for paper accounts. Through socat, internal TWS API port 4002. Mapped **externally** to 7498 in sample `tws-docker-compose.yml`. |
166+
| 3389 | Port for RDP server. Mapped **externally** to 3370 in sample `tws-docker-compose.yml`. |
167+
141168
Utility [socat](https://manpages.ubuntu.com/manpages/jammy/en/man1/socat.1.html) is used to publish TWS API port from container's `127.0.0.1:4001/4002` to container's `0.0.0.0:4003/4004`, the sample `docker-file.yml` maps ports to the host back to `4001/4002`. This way any application can use the "standard" IB Gateway ports.
142169

143170
Note that with the above `docker-compose.yml`, ports are only exposed to the docker host (127.0.0.1), but not to the host network. To expose it to the host network change the port mappings on accordingly (remove the '127.0.0.1:'). **Attention**: See [Leaving localhost](#leaving-localhost)
@@ -146,14 +173,15 @@ Note that with the above `docker-compose.yml`, ports are only exposed to the doc
146173

147174
Most if not all of the settings needed to run IB Gateway in a container are available as environment variables.
148175

149-
However, if you need to go beyond what's available, the image can be customized by overwriting the default configuration files with custom ones. To do this you must set environment variable `CUSTOM_CONFIG=yes`. By setting `CUSTOM_CONFIG=yes` `run.sh` script will not replace environment variables on config files. You must provide config files ready to be used by IB gateway and IBC, please make sure that you are familiar with [IBC](https://github.com/IbcAlpha/IBC/blob/master/userguide.md) settings.
176+
However, if you need to go beyond what's available, the image can be customized by overwriting the default configuration files with custom ones. To do this you must set environment variable `CUSTOM_CONFIG=yes`. By setting `CUSTOM_CONFIG=yes` `run.sh` script will not replace environment variables on config files. You must provide config files ready to be used by IB gateway/TWS and IBC, please make sure that you are familiar with [IBC](https://github.com/IbcAlpha/IBC/blob/master/userguide.md) settings.
150177

151178
Image IB Gateway and IBC config file locations:
152179

153180
| App | Config file | Default |
154181
| ------- | -------------- | ---------------- |
155182
| IB Gateway | /home/ibgateway/Jts/jts.ini | [jts.ini](https://github.com/gnzsnz/ib-gateway-docker/blob/sshclient/image-files/config/ibc/config.ini.tmpl) |
156183
| IBC | /home/ibgateway/ibc/config.ini | [config.ini](https://github.com/gnzsnz/ib-gateway-docker/blob/sshclient/image-files/config/ibc/config.ini.tmpl) |
184+
| TWS | /opt/ibkr/jts.ini | [jts.ini](https://github.com/gnzsnz/ib-gateway-docker/blob/sshclient/image-files/config/ibc/config.ini.tmpl) |
157185

158186
Sample settings
159187

@@ -164,7 +192,8 @@ Sample settings
164192
...
165193
volumes:
166194
- ${PWD}/config.ini:/home/ibgateway/ibc/config.ini
167-
- ${PWD}/jts.ini:/home/ibgateway/Jts/jts.ini
195+
- ${PWD}/jts.ini:/home/ibgateway/Jts/jts.ini # for IB Gateway
196+
- ${PWD}/jts.ini:/opt/ibkr/jts.ini # for TWS
168197
...
169198
```
170199

@@ -175,10 +204,12 @@ You can preserve IB Gateway configuration by setting environment variable `$TWS_
175204
```yaml
176205
...
177206
environment:
178-
- TWS_SETTINGS_PATH: /home/ibgateway/tws_settings
207+
- TWS_SETTINGS_PATH: /home/ibgateway/tws_settings # IB Gateway
208+
- TWS_SETTINGS_PATH: /config/tws_settings # IB Gateway
179209
...
180210
volumes:
181-
- ${PWD}/tws_settings:/home/ibgateway/tws_settings
211+
- ${PWD}/tws_settings:/home/ibgateway/tws_settings # IB Gateway
212+
- ${PWD}/config:/config # for TWS we can use linuxserver /config volume
182213
...
183214

184215
```
@@ -288,10 +319,12 @@ to `ib-gateway-docker` container. This is achieved through a volume mount
288319
```yaml
289320
...
290321
volumes:
291-
- ${PWD}/ssh:/home/ibgateway/.ssh
322+
- ${PWD}/ssh:/home/ibgateway/.ssh # IB Gateway
292323
...
293324
```
294325

326+
TWS image will search ssh keys on `HOME` directory, so store keys on `/config/.ssh`
327+
295328
Make sure that:
296329

297330
- you copy ssh keys with a standard name, ex ~/.ssh/id_rsa, ~/.ssh/id_ecdsa,

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ services:
2626
TIME_ZONE: ${TIME_ZONE:-Etc/UTC}
2727
TZ: ${TIME_ZONE:-Etc/UTC}
2828
CUSTOM_CONFIG: ${CUSTOM_CONFIG:-NO}
29+
JAVA_HEAP_SIZE: ${JAVA_HEAP_SIZE:-}
2930
SSH_TUNNEL: ${SSH_TUNNEL:-}
3031
SSH_OPTIONS: ${SSH_OPTIONS:-}
3132
SSH_ALIVE_INTERVAL: ${SSH_ALIVE_INTERVAL:-}

image-files/scripts/common.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,14 @@ set_ports() {
116116
echo ".> SOCAT_PORT set to: ${SOCAT_PORT}"
117117

118118
}
119+
120+
set_java_heap() {
121+
if [ -n "${JAVA_HEAP_SIZE}" ]; then
122+
_vmpath="${TWS_PATH}/ibgateway/${IB_GATEWAY_VERSION}"
123+
_string="s/-Xmx768m/-Xmx${JAVA_HEAP_SIZE}m/g"
124+
sed -i "${_string}" "${_vmpath}/ibgateway.vmoptions"
125+
echo ".> Java heap size set to ${JAVA_HEAP_SIZE}m"
126+
else
127+
echo ".> Usign default Java heap size 768m."
128+
fi
129+
}

image-files/scripts/run.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ apply_settings
7474
# set API and socat ports
7575
set_ports
7676

77+
# Java heap size
78+
set_java_heap
79+
7780
# forward ports, socat or ssh
7881
"${SCRIPT_PATH}/port_forwarding.sh" &
7982

image-files/tws-scripts/run_tws.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ set_ports
4141
# apply settings
4242
apply_settings
4343

44+
# Java heap size
45+
set_java_heap
46+
4447
# forward ports, socat or ssh
4548
"${SCRIPT_PATH}/port_forwarding.sh" &
4649

latest/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
FROM ubuntu:22.04 as setup
99

10-
ENV IB_GATEWAY_VERSION=10.26.1g
10+
ENV IB_GATEWAY_VERSION=10.26.1h
1111
ENV IB_GATEWAY_RELEASE_CHANNEL=latest
1212
ENV IBC_VERSION=3.18.0
1313

@@ -48,7 +48,7 @@ COPY ./scripts /root/scripts
4848

4949
FROM ubuntu:22.04
5050

51-
ENV IB_GATEWAY_VERSION=10.26.1g
51+
ENV IB_GATEWAY_VERSION=10.26.1h
5252
# IB Gateway user constants
5353
ARG USER_ID="${USER_ID:-1000}"
5454
ARG USER_GID="${USER_GID:-1000}"

latest/Dockerfile.tws

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# This is a dedicated stage used as source for needed files.
55
#
66
##############################################################################
7-
ARG IB_VERSION=10.26.1g
7+
ARG IB_VERSION=10.26.1h
88
FROM ghcr.io/gnzsnz/ib-gateway:${IB_VERSION} as setup
99

1010
WORKDIR /
@@ -15,7 +15,7 @@ WORKDIR /
1515

1616
FROM lscr.io/linuxserver/rdesktop:ubuntu-xfce
1717

18-
ENV IB_GATEWAY_VERSION=10.26.1g
18+
ENV IB_GATEWAY_VERSION=10.26.1h
1919
ENV IB_GATEWAY_RELEASE_CHANNEL=latest
2020
ENV IBC_VERSION=3.18.0
2121

@@ -34,12 +34,9 @@ ARG DEBIAN_FRONTEND=noninteractive
3434
RUN \
3535
apt-get update -y && \
3636
apt-get install --no-install-recommends --yes socat sshpass gettext-base \
37-
libnspr4 libnss3 libasound2 libatk-bridge2.0-0 libatk1.0-0 libatspi2.0-0 \
38-
libc6 libcairo2 libcrypto++8 libcups2 libdbus-1-3 libdrm2 libexpat1 \
39-
libfontconfig1 libgbm1 libgcc-s1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 \
40-
libpango-1.0-0 libpulse0 libx11-6 libxcb1 libxcomposite1 libxdamage1 \
41-
libxext6 libxfixes3 libxkbcommon0 libxrandr2 libxshmfence1 libxtst6 \
42-
xdg-utils && \
37+
libnspr4 libnss3 libcrypto++8 xdg-utils xfce4-cpugraph-plugin \
38+
xfce4-netload-plugin xfce4-taskmanager xfce4-xkb-plugin xfce4-notes \
39+
gvfs gvfs-backends gvfs-fuse && \
4340
apt-get clean && \
4441
rm -rf /var/lib/apt/lists/* # end
4542

latest/scripts/common.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,14 @@ set_ports() {
116116
echo ".> SOCAT_PORT set to: ${SOCAT_PORT}"
117117

118118
}
119+
120+
set_java_heap() {
121+
if [ -n "${JAVA_HEAP_SIZE}" ]; then
122+
_vmpath="${TWS_PATH}/ibgateway/${IB_GATEWAY_VERSION}"
123+
_string="s/-Xmx768m/-Xmx${JAVA_HEAP_SIZE}m/g"
124+
sed -i "${_string}" "${_vmpath}/ibgateway.vmoptions"
125+
echo ".> Java heap size set to ${JAVA_HEAP_SIZE}m"
126+
else
127+
echo ".> Usign default Java heap size 768m."
128+
fi
129+
}

0 commit comments

Comments
 (0)