Skip to main content

parse_l2_order_book_snapshot

Function parse_l2_order_book_snapshot 

Source
pub fn parse_l2_order_book_snapshot(
    snapshot: &LighterOrderBookOrders,
    instrument_id: InstrumentId,
    price_precision: u8,
    size_precision: u8,
) -> OrderBook
Expand description

Parses an HTTP orderBookOrders snapshot into an aggregated [OrderBook].

The REST endpoint returns each resting order separately, while WebSocket order_book updates carry already-aggregated price levels. To keep snapshot semantics consistent with the live feed, sizes are summed per price on each side and added as a single L2 entry per level.

The snapshot itself carries no venue timestamp (Lighter’s LighterSimpleOrder transaction_time is 0 for resting orders), so the constructed book’s ts_last is left at [UnixNanos::default]. The first WebSocket delta applied after the snapshot will install a real venue timestamp and avoid spurious “out-of-order” warnings against a wall-clock placeholder.