• Stars
    star
    142
  • Rank 258,495 (Top 6 %)
  • Language
  • Created over 7 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Interactive Brokers: Headless IB Gateway Installation using IBController on Ubuntu Server

Interactive Brokers: Headless IB Gateway Installation using IBController on Ubuntu Server

This guide was written for anyone that would like to host an instance of the IB Gateway API on an external network. This will allow you to use libraries like node-ib and ib-sdk in a production environment.

Influencers

SSH to your server

# once you've logged in, proceed as `sudo` user
sudo -i
# we'll start in root's home directory
cd ~

This is not exactly best Unix practice, but it'll do for now while we get everything up and running.

Dependencies

# unzip is used to unzip compressed downloads
apt install unzip
# xvfb is an x11 (GUI) screen simulator
apt install xvfb
# x11vnc is a remote screen simulator viewing tool
apt install x11vnc
  • xvfb will allow IB Gateway to launch because without an x11 container, it crashes.
  • x11vnc is used to host/serve the simulated x11 GUI allowing you to interact with IB Gateway's user interface remotely.
  • TightVNC is an x11vnc client you'll need to download to your development computer to remotely access the hosted x11vnc instance.
  • tvnjviewer-2.8.3-bin-gnugpl.zip.

Setup the x11 screen simulator

Xvfb :1 -ac -screen 0 1024x768x24 &
# press enter
export DISPLAY=:1
x11vnc -ncache 10 -ncache_cr -display :1 -forever -shared -logappend /var/log/x11vnc.log -bg -noipv6
  • You'll want to configure your server's firewall using ufw or iptables to allow port 5900

Install IB Gateway

# in your root's home directory
cd ~
# download installation script
wget https://download2.interactivebrokers.com/installers/ibgateway/latest-standalone/ibgateway-latest-standalone-linux-x64.sh
# make it executable
chmod a+x ibgateway-latest-standalone-linux-x64.sh
# run it
sh ibgateway-latest-standalone-linux-x64.sh -c
# when prompted:
Run IB Gateway?
Yes [y], No [n, Enter]
# choose No

Install IBController

The IBController is used to automate the IB Gateway using telnet.

# still in your root's home directory
cd ~
# get the link to latest IBController from https://github.com/ib-controller/ib-controller/releases
wget https://github.com/ib-controller/ib-controller/releases/download/3.4.0/IBController-3.4.0.zip
unzip ./IBController-3.4.0.zip -d ./ibcontroller.paper
# make the scripts executable
chmod a+x ./ibcontroller.paper/*.sh ./ibcontroller.paper/*/*.sh

Configuration

I'll provide you with my configuration files, but you'll need to modify them for your needs.

~/Jts/jts.ini

This is the configuration of the IB Gateway itself. You can use your local machine's jts.ini as a reference which can be found in the same location path.

[IBGateway]
WriteDebug=false
TrustedIPs=127.0.0.1
MainWindow.Height=550
RemoteHostOrderRouting=gdc1.ibllc.com
RemotePortOrderRouting=4000
ApiOnly=true
LocalServerPort=4000
MainWindow.Width=700

[Logon]
useRemoteSettings=false
UserNameToDirectory=Ij4tOygzbGV6,djgblkjyvm
Individual=1
tradingMode=p
colorPalletName=dark
Steps=5
Locale=en
SupportsSSL=gdc1.ibllc.com:4000,true,20170813,false
UseSSL=true
s3store=true

[ns]
darykq=1

[Communication]
Internal=false
LocalPort=0
Peer=gdc1.ibllc.com:4001
Region=us

~/ibcontroller.paper/IBControllerGatewayStart.sh

ONLY modify the top part of the file as indicated.

TWS_MAJOR_VRSN=967
IBC_INI=/root/ibcontroller.paper/IBController.ini
TRADING_MODE=
IBC_PATH=/root/ibcontroller.paper
TWS_PATH=/root/Jts
LOG_PATH=/root/ibcontroller.paper/Logs
TWSUSERID=
TWSPASSWORD=
JAVA_PATH=

~/ibcontroller.paper/IBController.ini

This is the IBController configuration. More info can be found here.

