Skip to content

Commit 9cb1f0e

Browse files
committed
initial commit
0 parents  commit 9cb1f0e

33 files changed

+2617
-0
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
._.DS_Store
2+

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.DS_Store
2+
.DS_Store?
3+
._*
4+
.Spotlight-V100
5+
.Trashes
6+
.vscode
7+

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# IB Gateway Automation (IBGA)
2+
3+
IBGA is <a href="https://www.interactivebrokers.com/en/trading/ibgateway-latest.php" target="_blank">IB Gateway</a> in headless mode. It is a container image preloaded with scripts for automating user interactions with IBG.
4+
5+
<img src="docs/images/ibga-video.gif">
6+
7+
## Benefits:
8+
9+
* A "docker compose" flavored configuration
10+
* Store username, password, time zone and other options in one place
11+
* Automatic installation and easy upgrade of IBG
12+
* Automatic handling of daily restarts beyond the one week limit, upon exit or crash
13+
* Automatic handling of paper trading confirmation and options dialog
14+
* Automatic daily export of logs
15+
* Retaining of settings after an upgrade
16+
* A disposable container design
17+
18+
## Under the hood:
19+
* IBGA runs in a set of bash scripts.
20+
* IBGA relies on <a href="https://heshiming.github.io/jauto/" target="_blank">JAuto, a JVMTI agent</a> to determine screen locations of windows, text boxes, and buttons.
21+
* IBGA relies on <a href="https://github.com/jordansissel/xdotool" target="_blank">xdotool</a> to simulate keyboard and mouse input.
22+
* IBGA relies on <a href="https://en.wikipedia.org/wiki/Xvfb" target="_blank">Xvfb</a>, <a href="https://github.com/LibVNC/x11vnc" target="_blank">x11vnc</a>, <a href="https://novnc.com/" target="_blank">novnc</a> to provide a VNC-capable <a href="https://en.wikipedia.org/wiki/X_Window_System" target="_blank">X11</a> environment for IBG.
23+
24+
## Documentation
25+
26+
<a href="https://heshiming.github.io/ibga/" target="_blank">https://heshiming.github.io/ibga/</a>
27+
28+
## Example docker-compose.yml
29+
30+
version: '2'
31+
services:
32+
my-ibga:
33+
image: heshiming/ibga
34+
restart: unless-stopped
35+
environment:
36+
- TERM=xterm
37+
- IB_USERNAME=username
38+
- IB_PASSWORD=password
39+
- IB_REGION=America
40+
- IB_TIMEZONE=America/New York
41+
- IB_LOGINTAB=IB API
42+
- IB_LOGINTYPE=Live Trading
43+
- IB_LOGOFF=11:55 PM
44+
- IB_APILOG=data
45+
- IB_LOGLEVEL=Error
46+
volumes:
47+
- ./run/program:/home/ibg
48+
- ./run/settings:/home/ibg_settings
49+
ports:
50+
- "15800:5800"
51+
- "4000:4000"
52+

build.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
docker build --progress plain --rm -f ./dockerfile -t ibga ./
4+
docker images

