Stream live bars
subscribe_barsLoads recent historical bars and keeps them live, updating the newest bar and appending new ones for real-time monitoring.
Instructions
Load recent bars of any size and keep the newest bar updating live.
First loads `duration` of history (like get_historical_bars), then IBKR updates the
last bar and appends new ones as time passes. get_subscription_data returns the
bars oldest first (the newest 100 by default; the server keeps up to 5000). One
stream per contract and parameter set: subscribing again returns the same handle.
Counts against IBKR's historical data pacing (about 60 requests per 10 minutes;
error 162 on a violation) and needs market data permissions. Stop it with
unsubscribe.
Errors: not_found if IBKR has no bars for the period (try a longer duration or
use_rth=false), ib_api_error 321 if IBKR rejects the combination of bar size,
duration and what_to_show (the message names the field).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| use_rth | No | True: regular trading hours only. False: include pre-market, after-hours and overnight data. | |
| bar_size | Yes | Length of one bar, 5 secs or more, e.g. '5 secs', '1 min', '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 much history to load first: a number and a unit, S (seconds), D, W, M or Y, e.g. '3600 S', '1 D', '2 W'. | 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 |
|---|---|---|---|
| key | Yes | What it streams for: the contract id plus parameters. | |
| kind | Yes | What streams: quotes, depth, tick_by_tick, realtime_bars, bars, scanner, news_bulletins, news or display_group. | |
| contract | No | The instrument, when there is one. | |
| created_at | Yes | ||
| idle_ttl_s | Yes | Seconds without a read before it is cancelled. | |
| deduplicated | No | True when an identical stream was already open and its handle was returned instead of opening a second one. | |
| subscription_id | Yes | Handle for get_subscription_data and unsubscribe. |