Live bars (SSE)
The Server-Sent Events contract for live K-lines: snapshot, forming, closed and status frames.
packages/core/src/data/live/types.ts and barsLive.ts.A connector streams live K-lines to the chart over Server-Sent Events. One connection carries one series: a source, a symbol, a period and a bar aggregation. Changing any of them closes the stream and opens a new one.
Endpoint
GET /api/v1/market-data/sources/{sourceId}/stream?symbol=…&period=…&barAggregation=…&instrumentId=…
Accept: text/event-stream| Query | Required |
|---|---|
symbol | Yes |
period | Yes |
barAggregation | Yes |
instrumentId | — |
instrumentId is the resolved instrument's stable id. It is sent only when known, so a bare code that exists on two exchanges still reaches the right one.
Frames
Each SSE data: line is one JSON frame. Comment lines (: keep-alives) and empty data are ignored.
type | Fields | Meaning |
|---|---|---|
snapshot | symbol: string period: string bars: LiveBar[] | The full tail of the series. Sent first and after a reconnect; the chart writes it in one batch and drops any pending closed bar. |
forming | symbol: string period: string bar: LiveBar | The bar that is still forming. Written together with a pending closed bar as one atomic update. |
closed | symbol: string period: string bar: LiveBar | A bar's final values. Held until the next forming bar arrives (or the stream stops), then written with it. |
status | symbol: string period: string status: string detail?: string | Connector state for the subscription, with optional detail. It does not change bars. |
LiveBar
| Field | Type | Required |
|---|---|---|
timestamp | number | Yes |
open | number | Yes |
high | number | Yes |
low | number | Yes |
close | number | Yes |
volume | number | — |
turnover | number | — |
timestamp is UTC milliseconds. Missing volume and turnover are written as 0.
data: {"type":"snapshot","symbol":"600519","period":"1min","bars":[…]}
data: {"type":"forming","symbol":"600519","period":"1min","bar":{"timestamp":…,"open":…,"high":…,"low":…,"close":…}}
data: {"type":"closed","symbol":"600519","period":"1min","bar":{…}}Connection state
The stream reports connecting, connected, disconnected. The browser's EventSource reconnects on its own; a connector can replay missed frames from Last-Event-ID.