#[repr(align(64))]pub struct OrderBook<const N: usize = 64> {
pub symbol: String,
pub exchange_timestamp_ns: u64,
pub system_timestamp_ns: u64,
pub bids: SmallVec<[PriceLevel; N]>,
pub asks: SmallVec<[PriceLevel; N]>,
}Expand description
Order book data structure with const generic capacity
Fields§
§symbol: StringThe trading symbol.
exchange_timestamp_ns: u64Nanosecond precision from exchange.
system_timestamp_ns: u64Nanosecond precision local time.
bids: SmallVec<[PriceLevel; N]>Must be initiated as sorted for binary search optimizations!
asks: SmallVec<[PriceLevel; N]>Must be initiated as sorted for binary search optimizations!
Implementations§
Source§impl<const N: usize> OrderBook<N>
impl<const N: usize> OrderBook<N>
Sourcepub fn new(
symbol: impl AsRef<str>,
exchange_timestamp_ns: u64,
system_timestamp_ns: u64,
bids: SmallVec<[PriceLevel; N]>,
asks: SmallVec<[PriceLevel; N]>,
) -> Self
pub fn new( symbol: impl AsRef<str>, exchange_timestamp_ns: u64, system_timestamp_ns: u64, bids: SmallVec<[PriceLevel; N]>, asks: SmallVec<[PriceLevel; N]>, ) -> Self
Create a new order book
Sourcepub fn from_iters<B, A>(
symbol: impl AsRef<str>,
exchange_timestamp_ns: u64,
system_timestamp_ns: u64,
bids: B,
asks: A,
) -> Self
pub fn from_iters<B, A>( symbol: impl AsRef<str>, exchange_timestamp_ns: u64, system_timestamp_ns: u64, bids: B, asks: A, ) -> Self
Create a new order book from iterators (for compatibility and zero-copy)
Sourcepub fn new_empty(instrument_id: InstrumentId) -> Self
pub fn new_empty(instrument_id: InstrumentId) -> Self
Create an empty order book from instrument ID
Sourcepub fn bids(&self) -> &[PriceLevel]
pub fn bids(&self) -> &[PriceLevel]
Get the bid levels
Sourcepub fn asks(&self) -> &[PriceLevel]
pub fn asks(&self) -> &[PriceLevel]
Get the ask levels
Sourcepub fn best_bid(&self) -> Option<&PriceLevel>
pub fn best_bid(&self) -> Option<&PriceLevel>
Get the best bid price
Sourcepub fn best_ask(&self) -> Option<&PriceLevel>
pub fn best_ask(&self) -> Option<&PriceLevel>
Get the best ask price
Sourcepub fn remove_bid(&mut self, price: Decimal)
pub fn remove_bid(&mut self, price: Decimal)
Remove a bid level
Sourcepub fn remove_ask(&mut self, price: Decimal)
pub fn remove_ask(&mut self, price: Decimal)
Remove an ask level
Sourcepub fn apply_snapshot(&mut self, snapshot: OrderBookSnapshot<N>)
pub fn apply_snapshot(&mut self, snapshot: OrderBookSnapshot<N>)
Apply a snapshot to the order book This replaces the current state with the snapshot data
Trait Implementations§
Auto Trait Implementations§
impl<const N: usize> Freeze for OrderBook<N>
impl<const N: usize> RefUnwindSafe for OrderBook<N>
impl<const N: usize> Send for OrderBook<N>
impl<const N: usize> Sync for OrderBook<N>
impl<const N: usize> Unpin for OrderBook<N>
impl<const N: usize> UnwindSafe for OrderBook<N>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more