Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backend_api_python/app/services/ibkr_trading/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion backend_api_python/app/services/live_trading/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions docs/IBKR_TRADING_GUIDE_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down