Skip to Content
Symmio Trading-SDK — the SDK surface for builders on Arbitrum
CoreCandleswatchBinanceKlines

watchBinanceKlines

Stream live bar updates for one Binance symbol and interval. This is the low-level stream in Binance’s own vocabulary — most consumers call CandleSource.watchCandles (or the useCandleStream hook) and never touch it; it is exported for anyone assembling their own source.

import { watchBinanceKlines } from "@symmio/trading-core"; const unwatch = watchBinanceKlines({ wsUrl: "wss://fstream.binance.com/market/stream", symbol: "BTCUSDT", interval: "1m", webSocketConstructor: WebSocket, onCandle: (candle, { closed }) => console.log(candle.close, closed), });

Parameters

wsUrlstring

Combined-stream WebSocket endpoint (…/stream). For futures this must be the /market/ route — see the routing note on createBinanceCandleSource.

symbolstring

Binance symbol, upper-case (e.g. "BTCUSDT").

intervalstring

Binance interval string (e.g. "1m"), not an SDK resolution. Translate with toBinanceInterval.

webSocketConstructorWebSocketConstructor

WebSocket implementation to dial with.

onCandle(candle: Candle, meta: CandleUpdateMeta) => void

Called for each update to the bar, and once more with closed: true when it closes.

onReset() => voidoptional

Called after a reconnect, when bars may have been missed. Refetch history rather than splicing a live bar onto a stale series.

onStatusChange(status: SocketStatus) => voidoptional

Called whenever the connection status changes.

onError(error: SymmError) => voidoptional

Called on a transport or parse error (BINANCE_KLINES_SOCKET_ERROR); does not stop the subscription.

Returns

Unwatch
An unwatch function that closes the connection.

Guarantees

  • One connection per call. Deliberate at this scale — a chart holds exactly one subscription — and it keeps the reconnect and unsubscribe paths trivially correct.
  • Reconnects re-subscribe themselves. Binance drops idle connections after 24 hours; the reconnecting socket re-dials, re-sends the SUBSCRIBE frame, and fires onReset so the consumer refetches the bars missed in the gap.
  • Frames are matched on symbol and interval. Matching on symbol alone lets two charts on different intervals feed each other’s series.
  • Both combined-stream ({ stream, data }) and raw frame shapes are parsed, so the same code works against either endpoint form.
Last updated on