Datafeed contract
The four-method interface that pipes bars + symbol metadata into ChartForge from any backend.
EliteChart talks to your backend through a single TypeScript
interface — Datafeed. You implement four methods (two required,
two optional); the chart handles caching, viewport refetch,
pagination, and live-bar merging.
Quick example
How it works
getBars(req) fetches a closed range of historical bars. The
chart calls this once on mount, then again whenever the user pans
into uncached territory. Return bars in ascending time order.
subscribe(req, onBar) opens a live stream. Call onBar once
per realtime update — for an in-progress bar this fires every tick;
for a closed bar it fires once. Return an unsubscribe function so
the chart can shut the stream down on unmount.
searchSymbols(query) (optional) powers the Symbol Search
modal. Return up to ~50 matches; the modal applies its own filtering.
resolveSymbol(id) (optional) returns metadata (tick size,
display name, exchange) for a single symbol. Required if you want
the price axis to format with the right decimals.
Bar shape
Use the as* constructors (asPrice, asTimestampMs, asVolume)
to brand raw numbers — this rules out unit-mismatch bugs at compile
time.
Variations
REST + polling
If you don't have WebSocket, return a setInterval from
subscribe:
Static fixture (tests / demos)
API
| Method | Required | Returns |
|---|---|---|
getBars(req) | yes | Promise<ReadonlyArray<Bar>> |
subscribe(req, onBar) | yes | () => void (unsubscribe) |
searchSymbols(query) | no | Promise<ReadonlyArray<SymbolInfo>> |
resolveSymbol(id) | no | Promise<SymbolInfo> |
See the API reference for the full type definitions.