Skip to main content

Level

Struct Level 

Source
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

Source

pub fn new(price: Price) -> Self

Create a new empty level at the given price.

Source

pub fn price(&self) -> Price

Returns the price of this level.

Source

pub fn is_empty(&self) -> bool

Returns true if there are no active orders at this level.

Source

pub fn order_count(&self) -> usize

Returns the number of orders at this level (including tombstones).

Source

pub fn total_quantity(&self) -> Quantity

Returns the total quantity across all orders at this level.

Source

pub fn tombstone_count(&self) -> usize

Returns the number of tombstones in the queue.

Source

pub fn front(&mut self) -> Option<OrderId>

Returns the OrderId at the front of the queue (next to fill). Skips tombstones.

Source

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).

Source

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.

Source

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.

Source

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.

Source

pub fn compact(&mut self)

Remove all tombstones from the queue.

Source

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.

Source

pub fn iter(&self) -> impl Iterator<Item = OrderId> + '_

Returns an iterator over the active order IDs in FIFO order.

Trait Implementations§

Source§

impl Clone for Level

Source§

fn clone(&self) -> Level

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Level

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Level

§

impl RefUnwindSafe for Level

§

impl Send for Level

§

impl Sync for Level

§

impl Unpin for Level

§

impl UnwindSafe for Level

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.