Mirexa

Wiki Guides

Finding and filling gaps

How to find the bars a Mirexa stream is missing, fill them with recovered data or with synthetic bars, declare holes that were expected, and resolve INCOMPLETE marks on derived bars — and what the node refuses.

When a feed drops, a stream ends up with holes. Mirexa records each one as a gap, classified against the stream's trading calendar, so you can ask which bars are genuinely missing — not merely which slots are empty because the market was shut — and repair them. This guide covers the workflow: find, decide, fill, verify. The model behind it is in Gaps and trading calendars.

1. Make sure the calendar is right

A gap is only as meaningful as the calendar that classified it. Before chasing "missing" data, set the stream's working hours and declare its holidays; a calendar change re-files recorded gaps at once, so a wrong calendar is fixed retroactively:

bash
./bin/cli calendar set -control 127.0.0.1:9091 -stream nyse:AAPL:1m \
    -timezone America/New_York -hours mon-fri=09:30-16:00
bash
./bin/cli calendar add-closure -control 127.0.0.1:9091 -stream nyse:AAPL:1m \
    -from 2026-11-26T09:30:00-05:00 -to 2026-11-26T16:00:00-05:00 -note Thanksgiving

If you know a hole was expected — an exchange halt, a venue's maintenance window — declare a closure over it too. It is then filed as OFF_TIME, stops counting as missing, and keeps that verdict through later calendar changes.

2. Find the gaps

ListGaps returns a stream's recorded gaps as ranges, with a summary of the whole window:[1]

go
resp, err := c.ListGaps(ctx, client.ListGapsRequest{
	StreamID:       stream,
	StartTime:      from,
	EndTime:        to,
	OpenOnly:       true, // only gaps still OPEN
	ExcludeOffTime: true, // drop market closures
	Limit:          200,  // default 200, max 1000 (larger is refused)
})
for _, g := range resp.Gaps { // ordered by start
	ok, why := g.Fillable()
	_ = ok
	_ = why
}
fmt.Println(time.Duration(resp.Summary.MissingDuration)) // genuinely missing time in the window
  • MissingDuration is the number to watch: it excludes closures, filled gaps and INCOMPLETE marks, and is clipped to the window. Counts of gaps or empty slots mislead for any market that is not open around the clock.
  • Page with Cursor (the last gap's StartTs) and HasCursor while HasMore is set.
  • A listing shows flushed data only. A hole still in the hot cache shows up in a query with IncludeGaps as an OPEN / UNKNOWN marker, and in the listing after the next flush.
  • Listing needs READ_CANDLES. Python: list_gaps. The web dashboard has a gap table per stream and a triage view across streams. mirexa-cli has no gap-listing command.

3. Decide: fillable or not

Never decide from the reason yourself; call GapRange.Fillable(), the same function the node enforces with:

Result Meaning
true OPEN and not a closure: fill it.
FillRefusalMarketClosed The market was shut. There is nothing to recover; writing bars here would fabricate them.
FillRefusalPermanent Written off as unrecoverable (or an unknown status, failing safe).
FillRefusalAlreadyClosed Already filled.
FillRefusalInProgress Another fill is under way.
FillRefusalAccepted An INCOMPLETE mark accepted as it is.

4a. Fill with recovered bars

If you can get the real bars back — from the exchange, a vendor, a second feed — write them as a correction:

go
err := c.IngestCorrectionCandles(ctx, stream, recovered, client.DurabilityAcked)
bash
./bin/cli ingest -correct -stream nyse:AAPL:1m < recovered.csv
  • Once the bars are durable, the node marks every gap that the batch fills completely (every slot) as CLOSED. The record is kept as provenance, not deleted.[2]
  • A partial fill leaves the gap OPEN with its original range, overstating what is missing — the safe direction. Fill the rest later; the gap closes when its last slot is filled.
  • The correction route refuses bars newer than the stream's newest bar, which catches a "recovered" file that is actually new data. A plain write works too and also takes new bars.
  • A bar inside a filed market closure refuses the whole batch, before anything is written, even if the rest of the batch fills a real outage. Remove the closure rows and re-send.[3]
  • From files: mirexa-cli load fills holes the same way and reports which gaps it closed and which remain open (Bulk loading).

4b. Fill with synthetic bars

When the real bars are gone for good, FillGap asks the node to make up the bars of one gap from the real bars on either side:[4]

go
resp, err := c.FillGap(ctx, client.FillGapRequest{
	StreamID: stream,
	GapStart: g.StartTs,               // exactly as ListGaps reported it
	Method:   client.FillMethodLinear, // or FillMethodForward, FillMethodBackward
})
// resp.Filled bars written; resp.HasMore: call again to continue
Method Each made-up bar Needs
linear A straight line from the close before the hole to the open after it; each bar opens where the last closed real bars on both sides
forward Flat at the close of the bar before the hole a bar before
backward Flat at the open of the bar after the hole a bar after
  • Every made-up bar has zero volume — the honest value, and the only mark a synthetic bar keeps once stored, so a consumer can still tell one apart.
  • Only slots that hold no bar are written; a bar you already wrote into the gap is kept and becomes an anchor.
  • One call writes at most 10,000 bars (MaxCandles lowers it); HasMore says to call again, and the next call continues the same line.
  • GapStart must match a gap's start exactly; a start no gap has is refused rather than applied to the nearest hole. Re-sending a request whose answer was lost is safe: it finds nothing left to fill and succeeds.
  • A market closure is refused, as is an INCOMPLETE mark (its slot already holds a bar).
  • A derived stream needs Overwrite: true. Filling needs WRITE_CANDLES. Python: fill_gap. The dashboard has a fill form too.

The bars are written as a correction, so a fully filled gap is closed exactly as in 4a, and streams derived from this one are re-derived over the filled range.

5. Verify

List the window again: a filled gap now reads CLOSED and its time has left MissingDuration. Query the range with IncludeGaps to see the bars in place.

INCOMPLETE marks on derived bars

A derived bar made while its source had a hole carries an INCOMPLETE mark. It is resolved one of two ways:

  • Fill the source's hole (4a or 4b on the source stream). The derived bar is re-derived and the mark cleared, down the whole chain.
  • Accept it as it is, if the source data is gone and the bar is good enough:
bash
./bin/cli gap accept -control 127.0.0.1:9091 -stream binance:ETHUSDT:5m \
    -start 2026-10-22T09:00:00Z

gap unaccept puts it back to OPEN. From Go, AcceptGap with Accept: true or false. GapRange.AcceptAction() says which way a record may go; a gap of missing data is filled or left open, never accepted.[5]

References

Source

Tests

Further reading


  1. /internal/wire/list_gaps.go; TestServer_ListGapsFiltersBeforePaging, TestServer_ListGapsSummaryDescribesTheWindowNotThePage. ↩︎

  2. closeFilledGaps in /internal/ingestion/dispatcher.go; TestDashboard_DiscoverGapThenFillItThenItIsGone. ↩︎

  3. TestCorrection_RefusesToFillAMarketClosure. ↩︎

  4. Dispatcher.AutoFillGap; the TestAutoFillGap_* tests listed above. ↩︎

  5. TestGapRange_AcceptActionIsOfferedOnlyOnAnIncompleteMark. ↩︎