-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
FROM debian:bookworm-slim as downloader | ||
# IBC Version : https://github.com/IbcAlpha/IBC/releases | ||
ARG IBC_VER="###IBC_VER###" | ||
ARG IBC_ASSET_URL="###IBC_ASSET_URL###" | ||
|
||
# set environment variables | ||
ENV IBC_INI=/root/ibc/config.ini \ | ||
IBC_PATH=/opt/ibc | ||
|
||
# install dependencies | ||
RUN apt-get update \ | ||
&& apt-get upgrade -y \ | ||
&& apt-get install -y wget \ | ||
unzip | ||
# make dirs | ||
RUN mkdir -p /tmp | ||
|
||
# download IB TWS | ||
RUN wget -q -O /tmp/ibgw.sh https://download2.interactivebrokers.com/installers/ibgateway/stable-standalone/ibgateway-stable-standalone-linux-x64.sh | ||
RUN chmod +x /tmp/ibgw.sh | ||
|
||
# download IBC | ||
RUN wget -q -O /tmp/IBC.zip ${IBC_ASSET_URL} | ||
RUN unzip /tmp/IBC.zip -d ${IBC_PATH} | ||
RUN chmod +x ${IBC_PATH}/*.sh ${IBC_PATH}/*/*.sh | ||
|
||
# copy IBC/Jts configs | ||
COPY ibc/config.ini ${IBC_INI} | ||
|
||
FROM debian:bookworm-slim | ||
ARG IB_GATEWAY_MAJOR="###IB_GATEWAY_MAJOR###" | ||
ARG IB_GATEWAY_MINOR="###IB_GATEWAY_MINOR###" | ||
|
||
|
||
# install dependencies | ||
RUN apt-get update \ | ||
&& apt-get upgrade -y \ | ||
&& apt-get install -y \ | ||
xvfb \ | ||
libxtst6 \ | ||
libxrender1 \ | ||
net-tools \ | ||
x11-utils \ | ||
socat \ | ||
procps \ | ||
xterm | ||
RUN apt install -y openjdk-17-jre | ||
|
||
# set environment variables | ||
ENV TWS_INSTALL_LOG=/root/Jts/tws_install.log \ | ||
IBC_INI=/root/ibc/config.ini \ | ||
IBC_PATH=/opt/ibc \ | ||
TWS_PATH=/root/Jts \ | ||
TWOFA_TIMEOUT_ACTION=restart \ | ||
IB_GATEWAY_MAJOR=${IB_GATEWAY_MAJOR} \ | ||
IB_GATEWAY_MINOR=${IB_GATEWAY_MINOR} \ | ||
IB_GATEWAY_VERSION=${IB_GATEWAY_MAJOR}${IB_GATEWAY_MINOR} | ||
|
||
# make dirs | ||
RUN mkdir -p /tmp && mkdir -p ${IBC_PATH} && mkdir -p ${TWS_PATH} | ||
|
||
# download IB TWS | ||
COPY --from=downloader /tmp/ibgw.sh /tmp/ibgw.sh | ||
|
||
RUN /tmp/ibgw.sh -q -dir /root/Jts/ibgateway/${IB_GATEWAY_VERSION} | ||
# remove downloaded files | ||
RUN rm /tmp/ibgw.sh | ||
|
||
COPY --from=downloader /opt/ibc /opt/ibc | ||
COPY --from=downloader /root/ibc /root/ibc | ||
|
||
# install healthcheck tool | ||
ADD healthcheck/healthcheck/build/distributions/healthcheck.tar / | ||
ENV PATH="${PATH}:/healthcheck/bin" | ||
|
||
ADD healthcheck/healthcheck-rest/build/distributions/healthcheck-rest-boot.tar / | ||
ENV PATH="${PATH}:/healthcheck-rest-boot/bin" | ||
|
||
# copy cmd script | ||
WORKDIR /root | ||
COPY start.sh /root/start.sh | ||
RUN chmod +x /root/start.sh | ||
|
||
# set display environment variable (must be set after TWS installation) | ||
ENV DISPLAY=:0 | ||
|
||
ENV IBGW_PORT 4002 | ||
ENV JAVA_HEAP_SIZE 768 | ||
|
||
EXPOSE $IBGW_PORT | ||
|
||
ENTRYPOINT [ "sh", "/root/start.sh" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# IB Gateway docker | ||
|
||
 | ||
[](https://hub.docker.com/r/manhinhang/ib-gateway-docker) | ||
[](https://github.com/manhinhang/ib-gateway-docker/blob/develop/LICENSE) | ||
|
||
lightweight interactive brokers gateway docker | ||
|
||
It's just pure `IB Gateway` and don't include any VNC service (for security reason, I don't like expose extra port) | ||
|
||
This docker image just installed: | ||
|
||
- [IB Gateway](https://www.interactivebrokers.com/en/index.php?f=16457) (###IB_GATEWAY_VER###) | ||
|
||
- [IBC](https://github.com/IbcAlpha/IBC) (###IBC_VER###) | ||
|
||
## Pull the Docker image from Docker Hub | ||
|
||
```bash | ||
docker pull manhinhang/ib-gateway-docker | ||
``` | ||
|
||
### Create a container from the image and run it | ||
```bash | ||
docker run -d \ | ||
--env IB_ACCOUNT= \ #YOUR_USER_ID | ||
--env IB_PASSWORD= \ #YOUR_PASSWORD | ||
--env TRADING_MODE= \ #paper or live | ||
--p 4002:4002 \ #brige IB gateway port to your local port 4002 | ||
manhinhang/ib-gateway-docker | ||
``` | ||
|
||
--- | ||
|
||
## Build & Run locally | ||
|
||
```bash | ||
git clone [email protected]:manhinhang/ib-gateway-docker.git | ||
cd ib-gateway-docker | ||
docker build --no-cache -t ib-gateway-docker . | ||
docker run -d \ | ||
--env IB_ACCOUNT= \ #YOUR_USER_ID | ||
--env IB_PASSWORD= \ #YOUR_PASSWORD | ||
--env TRADING_MODE= \ #paper or live | ||
-p 4002:4002 \ #brige IB gateway port to your local port 4002 | ||
ib-gateway-docker | ||
``` | ||
|
||
|
||
## Container usage example | ||
|
||
| Example | Link | Description | | ||
| - | - | - | | ||
| ib_insync | [examples/ib_insync](./examples/ib_insync) | This example demonstrated how to connect `IB Gateway` | ||
|
||
# Tests | ||
|
||
The [test cases](test/test_ib_gateway.py) written with testinfra. | ||
|
||
Run the tests | ||
|
||
``` | ||
pytest | ||
``` | ||
|
||
# Github Actions for continuous integration | ||
|
||
After forking `IB Gateway docker` repository, you need config your **interactive brokers** paper account & password in *github secret* | ||
|
||
| Key | Description | | ||
| - | - | | ||
| IB_ACCOUNT | your paper account name | | ||
| IB_PASSWORD | your paper account password | | ||
|
||
# Disclaimer | ||
|
||
This project is not affiliated with [Interactive Brokers Group, Inc.'s](https://www.interactivebrokers.com). | ||
|
||
Good luck and enjoy. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import requests | ||
import json | ||
import re | ||
|
||
if __name__ == "__main__": | ||
url = "https://download2.interactivebrokers.com/installers/ibgateway/stable-standalone/version.json" | ||
regex = r"([^(]+)\)" | ||
response = requests.get(url) | ||
response_text = response.text | ||
matches = re.finditer(regex, response_text) | ||
# print(matches) | ||
json_str = next(matches).group(1) | ||
data = json.loads(json_str) | ||
print(data["buildVersion"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import requests | ||
import os | ||
|
||
if __name__ == "__main__": | ||
url = "https://api.github.com/repos/IbcAlpha/IBC/releases" | ||
response = requests.get(url) | ||
data = response.json() | ||
latest = data[0] | ||
ver = latest["name"] | ||
for asset in latest["assets"]: | ||
if asset["name"].startswith("IBCLinux"): | ||
asset_url = asset["browser_download_url"] | ||
|
||
with open('.env', 'a') as fp: | ||
fp.write(f'IBC_VER={ver}\n') | ||
fp.write(f'IBC_ASSET_URL={asset_url}\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
if [[ $1 =~ ([0-9]+)\.([0-9]+) ]]; then | ||
IB_GATEWAY_MAJOR=${BASH_REMATCH[1]} | ||
IB_GATEWAY_MINOR=${BASH_REMATCH[2]} | ||
fi |