dockerfile

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
FROM openjdk:18-slim-bullseye AS jauto_build
2+
USER root
3+
RUN apt-get update && \
4+
apt-get install -y --no-install-recommends curl cmake gcc g++ make libc-dev && \
5+
apt-get clean && \
6+
rm -rf /var/lib/apt/lists/*
7+
ENV JAUTO_VER=1.0.0
8+
RUN curl -Lk https://github.com/heshiming/jauto/archive/refs/tags/v$JAUTO_VER.tar.gz -o /tmp/jauto.tar.gz
9+
WORKDIR /tmp
10+
RUN tar xfz jauto.tar.gz && \
11+
mkdir jauto_build && \
12+
cd jauto_build && \
13+
cmake ../jauto-$JAUTO_VER && \
14+
cmake --build .
15+
16+
FROM debian:bullseye-slim AS util_build
17+
USER root
18+
RUN apt-get update && \
19+
apt-get install -y --no-install-recommends gcc libx11-dev libc-dev && \
20+
apt-get clean && \
21+
rm -rf /var/lib/apt/lists/*
22+
ADD utils /tmp/utils
23+
WORKDIR /tmp/utils
24+
RUN gcc show_text.c -O2 -lX11 -o show_text
25+
26+
FROM debian:bullseye-slim
27+
USER root
28+
RUN apt-get update && \
29+
apt-get install -y --no-install-recommends curl sudo ed xvfb x11vnc x11-utils xdotool socat python3-websockify procps xfonts-scalable tzdata && \
30+
apt-get clean && \
31+
rm -rf /var/lib/apt/lists/*
32+
RUN useradd -ms /bin/bash -u 2000 ibg && \
33+
adduser ibg sudo && \
34+
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
35+
WORKDIR /opt
36+
RUN curl -Lk "https://github.com/novnc/noVNC/archive/refs/tags/v1.3.0.tar.gz" -o novnc.tar.gz && \
37+
tar xfz novnc.tar.gz && \
38+
rm novnc.tar.gz
39+
USER ibg
40+
WORKDIR /home/ibg
41+
COPY --from=util_build /tmp/utils/show_text /bin
42+
COPY --from=jauto_build /tmp/jauto_build/jauto.so /opt
43+
ADD scripts /opt/ibga/
44+
RUN sudo chmod a+rx /bin/show_text && \
45+
sudo chmod a+rx /opt/jauto.so && \
46+
sudo chmod a+rx /opt/ibga/*
47+
ENTRYPOINT /opt/ibga/manager.sh

docs/404.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
layout: default
3+
---
4+
5+
<style type="text/css" media="screen">
6+
.container {
7+
margin: 10px auto;
8+
max-width: 600px;
9+
text-align: center;
10+
}
11+
h1 {
12+
margin: 30px 0;
13+
font-size: 4em;
14+
line-height: 1;
15+
letter-spacing: -1px;
16+
}
17+
</style>
18+
19+
<div class="container">
20+
<h1>404</h1>
21+
22+
<p><strong>Page not found :(</strong></p>
23+
<p>The requested page could not be found.</p>
24+
</div>

docs/Gemfile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
source "https://rubygems.org"
2+
3+
# Hello! This is where you manage which Jekyll version is used to run.
4+
# When you want to use a different version, change it below, save the
5+
# file and run `bundle install`. Run Jekyll with `bundle exec`, like so:
6+
#
7+
# bundle exec jekyll serve
8+
#
9+
# This will help ensure the proper Jekyll version is running.
10+
# Happy Jekylling!
11+
#gem "jekyll", "~> 3.9.0"
12+
13+
# This is the default theme for new Jekyll sites. You may change this to anything you like.
14+
gem "minima", "~> 2.0"
15+
16+
# If you want to use GitHub Pages, remove the "gem "jekyll"" above and
17+
# uncomment the line below. To upgrade, run `bundle update github-pages`.
18+
# gem "github-pages", group: :jekyll_plugins
19+
gem "github-pages", "~> 225", group: :jekyll_plugins
20+
21+
# If you have any plugins, put them here!
22+
group :jekyll_plugins do
23+
gem "jekyll-feed", "~> 0.6"
24+
end
25+
26+
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
27+
# and associated library.
28+
install_if -> { RUBY_PLATFORM =~ %r!mingw|mswin|java! } do
29+
gem "tzinfo", "~> 1.2"
30+
gem "tzinfo-data"
31+
end
32+
33+
# Performance-booster for watching directories on Windows
34+
gem "wdm", "~> 0.1.0", :install_if => Gem.win_platform?
35+
36+
# kramdown v2 ships without the gfm parser by default. If you're using
37+
# kramdown v1, comment out this line.
38+
gem "kramdown-parser-gfm"
39+
40+
gem "webrick", "~> 1.7"

docs/_config.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Welcome to Jekyll!
2+
#
3+
# This config file is meant for settings that affect your whole blog, values
4+
# which you are expected to set up once and rarely edit after that. If you find
5+
# yourself editing this file very often, consider using Jekyll's data files
6+
# feature for the data you need to update frequently.
7+
#
8+
# For technical reasons, this file is *NOT* reloaded automatically when you use
9+
# 'bundle exec jekyll serve'. If you change this file, please restart the server process.
10+
11+
# Site settings
12+
# These are used to personalize your new site. If you look in the HTML files,
13+
# you will see them accessed via {{ site.title }}, {{ site.email }}, and so on.
14+
# You can create any custom variable you would like, and they will be accessible
15+
# in the templates via {{ site.myvariable }}.
16+
title: IB Gateway Automation (IBGA)
17+
logo: images/logo.png
18+
19+
description: >- # this means to ignore newlines until "baseurl:"
20+
IB Gateway Automation (IBGA)
21+
baseurl: "/ibga" # the subpath of your site, e.g. /blog
22+
url: "https://heshiming.github.io" # the base hostname & protocol for your site, e.g. http://example.com
23+
github_username: heshiming
24+
25+
# Build settings
26+
markdown: kramdown
27+
remote_theme: just-the-docs/just-the-docs
28+
plugins:
29+
- jekyll-remote-theme
30+
- jekyll-feed
31+
- jekyll-sitemap
32+
repository: heshiming/ibga
33+
34+
color_scheme: ibga
35+
aux_links:
36+
"IBGA on GitHub": "//github.com/heshiming/ibga"
37+
aux_links_new_tab: true
38+
39+
ga_tracking: UA-5688423-5
40+
41+
# Exclude from processing.
42+
# The following items will not be processed, by default. Create a custom list
43+
# to override the default setting.
44+
# exclude:
45+
# - Gemfile
46+
# - Gemfile.lock
47+
# - node_modules
48+
# - vendor/bundle/
49+
# - vendor/cache/
50+
# - vendor/gems/
51+
# - vendor/ruby/

docs/_includes/footer_custom.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Copyright &copy; 2022 He Shiming <small>&lt;heshiming at gmail dot com&gt;</small>.

docs/_sass/color_schemes/ibga.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
$link-color: $green-200;
2+
$sidebar-color: #f5faf6;

docs/faq.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
---
2+
layout: default
3+
title: Frequently Asked Questions
4+
description: Frequently asked questions for IBGA, including bash script and Docker Compose configuration examples.
5+
nav_order: 3
6+
---
7+
8+
# IBGA Frequently Asked Questions
9+
{: .no_toc }
10+
11+
<details open markdown="block">
12+
<summary>
13+
Table of contents
14+
</summary>
15+
{: .text-delta }
16+
1. TOC
17+
{:toc}
18+
</details>
19+
20+
---
21+
22+
## What OS does IBGA support?
23+
24+
IBGA is a self-sufficient image. It runs on Docker. <a href="https://docs.docker.com/engine/install/" target="_blank">Docker is available on a variety of Linux platforms, macOS, and Windows 10</a>.
25+
26+
---
27+
28+
## What makes IBGA different from IBC?
29+
30+
<a href="https://github.com/IbcAlpha/IBC" target="_blank">IBC</a> automates many aspects of the Interactive Broker trading software. It is, however, not designed to run in a headless server. Before I started on IBGA, I spent plenty of time trying to make IBC work inside a container but couldn't reliably do so.
31+
32+
Technically, IBC is a Java program hosting the IB Gateway main class. Certain aspects of IBC can only be done via reverse-engineering how IB Gateway works. IBGA on the other hand, uses two-component automation: one to extract UI coordinates, and another to simulate input. It is a more efficient way to achieve automation, and I don't need to reverse-engineer the app.
33+
34+
---
35+
36+
## Can I host IBGA on an internet server?
37+
38+
**Not recommended.**{: .text-red-200 } Please refer to [Security](references/security.md) to learn about the potential issues of hosting IBGA on a public server.
39+
40+
---
41+
42+
## Can IBGA handle two-factor logins (Interactive Brokers Secure Login System SLS)?
43+
44+
Unfortunately no, as two-factor login negates the purpose of automation. You can, however, still run IBGA, only that you have to manually type in your two-factor login code at VNC upon each daily restart.
45+
46+
At Interactive Brokers account management, you can <a href="https://guides.interactivebrokers.com/cp/am/settings/slsoptout.htm" target="_blank">choose to opt-out two-factor login just for trading, but maintain it for client portal</a>.
47+
48+
---
49+
50+
## How do I run multiple instances of IB Gateway on the same server?
51+
52+
In the [example configuration](getting-started/configuring.md#an-example-docker-compose-configuration-file), only one service node (`my-ibga`) is created. Within the context of IBGA, one service is one container running one instance of IB Gateway. Running another instance needs another service node, with different ports. For example:
53+
54+
version: '2'
55+
services:
56+
my-ibga:
57+
...
58+
environment:
59+
...
60+
- IB_USERNAME=username_account1
61+
...
62+
ports:
63+
- "15800:5800"
64+
- "4000:4000"
65+
my-other-account:
66+
...
67+
environment:
68+
...
69+
- IB_USERNAME=username_account2
70+
...
71+
ports:
72+
- "15801:5800"
73+
- "4001:4000"
74+
75+
However, you cannot share live account market data subscriptions with the paper trading account using this method. For market data sharing to work, both IB Gateway instances must share the same <a href="https://en.wikipedia.org/wiki/MAC_address" target="_blank">NIC MAC address</a>, which IBGA does not currently support.
76+
77+
---
78+
79+
## How do I export logs to a non-settings directory on the host?
80+
81+
First, log exporting is configured using the [`IBGA_EXPORT_LOGS`](references/config-args.html#IBGA_EXPORT_LOGS) variable. To export into a custom directory, mount it in `docker-compose.yml` like the program and settings directory, and set [`IBGA_LOG_EXPORT_DIR`](references/config-args.html#IBGA_LOG_EXPORT_DIR) respectively:
82+
83+
version: '2'
84+
services:
85+
my-ibga:
86+
image: ibga
87+
environment:
88+
...
89+
- IBGA_EXPORT_LOGS=true
90+
- IBGA_LOG_EXPORT_DIR=/home/ibg_logs
91+
volumes:
92+
- ./run/program:/home/ibg
93+
- ./run/settings:/home/ibg_settings
94+
- ./run/logs:/home/ibg_logs
95+
96+
---
97+
98+
## Why Xvfb but not the modern xserver-xorg-video-dummy as the framebuffer?
99+
100+
Mainly the size. Switching to `xserver-xorg-video-dummy` adds about 30MB of additional dependencies to the image without any improvement to the functionality whatsoever.
101+
102+
---
103+
104+
## Can I distribute IBGA as a commercial product?
105+
106+
IBGA is available under the [GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html){:target="_blank"} license as well as a commercial license. Users choosing to use IBGA under the free, open-source license must comply with its terms. Alternatively, users may choose to purchase a commercial license, which enables the distribution of IBGA in any form without restrictions.

docs/favicon.ico

15 KB
Binary file not shown.

docs/getting-started/configuring.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
layout: default
3+
title: Configuring
4+
description: Configuring IBGA (Docker Compose flavor) with examples
5+
parent: Getting Started
6+
nav_order: 1
7+
---
8+
9+
# Configuring IBGA (Docker Compose flavor)
10+
11+
IBGA docker image contains utilities and scripts for automating <a href="https://www.interactivebrokers.com/en/trading/ibgateway-latest.php" target="_blank">IB Gateway</a> in headless mode. To launch the program, you need to create a container. To automate the logins, you need to supply a username and password, among other arguments. An easy way to go about this is to use a <a href="https://docs.docker.com/compose/" target="_blank">Docker Compose</a> config file.
12+
13+
## Installing Docker Compose
14+
15+
Depending on your host OS (Linux, for instance), Docker Compose may be a standalone executable, separate from Docker itself. Please refer to the <a href="https://docs.docker.com/compose/install/#install-compose" target="_blank">official documentation</a> to see if you need to follow extra steps to install Docker Compose.
16+
17+
## An Example Docker Compose Configuration File
18+
19+
The Docker Compose configuration file is in <a href="https://yaml.org/" target="_blank">YAML</a> syntax, typically named `docker-compose.yml`. You can create and edit this file in a text editor. Don't worry if you are new to the YAML format. <a href="https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html" target="_blank">A couple of examples</a> should get you started.
20+
21+
version: '2'
22+
services:
23+
my-ibga:
24+
image: heshiming/ibga
25+
restart: unless-stopped
26+
environment:
27+
- TERM=xterm
28+
- IB_USERNAME=username
29+
- IB_PASSWORD=password
30+
- IB_REGION=America
31+
- IB_TIMEZONE=America/New York
32+
- IB_LOGINTAB=IB API
33+
- IB_LOGINTYPE=Live Trading
34+
- IB_LOGOFF=11:55 PM
35+
- IB_APILOG=data
36+
- IB_LOGLEVEL=Error
37+
volumes:
38+
- ./run/program:/home/ibg
39+
- ./run/settings:/home/ibg_settings
40+
ports:
41+
- "15800:5800"
42+
- "4000:4000"
43+
44+
For more information about a Docker Compose configuration, including mechanisms such as `volumes`, `ports`, `restart`, refer to [Docker Basics](../references/docker-basics.md).
45+
46+
For more information about IBGA-specific `IB_*` arguments (in fact, environment variables), refer to [IBGA Configuration Arguments](../references/config-args.md).

0 commit comments

Comments
 (0)