Skip to content

fix: drop orderbook deltas before snapshot instead of creating ghost entries#25

Merged
pbeets merged 2 commits intomainfrom
fix/orderbook-delta-before-snapshot
Feb 21, 2026
Merged

fix: drop orderbook deltas before snapshot instead of creating ghost entries#25
pbeets merged 2 commits intomainfrom
fix/orderbook-delta-before-snapshot

Conversation

@pbeets
Copy link
Owner

@pbeets pbeets commented Feb 21, 2026

Summary

  • Fix: OrderbookAggregator::handle_delta() now returns early when no snapshot has been received for a market, instead of calling .entry().or_default() which silently created empty uninitialized orderbook entries. This prevented full_book() and tracked_markets() from returning stale/invalid data.
  • Breaking: Removed the initialized field from OrderbookSummary since the aggregator now guarantees summaries are only produced for fully initialized orderbooks.
  • Updated Channel::requires_market_ticker() to only require tickers for OrderbookDelta — other market data channels support subscribing with an empty ticker list.

Test plan

  • Added test_delta_before_snapshot_ignored — verifies deltas before a snapshot are silently dropped and no ghost entry is created
  • Added test_full_book — verifies full_book() returns correct ladder after snapshot + delta application
  • Existing tests pass (cargo test)

Previously, `handle_delta` used `or_default()` which silently created
uninitialized OrderbookState entries when deltas arrived before a
snapshot. This produced corrupt partial books.

Now deltas for unknown or uninitialized markets are dropped. The
`initialized` field is removed from the public OrderbookSummary since
the aggregator guarantees it only emits data for initialized books.

Also narrows `Channel::requires_market_ticker()` to only OrderbookDelta
and fixes minor style issues in examples.
@pbeets pbeets merged commit d1c5cca into main Feb 21, 2026
5 checks passed
@pbeets pbeets deleted the fix/orderbook-delta-before-snapshot branch February 21, 2026 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant