Skip to content

Commit

Permalink
Merge pull request #107 from manhinhang/develop
Browse files Browse the repository at this point in the history
Upgrade IB gateway version
  • Loading branch information
manhinhang authored Jul 8, 2024
2 parents 49986c4 + 98171a2 commit a39bfff
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
CUR_IB_GATEWAY_VER=10.19.2l
CUR_IBC_VER=3.18.0
CUR_IB_GATEWAY_VER=10.19.2o
CUR_IBC_VER=3.19.0
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy to docker hub
name: "Publish Docker"

on:
push:
Expand All @@ -13,6 +13,19 @@ on:

jobs:
build:
strategy:
matrix:
include:
# Dockerhub
- images: manhinhang/ib-gateway-docker
username: DOCKERHUB_USERNAME
password: DOCKERHUB_PASSWORD
registry: ''
# Github
- images: ghcr.io/manhinhang/ib-gateway-docker
username: ${{ github.actor }}
password: GITHUB_TOKEN
registry: 'ghcr.io'
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
Expand All @@ -21,12 +34,13 @@ jobs:
id: meta
uses: docker/metadata-action@v5
with:
images: manhinhang/ib-gateway-docker
images: ${{ matrix.images }}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
registry: ${{ matrix.registry }}
username: ${{ matrix.registry == 'ghcr.io' && matrix.username || secrets[matrix.username] }}
password: ${{ secrets[matrix.password] }}
- name: Build and push
uses: docker/build-push-action@v5
with:
Expand Down
20 changes: 11 additions & 9 deletions .github/workflows/detect-new-ver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ jobs:
IBC_VERSION_JSON_URL: "https://api.github.com/repos/IbcAlpha/IBC/releases"
steps:
- uses: actions/checkout@master
- name: Setup python
uses: actions/setup-python@v5
- name: detect new ib gateway version
id: check-update
run: |
Expand All @@ -24,21 +22,25 @@ jobs:
IBC_VER=$(curl ${IBC_VERSION_JSON_URL} | jq -r '.[0].name')
source .env
HAS_UPDATE='false'
if [ "$IB_GATEWAY_VER" = "$CUR_IB_GATEWAY_VER" ]; then
echo "No dated IB gateway version"
echo "No new IB gateway version available"
echo has_update=false >> "$GITHUB_OUTPUT"
else
echo "New IB gateway version($IB_GATEWAY_VER)"
echo has_update=true >> "$GITHUB_OUTPUT"
HAS_UPDATE='true'
fi
if [ "$IBC_VER" = "$CUR_IBC_VER" ]; then
echo "No dated IBC version"
if [ "$HAS_UPDATE" = 'false' ]; then
if [ "$IBC_VER" = "$CUR_IBC_VER" ]; then
echo "No new IBC version available"
echo has_update=false >> "$GITHUB_OUTPUT"
else
echo "New IBC version($IBC_VER)"
echo has_update=true >> "$GITHUB_OUTPUT"
else
echo "New IBC version($IBC_VER) available"
echo has_update=true >> "$GITHUB_OUTPUT"
fi
fi
echo "ib-gateway-ver=$IB_GATEWAY_VER" >> "$GITHUB_OUTPUT"
echo "ibc-ver=$IBC_VER" >> "$GITHUB_OUTPUT"
- name: Update files with new version
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ ENV DISPLAY=:0

ENV IBGW_PORT 4002
ENV JAVA_HEAP_SIZE 768
ENV HEALTHCHECK_API_ENABLE=false

EXPOSE $IBGW_PORT

Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ 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.2l)
- [IB Gateway](https://www.interactivebrokers.com/en/index.php?f=16457) (10.19.2o)

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

## Pull the Docker image from Docker Hub

Expand All @@ -26,7 +26,7 @@ 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
-p 4002:4002 \ #brige IB gateway port to your local port 4002
manhinhang/ib-gateway-docker
```

Expand Down Expand Up @@ -60,6 +60,8 @@ ib-gateway-docker

Healthcheck via api call `http://localhost:8080/healthcheck`

Config `HEALTHCHECK_API_ENABLE=true` in environment variable to enable API

```bash
curl -f http://localhost:8080/healthcheck
```
Expand All @@ -76,6 +78,7 @@ services:
- IB_ACCOUNT=$IB_ACCOUNT
- IB_PASSWORD=$IB_PASSWORD
- TRADING_MODE=$TRADING_MODE
- HEALTHCHECK_API_ENABLE=true
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/healthcheck"]
interval: 60s
Expand Down
7 changes: 6 additions & 1 deletion start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ set_java_heap() {
set_java_heap

# start rest api for healthcheck
healthcheck-rest >&1 &
if [ "$HEALTHCHECK_API_ENABLE" = true ] ; then
echo "starting healthcheck api..."
healthcheck-rest >&1 &
else
echo "Skip starting healthcheck api"
fi

echo "detect IB gateway version: $IBGW_VERSION"

Expand Down
25 changes: 24 additions & 1 deletion test/test_ib_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_healthcheck():
assert subprocess.check_call(['docker', 'exec', docker_id, 'healthcheck']) == 0
subprocess.check_call(['docker', 'rm', '-f', docker_id])

def test_healthcheck_rest():
def test_healthcheck_api():
account = os.environ['IB_ACCOUNT']
password = os.environ['IB_PASSWORD']
trading_mode = os.environ['TRADING_MODE']
Expand All @@ -34,9 +34,32 @@ def test_healthcheck_rest():
'--env', 'IB_ACCOUNT={}'.format(account),
'--env', 'IB_PASSWORD={}'.format(password),
'--env', 'TRADING_MODE={}'.format(trading_mode),
'--env', 'HEALTHCHECK_API_ENABLE=true',
'-p', '8080:8080',
'-d', IMAGE_NAME]).decode().strip()
time.sleep(30)
response = requests.get("http://127.0.0.1:8080/healthcheck")
assert response.ok
subprocess.check_call(['docker', 'rm', '-f', docker_id])

def test_healthcheck_api_fail():
account = 'test'
password = 'test'
trading_mode = os.environ['TRADING_MODE']

# run a container
docker_id = subprocess.check_output(
['docker', 'run',
'--env', 'IB_ACCOUNT={}'.format(account),
'--env', 'IB_PASSWORD={}'.format(password),
'--env', 'TRADING_MODE={}'.format(trading_mode),
'--env', 'HEALTHCHECK_API_ENABLE=true',
'-p', '8080:8080',
'-d', IMAGE_NAME]).decode().strip()
time.sleep(30)
try:
response = requests.get("http://127.0.0.1:8080/healthcheck")
assert not response.ok
except requests.exceptions.ConnectionError:
pass
subprocess.check_call(['docker', 'rm', '-f', docker_id])
7 changes: 5 additions & 2 deletions test/test_ib_gateway_fail.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,8 @@ def test_healthcheck_fail(host):

def test_healthcheck_rest_fail(host):
time.sleep(30)
response = requests.get("http://127.0.0.1:8080/healthcheck")
assert not response.ok
try:
response = requests.get("http://127.0.0.1:8080/healthcheck")
assert False
except requests.exceptions.ConnectionError:
pass

0 comments on commit a39bfff

Please sign in to comment.