Skip to content
All library documents

Comparing Consecutive Order Book Snapshots to Detect Level Changes

Code Stratmill research code

Summary

This code describes a stateful method for comparing consecutive limit-order-book snapshots. It stores bid and ask levels from the current and previous snapshots, then flags each current level as unchanged, changed, or inserted based on price and quantity. Prices are compared after conversion to tick units, and quantities are rounded to lot units. Previous levels missing from the new snapshot are returned with a deletion category indicating whether they disappeared inside the observed price range or fell outside it.

The first snapshot initializes the state and returns no deletions. Later calls return the current bid and ask arrays together with the detected deletions. The implementation relies on configured tick size and lot size, and detects changes only across the supplied snapshots, so it does not reveal the cause or sequence of intervening events. It also assumes snapshots fit the configured number of levels and does not describe how to handle empty sides or malformed market data beyond mismatched price and quantity lengths.

Key ideas

  • The class tracks current and previous bid and ask snapshots to identify level changes.
  • Prices are matched in tick units, while quantities are compared in lot units.
  • Current levels are classified as unchanged, changed, or inserted.
  • Missing prior levels are categorized by whether they disappeared within or beyond the observed book range.
  • Snapshot differencing shows state changes but cannot reconstruct the sequence or cause of intervening events.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.