pub struct FastBookLevel {
pub price: Price,
pub size: Qty,
}Expand description
Order book level (price/size pair) - INTERNAL HOT PATH VERSION
This is what we use internally for maximum performance. All order book operations use this to avoid Decimal overhead.
The performance difference is huge:
- BookLevel: ~50ns per operation (Decimal math + allocation)
- FastBookLevel: ~2ns per operation (integer math, no allocation)
That’s a 25x speedup on the critical path
Fields§
§price: Price§size: QtyImplementations§
Source§impl FastBookLevel
impl FastBookLevel
Sourcepub fn to_book_level(self) -> BookLevel
pub fn to_book_level(self) -> BookLevel
Convert to external BookLevel for API responses This is only called at the edges when we need to return data to users
Sourcepub fn from_book_level(level: &BookLevel) -> Result<Self, &'static str>
pub fn from_book_level(level: &BookLevel) -> Result<Self, &'static str>
Create from external BookLevel (with validation) This is called when we receive data from the API
Sourcepub fn notional(self) -> i64
pub fn notional(self) -> i64
Calculate notional value (price * size) in fixed-point Returns the result scaled appropriately to avoid overflow
This is much faster than the Decimal equivalent:
- Decimal: price.mul(size) -> ~20ns + allocation
- Fixed-point: (price as i64 * size) / SCALE_FACTOR -> ~1ns, no allocation
Trait Implementations§
Source§impl Clone for FastBookLevel
impl Clone for FastBookLevel
Source§fn clone(&self) -> FastBookLevel
fn clone(&self) -> FastBookLevel
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for FastBookLevel
impl Debug for FastBookLevel
Source§impl PartialEq for FastBookLevel
impl PartialEq for FastBookLevel
impl Copy for FastBookLevel
impl Eq for FastBookLevel
impl StructuralPartialEq for FastBookLevel
Auto Trait Implementations§
impl Freeze for FastBookLevel
impl RefUnwindSafe for FastBookLevel
impl Send for FastBookLevel
impl Sync for FastBookLevel
impl Unpin for FastBookLevel
impl UnwindSafe for FastBookLevel
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more