From b624a54b3e4d630352ca13f0627b56ee97b6c57d Mon Sep 17 00:00:00 2001 From: Dinger Date: Thu, 11 Jun 2026 07:20:05 +0000 Subject: [PATCH] fix(docs): refine IBKR TWS port docs with official IB references Align comments and trading guide with IB defaults (7496 live, 7497 paper) and link to the official TWS API initial setup documentation. Co-authored-by: Cursor --- backend_api_python/app/services/ibkr_trading/client.py | 4 ++-- backend_api_python/app/services/live_trading/factory.py | 2 +- docs/IBKR_TRADING_GUIDE_EN.md | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/backend_api_python/app/services/ibkr_trading/client.py b/backend_api_python/app/services/ibkr_trading/client.py index d311b0b69..40b3cdf1d 100644 --- a/backend_api_python/app/services/ibkr_trading/client.py +++ b/backend_api_python/app/services/ibkr_trading/client.py @@ -56,7 +56,7 @@ def _ensure_ib_insync(): class IBKRConfig: """IBKR connection configuration.""" host: str = "127.0.0.1" - port: int = 7497 # TWS Live:7496, TWS Paper:7497, Gateway Live:4001, Gateway Paper:4002 + port: int = 7497 # TWS Live:7496, TWS Paper:7497 (IB defaults), Gateway Live:4001, Gateway Paper:4002 client_id: int = 1 readonly: bool = False account: str = "" # Leave empty to auto-select first account @@ -80,7 +80,7 @@ class IBKRClient: Interactive Brokers Trading Client Usage: - config = IBKRConfig(port=7497) # TWS Paper default + config = IBKRConfig(port=7497) # IB default for TWS Paper client = IBKRClient(config) if client.connect(): diff --git a/backend_api_python/app/services/live_trading/factory.py b/backend_api_python/app/services/live_trading/factory.py index c831cc354..3366e7888 100644 --- a/backend_api_python/app/services/live_trading/factory.py +++ b/backend_api_python/app/services/live_trading/factory.py @@ -283,7 +283,7 @@ def create_ibkr_client(exchange_config: Dict[str, Any]): exchange_config should contain: - ibkr_host: TWS/Gateway host (default: 127.0.0.1) - - ibkr_port: TWS/Gateway port (default: 7497 = TWS Paper; TWS Live default is 7496) + - ibkr_port: TWS/Gateway port (default 7497 = TWS Paper per IB; Live TWS default 7496) - ibkr_client_id: Client ID (see below — must not collide with /api/ibkr UI) - ibkr_account: Account ID (optional, auto-select if empty) diff --git a/docs/IBKR_TRADING_GUIDE_EN.md b/docs/IBKR_TRADING_GUIDE_EN.md index 24a2b425e..aaa34888e 100644 --- a/docs/IBKR_TRADING_GUIDE_EN.md +++ b/docs/IBKR_TRADING_GUIDE_EN.md @@ -27,7 +27,7 @@ pip install ib_insync | TWS | 7496 | 7497 | | IB Gateway | 4001 | 4002 | -> Per IBKR TWS API defaults: production TWS uses **7496**, paper TWS uses **7497**. Ports are configurable in TWS/Gateway, so your client must match the value shown under API settings. +> Per [IB TWS API Initial Setup](https://interactivebrokers.github.io/tws-api/initial_setup.html): production TWS defaults to **7496**, paper TWS to **7497**. Ports are configurable in TWS/Gateway — your client must match the value shown under API → Settings. ## TWS / IB Gateway Configuration @@ -117,7 +117,7 @@ GET /api/ibkr/quote?symbol=AAPL&marketType=USStock ```bash curl -X POST http://localhost:5000/api/ibkr/connect \ -H "Content-Type: application/json" \ - -d '{"host": "127.0.0.1", "port": 7497, "clientId": 1}' # TWS Paper default + -d '{"host": "127.0.0.1", "port": 7497, "clientId": 1}' # 7497 = TWS Paper default ``` ### Place Order