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:
Docker image for IBKR gateway with IBC. While there are several images none met my requirements for reliability and self-recovery.
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:
The docker.io/omdv/ib-gateway
container expect three variables:
$TRADING_MODE
: paper
or live
.$TWSUSERID
$TWSPASSWORD
:warning: It is recommended to create a second account in Interactive Brokers and limit permissions.
Add your variables to .env
. Then run make dev
, which will start docker-compose
.
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
Some recommended dependencies for pre-commit hooks.
pre-commit
ripsecrets
gcloud compute instances update-container ib-app --container-image $TF_VAR_app_image
terraform import google_project.project $TF_VAR_project_id
Inspired by the following projects: