Documentation Index
Fetch the complete documentation index at: https://mathematicalcompany.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Partially verified. As of v0.8.8+, the IBKR client has been audited against
the official Client Portal Web API documentation. Significant fixes were applied:
- Removed the fabricated
paper-api.ibkr.comhost. IBKR paper accounts share the sameapi.ibkr.comhost as live accounts; the distinction is in the account ID prefix (DU*for paper). Pass yourDU…account ID, not apaper=Trueflag. - Positions endpoint now includes the required
{pageId}path segment and walks pages until the result set is exhausted (was returning 404 / nothing before). - Order submission now handles chained confirmation prompts (up to 5 hops). Previously the second prompt’s reply id was silently returned as the order id, corrupting downstream tracking.
cancel_alland fill polling now filter results byaccount_id. Previously they touched orders/trades across every account on the session — dangerous on Financial Advisor or multi-account logins.- Commission strings like
"1.00 USD"parse correctly (was silently zeroing fees). - Timestamps now read
trade_time_r(epoch ms) — was returning0.0for every fill. - Contract multiplier is inferred from
secType(OPT/FOP→ 100x). Options PnL was previously off by 100x. - On 401, the client calls
/iserver/auth/ssodh/init(which actually re-establishes the brokerage session) instead of just/tickle(which only keeps it alive). acctIdis now included in the order body for FA / multi-account safety.
- The
private_key_jwtSSO bearer (mint a short-lived JWT via the OAuth 2.0 client-credentials handshake; refresh out-of-band before expiry). - A local Client Portal Gateway running at
https://localhost:5000/v1/api(pass the gateway URL viaapi_url=and any non-empty placeholder token). - An OAuth 1.0a HMAC-SHA256 signer running as a sidecar that mints session bearers; this client does NOT implement OAuth 1.0a signing itself.
DU*) or small size first. Polymarket remains the only exchange with
end-to-end verified live trading.Quick Setup
Credentials
- Explicit
- Environment variables
Configuration
| Field | Default | Description |
|---|---|---|
access_token | None | OAuth2 access token (env: IBKR_ACCESS_TOKEN) |
account_id | None | IBKR account ID, e.g. "U1234567" (env: IBKR_ACCOUNT_ID) |
paper | True | Use paper trading URL |
api_url | Auto | Override API URL (set automatically from paper flag) |
Paper vs Live
Authentication
IBKR uses OAuth2 Bearer token auth via the Client Portal API:Authorization: Bearer {access_token}
Market Data Feed
IBKR market data via REST snapshot polling:| Field | Type | Default | Description |
|---|---|---|---|
conids | list[str] | required | IBKR contract IDs to poll |
access_token | str | None | Override access token (defaults to env var) |
api_url | str | Auto | Override API URL |
paper | bool | True | Use paper trading URL |
interval | float | 5.0 | Polling interval in seconds |
ForecastEx Event Contracts
IBKR’s ForecastEx is a CFTC-regulated event contracts platform, similar to Polymarket and Kalshi. You can trade event contracts on economics, elections, and more directly through the sameInteractiveBrokers exchange.
ForecastEx contracts use IBKR conids just like stocks and options. Look up conids in the IBKR contract search or TWS.
Symbol Mapping
IBKR uses integer contract IDs (conids):| Horizon Field | IBKR Field | Notes |
|---|---|---|
OrderRequest.market_id | conid | Integer contract ID as string |
OrderRequest.order_side | side | "BUY" or "SELL" |
OrderRequest.price | price | Limit order price |
OrderRequest.size | quantity | Number of shares/contracts |
IBKR uses
Side.Long for stock and option positions. Prediction market concepts like Side.Yes / Side.No only apply to ForecastEx event contracts.Multi-Exchange
Use IBKR for stock/options hedging alongside prediction markets:Getting API Keys
- Log in at interactivebrokers.com
- Navigate to Settings > API > OAuth2
- Register a client application and obtain an access token
- Note your account ID from the top of any account page (format:
U1234567) - For paper trading, create a paper account under Account Management