LogToConsole=no
FIX=no
IbLoginId=<YOUR IB ACCOUNT USERNAME>
IbPassword=<YOUR IB ACCOUNT PASSWORD>
PasswordEncrypted=no
FIXLoginId=
FIXPassword=
FIXPasswordEncrypted=yes
TradingMode=paper
IbDir=
StoreSettingsOnServer=no
MinimizeMainWindow=no
ExistingSessionDetectedAction=manual
AcceptIncomingConnectionAction=accept
ShowAllTrades=no
ForceTwsApiPort=
ReadOnlyLogin=no
AcceptNonBrokerageAccountWarning=yes
IbAutoClosedown=no
ClosedownAt=Saturday 04:11
AllowBlindTrading=yes
DismissPasswordExpiryWarning=no
DismissNSEComplianceNotice=yes
SaveTwsSettingsAt=
IbControllerPort=7462
IbControlFrom=
IbBindAddress=127.0.0.1
CommandPrompt=
SuppressInfoMessages=yes
LogComponents=never

Start the IB Gateway

We'll use the simulated x11 (DISPLAY=:1) we created with xvfb to start the IBController script.

DISPLAY=:1 ~/ibcontroller.paper/IBControllerGatewayStart.sh

Firewall

Make sure the following ports are accessible from the outside network:

  • 5900: x11vnc remote viewer
  • 4002: default IB Gateway API

Validate and debug

Use the TightVNC to make sure the IB Gateway is up and running.

# launch the TightVNC app
java -jar tightvnc-jviewer.jar

Caveats

I tried using nginx to proxy the websocket connection to port 4002 but was unsuccessful. You'll want to add any external IP's to the Trusted IPs list at the bottom of the IB Gateway's API - Settings. config The IBController should be automatically allowing external IPs, but I was not able to get that working in v3.4.0.

Trouble Shooting

Missing Xfonts

You may get following error message (or similar) when you start the IBController,

xterm can not load font "-misc-fixed-medium-r-semicondensed ...

You need to install the fonts, here is the command for Ubuntu

sudo apt install xfonts-base

You may need to find out the way for your Linux distribution

Missing libXi.so

You may see the error message about missing libXi.so.6 in the log file of IBController, just need to run

sudo apt install libxi-dev libxmu-dev

You may need to find out the way for your Linux distribution

Testing

Using the ib-sdk:

const ibsdk = require('ib-sdk')
ibsdk.open({
	clientId: 0,
	host: '123.45.67.890',
	port: 4002,
}, function(error, session) {
	if (error) return console.error('ibsdk.open > error', error);
	let account = session.account()
	console.log('account', account)
})

More Repositories

1

robinhood.tools

๐Ÿ“ˆ๐Ÿค‘๐Ÿ’ฐ Advanced trading tools and resources for Robinhood Web.
TypeScript
31
star
2

nativescript-onesignal

A Nativescript plugin that wraps the iOS and Android OneSignal Push Notifications SDK.
JavaScript
24
star
3

nativescript-telephony

A Nativescript plugin to get the device's SIM data (carrier name, mcc mnc, country code, telephonenumber, etc)
TypeScript
22
star
4

futon-media

Instantly stream Movies and TV Shows via Emby Media
TypeScript
12
star
5

robinstocks-src

๐Ÿ“‰๐Ÿ˜“๐Ÿ’ธrobinstocks.com source code
TypeScript
7
star
6

jellyfin-debrids

Autonomous Jellyfin library via debrid download link providers
TypeScript
5
star
7

dotfiles

๐Ÿ“บโŒจ๏ธ Terminal super powers
Shell
3
star
8

blue-pill

Don't take the ๐Ÿ”ด red pill down some rabbit hole, the ๐Ÿ”ต blue pill will keep you focused on a task.
JavaScript
3
star
9

dts-generate

๐Ÿ”ฎโšก Generate TypeScript definitions for anything
TypeScript
2
star
10

nativescript-fcuuid

A NativeScript plugin that wraps FCUUID for iOS
Objective-C
1
star
11

bbrew

A better Homebrew CLI
TypeScript
1
star
12

ilp-plugin-lightning

TypeScript
1
star
13

roblav96-snippets

roblav96's sublime text snippets
1
star
14

tsc-wtf

๐Ÿ˜ฆ WTF `tsc --watch` don't clear my terminal/console bro!
JavaScript
1
star
15

phishyapps.com

๐Ÿค–๐ŸŸโ˜ ๏ธ Malicious phishing app removing robot for iTunes App Store & Google Play Store
TypeScript
1
star
16

help2comp

Zsh completion generator from manpage or --help
TypeScript
1
star
17

resume

Robert Laverty's Resume
TypeScript
1
star
18

ffprobe-binaries

Universal FFprobe static binaries
TypeScript
1
star
19

tns-template-vue

NativeScript Vue template with TypeScript, PostCSS, Tailwind, Vuex, Vue Router, Webpack, etc.
1
star