ibkr-trading

ib-gateway-ver ib-gateway-size ib-app-ver ib-app-size

Interactive Brokers Application

Boilerplate or framework to create your own trading application or bot using Interactive Brokers gateway. At the basic level this repo hosts images for two docker containers:

  1. Docker image for IBKR gateway with IBC. While there are several images none met my requirements for reliability and self-recovery.

  2. Docker image for the python application using ib_insync library, which supports scheduling and can be used for trading bot.

You can use these images as-is. In addition I provide several ways to deploy the application:

Usage

Standalone Docker

The docker.io/omdv/ib-gateway container expect three variables:

:warning: It is recommended to create a second account in Interactive Brokers and limit permissions.

Local deployment

Add your variables to .env. Then run make dev, which will start docker-compose.

Cloud deployment

For production I recommend to use server environment or one of cloud platforms. This repository has Terraform recipes for GCP.

It is based on two separate VMs hosting gateway and application containers, connected via VPC. Such separation allows to remove concerns around security by making gateway accessible only by trading application via internal network. Trading application is expected (at least at the moment) to be stateless with the hope to make it serverless in the future.

To deploy you will need to expose the following env variables or enter them in console during terraform application:

export TF_VAR_TWS_USER_ID = <your-TWS-login>
export TF_VAR_TWS_PASSWORD = <your-TWS-pass>
export TF_VAR_TRADING_MODE = <"paper" or "live">
export TF_VAR_project_id = <your-GCP-project-id>

Review and deploy Terraform plan:

cd ./deployments/google
terraform init
terraform plan
terraform apply

Development

Dependencies

Some recommended dependencies for pre-commit hooks.

Troubleshooting / Usefull snippets

References

Inspired by the following projects: