11

I am looking to connect Python to the Interactive Brokers API. A google search reveals the availability of ibPy (see https://pypi.python.org/pypi/ib) however it appears this library is not maintained nor does it support Python 3. I also found https://github.com/colin1alexander/IbPython3 however the project has since been taken down.

I am aware that Quantopian uses Interactive Brokers as their execution agent but has a python front-end for algorithmic strategies. I am interested in knowing how they achieve this? More broadly however does anyone have any recommended resources/insights on how to connect python to interactive brokers?

feetwet
  • 3,248
  • 7
  • 46
  • 84

3 Answers3

11

Update

IB has now (Feb 2017) an official Python SDK (aka API). It supports Python 3 only (use IbPy if Python 2 is a must)

Supports API versions 9.72 and later.


The ibpy project found a new home under https://github.com/blampe/IbPy (and apparently a new owner with it)

As you may see in the README the API version supported is 9.70. Current IB API version is 9.72, but the existing ibpy works like a charm with the current versions of TWS (952 stable, 954 latest as of Jan-2015) and the corresponding 9.72 API.

If using Python 3 I would put most of the emphasis in the bytes vs unicode topic because the strings passed into the API (according to my experience) must be bytes (I usually do Python 2 with from future ... unicode_literals)

The examples provided with the ibpy distribution work out of the box.

Edit:

I have added a couple of working samples in other answers:

They use Queue to make it a complete working example (the same concept can be applied to deliver historic or real-time data) which deliver what's requested (or the corresponding error)

Community
  • 1
  • 1
mementum
  • 3,153
  • 13
  • 20
5

Interactive Brokers now has an official Python API (beta 9.73) download. It requires Python 3.1+.

See the docs.

ChaimG
  • 7,024
  • 4
  • 38
  • 46
chris
  • 7,222
  • 5
  • 31
  • 37
0

Apart from official IB's webinar. There is on-line workshop and Github as following.

Udemy: https://www.udemy.com/python-algo-trading-with-interactive-brokers/

Github: https://github.com/anthonyng2/ib

The content is relatively holistic and covering how to use python 3.x:

  1. Extract Account and Portfolio Information
  2. Placing Orders
  3. Request Market Data
  4. Obtain Historical Data
  5. Access Market Depth Information
  6. Download Real Time Bars
  7. Extract Executions Information, including commission report
Aqueous Carlos
  • 445
  • 7
  • 20