Skip to content

@livefolio/sdk / LiveEvent

Type Alias: LiveEvent<F, _S>

LiveEvent<F, _S> = { features: F; portfolio: Portfolio; previewOrders: ReadonlyArray<Order>; previewPortfolio: Portfolio; prices: ReadonlyMap<AssetId, number>; t: Date; type: "mark"; } | BacktestSnapshot & object

Defined in: strategy/run-live.ts:28

Unified event stream from runLive. Discriminated union of two variants:

  • mark — emitted per tick. The strategy is run in PREVIEW mode (state is snapshot/restored, no executor call, no portfolio commit). Use this to render the wiggling rightmost chart point and the "if the session ended now, the strategy would do X" preview UX.
  • snapshot — emitted when a tick crosses a session boundary. The just-closed bar is finalized, strategy.build runs for real, orders are submitted to the executor, fills are applied, and state advances. Same shape as BacktestSnapshot from runBacktest (plus the type: 'snapshot' discriminant), so consumers can append snapshot events to the same chart array used by historical results.

Type Parameters

Type ParameterDefault type
F extends FeaturesFeatures
_Sunknown

Union Members

Type Literal

{ features: F; portfolio: Portfolio; previewOrders: ReadonlyArray<Order>; previewPortfolio: Portfolio; prices: ReadonlyMap<AssetId, number>; t: Date; type: "mark"; }

NameTypeDescriptionDefined in
featuresFFeatures recomputed for the in-progress session.strategy/run-live.ts:41
portfolioPortfolioPortfolio at the start of the current session — unchanged by the preview.strategy/run-live.ts:34
previewOrdersReadonlyArray<Order>Orders the strategy would emit if the session closed at the current tick price. Computed from a state SNAPSHOT — the returned state value is discarded, so no committed state is mutated.strategy/run-live.ts:47
previewPortfolioPortfolioBest-effort placeholder — returns the unchanged portfolio. A future simulateFills(orders, prices) helper will compute the hypothetical post-rebalance NAV that would result from applying previewOrders at prices. Until then, consumers compute NAV themselves from portfolio + prices.strategy/run-live.ts:55
pricesReadonlyMap<AssetId, number>Per-asset accumulating close so far in the current session. Only assets that have received at least one tick this session appear in the map.strategy/run-live.ts:39
tDateWall-clock arrival time of this tick.strategy/run-live.ts:32
type"mark"-strategy/run-live.ts:30

BacktestSnapshot & object

Released under the MIT License.