pub struct LocalOrderbook { /* private fields */ }Expand description
Local orderbook maintained from WebSocket updates.
This structure maintains a sorted orderbook from snapshot and delta updates. Bids are sorted by price descending (highest first), asks ascending (lowest first).
Implementations§
Source§impl LocalOrderbook
impl LocalOrderbook
Sourcepub fn is_initialized(&self) -> bool
pub fn is_initialized(&self) -> bool
Check if the orderbook has been initialized with a snapshot.
Sourcepub fn last_update_ts(&self) -> u64
pub fn last_update_ts(&self) -> u64
Get the last update timestamp.
Sourcepub fn apply_update(
&mut self,
update: &WsStreamMessage<OrderbookData>,
) -> Result<(), BybitError>
pub fn apply_update( &mut self, update: &WsStreamMessage<OrderbookData>, ) -> Result<(), BybitError>
Apply an orderbook update (snapshot or delta).
§Update Rules
- Snapshots replace the entire orderbook.
- Deltas are applied incrementally:
- If size is “0”, the price level is removed.
- If the price level does not exist, it is inserted.
- If the price level exists, the size is updated.
- If
update_idis 1, treat it as a snapshot.
Sourcepub fn best_bid(&self) -> Option<&PriceLevel>
pub fn best_bid(&self) -> Option<&PriceLevel>
Get the best bid (highest buy price).
Sourcepub fn best_ask(&self) -> Option<&PriceLevel>
pub fn best_ask(&self) -> Option<&PriceLevel>
Get the best ask (lowest sell price).
Sourcepub fn top_bids(&self, n: usize) -> Vec<&PriceLevel>
pub fn top_bids(&self, n: usize) -> Vec<&PriceLevel>
Get the top N bids (sorted by price descending).
Sourcepub fn top_asks(&self, n: usize) -> Vec<&PriceLevel>
pub fn top_asks(&self, n: usize) -> Vec<&PriceLevel>
Get the top N asks (sorted by price ascending).
Sourcepub fn bids(&self) -> impl Iterator<Item = &PriceLevel>
pub fn bids(&self) -> impl Iterator<Item = &PriceLevel>
Get all bids (sorted by price descending).
Sourcepub fn asks(&self) -> impl Iterator<Item = &PriceLevel>
pub fn asks(&self) -> impl Iterator<Item = &PriceLevel>
Get all asks (sorted by price ascending).
Sourcepub fn bid_levels(&self) -> usize
pub fn bid_levels(&self) -> usize
Get the number of bid levels.
Sourcepub fn ask_levels(&self) -> usize
pub fn ask_levels(&self) -> usize
Get the number of ask levels.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for LocalOrderbook
impl RefUnwindSafe for LocalOrderbook
impl Send for LocalOrderbook
impl Sync for LocalOrderbook
impl Unpin for LocalOrderbook
impl UnwindSafe for LocalOrderbook
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