pub struct OrderBook {
pub ts: DateTime<Utc>,
pub symbol: String,
pub bids: Vec<OrderBookLevel>,
pub asks: Vec<OrderBookLevel>,
}Expand description
Full depth-of-market order book snapshot (Level 2).
Contains all visible bid and ask price levels at a single point in
time. Bids are sorted descending (best bid first), asks ascending
(best ask first). Use imbalance_ratio to
gauge buying vs. selling pressure.
Fields§
§ts: DateTime<Utc>Ts of the snapshot
symbol: StringSymbol
bids: Vec<OrderBookLevel>Bid levels (sorted descending by price)
asks: Vec<OrderBookLevel>Ask levels (sorted ascending by price)
Implementations§
Source§impl OrderBook
impl OrderBook
Sourcepub fn best_bid(&self) -> Option<&OrderBookLevel>
pub fn best_bid(&self) -> Option<&OrderBookLevel>
Get best bid (highest bid price)
Sourcepub fn best_ask(&self) -> Option<&OrderBookLevel>
pub fn best_ask(&self) -> Option<&OrderBookLevel>
Get best ask (lowest ask price)
Sourcepub fn to_level1(&self) -> Option<Level1Quote>
pub fn to_level1(&self) -> Option<Level1Quote>
Convert to Level 1 quote
Sourcepub fn total_bid_volume(&self) -> f64
pub fn total_bid_volume(&self) -> f64
Calculate total bid volume
Sourcepub fn total_ask_volume(&self) -> f64
pub fn total_ask_volume(&self) -> f64
Calculate total ask volume
Sourcepub fn imbalance_ratio(&self) -> f64
pub fn imbalance_ratio(&self) -> f64
Calculate the order-book imbalance ratio (bid_volume / total_volume).
Returns a value in [0, 1]. Values above 0.5 indicate more resting
bid volume (buying interest); values below 0.5 indicate more ask
volume (selling interest). Returns 0.5 when the book is empty.
Sourcepub fn is_crossed(&self) -> bool
pub fn is_crossed(&self) -> bool
Whether the best bid is above the best ask. Bids and asks overlap during pre-open and auction phases, while a venue publishes an indicative opening price, and in books consolidated from several venues, so a crossed book is valid data: the chart keeps it as the feed sends it. A best bid equal to the best ask is locked, not crossed.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for OrderBook
impl<'de> Deserialize<'de> for OrderBook
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl StructuralPartialEq for OrderBook
Auto Trait Implementations§
impl Freeze for OrderBook
impl RefUnwindSafe for OrderBook
impl Send for OrderBook
impl Sync for OrderBook
impl Unpin for OrderBook
impl UnsafeUnpin 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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> ⓘ
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> ⓘ
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