ibgateway-raspberry-64

Running Interactive Brokers Gateway on Raspberry 4B + Debian 64-bit or Raspberry 5 + Raspberry Pi OS 64-bit

 

Read this and other Raspberry Pi guides here

 

Credits

This thread helped me immensely - https://groups.io/g/twsapi/topic/install_tws_or_ib_gateway_on/25165590

 

Install OS

 

Download ibgateway/tws

$ wget https://download2.interactivebrokers.com/installers/ibgateway/latest-standalone/ibgateway-latest-standalone-linux-x64.sh
$ wget https://download2.interactivebrokers.com/installers/tws/latest-standalone/tws-latest-standalone-linux-x64.sh

 

Bellsoft Liberica JDK

Download Bellsoft Liberica JDK, which bundles all Java modules that IB gateway needed.

(2025) I have downloaded JDK 17 LTS / 64-bit / Linux / ARM / Package: Full JDK.

For me it was https://download.bell-sw.com/java/17.0.14+10/bellsoft-jdk17.0.14+10-linux-aarch64-full.deb.

(2023) I have downloaded JDK 11 LTS / 64-bit / Linux / ARM / Package: Full JDK.

For me it was https://download.bell-sw.com/java/11.0.20+8/bellsoft-jdk11.0.20+8-linux-aarch64-full.deb.

Don’t forget to switch to “Full JDK”!

bellsoft

Install it:

$ dpkg -i bellsoft-jdk11.0.20+8-linux-aarch64-full.deb
Selecting previously unselected package bellsoft-java11-full.
(Reading database ... 28164 files and directories currently installed.)
Preparing to unpack bellsoft-jdk11.0.20+8-linux-aarch64-full.deb ...
Unpacking bellsoft-java11-full (11.0.20+8) ...
dpkg: dependency problems prevent configuration of bellsoft-java11-full:
 bellsoft-java11-full depends on libasound2; however:
  Package libasound2 is not installed.

dpkg: error processing package bellsoft-java11-full (--install):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 bellsoft-java11-full

After a successful installation you can find your new JDK in /usr/lib/jvm/bellsoft-java11-full-aarch64/bin.

 

Update October 2025: Back in 2023 I had to run the installer using OpenJDK and then run the actual gateway/TWS using Bellsoft Java. That was no longer true in 2025, you can use Bellsoft for both. If you run into problems with the installer, you can try OpenJDK, but it will never work to run gateway/TWS, those only work with Bellsoft.

 

Update October 2025: You don’t need Oracle JDK, use only Bellsoft

Download Java SE Development Kit 8uXXX (Java 8). You may find it towards the end of the page.

Specifically Linux / ARM64 Compressed Archive, in my case it was jdk-8u381-linux-aarch64.tar.gz.

Yeah, you need to register for an account.

Unpack the JDK somewhere, for example to /opt. There is no installation.

$ cd /opt/
$ wget <whatever_url>
$ tar -xf jdk-8u381-linux-aarch64.tar.gz

 

Run the Gateway/TWS installer

Run the installer like this:

$ app_java_home="/usr/lib/jvm/bellsoft-java11-aarch64" sh ibgateway-latest-standalone-linux-x64.sh

…while passing your Bellsoft JDK folder as the “app_java_home” parameter.

(Update October 2025: No longer true, running from remote shell worked fine) With Bellsoft JDK, I had to run this installer in Raspberry GUI / Window Manager, not just remotely in the shell, or else it failed looking for some Java GUI components.

You might need to change “sh” to “bash”, based on your circumstances.

The same then applies for the TWS installer.

 

Configuring the gateway

I could not make it work without IBC. IBC passes some additional arguments to Java and I have always tried to keep my distance from Java.

Download, install and configure your IBC.

… IBC configuration is out of scope …

After you have set up your IBC, do not forget to make all scripts executable. I made that mistake several times.

$ cd ibc
$ chmod +x *.sh
$ chmod +x scripts/*.sh

Edit ibc/gatewaystart.sh or twsstart.sh and at the head of the file there are some basic configuration parameters:

TWS_MAJOR_VRSN=1019
IBC_INI=~/ibc/config.ini
TRADING_MODE=
TWOFA_TIMEOUT_ACTION=exit
IBC_PATH=/opt/ibc
TWS_PATH=~/Jts
TWS_SETTINGS_PATH=
LOG_PATH=~/ibc/logs
TWSUSERID=
TWSPASSWORD=
FIXUSERID=
FIXPASSWORD=
JAVA_PATH=
HIDE=

You obviously need to enter your values, such as TWS_MAJOR_VRSN=1023, not 1019.

BTW, you can use these values / scripts to run several gateways in parallel, with different configurations, IB logins and on different ports.

The single most important argument is the JAVA_PATH, though.

Edit your ibc/gatewaystart.sh script and change JAVA_PATH to

JAVA_PATH=/usr/lib/jvm/bellsoft-java11-full-aarch64/bin

or whichever version you have used.

Running the gateway

$ cd ibc
$ ./gatewaystart.sh

IBC should fire up your gateway after a short delay.

 

Start the gateway from a script or cron

In my python scripts I am starting the gateway before any actual processing starts. However the gateway/TWS can only run in GUI, it cannot run headless, in shell. For graphical environment you can use whatever GNOME / KDE came with your desktop. On server without a physical screen you can replace X server with “xvfb” - Virtual Framebuffer ‘fake’ X server. There are plenty of HOWTO’s over the internet.

In any case, if you execute your scripts from a remote shell, not from shell on your physical/virtual screen, you need to pass the DISPLAY variable to project the application on the X display. You also need to avoid the modern Wayland, since Wayland is a communication protocol and not a server like X11, so AFAIK you can NOT do the above with Wayland. Wayland does not provide the DISPLAY variable and WAYLAND_DISPLAY does not work.

For further reading see https://github.com/nemozny/vnc-share-physical-monitor.

Update your IBC scripts (twsstart.sh and gatewaystart.sh), at the very end of the script you can see:

if [[ "$1" == "-inline" ]]; then
    exec "${IBC_PATH}/scripts/displaybannerandlaunch.sh"
else
    title="IBC ($APP $TWS_MAJOR_VRSN)"
    xterm $iconic -T "$title" -e "${IBC_PATH}/scripts/displaybannerandlaunch.sh" &
fi

First make sure you actually have “xterm”. Change xterm for whatever GUI console app you had installed. It happened to me I had “lxterminal” and no “xterm” on a fresh install.

Add “DISPLAY=:0” to the second to last line:

    DISPLAY=:0 xterm $iconic -T "$title" -e "${IBC_PATH}/scripts/displaybannerandlaunch.sh" &
fi

This will run the app in your X session.

You can then kill the app by running a shell command “pkill java”.