@livefolio/sdk / DataFeed
Interface: DataFeed
Defined in: interfaces/data-feed.ts:86
Market-data source. Provides price bars, fundamentals, and corporate events.
Implementations MUST guarantee:
barsyields Bar objects in ascendingtorder. Gaps (e.g. non-trading days) MUST be omitted rather than filled with synthetic bars.barsrespects the half-open interval: the first bar'stis>= range.fromand the last bar'stis< range.to.fundamentals(optional) returns a snapshot as oft; returningundefinedis valid when no data is available.events(optional) yields events in ascendingtorder, filtered to the requestedkinds.
Reference implementations: use vi.fn() in tests or provide a typed mock that returns pre-seeded bar arrays.
Example
import type { DataFeed, Asset, DateRange } from '@livefolio/sdk';
import { vi } from 'vitest';
const feed: DataFeed = {
bars: vi.fn().mockImplementation(async function* () {
yield { t: new Date('2024-01-02'), open: 100, high: 102, low: 99, close: 101, volume: 1_000_000 };
}),
};Methods
bars()
bars(
asset,range,freq):AsyncIterable<Bar>
Defined in: interfaces/data-feed.ts:99
Streams price bars for asset over the half-open interval [range.from, range.to) at the requested freq granularity.
Bars MUST be yielded in ascending t order. Non-trading periods MUST be omitted (sparse output is expected and normal).
Parameters
| Parameter | Type | Description |
|---|---|---|
asset | Asset | The instrument to fetch bars for. |
range | DateRange | Half-open date range; range.from inclusive, range.to exclusive. |
freq | Frequency | Bar width. '1d' returns one bar per trading day. |
Returns
AsyncIterable<Bar>
An async iterable of Bar objects.
events()?
optionalevents(range,kinds):AsyncIterable<DataEvent>
Defined in: interfaces/data-feed.ts:121
Streams corporate events within range filtered to the requested kinds. Optional — providers that do not carry event data may omit this.
Events MUST be yielded in ascending t order.
Parameters
| Parameter | Type | Description |
|---|---|---|
range | DateRange | Half-open date range. |
kinds | readonly EventKind[] | Event categories to include. |
Returns
AsyncIterable<DataEvent>
An async iterable of DataEvent objects.
fundamentals()?
optionalfundamentals(asset,t):Promise<Readonly<Record<string,string|number|null>>>
Defined in: interfaces/data-feed.ts:109
Returns a snapshot of fundamental data for asset as of t. Optional — not all data providers carry fundamentals.
Parameters
| Parameter | Type | Description |
|---|---|---|
asset | Asset | The instrument to query. |
t | Date | The point-in-time date for the snapshot. |
Returns
Promise<Readonly<Record<string, string | number | null>>>
A flat record of fundamental values, or undefined if unavailable.