A modern, user-friendly Python wrapper for Interactive Brokers TWS API, making it easier to download and manage market data.
- Simple Interface: Intuitive Pythonic interface for interacting with IBKR TWS API
- Real-time Data: Stream and save real-time market data for stocks, forex, and futures
- Historical Data: Fetch historical market data with flexible timeframes and bar sizes
- Thread-Safe: Built with thread safety in mind for concurrent operations
- Comprehensive: Supports multiple asset classes and data types
- Foreign Equities: Fetch data for non-US equities
- Options Data: Fetch data for options
- Data Feeding: Feed incoming data into your own strategy
- Order Placement: Place orders (OCA, Multileg, etc.)
pip install ibkrtools- Python 3.8+
- Interactive Brokers TWS installed and running
- Enabling Ibapi use on TWS
- Active IBKR account with market data subscriptions
RealTimeData(
stocks: List[str] = [],
forex: List[str] = [],
futures: List[str] = []
)Fetches and saves in real time, bid, ask, bidsize, and asksize to "RealTimeData/Stocks(Futures, or Forex)"
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.DataFramewhat_to_show: Type of market data (see https://ibkrcampus.com/campus/ibkr-api-page/twsapi-doc/#historical-whattoshow)duration: Amount of historical data to fetch (see https://ibkrcampus.com/campus/ibkr-api-page/twsapi-doc/#requesting-historical-bars)bar_size: Bar size (see https://ibkrcampus.com/campus/ibkr-api-page/twsapi-doc/#requesting-historical-bars)path: Directory to save the datasave: Whether to save the data to diskverbose: Enable verbose output
from ibkrtools import RealTimeData
# Initialize with your symbols
rt = RealTimeData(
stocks=["AAPL", "MSFT"],
forex=["EUR/USD"],
futures=["ES"]
)
# Start streaming data
rt.run()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"
)Contributions are welcome! Please feel free to submit a Pull Request.
This project, except ibapi is licensed under the MIT License - see the LICENSE file for details. The ibapi is 100% developed & owned by Interactive Brokers LLC ("IB"). By using this package (ibpy-native), you are assumed that you agreed the TWS API Non-Commercial License.
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.