diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml index eb4b27b7..0d8a8b4d 100644 --- a/.github/workflows/build-and-publish.yml +++ b/.github/workflows/build-and-publish.yml @@ -20,28 +20,16 @@ jobs: name: Build IB WHL runs-on: ubuntu-20.04 steps: - - name: Setup Python - uses: actions/setup-python@v1 - with: - python-version: 3.7 - - name: Install dependencies - run: | - python -m pip install --upgrade pip - python -m pip install --upgrade setuptools wheel build twine + - name: Checkout + uses: actions/checkout@v1 - name: Build - run: | - IB_VERSION_DOWNLOAD=$(echo ${IB_VERSION} | sed 's/[.]//') - echo "Downloading IB API version ${IB_VERSION_DOWNLOAD}" - curl -o ./api.zip "https://interactivebrokers.github.io/downloads/twsapi_macunix.${IB_VERSION_DOWNLOAD}.zip" - unzip api.zip - cd ./IBJts/source/pythonclient - python -m build + run: cd ibwhl && docker-compose -f "docker-compose.yml" up -d --build - name: Archive build artifacts uses: actions/upload-artifact@v2 with: name: ib-wheels path: | - ./IBJts/source/pythonclient/dist/* + ibwhl/dist/* build-whl: diff --git a/.gitignore b/.gitignore index 73b04775..3c257aff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .idea venv +build dist src/deephaven_ib.egg-info docker/data diff --git a/ibwhl/README.md b/ibwhl/README.md new file mode 100644 index 00000000..0d89433c --- /dev/null +++ b/ibwhl/README.md @@ -0,0 +1,30 @@ +# Interactive Brokers Python Wheels Builder + +This directory provides a Docker Compose setup for building Python wheels for the Interactive Brokers API. + +## Requirements + +- Docker +- Docker Compose + +## Usage + +1. Set the `IB_VERSION` environment variable to the version of Interactive Brokers' API you want to use. +2. Run `docker compose up` from the directory containing the Docker Compose file. This will build the wheels. +3. After the build process is complete, the wheels will be available in the `./dist` directory. +4. To install the wheels, run `pip install ./dist/*.whl`. + +> **Note:** Steps 1 and 2 can be combined as `IB_VERSION=10.19.04 docker compose up`. + +## Details + +The build process is defined in the `build_ibpy.sh` script. +The `./build` directory contains the scratch work for building the wheels. + +By using Docker, you can build the wheels in a clean environment that is isolated from your local machine. +This setup will work on any platform that supports Docker. + +## Note + +Interactive Brokers does not make their Python wheels available via PyPI, and the wheels are not redistributable. +This script lets you build the wheels locally, and then install them via pip. \ No newline at end of file diff --git a/ibwhl/build_ibpy.sh b/ibwhl/build_ibpy.sh new file mode 100755 index 00000000..9512a743 --- /dev/null +++ b/ibwhl/build_ibpy.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +# This script is used to build Python wheels for the Interactive Brokers' API. + + +# check that IB_VERSION is set +if [ -z "$IB_VERSION" ]; then + echo "IB_VERSION must be set" + exit 1 +fi + +# IB has a funky versioning scheme, so we need to strip out the periods in some places before download +IB_VERSION_DOWNLOAD=$(echo ${IB_VERSION} | sed 's/[.]//') + +rm -rf ./build +rm -rf ./dist + +mkdir ./build +mkdir ./dist + +pushd ./build + +python3 -m pip install build + +echo "Downloading IB API version ${IB_VERSION} (${IB_VERSION_DOWNLOAD})" +curl -o ./api.zip "https://interactivebrokers.github.io/downloads/twsapi_macunix.${IB_VERSION_DOWNLOAD}.zip" +unzip api.zip +cd ./IBJts/source/pythonclient +python3 -m build --wheel +popd +cp ./build/IBJts/source/pythonclient/dist/* ./dist/ + diff --git a/ibwhl/docker-compose.yml b/ibwhl/docker-compose.yml new file mode 100644 index 00000000..d37a910f --- /dev/null +++ b/ibwhl/docker-compose.yml @@ -0,0 +1,29 @@ + +# This is a Docker Compose file for building Interactive Brokers python wheels. +# Ideally, the wheels would be published by IB for installation via pip, but +# (1) IB does not make them available via pypi, and +# (2) the wheels are not redistributable. +# This script lets you build the wheels locally, and then install them via pip. +# +# To build the wheels, run `docker-compose up` from the directory containing this file. +# To install the wheels, run `pip install ./dist/*.whl`. +# After running the script, the wheels will be available in the `./dist` directory. +# The `./build` directory contains the scratch work for building the wheels. +# +# The build process is defined in the `build_ibpy.sh` script. +# +# By using Docker, you can build the wheels in a clean environment that is isolated from your local machine. +# It also will work on any platform that supports Docker. + +version: '3.8' + +services: + build: + image: python:3.10 + environment: + - IB_VERSION + volumes: + - .:/app + - ./build:/build + - ./dist:/dist + command: /bin/bash -c "/app/build_ibpy.sh" \ No newline at end of file