pub struct OrderBook {
pub symbol: String,
pub asks: Vec<Ask>,
pub bids: Vec<Bid>,
pub timestamp: u64,
pub update_id: u64,
pub sequence: u64,
pub matching_engine_timestamp: u64,
}Expand description
Represents the order book for a trading pair.
Contains the current bid and ask levels, along with metadata like the update ID. Bots use this to analyze market depth and liquidity in perpetual futures.
Fields§
§symbol: StringThe trading pair symbol (e.g., “BTCUSDT”).
Confirms the trading pair for the order book. Bots should verify this matches the requested symbol.
asks: Vec<Ask>A list of ask (sell) orders.
Contains the current ask prices and quantities. Bots use this to assess selling pressure and determine resistance levels in perpetual futures.
bids: Vec<Bid>A list of bid (buy) orders.
Contains the current bid prices and quantities. Bots use this to assess buying support and determine support levels in perpetual futures.
timestamp: u64The timestamp of the order book snapshot (Unix timestamp in milliseconds).
Indicates when the order book data was captured. Bots should use this to ensure the data is recent, as stale order book data can lead to poor trading decisions.
update_id: u64The update ID of the order book.
A unique identifier for the order book snapshot. Bots can use this to track updates and ensure they’re processing the latest data, especially in WebSocket streams.
sequence: u64Cross sequence.
You can use this field to compare different levels orderbook data, and for the smaller seq, then it means the data is generated earlier.
matching_engine_timestamp: u64The timestamp from the matching engine when this orderbook data is produced.
It can be correlated with T from public trade channel.
Implementations§
Source§impl OrderBook
impl OrderBook
Sourcepub fn spread_percentage(&self) -> Option<f64>
pub fn spread_percentage(&self) -> Option<f64>
Returns the spread as a percentage of mid price.
Sourcepub fn total_ask_quantity(&self) -> f64
pub fn total_ask_quantity(&self) -> f64
Returns the total quantity on the ask side.
Sourcepub fn total_bid_quantity(&self) -> f64
pub fn total_bid_quantity(&self) -> f64
Returns the total quantity on the bid side.
Sourcepub fn total_quantity(&self) -> f64
pub fn total_quantity(&self) -> f64
Returns the total quantity (bids + asks).
Sourcepub fn bid_ask_quantity_ratio(&self) -> f64
pub fn bid_ask_quantity_ratio(&self) -> f64
Returns the bid-ask quantity ratio.
Sourcepub fn order_book_imbalance(&self) -> f64
pub fn order_book_imbalance(&self) -> f64
Returns the order book imbalance (bid - ask) / (bid + ask).
Sourcepub fn weighted_average_ask_price(&self, target_quantity: f64) -> Option<f64>
pub fn weighted_average_ask_price(&self, target_quantity: f64) -> Option<f64>
Returns the weighted average price for a given quantity on the ask side.
Sourcepub fn weighted_average_bid_price(&self, target_quantity: f64) -> Option<f64>
pub fn weighted_average_bid_price(&self, target_quantity: f64) -> Option<f64>
Returns the weighted average price for a given quantity on the bid side.
Sourcepub fn ask_price_impact(&self, quantity: f64) -> Option<f64>
pub fn ask_price_impact(&self, quantity: f64) -> Option<f64>
Returns the price impact for a given quantity on the ask side.
Sourcepub fn bid_price_impact(&self, quantity: f64) -> Option<f64>
pub fn bid_price_impact(&self, quantity: f64) -> Option<f64>
Returns the price impact for a given quantity on the bid side.
Sourcepub fn cumulative_ask_quantity_to_price(&self, price: f64) -> f64
pub fn cumulative_ask_quantity_to_price(&self, price: f64) -> f64
Returns the cumulative quantity up to a given price level on the ask side.
Sourcepub fn cumulative_bid_quantity_to_price(&self, price: f64) -> f64
pub fn cumulative_bid_quantity_to_price(&self, price: f64) -> f64
Returns the cumulative quantity up to a given price level on the bid side.
Sourcepub fn ask_price_for_cumulative_quantity(
&self,
target_quantity: f64,
) -> Option<f64>
pub fn ask_price_for_cumulative_quantity( &self, target_quantity: f64, ) -> Option<f64>
Returns the price level that contains a given cumulative quantity on the ask side.
Sourcepub fn bid_price_for_cumulative_quantity(
&self,
target_quantity: f64,
) -> Option<f64>
pub fn bid_price_for_cumulative_quantity( &self, target_quantity: f64, ) -> Option<f64>
Returns the price level that contains a given cumulative quantity on the bid side.
Sourcepub fn market_depth(&self, percentage_range: f64) -> (f64, f64)
pub fn market_depth(&self, percentage_range: f64) -> (f64, f64)
Returns the market depth (quantity within a percentage range of mid price).
Sourcepub fn liquidity_score(&self) -> f64
pub fn liquidity_score(&self) -> f64
Returns the liquidity score (higher is more liquid).
Sourcepub fn timestamp_datetime(&self) -> DateTime<Utc>
pub fn timestamp_datetime(&self) -> DateTime<Utc>
Returns the timestamp as a DateTime.
Sourcepub fn matching_engine_timestamp_datetime(&self) -> DateTime<Utc>
pub fn matching_engine_timestamp_datetime(&self) -> DateTime<Utc>
Returns the matching engine timestamp as a DateTime.
Sourcepub fn processing_latency_ms(&self) -> i64
pub fn processing_latency_ms(&self) -> i64
Returns the latency between system generation and matching engine.
Sourcepub fn vwap(&self) -> Option<f64>
pub fn vwap(&self) -> Option<f64>
Returns the VWAP (Volume Weighted Average Price) for the visible order book.
Sourcepub fn microprice(&self) -> Option<f64>
pub fn microprice(&self) -> Option<f64>
Returns the microprice (weighted by inverse of spread).
Sourcepub fn order_book_slope(
&self,
side: OrderBookSide,
levels: usize,
) -> Option<f64>
pub fn order_book_slope( &self, side: OrderBookSide, levels: usize, ) -> Option<f64>
Returns the order book slope (price change per unit quantity).
Sourcepub fn order_book_curvature(
&self,
side: OrderBookSide,
levels: usize,
) -> Option<f64>
pub fn order_book_curvature( &self, side: OrderBookSide, levels: usize, ) -> Option<f64>
Returns the order book curvature (second derivative).
Sourcepub fn order_book_resilience(&self) -> f64
pub fn order_book_resilience(&self) -> f64
Returns the order book resilience (how quickly liquidity replenishes).
Sourcepub fn order_book_toxicity(&self) -> f64
pub fn order_book_toxicity(&self) -> f64
Returns the order book toxicity (probability of informed trading).
Sourcepub fn effective_cost(&self, quantity: f64) -> Option<f64>
pub fn effective_cost(&self, quantity: f64) -> Option<f64>
Returns the effective cost of trading (spread + impact for a given quantity).
Sourcepub fn round_trip_cost(&self, quantity: f64) -> Option<f64>
pub fn round_trip_cost(&self, quantity: f64) -> Option<f64>
Returns the market impact cost for a round trip trade.
Sourcepub fn optimal_order_size(&self, max_impact: f64) -> Option<f64>
pub fn optimal_order_size(&self, max_impact: f64) -> Option<f64>
Returns the optimal order size based on market impact.