Skip to main content

L2Book

Struct L2Book 

Source
#[repr(C)]
pub struct L2Book { pub bids: [Level; 20], pub asks: [Level; 20], pub bid_ct: u8, pub ask_ct: u8, pub symbol_id: u16, pub _pad: u32, pub recv_ns: u64, }
Expand description

L2 order book with up to 20 levels per side. Total size: 688 bytes (fits in L1 cache).

Fields§

§bids: [Level; 20]§asks: [Level; 20]§bid_ct: u8§ask_ct: u8§symbol_id: u16§_pad: u32§recv_ns: u64

Implementations§

Source§

impl L2Book

Source

pub fn best_bid(&self) -> Option<&Level>

Source

pub fn best_ask(&self) -> Option<&Level>

Source

pub fn mid_px_1e9(&self) -> u64

Source

pub fn spread_1e9(&self) -> u64

Raw unsigned spread in 1e9 price units. Returns 0 for crossed books (ask < bid) due to saturating_sub. Use spread_signed_1e9() or is_crossed() for proper handling.

Source

pub fn spread_signed_1e9(&self) -> i64

Signed spread in 1e9 price units. Negative = crossed book.

Source

pub fn spread_bps(&self) -> u32

Spread in integer basis points (truncated). WARNING: Returns 0 for sub-bps spreads common on liquid assets (BTC, ETH). Use spread_bps_x1000() for milli-bps precision on liquid markets.

Source

pub fn spread_bps_x1000(&self) -> i32

Spread in milli-basis-points (1 bps = 1000 milli-bps), signed. Handles sub-bps precision for liquid markets and negative values for crossed books. Uses u128 intermediate to avoid overflow on high-priced assets.

Source

pub fn is_crossed(&self) -> bool

Whether the book is crossed (best bid > best ask). Common in consolidated NBBO when different venues have different prices.

Source

pub fn bid_depth_1e8(&self, levels: usize) -> u64

Source

pub fn ask_depth_1e8(&self, levels: usize) -> u64

Source

pub fn imbalance_bps(&self, levels: usize) -> i32

Trait Implementations§

Source§

impl Clone for L2Book

Source§

fn clone(&self) -> L2Book

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 Default for L2Book

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Copy for L2Book

Auto Trait Implementations§

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.