oarjones/mcp-ibkr-trader
If you are the rightful owner of mcp-ibkr-trader and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
The MCP-IBKR Trader is an autonomous trading system that integrates a Master Control Program (MCP) with the Interactive Brokers Gateway for efficient trading operations.
mcp-ibkr-trader
Autonomous trading system connecting a Master Control Program (MCP) with Interactive Brokers Gateway.
Quick Start
-
Install dependencies:
pip install -r requirements.txt -
Run the server:
uvicorn mcp_server.main:app --reload -
Run tests:
pytest -q -
Example usage:
curl -s -X POST http://localhost:8000/tool/market_data.get_bars \ -H 'Content-Type: application/json' \ -d '{"symbol":"EUR.USD","asset_type":"FX","tf":"1m","start":"2025-08-01T07:00:00Z","end":"2025-08-01T07:30:00Z"}'
Configuration
The system can be configured via config.example.yaml. Key settings include:
ibkr.market_data.hist_defaults.outside_rth: A boolean flag to control whether historical data requests include data outside Regular Trading Hours (RTH).- If
true,useRTHis set to0(data outside RTH is included). - If
false,useRTHis set to1(only RTH data is included).
- If
IBKR Adapter Details
The ibkr_adapter module includes several refinements for robust interaction with the Interactive Brokers TWS API:
-
Real-time Subscription Management:
- Teardown on Disconnect: Active real-time market data and real-time bars subscriptions are automatically cancelled when the
TWSClientdisconnects, preventing orphaned subscriptions and resource leaks. - Resubscription on Reconnect: Upon successful reconnection to the TWS Gateway, the adapter attempts to re-establish any real-time market data or real-time bars subscriptions that were active prior to the disconnection. This ensures continuity of data streams.
- Teardown on Disconnect: Active real-time market data and real-time bars subscriptions are automatically cancelled when the
-
Historical Data Concurrency:
get_historical_datacalls are limited to a maximum of 2 concurrent requests using a threading semaphore. This helps to prevent pacing violations with the IBKR API. If more than 2 requests are made simultaneously, subsequent requests will wait or raise aTimeoutErrorif the semaphore cannot be acquired within the specified timeout.
-
get_barsDataFrame dtypes:- The
get_barsmethod inibkr_adapter/adapter.pyensures consistent data types for the returned Pandas DataFrame:open,high,low,close:float64volume:Int64(nullable integer)ts(timestamp):datetime64[ns](timezone-naive) This guarantees data quality for subsequent analytical operations.
- The