@reincharts/datafeed

Datafeed adapters, realtime updates, aggregation and replay.

npm install @reincharts/datafeed

Everything here is also re-exported by the umbrella package reincharts.

Hooks

NameDescription
useBarReplayBar replay: hides bars after a start index and reveals them one by one (play, pause, step, step back, speed).
useDatafeedConnects a Datafeed to a chart: loads history, merges realtime bars, paginates backwards, resets on symbol / resolution change and ignores stale responses.

Functions

NameDescription
aggregateBarsBuilds higher timeframe bars (e.g.
alignSeriesAligns a second series (compare symbol) to base by time: each base item gets [key] set to the other bar with the same time.
alignTimeStart time of the bar containing time (ms epoch).
applyTickRealtime tick merge (pure): folds tick into the last bar or appends a new bar.
compareResolutionsCompares resolutions by duration (for sorting).
createMemoryDatafeedA datafeed serving in-memory bars, e.g.
createRandomDatafeedA browser-only demo / test feed: deterministic random-walk prices for any symbol and resolution (open / close consistent across resolutions and pages) plus a realtime ticker that updates the last bar and rolls new ones.
formatResolutionHuman label: "1s", "5m", "1h", "4h", "1D", "1W", "1M", "1Y" (style: "short", default) or "5 minutes", "1 hour" (style: "long").
isResolutionReturns true when the string is a valid resolution.
mergeBarRealtime merge (pure): replaces the last bar when bar.time equals it, appends when newer, and ignores older bars (returns data unchanged).
mergeBarsMerges two sorted series (e.g.
nextBarTimeStart time of the bar following the one that starts at (or contains) time.
normalizeResolutionCanonical resolution string: "1h" → "60", "1d" → "1D", "1y" → "12M", "1s" → "1S".
parseCsvParses CSV / TSV OHLC text (with a header row) into bars sorted by time.
parseResolutionParses a resolution string.
parseTimeValueDefault time cell parser (see ParseCsvOptions.parseTime).
resolutionToMsNominal bar duration in milliseconds (months count as 30 days).
sliceBarsReturns bars with time < to: the last countBack ones, or those >= from when countBack is 0.
sortBarsSorts by time and removes duplicates (the last occurrence wins).
ticksToBarsBuilds bars from trades (seconds or minute bars from ticks).
tickToBarUpdates (or starts) the bar for tick.
timeZoneOffsetOffset (ms) of timeZone from UTC at time: local wall-clock = time + offset.
toChartBarAdds date so the bar can be passed straight to <ChartCanvas data>.

Constants

NameDescription
DAYOne day in milliseconds.
HOUROne hour in milliseconds.
MINUTEOne minute in milliseconds.
RESOLUTIONSCommon resolutions, in increasing order (handy for interval pickers).
SECONDOne second in milliseconds.
WEEKOne week in milliseconds.

Types

NameDescription
AlignOptionsOptions for calendar alignment of bars.
AlignSeriesOptionsOptions of alignSeries.
BarOne OHLCV bar.
ChartBarA bar ready for <ChartCanvas data>: date makes the chart detect a time axis automatically.
CsvBarA parsed CSV / TSV row: OHLCV plus any extra column (numbers when numeric, strings otherwise).
DatafeedThe adapter between your backend and the chart: history requests, realtime updates and symbol search.
GetBarsRequestHistory request: bars with from <= time < to, at least the countBack most recent ones before to.
GetBarsResultHistory response.
MemoryDatafeedA Datafeed over in-memory arrays, with pushBar to simulate realtime updates.
MemoryDatafeedOptionsOptions of createMemoryDatafeed.
ParseCsvOptionsOptions of parseCsv.
ParsedResolutionA parsed resolution: count × unit (hours are expressed as minutes, years as months).
RandomDatafeedA demo Datafeed with deterministic history and a simulated realtime ticker.
RandomDatafeedOptionsOptions of createRandomDatafeed.
ResolutionBar interval in the common charting notation: "1S"/"5S" seconds, "1"/"5"/"15"/"60"/"240" minutes, "1D" days, "1W" weeks, "1M" months.
ResolutionUnit
SymbolInfoInstrument metadata .
TickA single trade / price update.
UseBarReplayOptionsOptions of useBarReplay.
UseBarReplayResultState and controls returned by useBarReplay.
UseDatafeedOptionsOptions of useDatafeed.
UseDatafeedResultState returned by useDatafeed.

On this page