Skip to content

@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:

  • bars yields Bar objects in ascending t order. Gaps (e.g. non-trading days) MUST be omitted rather than filled with synthetic bars.
  • bars respects the half-open interval: the first bar's t is >= range.from and the last bar's t is < range.to.
  • fundamentals (optional) returns a snapshot as of t; returning undefined is valid when no data is available.
  • events (optional) yields events in ascending t order, filtered to the requested kinds.

Reference implementations: use vi.fn() in tests or provide a typed mock that returns pre-seeded bar arrays.

Example

ts
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

ParameterTypeDescription
assetAssetThe instrument to fetch bars for.
rangeDateRangeHalf-open date range; range.from inclusive, range.to exclusive.
freqFrequencyBar width. '1d' returns one bar per trading day.

Returns

AsyncIterable<Bar>

An async iterable of Bar objects.


events()?

optional events(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

ParameterTypeDescription
rangeDateRangeHalf-open date range.
kindsreadonly EventKind[]Event categories to include.

Returns

AsyncIterable<DataEvent>

An async iterable of DataEvent objects.


fundamentals()?

optional fundamentals(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

ParameterTypeDescription
assetAssetThe instrument to query.
tDateThe 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.

Released under the MIT License.