Expand description
Pure orderbook data structure and matching engine.
This module provides OrderBook, a price-time priority limit order book
for a single instrument. It supports:
- Adding and cancelling orders with full metadata
- Incremental matching (one maker at a time) with self-trade prevention
- L2 (price-level) snapshot and incremental diff computation
- Snapshot/restore for WAL-based persistence
§Design
The orderbook is a pure data structure with no async runtime, no channels, and no side effects. All operations are synchronous and deterministic.
Event emission is handled by the caller. The orderbook computes L2 diffs and
returns fill results, but never sends events itself. The runtime layer in the
hypercall crate is responsible for routing these to WebSocket clients,
persistence, and downstream caches.
§Price-level storage
Bids are stored in a BTreeMap keyed by negated price for descending order.
Asks are stored with natural (ascending) price keys. Within each price level,
orders are stored in a VecDeque for FIFO (time priority) matching.
Structs§
- L2Update
Set - Set of L2 incremental updates computed by
OrderBook::compute_l2_updates. - Order
- An order resting on a price level.
- Order
Book - A pure, synchronous limit order book for a single instrument.
- Order
Meta 🔒 - Metadata stored alongside the price-level
Order. - Order
Record - Full order record returned by
OrderBook::get_all_ordersand accepted byOrderBook::restore_from_orders. - Price
Level 🔒
Enums§
- Match
Result - Result of attempting to match a single maker order.
- Order
Book Event - Events produced by orderbook operations.