Skip to main content

Module bar_align

Module bar_align 

Source
Expand description

Bar-aligned historical series for non-OHLCV streams.

The mlq backtester warmup is a slice factory: per (symbol, timeframe) it drives each indicator bar-by-bar. To feed the ~130 non-OHLCV mli indicators it needs, per (symbol, timeframe, stream), a series time-aligned to the OHLCV bar grid — one value per bar — that warmup routes into the matching mli update_* method. This module is dig3’s side of that contract: a fetch that returns, for (exchange, account, symbol, kind, range), a bar-aligned series pulled through the shared ExchangeHub REST surface.

Fill policy is decided by the nature of the stream, not a global flag (see Kind::fill_policy):

  • State streams (funding, OI, mark/index price, long/short ratio) are levels → last-value carry-forward onto the bar grid. A bar with no fresh observation carries the previous value (filled = true).
  • Flow streams (liquidation, aggTrade) are event flows → bucket-sum per bar, gaps are a real 0.0 (filled = false).

Kline-family kinds (mark/index/premium price klines) arrive already on the bar grid; they are returned verbatim as BarPoints, no resample needed.

Structs§

ScalarBar
One bar’s worth of a scalar non-OHLCV stream, aligned to the OHLCV grid.

Enums§

BarAlignedSeries
Bar-aligned series, shaped by the stream kind. Mirrors the kline path so mlq keys it the same way and warmup feeds it to the matching update_*.
FillPolicy
How a stream’s observations collapse onto a bar.

Functions§

bar_align_from_disk
Track-C read-path: read a recorded stream off its DiskStore and bar-align it in one call. Reads the last max_points records (the daemon appends forward-only, so the tail is the captured window), range-filters, and resamples per project/policy. Native-only — the wasm OPFS store has a divergent read error type; wasm consumers read points then call bar_align_points directly.
bar_align_points
Bar-align an in-memory series of recorded [DataPoint]s onto the OHLCV grid (Track C — daemon-recorded streams with no REST history: liquidations, L2, aggTrades). The forward-recording daemon (dig3 watch / Station persistence) writes typed points to a DiskStore<T>; a consumer reads them back (DiskStore::read_tail / Series) and feeds the slice here with a scalar projection to get the same bar-aligned shape the REST loader produces.
load_bar_aligned
Load a bar-aligned historical series for one (exchange, account, symbol, kind, interval) over [start_ms, end_ms).
load_for_key
Convenience wrapper keyed by SeriesKey. The interval is read from the key’s kline-family kind; non-kline scalar kinds require interval to be passed via load_bar_aligned directly (they carry no interval in the key).