Skip to main content

IBKRTools

PyPI version License: MIT Python Version Code style: black

A modern, user-friendly Python wrapper for Interactive Brokers TWS API, making it easier to download and manage market data.

Features

  • Simple Interface: Intuitive Pythonic interface for interacting with IBKR TWS API
  • Real-time Data: Stream real-time market data for stocks, forex, and futures
  • Historical Data: Fetch historical market data with flexible timeframes and bar sizes
  • Type Hints: Full Python type hints for better IDE support and code clarity
  • Thread-Safe: Built with thread safety in mind for concurrent operations
  • Comprehensive: Supports multiple asset classes and data types

Installation

pip install ibkrtools

Prerequisites

  • Python 3.8+
  • Interactive Brokers TWS or IB Gateway installed and running
  • Active IBKR account with market data subscriptions

Quick Start

Real-time Data

from ibkrtools import RealTimeData

# Initialize with your symbols
rt = RealTimeData(
    stocks=["AAPL", "MSFT"],
    forex=["EUR/USD"],
    futures=["ES"]
)

# Start streaming data
rt.run()

Historical Data

from ibkrtools import HistoricalData

# Fetch historical data
df = HistoricalData(
    stock_symbols=["AAPL"],
    forex_pairs=["EUR/USD"],
    future_symbols=["ES"],
    what_to_show="TRADES",
    duration="1 D",
    bar_size="1 hour",
    save=True,
    path="historical_data"
)

Documentation

RealTimeData

RealTimeData(
    stocks: List[str] = [],
    forex: List[str] = [],
    futures: List[str] = []
)

Methods

  • run(): Start the real-time data streaming
  • stop(): Stop the data streaming
  • get_latest(symbol: str): Get the latest data for a symbol

HistoricalData

HistoricalData(
    stock_symbols: List[str] = [],
    forex_pairs: List[str] = [],
    future_symbols: List[str] = [],
    what_to_show: str = "TRADES",
    duration: str = "1 D",
    bar_size: str = "1 hour",
    path: str = "Historical_Data",
    save: bool = True,
    verbose: bool = False
) -> pd.DataFrame

Parameters

  • what_to_show: Type of market data (e.g., "TRADES", "BID", "ASK", "MIDPOINT")
  • duration: Amount of historical data to fetch (e.g., "1 D", "1 M", "1 Y")
  • bar_size: Bar size (e.g., "1 min", "5 mins", "1 hour", "1 day")
  • path: Directory to save the data
  • save: Whether to save the data to disk
  • verbose: Enable verbose output

Examples

Real-time Data with Callbacks

def on_data(symbol, data):
    print(f"{symbol}: {data}")

rt = RealTimeData(stocks=["AAPL"])
rt.on_data = on_data
rt.run()

Fetching Historical Data for Multiple Assets

df = HistoricalData(
    stock_symbols=["AAPL", "MSFT"],
    forex_pairs=["EUR/USD", "GBP/USD"],
    duration="1 W",
    bar_size="1 hour"
)
print(df.head())

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Disclaimer

This software is for educational purposes only. Use it at your own risk. The author is not responsible for any financial losses incurred while using this software. Always test with paper trading before using real money.

Metadata

Release files for ibkrtools 0.1.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 ibkrtools 0.1.0
File Size Uploaded Provenance
ibkrtools-0.1.0.tar.gz 12.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for ibkrtools 0.1.0
File Interpreter ABI Platform
ibkrtools-0.1.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 21.5 kB

Release files / ibkrtools-0.1.0.tar.gz

Download URL ibkrtools-0.1.0.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
61b57ff3082c240548103cef7dcec0a86d48eaf69f7d5359c6f5ac51f6e96ae4
BLAKE2b-256 checksum
How to use checksums
ed8f64f4d0655270cfdb4060b462e2d83d2657f0896f0e671e96485a68d51bdc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.4

Release files / ibkrtools-0.1.0-py2.py3-none-any.whl

Download URL ibkrtools-0.1.0-py2.py3-none-any.whl
Size 9.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
0e9f013dcd6c0d4701c4ea63d39e218e71b05624f1896f5c88f09fd2c729dab0
BLAKE2b-256 checksum
How to use checksums
581ed99fcde1f9506942c36ab895cd0cf7322bf40b4826b5497cc3c0aa096883
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.4

Security for ibkrtools 0.1.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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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