Skip to content

@livefolio/sdk / RoutingDataFeed

Class: RoutingDataFeed

Defined in: reference/routing-data-feed.ts:54

A DataFeed that delegates each call to one of several underlying feeds based on the asset. Use this to compose vendors — e.g. Yahoo for equities and FRED for macro series — behind a single DataFeed instance accepted by runBacktest, FeatureRuntime, and BacktestExecutor.

Routing rules:

  • Map form: new RoutingDataFeed({ equity: yahoo, macro: fred }). Keys are asset.kind discriminants. The 90% case.
  • Function form: new RoutingDataFeed((a) => a.kind === 'macro' ? fred : yahoo). Use when routing depends on more than kind (e.g. allowlists).

The router does not implement events() — the optional method is genuinely absent ('events' in router === false). Cross-feed event fan-out is deferred until a real consumer materializes.

Example

ts
import { RoutingDataFeed } from '@livefolio/sdk';

const feed = new RoutingDataFeed({ equity: yahooFeed, macro: fredFeed });

const result = await runBacktest({
  strategy, range, initialPortfolio,
  dataFeed: feed,
  executor,
  calendar,
});

Implements

Constructors

Constructor

new RoutingDataFeed(routes): RoutingDataFeed

Defined in: reference/routing-data-feed.ts:57

Parameters

ParameterType
routesReadonly<Partial<Record<"equity" | "macro", DataFeed>>> | RoutingDataFeedRouteFn

Returns

RoutingDataFeed

Methods

bars()

bars(asset, range, freq): AsyncGenerator<Bar>

Defined in: reference/routing-data-feed.ts:68

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

AsyncGenerator<Bar>

An async iterable of Bar objects.

Implementation of

DataFeed.bars


fundamentals()

fundamentals(asset, t): Promise<Readonly<Record<string, string | number | null>>>

Defined in: reference/routing-data-feed.ts:73

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.

Implementation of

DataFeed.fundamentals

Released under the MIT License.