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

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

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

After cloning the repo, the framework can be installed for use as intended with:

# assuming conda
conda env create -n ibquant -y
conda activate ibquant
pip install {{ path to ibquant clone }}

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 Distribution

ibquant-0.1.tar.gz (27.2 kB view hashes)

Uploaded Source

Built Distributions

ibquant-0.1.0-py3-none-any.whl (51.2 kB view hashes)

Uploaded Python 3

ibquant-0.1-py3-none-any.whl (36.0 kB view hashes)

Uploaded Python 3

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