Skip to content

@livefolio/sdk / RoutingStreamingDataFeed

Class: RoutingStreamingDataFeed

Defined in: reference/routing-streaming-data-feed.ts:46

A StreamingDataFeed that delegates subscribe() to one of several underlying feeds based on the asset. Use this to compose vendors — e.g. Polygon for equities and a polling adapter for macro series — behind a single StreamingDataFeed instance accepted by runLive.

Routing rules:

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

Assets are grouped by routed feed (by reference identity) before calling upstream subscribe() — so a vendor adapter that opens one socket for [AAPL, MSFT] keeps doing that rather than receiving one-asset-at-a-time calls.

Example

ts
import { RoutingStreamingDataFeed, pollingStreamFromHistorical } from '@livefolio/sdk';

const feed = new RoutingStreamingDataFeed({
  equity: polygonStreaming,
  macro: pollingStreamFromHistorical({ feed: fredHistorical, freq: '1d', schedule: { kind: 'session-close', calendar: nyse } }),
});

Implements

Constructors

Constructor

new RoutingStreamingDataFeed(routes): RoutingStreamingDataFeed

Defined in: reference/routing-streaming-data-feed.ts:49

Parameters

ParameterType
routesReadonly<Partial<Record<"equity" | "macro", StreamingDataFeed>>> | RoutingStreamingDataFeedRouteFn

Returns

RoutingStreamingDataFeed

Methods

subscribe()

subscribe(assets): AsyncIterable<StreamingBar>

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

Subscribes to live tick updates for the given assets.

Frequency note: This interface intentionally omits a freq parameter. Bar/tick aggregation is the runtime's responsibility — see the runLive design in docs/specs/2026-05-02-v0.4-phase-9-streaming-design.md Decision #1 (resolved during design). Adapters emit raw ticks at whatever cadence the vendor provides; the runtime decides which session/bar each tick belongs to via the Calendar. Multi-frequency streaming (sub-daily strategies) is a separate phase, currently out of scope.

Parameters

ParameterTypeDescription
assetsreadonly Asset[]The instruments to subscribe to.

Returns

AsyncIterable<StreamingBar>

An open-ended async iterable of StreamingBar updates.

Implementation of

StreamingDataFeed.subscribe

Released under the MIT License.