Historical bars
get_historical_barsGet historical OHLCV bars for any financial instrument, from intraday to monthly. Specify duration, bar size, and trading hours to retrieve the price history you need.
Instructions
Return historical OHLCV bars for one instrument, oldest first.
Bars cover `duration` back from `end` (now when omitted). Intraday bar times are UTC;
daily, weekly and monthly bars carry the trading date. Default limit 1000 bars, at
most 10000; when there are more, the NEWEST are kept and `truncated` is true (request
a shorter duration or larger bars to see older ones).
Limits (IBKR): bars of 30 seconds or less reach back about 6 months, allow short
durations only (1 secs up to 1800 S, 5 secs up to 3600 S, 10/15 secs up to 14400 S,
30 secs up to 28800 S), and are paced at about 60 requests per 10 minutes, 5 per
contract and data type in 2 seconds, and no identical request within 15 s (this
server answers identical requests from a 15-second cache). Larger bars are not paced
that way; IBKR's guide for the longest duration: 1 min bars about 1 D, 3 mins 1 W,
30 mins 1 M, daily bars years. Needs market-data permissions for the instrument (the
same subscription as live quotes). IBKR keeps no data for expired options; expired
futures need include_expired in the contract.
Errors: not_found (no such contract, or no data in the range: check
what_to_show, use_rth and get_head_timestamp), invalid_request (bad duration or
bar size combination), rate_limit (pacing; retry after the stated time),
ib_api_error 162 (pacing, permissions), request_timeout (shorten the request).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| end | No | End of the range, ISO 8601 (no offset means UTC). Omit for now. | |
| limit | No | Maximum number of items to return. Omit for the tool's default; larger values are capped. The result's truncated flag says whether more were available. | |
| use_rth | No | True: regular trading hours only. False: include pre-market, after-hours and overnight data. | |
| bar_size | No | Length of one bar, e.g. '5 secs', '1 min', '15 mins', '1 hour', '1 day'. | 1 hour |
| contract | Yes | The instrument. A con_id alone is unambiguous; otherwise give symbol and sec_type, plus expiry, strike and right for options. | |
| duration | No | How far back from end: '<n> S|D|W|M|Y', e.g. '1800 S', '5 D', '2 W', '6 M', '1 Y' (M means months). Words like '30 mins' also work. | 1 D |
| what_to_show | No | Data the values are built from. TRADES (not for forex), MIDPOINT, BID, ASK, BID_ASK (counts double for pacing), ADJUSTED_LAST (split/dividend adjusted; end must be empty), HISTORICAL_VOLATILITY and OPTION_IMPLIED_VOLATILITY (stocks, indexes), REBATE_RATE and FEE_RATE (stock loan), YIELD_BID, YIELD_ASK, YIELD_BID_ASK, YIELD_LAST (bonds), AGGTRADES (crypto). | TRADES |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| end | No | Requested end (UTC); null means now. | |
| bars | Yes | Oldest first; when truncated, the newest bars are the ones kept. | |
| total | Yes | How many bars IBKR returned before the limit. | |
| use_rth | Yes | True when only regular trading hours are included. | |
| bar_size | Yes | ||
| contract | Yes | ||
| duration | Yes | The duration sent to IBKR, e.g. '5 D' or '1800 S'. | |
| truncated | No | True when the result was cut to the limit. | |
| what_to_show | Yes |