pub struct Orderbook { /* private fields */ }Expand description
A orderbook order book that handles updates and snapshots.
This struct wraps the core InnerOrderbook and manages pending updates before a snapshot is applied.
Implementations§
Source§impl Orderbook
impl Orderbook
Sourcepub const fn last_update_id(&self) -> u64
pub const fn last_update_id(&self) -> u64
Returns the last update id applied to the current orderbook.
Sourcepub const fn next_update_id(&self) -> u64
pub const fn next_update_id(&self) -> u64
Returns the next update id & increment the state of the inner Orderbook.
Sourcepub const fn snapshot_was_applied(&self) -> bool
pub const fn snapshot_was_applied(&self) -> bool
Returns true if a snapshot has been applied to the current orderbook, else false.
Sourcepub fn best_bid(&self) -> Option<&BigDecimal>
pub fn best_bid(&self) -> Option<&BigDecimal>
Returns the current best_bid - if any.
Sourcepub fn best_ask(&self) -> Option<&BigDecimal>
pub fn best_ask(&self) -> Option<&BigDecimal>
Returns the current best_ask - if any.
Sourcepub fn mid_price(&self) -> Option<BigDecimal>
pub fn mid_price(&self) -> Option<BigDecimal>
Get the mid price (average of best bid and ask).
Sourcepub fn depth(&self, percentage: f64) -> Option<DepthLevel>
pub fn depth(&self, percentage: f64) -> Option<DepthLevel>
Compute depth at a given percentage.
Sourcepub fn apply_update(
&mut self,
bids: Vec<(f64, f64)>,
asks: Vec<(f64, f64)>,
update_id: u64,
) -> Result<(), OrderbookError>
pub fn apply_update( &mut self, bids: Vec<(f64, f64)>, asks: Vec<(f64, f64)>, update_id: u64, ) -> Result<(), OrderbookError>
Applies an update to the order book.
Before a snapshot, updates are merged into pending_updates. After a snapshot, updates are
applied directly if their update_id is newer than the current last_update_id.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Orderbook
impl RefUnwindSafe for Orderbook
impl Send for Orderbook
impl Sync for Orderbook
impl Unpin for Orderbook
impl UnwindSafe for Orderbook
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