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

Candles hooks

React bindings over the candles slice. The hooks own the source’s memoization, the subscription lifecycle, and error normalization; everything about how bars are fetched, paged, and streamed lives in core.

All reads.

Import

import { useBinanceCandleSource, useCandles, useCandleStream, useTradingViewDatafeed, type UseBinanceCandleSourceParameters, type UseCandlesParameters, type UseCandlesReturnType, type UseCandleStreamParameters, type UseCandleStreamReturnType, type UseTradingViewDatafeedParameters, } from "@symmio/trading-react";

The same hooks are also available from the @symmio/trading-react/candles subpath. Value types (Candle, CandleSource, CandleResolution, CandleSymbol, TradingViewDatafeed) come from @symmio/trading-core.

Choosing a hook

You wantUse
Historical bars through TanStack QueryuseCandles
The live bar — a price header, a sparkline, an imperative chartuseCandleStream
A full TradingView Charting Library widgetuseTradingViewDatafeed

All three need a source. Build it once with useBinanceCandleSource.

useBinanceCandleSource

Creates a memoized Binance CandleSource.

A source caches the venue’s exchangeInfo for its lifetime, so recreating it on every render would refetch that on every symbol resolve — and a new source identity tears down any live subscription built on it.

const source = useBinanceCandleSource();

Parameters

Takes the same options as createBinanceCandleSource.

NameTypeDefaultNotes
market?"usd-m-futures" | "spot""usd-m-futures"Futures symbols are perpetual contracts, matching what a SYMMIO market is.
restUrl?stringvenue defaultA regional mirror or your own caching proxy.
wsUrl?stringvenue defaultKeep the futures /market/ route — see the core page’s routing note.
resolveSymbol?(marketName: string) => string | undefinedupper-case identityPass a stable reference — it participates in the memo.
webSocketConstructor?WebSocketConstructorglobalThis.WebSocketPass the ws package in Node.

Return type

A CandleSource, stable for as long as its options are unchanged.

useCandles

Historical bars through TanStack Query.

const source = useBinanceCandleSource(); const { data, isLoading, error } = useCandles({ source, marketName: "BTCUSDT", resolution: "1m", from: rangeStart, to: rangeEnd, });

Parameters

NameTypeDefaultNotes
sourceCandleSourceIts id is part of the query key, so venues never share a cache entry.
marketNamestringMarket name as SYMMIO names it.
resolutionCandleResolutionMust be listed in source.supportedResolutions.
fromnumberRange start, unix ms, inclusive.
tonumberRange end, unix ms, exclusive.
limit?numberMax bars; the source pages internally to satisfy it.
query?QueryParameterTanStack overrides.

Return type

UseQueryResult<GetCandlesReturnType, SymmioRequestError>data.candles in ascending time order plus data.noMoreData, which tells a chart paging backwards to stop.

from/to are part of the query key. Passing a live Date.now() mints a new cache entry on every render — derive the range from state that only changes when the user actually pans or changes resolution.

useCandleStream

Subscribe to live bar updates for one market and resolution.

const { candle, closed, status, error } = useCandleStream({ source, marketName: "BTCUSDT", resolution: "1m", onCandle: (candle) => series.update(candle), onReset: () => refetchHistory(), });

Parameters

NameTypeDefaultNotes
sourceCandleSourceMust implement watchCandles; the hook stays closed otherwise.
marketNamestringChanging it tears down the old subscription.
resolutionCandleResolutionBar size to stream.
enabled?booleantrueSubscribe only when true.
onCandle?(candle: Candle, meta: CandleUpdateMeta) => voidCalled ahead of the state update. Read through a ref, so an inline arrow does not re-subscribe.
onReset?() => voidBars were missed during a reconnect — refetch history. Also read through a ref.

Return type

FieldTypeNotes
candleCandle | nullThe most recent bar, null until the first update.
closedbooleantrue when candle has finalized.
statusSocketStatusLive socket status.
errorSymmioRequestError | nullLast transport or parse error, normalized.

Returns the latest bar as state for simple cases (a price header, a sparkline). For a full chart, prefer the onCandle callback and let the charting library own the series — re-rendering a React tree on every tick is wasted work when the chart mutates its own canvas.

useTradingViewDatafeed

Create a memoized TradingView datafeed over a CandleSource.

const source = useBinanceCandleSource(); const datafeed = useTradingViewDatafeed({ source, exchange: "Binance" }); useEffect(() => { const widget = new TradingView.widget({ datafeed, symbol: "BTCUSDT", interval: "60" }); return () => widget.remove(); }, [datafeed]);

Parameters

source plus the presentation options of toTradingViewDatafeed (exchange?, session?, timezone?).

Return type

A TradingViewDatafeed to pass straight to widget({ datafeed }).

The datafeed owns its live subscriptions, so it must outlive a render — a new instance would orphan the sockets the chart is already holding. Keep the source stable (see useBinanceCandleSource) and this stays stable too.

Know which price you are drawing

Every source declares a priceBasis. Binance’s is reference-exchange — a third-party venue’s perp price, not the SYMMIO solver’s mark a trade settles against. Trade math (margin, PnL, liquidation, TP/SL) must read the Price Service, never the chart’s series.

Last updated on