Interactive Brokers API GET /iserver/marketdata/history
OHLC bars for a contract over a period, with bar size, start time, data source and outside hours option.
Risk warning: CFDs and spread bets are complex instruments and come with a high risk of losing money rapidly due to leverage. You can lose money on these products, and each provider publishes its own loss figure under FCA rules. You should consider whether you understand how they work and whether you can afford to take the high risk of losing your money. Automated and API trading can amplify losses through bugs, connectivity failures and runaway orders.
Each bar has o, h, l, c, v and t, a Unix time in milliseconds.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
| conidrequired | query | integer | IB contract ID of the instrument. |
| periodrequired | query | string | Length of the request, in min, h, d, w, m or y. Default 1d. |
| barrequired | query | string | Bar size, in S, min, h, d, w or m. Default 1min. |
| exchange | query | string | Exchange, or SMART, to request data from. |
| outsideRth | query | boolean | Include data outside regular trading hours. Default false. |
| startTime | query | string | Format YYYYMMDD-hh:mm:ss. |
| direction | query | integer | -1 (default): data ends at the current time. 1: data begins at startTime. |
| source | query | string | Last (default), Bid_Ask or Midpoint. |
Authentication headers
| Name | Type | Description |
|---|---|---|
| Authorization | string | OAuth only; the Gateway sends none. On the OAuth host this is the SSO bearer token IBKR's reference lists for this call. With the Client Portal Gateway on your own computer the browser login holds the session. Placeholder only. |
Request
Written from the method, path and parameters recorded on this page. No demo host is recorded as a plain address for this API, so the samples read the base address from an environment variable. Not executed against a live or demo account. Credentials are read from environment variables on your own machine and are never entered on this site. The request builder writes these same snippets, from the same record.
Python
# Set IBKR_BASE_URL as an environment variable first. Never paste real values into code.
# No demo host is recorded as a plain address for this API, so the base address is read from IBKR_BASE_URL.
# Replace each {placeholder}, "..." and 0 with a real value before running.
# Optional and not shown: headers Authorization; query parameters exchange, outsideRth, startTime, direction, source.
import os
import requests
BASE_URL = os.environ["IBKR_BASE_URL"]
headers = {}
params = {"conid": "{conid}", "period": "{period}", "bar": "{bar}"}
resp = requests.get(BASE_URL + "/iserver/marketdata/history", headers=headers, params=params, timeout=10)
resp.raise_for_status()
print(resp.json())JavaScript
// Set IBKR_BASE_URL as an environment variable first. Never paste real values into code.
// No demo host is recorded as a plain address for this API, so the base address is read from IBKR_BASE_URL.
// Replace each {placeholder}, "..." and 0 with a real value before running.
// Optional and not shown: headers Authorization; query parameters exchange, outsideRth, startTime, direction, source.
// Run as a module, for example a .mjs file, on a Node version that has fetch built in.
const BASE_URL = process.env.IBKR_BASE_URL;
const res = await fetch(BASE_URL + "/iserver/marketdata/history" + "?conid={conid}&period={period}&bar={bar}", {
method: "GET",
headers: {
},
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
console.log(await res.json());curl
# Set IBKR_BASE_URL as an environment variable first. Never paste real values into code.
# No demo host is recorded as a plain address for this API, so the base address is read from IBKR_BASE_URL.
# Replace each {placeholder}, "..." and 0 with a real value before running.
# Optional and not shown: headers Authorization; query parameters exchange, outsideRth, startTime, direction, source.
curl -X GET "$IBKR_BASE_URL/iserver/marketdata/history?conid={conid}&period={period}&bar={bar}"Response
A mock response. The values are invented, so check field names against the official reference.
{
"_mock": true,
"symbol": "AAPL",
"text": "APPLE INC",
"timePeriod": "1w",
"barLength": 86400,
"startTime": "20260911-13:30:00",
"points": 1,
"priceFactor": 100,
"volumeFactor": 100,
"outsideRth": false,
"mktDataDelay": 0,
"serverId": "MOCK-0001",
"data": [
{
"o": 188.5,
"h": 191.2,
"l": 187.9,
"c": 190,
"v": 0,
"t": 1789725600000
}
]
}Response schema, HTTP 200
Every field this site's OpenAPI file for Interactive Brokers declares for this response.
| Field | Type | Description |
|---|---|---|
| symbol | string | Not recorded |
| text | string | Not recorded |
| timePeriod | string | Not recorded |
| barLength | integer | Not recorded |
| startTime | string | Not recorded |
| chartPanStartTime | string | Not recorded |
| direction | integer | Not recorded |
| high | string | Not recorded |
| low | string | Not recorded |
| points | integer | Not recorded |
| priceFactor | integer | Not recorded |
| volumeFactor | integer | Not recorded |
| priceDisplayRule | integer | Not recorded |
| priceDisplayValue | string | Not recorded |
| negativeCapable | boolean | Not recorded |
| mdAvailability | string | Not recorded |
| mktDataDelay | integer | Not recorded |
| messageVersion | integer | Not recorded |
| outsideRth | boolean | Not recorded |
| serverId | string | Not recorded |
| travelTime | integer | Not recorded |
| data | array of values | Not recorded |
| o | number | Not recorded |
| h | number | Not recorded |
| l | number | Not recorded |
| c | number | Not recorded |
| v | number | Not recorded |
| t | integer | Unix time in milliseconds. |
interactivebrokers.comchecked
Limits that apply at Interactive Brokers
| Limit | Value | Scope | Source |
|---|---|---|---|
| Global requests a second (Web API) | 10 | Per authenticated username, that is per Web API session | ibkrcampus.comchecked corroborated by interactivebrokers.com/docs/web-api/trading/usage-and-availability/pacing-limitations |
| Historical market data requests | Either 10 req/s or 50 req/minute, as the page words it | GET /iserver/marketdata/history only | interactivebrokers.comchecked corroborated by ibkrcampus.com/campus/ibkr-api-page/webapi-doc/ |
| Market data snapshot requests a second | 10 | GET /iserver/marketdata/snapshot only | interactivebrokers.comchecked corroborated by ibkrcampus.com/campus/ibkr-api-page/webapi-doc/ |
| Order and trade list requests | 1 req/5 s | GET /iserver/orders and GET /iserver/trades, each counted on its own | interactivebrokers.comchecked corroborated by ibkrcampus.com/campus/ibkr-api-page/webapi-doc/ |
| Session validation requests a minute | 1 | GET /sso/validate only | interactivebrokers.comchecked corroborated by ibkrcampus.com/campus/ibkr-api-page/webapi-doc/ |
| Session keep alive requests a second | 1 | GET /tickle only | interactivebrokers.comchecked corroborated by ibkrcampus.com/campus/ibkr-api-page/webapi-doc/ |
Interactive Brokers API errors you may meet
- 0 (internal server error)Listed by the vendor as "Internal server error".
- 100 (max message rate exceeded)Max rate of messages per second has been exceeded.
- 10000 (cross currency combo)Listed by the vendor as "Cross currency combo error".
- 10001 (cross currency vol)Listed by the vendor as "Cross currency vol error".
- 10002 (non guaranteed legs)Listed by the vendor as "Invalid non-guaranteed legs".
- 10003 (ibsx not allowed)Listed by the vendor as "IBSX not allowed".
All Interactive Brokers API error codes, including 505 more not listed here.