Mirexa

Wiki Concepts

Derived streams and lineage

How a Mirexa stream's candles can be made by the node itself from the same instrument's trades or shorter candles — the lineage declaration, the derivation rules, re-derivation, and query-time rollups.

Most candle data is computed from something finer: one-minute bars from trades, five-minute bars from one-minute bars, daily bars from intraday ones. Mirexa can do that computation itself. You declare a stream's lineage — what it is derived from — and from then on the node writes the stream's candles as the source arrives, re-derives them when the source is corrected, and marks a bar that was made from a source with a hole under it. For a one-off look at longer bars there are also rollups, computed at query time and stored nowhere, by the same rules.

Lineage

A lineage is part of a stream's metadata:[1]

Field Meaning Default
Source The stream derived from. —
Kind ticks (the source's trades) or candles (the source's shorter candles). —
CloseGrace How long past a bar's natural close late source data still joins the bar, rather than correcting it afterwards. 1 s
NoTradeLimit Ticks only: the longest silence between trades that is not missing data. 10 s
Since When the derived stream begins: set by the node to the moment of declaration (or, for rederive, the source's first datum). stamped by the node

The rules a declaration must obey:[2]

  • Same instrument. The source has the same exchange and symbol as the derived stream. It therefore shares the derived stream's partition and node, and derivation never crosses the network.
  • A tick source may be the stream itself: trades written to the tick half of binance:ETHUSDT:1m feed the candle half of the same id.
  • A candle source is shorter, and the derived timeframe is a whole multiple of it, at least twice as long (1m → 5m, 5m → 1h, 1h → 1d). Because every candle link strictly lengthens the interval and ticks are never derived, a cycle is impossible by construction.
  • Above one day, only 1d and 1w. A "two-day bar" has no calendar meaning.
  • A no-trade limit on a candle source is refused, not ignored.

Chains work: ticks → 1m → 5m → 1h → 1d, each link declared on its own stream.

How bars are made

From trades

The rules, applied per bar slot:[3]

  • A slot with trades is their OHLCV: open is the first trade by timestamp (ties in arrival order), close the last, high and low the extremes, volume the sum.
  • A slot with no trading time in the calendar is not written; the derived stream's own calendar files it as a closure.
  • A slot before the source's first trade (since Since) is nothing: the stream starts there.
  • A trade-less slot during trading time lies in a silence. A silence is short if it lasts no more than the no-trade limit and long otherwise, and a closure cuts a silence (it restarts at the next session open). A slot wholly inside short silence is written flat at the previous close with zero volume; a slot whose trading time is wholly inside long silence is a gap; a slot partly in long silence is written flat and marked INCOMPLETE; a slot whose silence could still turn out either way is pending and decided later.
  • Any written bar overlapping a long silence carries the INCOMPLETE mark.

From candles

A derived bucket expects the source slots that belong to it and have trading time. It is final once every expected source bar is present, once a source bar of a later bucket exists, or once the clock passes the bucket's end plus the grace plus one source interval (the quiet-source clock). Final, it is the OHLCV of what it holds — INCOMPLETE if an expected slot is missing or a source bar is itself incomplete — a gap if it holds nothing it expected, and a closure if it expected nothing.[4]

Bucketing and stamps

Below a day, a derived bar is aligned to the Unix epoch like any stream. A daily bar holds the trading date in the stream's calendar timezone (UTC without one) and is stamped 00:00 UTC of that date; a weekly bar holds the Monday-start week and is stamped Monday 00:00 UTC. The stamp keeps a constant stride while the window follows the local calendar, so a daily window is 23 or 25 hours across a daylight-saving change.[5] A session crossing local midnight (spot FX, for example) is split by date.

INCOMPLETE marks

A derived bar made while its source had a hole is stored and served, with an INCOMPLETE mark rather than being dropped: the data in it is real, and the mark says it was made from less than its whole window. In a query it is a bar (IsGap false) with reason INCOMPLETE (CandlePoint.Incomplete()), and a gap listing shows the mark as a range. A mark is resolved by filling the source's hole — the bar is re-derived and the mark cleared — or by accepting it (mirexa-cli gap accept, AcceptGap), which keeps the bar and sets the mark ACCEPTED. Marks propagate down a chain. See Gaps and trading calendars.

Live derivation

  • What triggers it. A live write of the source activates derivation of the streams derived from it; a pass runs every 100 ms. A node that takes no live writes of the source — a copy in a cluster, or a node just restarted until its first live write — does not derive. In a cluster, only the node serving the derived stream's partition derives it, and a failed-over copy carries on from its own newest bar.[6]
  • Derived bars are ordinary candles. They are written through the normal write routes, so they reach subscribers and copies like any write, and a bar older than the hot cache goes in as a correction or a history install as appropriate.
  • Late data. A late trade inside a bar's grace simply joins it. One after the grace corrects its bar (and can fill a gap it ends, or clear a mark) and is counted in mirexa_materialize_late_corrections_total; a steady rate means the grace is too short.
  • Source corrections cascade. A correction or fill of the source — by hand or by auto-fill — re-derives the buckets it touches, and that write reaches the next link in the chain the same way. Far-back changes are walked in windows of 2,048 target bars per pass.[7]
  • Retention. A candle-derived stream never keeps history older than its source's oldest chunk.[8]

Writing to a derived stream

An ordinary write to a derived stream is refused with DerivedStream (0x000A), before anything is stored, because the node would interleave its bars with yours. To replace derived bars on purpose, write with the overwrite flag (OverwriteCandles in Go, -overwrite on mirexa-cli ingest, Overwrite on a fill request). Between your write and a later re-derivation of the same bar, the last one written wins; a bar you overwrote stands until the source changes under it.[9]

Declaring, history and clearing

A declaration must say what to do with the source's existing history:

History option Effect
from-now (LineageHistoryFromNow) Derive what arrives from now on. Since is the moment of declaration.
rederive (LineageHistoryRederive) Also derive the history the source already holds, from its first datum. The node walks it in the background, rewriting only bars that differ; the lineage reports rederive_pending until it has caught up. A restart resumes the walk from the start (no position is stored).
clear (LineageHistoryClear, with no lineage) Stop deriving. Bars already derived are kept.

Declare a chain with rederive link by link, each once the link before it has finished: a link whose source is still empty when declared simply starts at now.

bash
./bin/cli lineage set -control 127.0.0.1:9091 -stream binance:ETHUSDT:1m \
    -kind ticks -history from-now

The lineage is set only by its own call (SetStreamLineage, mirexa-cli lineage set): a calendar update keeps it. Changing it needs ADMIN_STREAM through the SDK, or the control listener through the CLI. In a cluster, send it to the stream's primary; copies take their primary's lineage. Walkthrough: Deriving bars.

Rollups at query time

A rollup asks for bars of a longer length made at query time from a stream's candles, or with the ticks flag from its trades, and stored nowhere (QueryRequest.Rollup, mirexa-cli query -rollup).[10]

  • It runs the same rules as a declared derivation, with the stream's own calendar and the default grace and no-trade limit, so a rollup and a stored derivation of the same source answer the same bars, INCOMPLETE marks included.
  • It obeys the same length rules (whole multiple, at least twice the source; above a day only 1d and 1w); anything else is refused, naming why.
  • Only closed buckets are answered: one still open or inside its grace answers nothing. A bucket stamped before the range's start is not answered, so paging "after the last bar" sees each once.
  • It needs the read permission of what it reads (READ_TICKS from trades, READ_CANDLES from candles), and cannot be combined with stale reads or column queries.

When to use which. A rollup costs its computation on every read (measured 2026-10-22, one laptop: a million trades into one-minute bars in 45 ms, a year of one-minute bars into hourly in 67 ms). A declared derivation pays once, as data arrives, stores the result, and can be read, subscribed to and replicated like any stream. Use rollups for exploration and odd lengths (7m); declare a lineage for bars you read often.

References

Source

Tests

Further reading


  1. types.Lineage; DefaultCloseGrace, DefaultNoTradeLimit; TestLineage_DefaultsFillOnlyWhatIsUnset. ↩︎

  2. Lineage.Validate; TestLineage_RefusedDeclarations. ↩︎

  3. materialize.DeriveTicks; one test per rule in internal/materialize/ticks_test.go. ↩︎

  4. materialize.DeriveCandles; TestCandleDeriver_FiveMinutesMakeABarAndAMissingOneMarksIt. ↩︎

  5. materialize.Buckets; TestBuckets_ADaylightSavingDayHasA23HourWindowAndTheSameStride, TestTickDeriver_ADailyBarIsTheLocalTradingDate. ↩︎

  6. /internal/ingestion/tick_deriver.go; TestTickDeriver_NothingIsDerivedWithoutLiveTicksOfTheSource. ↩︎

  7. TestDeriveCascade_AnAutoFillOfTheSourceMakesTheChainWhole, TestCandleDeriver_AChainFromTicksCarriesItsMarks, TestTickDeriver_ALateTickAfterTheGraceCorrectsItsBarAndIsCounted. ↩︎

  8. TestDerivedRetention_ADerivedBarNeverOutlivesItsSource. ↩︎

  9. TestServer_AWriteToADerivedStreamIsRefusedWithoutOverwrite, TestTickDeriver_AnOverwriteStandsUntilTheSourceChangesUnderIt. ↩︎

  10. /internal/ingestion/rollup.go; TestRollup_AnswersWhatAStoredDerivationWould. Timings from BenchmarkRollup_QueryTime as recorded in the repository's developer overview. ↩︎