Skip to main content

Data

Keisen handles caching, viewport, and redraws. Where K-lines come from is up to you — REST, WebSocket, or local JSON — as long as you hand in KlineBar[] under the contract below.

Common pattern: getData for history, onSubscribe for live updates; offline demos can pass data directly.

API

KeisenChart

PropTypeDescription
dataKlineBar[]Controlled static series; good for offline demos / precomputed arrays
getDataGetDataFnOn-demand history: (params) => Promise<KlineBar[]>
onSubscribeOnSubscribeFnOpen a live subscription; push via emit; may return unsubscribe
symbolstringInstrument id, passed through to getData / onSubscribe
resolutionResolutionInterval, default "1" (minute number string, or "1D" / "1W" / "1M")

Use either data or getData; add onSubscribe for live feeds.

KlineBar

One candle:

FieldTypeDescription
tnumberOpen time, millisecond Unix
o / h / l / cnumberOpen / high / low / close
vnumberVolume

getData(params)

Called on first load, when resolution / symbol changes, and when scrolling left into history. Fetch from your API using params and return time-ascending KlineBar[].

params fieldTypeDescription
resolutionResolutionCurrent interval
symbolstring?Current instrument (from prop)
fromnumber?Window start (ms)
tonumber?Window end (ms)
countBacknumber?Expected bar count (viewport estimate; use as limit)
const getData: GetDataFn = async ({ symbol, resolution, from, to, countBack }) => {
return api.getKlines({ symbol, interval: resolution, from, to, limit: countBack });
};

onSubscribe(params, emit)

Called when chart context is ready. Connect WS (or poll), push with emit; if you return a function, the library calls it on resolution change / unmount.

ParamTypeDescription
params.resolutionResolutionCurrent interval
params.symbolstring?Current instrument
emitSubscribeEmitPush entry point — see below
returnvoid | (() => void)Optional unsubscribe (close WS / clear timer)

emit methods:

MethodUsage
emit.bar(bar)Recommended default: route by t — same as last → update, greater → append, smaller → ignore
emit.updateLast(bar)Explicitly update the last bar (t must match last)
emit.append(bar)Explicitly append a new bar (t must be strictly greater than last)
emit.replace(bars)Replace the whole series

Most live sources (pushing “current candle”) only need emit.bar:

const onSubscribe: OnSubscribeFn = ({ symbol, resolution }, emit) => {
const ws = api.subscribe(symbol, resolution);
ws.on("candle", (bar) => emit.bar(bar));
return () => ws.close();
};

If upstream already separates tick refresh vs new bar:

ws.on("tick", (bar) => emit.updateLast(bar));
ws.on("bar", (bar) => emit.append(bar));

useKlineData()

Must be called inside the KeisenChart subtree. Prefer getData / onSubscribe for most cases; use this when UI needs to read/write the store directly.

ReturnTypeDescription
dataChartDataState (Ref in Vue)Current { kline, meta }
setData(patch) => voidShallow-merge into data / meta
replaceKline(bars) => voidReplace whole series
appendBars(bars) => voidAppend bars one by one
prependBars(bars) => voidPrepend history (pagination)

Example

getData loads a preset snapshot + onSubscribe mock push:

Loading interactive example…