Skip to main content

A Python Framework for Interactive Brokers TWS API

Project description

IB Quant

A command line interface and Python framework for the Interactive Brokers APIs.

Overview

IB Quant leverages ib-insync to interface with Interactive Brokers TWS or Gateway.

The CLI is named ib.

After installing ibquant, ib's command groups can be shown in terminal with:

ib --help

For now, the CLI mostly serves to replace pytest as qualifying tests that a function or method is working as intended before including in a script. Most CLI commands replicate tasks that can be easily accomplished in the TWS platform.

The end goal is that these CLI commands come together in a high level command such as ib trader run --strategy=some_strategy_name.py to have core.Trader run the given strategy and perform appropriate pre, intra, and post trade reporting (logging) requirements, if any.

Core Classes and Mixin Interfaces

core.AppBase serves as a base for all other core classes

core.Trader drives a user defined strategy in live trading

core.Brute enables brute force optimization of rules based trading strategies

core.Learner is used to optimize gradient based learning strategies

mixins.AccountMixins enables account features for non-advisor accounts

mixins.AdvisorMixins enables features for an advisor account (groups, model portfolios)

mixins.ConnectionMixins handles the connection to the running TWS or Gateway sesion

mixins.ContractMixins provides an extended class to define contracts for the TWS API

mixins.DataMixins provides utilities for fetching historical data, and for streaming top of book or limit order book data.

mixins.OrderMixins provides interfaces for several TWS order types

mixins.StrategyMixins provides a base class for user defined strategies

core.Learner should be used with my ML template, lightning-pod

Installation

The package can be installed for standard use or for development.

Required dependencies for standard use as a package are shown in setup.cfg under install_requires of the options group.

Dev dependencies are shown in setup.cfg under the options.extras_require group.

Installing the package for standard use

ibquant is available via PyPi with pip. Installation can be done with:

conda

conda env create -n ibquant python -y
conda activate ibquant
pip install ibquant

venv

cd {{ path to your project }}
python3 -m venv .venv/
# Activate the environment
# Linux and MacOS
source .venv/bin/activate
# Windows
.venv\Scripts\activate.bat
# install the package
pip install ibquant

Installing the package for development

After cloning the repo, the framework can be installed for development with:

# creating a virtual environment
cd {{ path to ibquant clone }}
python3 -m venv .venv/
# Activate the environment
# Linux and MacOS
source .venv/bin/activate
# Windows
.venv\Scripts\activate.bat
# install an editable version of the package
pip install -e ".[dev]"

Usage

After installing ibquant, log into a TWS paper account and test example flows from terminal with:

ib advisor managed-accounts
ib account summary
ib contract lookup --contract-type=Future

Each of the above commands will prompt the user for required inputs.

localSymbol, multiplier, and currency prompts of ib contract lookup are not required

Ecosystem

Aside from using ib-insync, ibtrader also provides users with:

Factors, Indicators, Studies, Strategies

Zipline Reloaded provides factors and indicators in the pipeline API. TA-Lib is installed as a dependency of Zipline. Most factors and indicators of both libraries will be reachable via ibtrader.factors.

Indicator definitions can be found at:

Sample strategies can be found via the link below.

Suggested Reading and References

Algorithmic Trading

The texts shown below are merely suggestions; each text is written by Dr. Yves Hilpisch. The content is not heavy on math notation, and the author has done a great job at providing code examples.

Python

As with the above, the books shown below are considered standard suggestions.

Aside from the texts, and possibly a more suitable way to learn professional level Python programming, is to look at the source code of the Quantopian reloaded projects.

Trading Information and Education

The resources shown below are free, and sourced from reputable providers.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

ibquant-0.1.1-py3-none-any.whl (51.2 kB view details)

Uploaded Python 3

File details

Details for the file ibquant-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ibquant-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 51.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for ibquant-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 02e58845bac10a043dbf3f7fdb95fb92c10eeca10902b4056856e0cd9f3f947a
MD5 f65fe21f795d5c5f38effa716017d986
BLAKE2b-256 3de24b817f1e9eb6bfca663268e94888e288212f4e1080604680cbeb35350008

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page