pub struct Level { /* private fields */ }Expand description
A queue of orders at a single price level.
Orders are processed FIFO (first-in-first-out) for time priority. The level tracks total quantity for efficient depth queries.
Implementations§
Source§impl Level
impl Level
Sourcepub fn order_count(&self) -> usize
pub fn order_count(&self) -> usize
Returns the number of orders at this level (including tombstones).
Sourcepub fn total_quantity(&self) -> Quantity
pub fn total_quantity(&self) -> Quantity
Returns the total quantity across all orders at this level.
Sourcepub fn tombstone_count(&self) -> usize
pub fn tombstone_count(&self) -> usize
Returns the number of tombstones in the queue.
Sourcepub fn front(&mut self) -> Option<OrderId>
pub fn front(&mut self) -> Option<OrderId>
Returns the OrderId at the front of the queue (next to fill). Skips tombstones.
Sourcepub fn push_back(&mut self, order_id: OrderId, quantity: Quantity)
pub fn push_back(&mut self, order_id: OrderId, quantity: Quantity)
Add an order to the back of the queue.
The quantity is added to the level’s total (saturating on overflow).
Sourcepub fn pop_front(&mut self, quantity: Quantity) -> Option<OrderId>
pub fn pop_front(&mut self, quantity: Quantity) -> Option<OrderId>
Remove and return the order at the front of the queue.
The provided quantity is subtracted from the level’s total. This should be the order’s remaining quantity at time of removal.
Returns None if the level is empty.
Sourcepub fn mark_tombstone(&mut self, index: usize, quantity: Quantity)
pub fn mark_tombstone(&mut self, index: usize, quantity: Quantity)
Mark an order as a tombstone (O(1) cancellation).
The caller provides the index into the VecDeque (tracked in OrderBook’s HashMap). The order’s quantity is subtracted from the level total.
Sourcepub fn remove(&mut self, order_id: OrderId, quantity: Quantity) -> bool
pub fn remove(&mut self, order_id: OrderId, quantity: Quantity) -> bool
Remove a specific order from anywhere in the queue (for cancellation).
Returns true if the order was found and removed, false otherwise.
The provided quantity is subtracted from the level’s total.
Note: This is O(n) where n is the number of orders at this price level.
For O(1) cancel, we now use mark_tombstone called from OrderBook.
Sourcepub fn decrease_quantity(&mut self, amount: Quantity)
pub fn decrease_quantity(&mut self, amount: Quantity)
Decrease the total quantity (e.g., after a partial fill).
Use this when an order is partially filled but remains in the queue.