-
Notifications
You must be signed in to change notification settings - Fork 44
/
README.template
150 lines (112 loc) · 3.48 KB
/
README.template
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# IB Gateway docker
![Build test](https://github.com/manhinhang/ib-gateway-docker/workflows/Build%20test/badge.svg?branch=master)
[![Docker Pulls](https://img.shields.io/docker/pulls/manhinhang/ib-gateway-docker)](https://hub.docker.com/r/manhinhang/ib-gateway-docker)
[![GitHub](https://img.shields.io/github/license/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 git@github.com: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`
## Health check container
### API
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
```
- Docker compose example
```yaml
services:
ib-gateway:
image: manhinhang/ib-gateway-docker
ports:
- 4002:4002
environment:
- 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
timeout: 30s
retries: 3
start_period: 60s
```
### CLI
Execute `healthcheck` to detect IB gateway haelth status
```bash
healthcheck
# output: Ping IB Gateway successful
echo $?
# output: 0
```
```bash
healthcheck
# output: Can not connect to IB Gateway
echo $?
# output: 1
```
- Docker compose example
```yaml
services:
ib-gateway:
image: manhinhang/ib-gateway-docker
ports:
- 4002:4002
environment:
- IB_ACCOUNT=$IB_ACCOUNT
- IB_PASSWORD=$IB_PASSWORD
- TRADING_MODE=$TRADING_MODE
healthcheck:
test: /healthcheck/bin/healthcheck
interval: 60s
timeout: 30s
retries: 3
start_period: 60s
```
# 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.