Skip to main content

Build PyVersion PyPiVersion License Docs

ib_async

Update

Under new management. See original discussions for recent history. Create new discussions or PRs or issues under the new primary repo for ongoing updates.

New contributions welcome. We are open to adding more maintainers with commit access if your updates and understanding of IBKR/TWS and Python are all high quality.

This is a small project with a userbase of widely varying experience and knowledge, so if you open issues which are more about IBKR problems and less about client problems, we may not be able to assist you unless your problem is a direct client issue and not one of many IBKR API edge cases. Feel free to open Discussion topics about anything if you are unsure about a problem being IBKR, our client, or your own code usage.

Introduction

The goal of the ib_async library is to make working with the Trader Workstation API from Interactive Brokers as easy as possible.

The main features are:

  • An easy to use linear style of programming;
  • An IB component that automatically keeps in sync with the TWS or IB Gateway application;
  • A fully asynchonous framework based on asyncio and eventkit for advanced users;
  • Interactive operation with live data in Jupyter notebooks.

Be sure to take a look at the notebooks, the recipes and the API docs.

Installation

pip install ib_async

Requirements:

  • Python 3.10 or higher
    • We plan to support Python releases 2 years back which allows us to continue adding newer features and performance improvements over time.
  • A running IB Gateway application (or TWS with API mode enabled)
  • Make sure the API port is enabled and 'Download open orders on connection' is checked.
  • You may also want to increase the Java memory usage under Configure->Settings->Memory Allocation to 4096 MB minimum to prevent gateway crashes when loading bulk data.

The ibapi package from IB is not needed. ib_async implements the full IBKR API protocol internally.

Build Manually

First, install poetry:

pip install poetry -U

Installing Only Library

poetry install

Install Everything (enable docs + dev testing)

poetry install --with=docs,dev

Generate Docs

poetry install --with=docs
poetry run sphinx-build -b html docs html

Check Types

poetry run mypy ib_async

Build Package

poetry build

Upload Package (if maintaining)

poetry install
poetry config pypi-token.pypi your-api-token
poetry publish --build

Example

This is a complete script to download historical data:

from ib_async import *
# util.startLoop()  # uncomment this line when in a notebook

ib = IB()
ib.connect('127.0.0.1', 7497, clientId=1)

contract = Forex('EURUSD')
bars = ib.reqHistoricalData(
    contract, endDateTime='', durationStr='30 D',
    barSizeSetting='1 hour', whatToShow='MIDPOINT', useRTH=True)

# convert to pandas dataframe (pandas needs to be installed):
df = util.df(bars)
print(df)

Output:

                   date      open      high       low     close  volume
0   2019-11-19 23:15:00  1.107875  1.108050  1.107725  1.107825      -1
1   2019-11-20 00:00:00  1.107825  1.107925  1.107675  1.107825      -1
2   2019-11-20 01:00:00  1.107825  1.107975  1.107675  1.107875      -1
3   2019-11-20 02:00:00  1.107875  1.107975  1.107025  1.107225      -1
4   2019-11-20 03:00:00  1.107225  1.107725  1.107025  1.107525      -1
..                  ...       ...       ...       ...       ...     ...
705 2020-01-02 14:00:00  1.119325  1.119675  1.119075  1.119225      -1

Documentation

The complete API documentation.

Changelog.

Disclaimer

The software is provided on the conditions of the simplified BSD license.

This project is not affiliated with Interactive Brokers Group, Inc.

Official Interactive Brokers API Docs

History

This library was originally created by Ewald de Wit as tws_async in early-2017 then became the more prominent ib_insync library in mid-2017. He maintained and improved the library for the world to use for free until his unexpected passing in early 2024. Afterward, we decided to rename the project to ib_async under a new github organization since we lost access to modify anything in the original repos and packaging and docs infrastructure.

The library is currently maintained by Matt Stancliff and we are open to adding more committers and org contributors if people show interest in helping out.

Metadata

Release files for ib_async 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ib_async 1.0.0
File Size Uploaded Provenance Actions
ib_async-1.0.0.tar.gz 72.1 kB Without provenance Details for ib_async-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ib_async 1.0.0
File Interpreter ABI Platform Actions
ib_async-1.0.0-py3-none-any.whl Python 3 none any Details for ib_async-1.0.0-py3-none-any.whl

Total release size: 147.0 kB

Release files / ib_async-1.0.0.tar.gz

Download URL ib_async-1.0.0.tar.gz
Size 72.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0781e5f5e5b6f7fd3bbd3dc4f9b35af97cb25b12509cce01480cf22e0616f784
BLAKE2b-256 checksum
How to use checksums
0aacff0e9acead35c8d9290245d3a6a25e004eacec41bc3ecc890e269b01d214
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.10.5 Darwin/23.3.0

Release files / ib_async-1.0.0-py3-none-any.whl

Download URL ib_async-1.0.0-py3-none-any.whl
Size 74.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
825f87d633c05b8d4f6971feaa2abbe9648b3d1da589d095b32b451c37dac0ed
BLAKE2b-256 checksum
How to use checksums
28eb9270a55322a9f0c0b30dd036de1c2097f9235a892d36ca8262adbd5733b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.10.5 Darwin/23.3.0

Security for ib_async 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page