Skip to content

Commit

Permalink
feat: remove ib-insync (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
manhinhang authored Apr 15, 2024
1 parent 7c6db13 commit 8a4e11b
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 244 deletions.
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export IMAGE_NAME=ib-gateway-docker
export TRADE_MODE=paper
export TRADING_MODE=paper
if [ -f ".secrets" ] ; then
source ./.secrets
fi
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ jobs:
env:
IB_ACCOUNT: ${{ secrets.IB_ACCOUNT }}
IB_PASSWORD: ${{ secrets.IB_PASSWORD }}
TRADE_MODE: paper
TRADING_MODE: paper

- name: Run ib_insync example
run: |
docker run --rm \
-e IB_ACCOUNT=$IB_ACCOUNT \
-e IB_PASSWORD=$IB_PASSWORD \
-e TRADE_MODE=paper \
-e TRADING_MODE=paper \
-p 4001:4002 \
-d \
$IMAGE_NAME tail -f /dev/null;
$IMAGE_NAME;
sleep 30;
pip install ib_insync pandas;
python examples/ib_insync/scripts/connect_gateway.py;
docker stop $(docker ps -a -q)
env:
TRADE_MODE: paper
TRADING_MODE: paper
IB_ACCOUNT: ${{ secrets.IB_ACCOUNT }}
IB_PASSWORD: ${{ secrets.IB_PASSWORD }}

30 changes: 8 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,27 @@ RUN apt-get update \
procps \
xterm
RUN apt install -y openjdk-17-jre
RUN pip install ib_insync==$IB_INSYNC_VER

# set environment variables
ENV TWS_INSTALL_LOG=/root/Jts/tws_install.log \
ibcIni=/root/ibc/config.ini \
ibcPath=/opt/ibc \
IBC_INI=/root/ibc/config.ini \
IBC_PATH=/opt/ibc \
javaPath=/opt/i4j_jres \
twsPath=/root/Jts \
TWS_PATH=/root/Jts \
twsSettingsPath=/root/Jts \
IB_GATEWAY_PING_CLIENT_ID=1 \
ibAccMaxRetryCount=30
TWOFA_TIMEOUT_ACTION=restart

# make dirs
RUN mkdir -p /tmp && mkdir -p ${ibcPath} && mkdir -p ${twsPath}
RUN mkdir -p /tmp && mkdir -p ${IBC_PATH} && mkdir -p ${TWS_PATH}

# 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 https://github.com/IbcAlpha/IBC/releases/download/$IBC_VER-Update.1/IBCLinux-$IBC_VER.zip
RUN unzip /tmp/IBC.zip -d ${ibcPath}
RUN chmod +x ${ibcPath}/*.sh ${ibcPath}/*/*.sh
RUN unzip /tmp/IBC.zip -d ${IBC_PATH}
RUN chmod +x ${IBC_PATH}/*.sh ${IBC_PATH}/*/*.sh

# install TWS, write output to file so that we can parse the TWS version number later
RUN touch $TWS_INSTALL_LOG
Expand All @@ -54,29 +52,17 @@ RUN /tmp/install_ibgw.exp
RUN rm /tmp/ibgw.sh /tmp/IBC.zip

# copy IBC/Jts configs
COPY ibc/config.ini ${ibcIni}
COPY ibc/config.ini ${IBC_INI}

# copy cmd script
WORKDIR /root
COPY cmd.sh /root/cmd.sh
RUN chmod +x /root/cmd.sh

# python script for /root directory
COPY src/bootstrap.py /root/bootstrap.py
RUN chmod +x /root/bootstrap.py
COPY src/ib_account.py /root/ib_account.py
RUN chmod +x /root/ib_account.py

# set display environment variable (must be set after TWS installation)
ENV DISPLAY=:0
ENV GCP_SECRET=False

ENV IBGW_PORT 4002
ENV IBGW_WATCHDOG_CONNECT_TIMEOUT 30
ENV IBGW_WATCHDOG_APP_STARTUP_TIME 30
ENV IBGW_WATCHDOG_APP_TIMEOUT 30
ENV IBGW_WATCHDOG_RETRY_DELAY 2
ENV IBGW_WATCHDOG_PROBE_TIMEOUT 4

EXPOSE $IBGW_PORT

Expand Down
29 changes: 5 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ It's just pure `IB Gateway` and don't include any VNC service (for security reas

This docker image just installed:

- [IB Gateway](https://www.interactivebrokers.com/en/index.php?f=16457) (10.19.2)
- [IB Gateway](https://www.interactivebrokers.com/en/index.php?f=16457) (10.19.2l)

- [IBC](https://github.com/IbcAlpha/IBC) (3.18.0)

- [ib_insync](https://github.com/erdewit/ib_insync) (0.9.86)

- [google-cloud-secret-manager](https://github.com/googleapis/python-secret-manager) (2.11.1)

## Pull the Docker image from Docker Hub

```bash
Expand All @@ -29,9 +25,9 @@ docker pull manhinhang/ib-gateway-docker
docker run -d \
--env IB_ACCOUNT= \ #YOUR_USER_ID
--env IB_PASSWORD= \ #YOUR_PASSWORD
--env TRADE_MODE= \ #paper or live
--env TRADING_MODE= \ #paper or live
--p 4002:4002 \ #brige IB gateway port to your local port 4002
manhinhang/ib-gateway-docker tail -f /dev/null
manhinhang/ib-gateway-docker
```

---
Expand All @@ -45,10 +41,9 @@ docker build --no-cache -t ib-gateway-docker .
docker run -d \
--env IB_ACCOUNT= \ #YOUR_USER_ID
--env IB_PASSWORD= \ #YOUR_PASSWORD
--env TRADE_MODE= \ #paper or live
--env TRADING_MODE= \ #paper or live
-p 4002:4002 \ #brige IB gateway port to your local port 4002
ib-gateway-docker \
tail -f /dev/null
ib-gateway-docker
```


Expand All @@ -57,8 +52,6 @@ tail -f /dev/null
| Example | Link | Description |
| - | - | - |
| ib_insync | [examples/ib_insync](./examples/ib_insync) | This example demonstrated how to connect `IB Gateway`
| google cloud secret manager | [examples/google_cloud_secret_manager](./examples/google_cloud_secret_manager) | retreive your interactive brokers account from google cloud secret manager |


# Tests

Expand All @@ -79,18 +72,6 @@ After forking `IB Gateway docker` repository, you need config your **interactive
| IB_ACCOUNT | your paper account name |
| IB_PASSWORD | your paper account password |

# Other environment variable

| Variable Name | Description | Default value |
| - | - | - |
| IB_GATEWAY_PING_CLIENT_ID | ib gateway client id for pinging client status | 1 |
| IBGW_WATCHDOG_CONNECT_TIMEOUT | Ref to [ib_insync.ibcontroller.Watchdog.connectTimeout](https://ib-insync.readthedocs.io/api.html#ib_insync.ibcontroller.Watchdog.connectTimeout) | 30 |
| IBGW_WATCHDOG_APP_STARTUP_TIME | [ib_insync.ibcontroller.Watchdog.appStartupTime](https://ib-insync.readthedocs.io/api.html#ib_insync.ibcontroller.Watchdog.appStartupTime) | 30 |
| IBGW_WATCHDOG_APP_TIMEOUT | Ref to [ib_insync.ibcontroller.Watchdog.appTimeout](https://ib-insync.readthedocs.io/api.html#ib_insync.ibcontroller.Watchdog.appTimeout) | 30 |
| IBGW_WATCHDOG_RETRY_DELAY | Ref to [ib_insync.ibcontroller.Watchdog.retryDelay](https://ib-insync.readthedocs.io/api.html#ib_insync.ibcontroller.Watchdog.retryDelay) | 2 |
| IBGW_WATCHDOG_PROBE_TIMEOUT | Ref to [ib_insync.ibcontroller.Watchdog.probeTimeout](https://ib-insync.readthedocs.io/api.html#ib_insync.ibcontroller.Watchdog.probeTimeout) | 4 |


# Disclaimer

This project is not affiliated with [Interactive Brokers Group, Inc.'s](https://www.interactivebrokers.com).
Expand Down
11 changes: 8 additions & 3 deletions cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ echo "Setup port forwarding..."
socat TCP-LISTEN:$IBGW_PORT,fork TCP:localhost:4001,forever &
echo "*****************************"

python /root/bootstrap.py
# python /root/bootstrap.py

echo "IB gateway is ready."
# echo "IB gateway is ready."

#Define cleanup procedure
cleanup() {
Expand All @@ -31,5 +31,10 @@ cleanup() {

#Trap TERM
trap 'cleanup' INT TERM
echo "IB gateway starting..."

$@
${IBC_PATH}/scripts/ibcstart.sh "1019" -g \
"--tws-path=${TWS_PATH}" \
"--ibc-path=${IBC_PATH}" "--ibc-ini=${IBC_INI}" \
"--user=${IB_ACCOUNT}" "--pw=${IB_PASSWORD}" "--mode=${TRADING_MODE}" \
"--on2fatimeout=${TWOFA_TIMEOUT_ACTION}"
4 changes: 2 additions & 2 deletions doc/Debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ For debugging, Use x11 forwarding to visit IB gateway GUI for the investigation.
docker run --platform linux/amd64 -d \
--env IB_ACCOUNT= \
--env IB_PASSWORD= \
--env TRADE_MODE= \
--env TRADING_MODE= \
-v ~/.Xauthority:/root/.Xauthority \
-e DISPLAY=$ip:0 \
-p 4002:4002 \
ib-gateway-docker tail -f /dev/null
ib-gateway-docker
```
7 changes: 3 additions & 4 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
services:
ib-gateway:
image: manhinhang/ib-gateway-docker
command: tail -f /dev/null
ports:
- 4002:4002
environment:
- IB_ACCOUNT=$IB_ACCOUNT
- IB_PASSWORD=$IB_PASSWORD
- TRADE_MODE=$TRADE_MODE
- TRADING_MODE=$TRADING_MODE
secrets:
IB_ACCOUNT:
environment: "IB_ACCOUNT"
IB_PASSWORD:
environment: "IB_PWD"
TRADE_MODE:
environment: "TRADE_MODE"
TRADING_MODE:
environment: "TRADING_MODE"
35 changes: 0 additions & 35 deletions examples/google_cloud_secret_manager/README.md

This file was deleted.

6 changes: 3 additions & 3 deletions examples/ib_insync/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ Python script

## Docker run command
```bash
export TRADE_MODE=#paper or live
export TRADING_MODE=#paper or live
export IB_ACCOUNT=# your interactive brokers account name
export IB_PASSWORD=# your interactive brokers account password

docker run --rm \
-e IB_ACCOUNT=$IB_ACCOUNT \
-e IB_PASSWORD=$IB_PASSWORD \
-e TRADE_MODE=$TRADE_MODE \
-e TRADING_MODE=$TRADING_MODE \
-p 4001:4002 \
-d \
manhinhang/ib-gateway-docker:latest tail -f /dev/null
manhinhang/ib-gateway-docker:latest

pip install ib_insync pandas
python ib_insync/scripts/connect_gateway.py
Expand Down
64 changes: 0 additions & 64 deletions src/bootstrap.py

This file was deleted.

44 changes: 0 additions & 44 deletions src/ib_account.py

This file was deleted.

Loading

0 comments on commit 8a4e11b

Please sign in to comment.