Struct L2Book
pub struct L2Book { /* private fields */ }Expand description
In-memory L2 order book keyed by price.
- Bids: highest price is best bid.
- Asks: lowest price is best ask.
Implementations§
§impl L2Book
impl L2Book
pub fn new() -> L2Book
pub fn clear(&mut self)
pub fn apply_snapshot(
&mut self,
bids: &[(Decimal, Decimal)],
asks: &[(Decimal, Decimal)],
)
pub fn apply_snapshot( &mut self, bids: &[(Decimal, Decimal)], asks: &[(Decimal, Decimal)], )
Replace both sides from a full snapshot.
Non-positive quantities are ignored.
pub fn apply_delta(
&mut self,
bids: &[(Decimal, Decimal)],
asks: &[(Decimal, Decimal)],
)
pub fn apply_delta( &mut self, bids: &[(Decimal, Decimal)], asks: &[(Decimal, Decimal)], )
Apply incremental updates.
qty == 0 means delete level. Positive qty means upsert level.
pub fn best_bid(&self) -> Option<Decimal>
pub fn best_ask(&self) -> Option<Decimal>
pub fn mid_price(&self) -> Option<Decimal>
pub fn bid_levels(&self) -> usize
pub fn ask_levels(&self) -> usize
pub fn fill_against_book(
&mut self,
side: Side,
limit_price: Option<Decimal>,
max_qty: Decimal,
) -> Option<FillResult>
pub fn fill_against_book( &mut self, side: Side, limit_price: Option<Decimal>, max_qty: Decimal, ) -> Option<FillResult>
Walk the book to fill up to max_qty at prices within limit_price.
For Side::Buy: walks asks (lowest first), consuming levels where
ask_price <= limit_price. For Side::Sell: walks bids (highest first),
consuming levels where bid_price >= limit_price.
If limit_price is None, walks the entire side (market order).
Mutates the book: consumed quantities are removed from levels. Zero-quantity levels are deleted.
Returns None if no liquidity is available within the limit.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for L2Book
impl RefUnwindSafe for L2Book
impl Send for L2Book
impl Sync for L2Book
impl Unpin for L2Book
impl UnsafeUnpin for L2Book
impl UnwindSafe for L2Book
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)