A modern Python wrapper for Interactive Brokers TWS API
Project description
IBKRTools
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 streamingstop(): Stop the data streamingget_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 datasave: Whether to save the data to diskverbose: 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ibkrtools-0.1.0.tar.gz.
File metadata
- Download URL: ibkrtools-0.1.0.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61b57ff3082c240548103cef7dcec0a86d48eaf69f7d5359c6f5ac51f6e96ae4
|
|
| MD5 |
6f9c0ca88d47cf4a96ed6726eb94d0a8
|
|
| BLAKE2b-256 |
ed8f64f4d0655270cfdb4060b462e2d83d2657f0896f0e671e96485a68d51bdc
|
File details
Details for the file ibkrtools-0.1.0-py2.py3-none-any.whl.
File metadata
- Download URL: ibkrtools-0.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e9f013dcd6c0d4701c4ea63d39e218e71b05624f1896f5c88f09fd2c729dab0
|
|
| MD5 |
35b5d02e525006569092da3f4762dcf1
|
|
| BLAKE2b-256 |
581ed99fcde1f9506942c36ab895cd0cf7322bf40b4826b5497cc3c0aa096883
|