Stream 5-second bars
subscribe_realtime_barsStream 5-second OHLCV bars for a contract into a ring buffer for retrieval and real-time analysis.
Instructions
Start streaming 5-second OHLCV bars for one contract into a ring buffer.
A new bar arrives every 5 seconds; get_subscription_data returns them oldest first
with open, high, low, close, volume, VWAP and trade count. Only 5-second bars exist;
for other sizes use subscribe_bars. One stream per contract, what_to_show and
use_rth: subscribing again returns the same handle. Uses a market data line and
counts against IBKR's historical data pacing. Needs market data permissions; TRADES
is not available for forex (use MIDPOINT). Errors 420 and 162 mean IBKR refused the
request (invalid for the contract, or pacing). Stop it with unsubscribe.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"contract": "<contract>"
},
"name": "subscribe_realtime_bars"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| use_rth | No | True: regular trading hours only. False: include pre-market, after-hours and overnight data. | |
| contract | Yes | The instrument. A con_id alone is unambiguous; otherwise give symbol and sec_type, plus expiry, strike and right for options. | |
| buffer_size | No | How many of the newest bars the server keeps (720 = one hour). | |
| what_to_show | No | Build bars from TRADES, MIDPOINT, BID or ASK prices. | 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. |