depth module provides market depth (order book) implementations and traits for managing Level-1, Level-2, and Level-3 market data.
Core Traits
MarketDepth
Provides the basic market depth interface for accessing best bid/ask and quantities.best_bid()- Returns the best bid price, orf64::NANif no bid existsbest_ask()- Returns the best ask price, orf64::NANif no ask existsbest_bid_tick()- Returns the best bid price in ticks, orINVALID_MINif no bidbest_ask_tick()- Returns the best ask price in ticks, orINVALID_MAXif no askbest_bid_qty()- Returns the quantity at the best bidbest_ask_qty()- Returns the quantity at the best asktick_size()- Returns the minimum price incrementlot_size()- Returns the minimum quantity incrementbid_qty_at_tick(price_tick)- Returns bid quantity at a specific price levelask_qty_at_tick(price_tick)- Returns ask quantity at a specific price level
L2MarketDepth
Provides Level-2 (Market-By-Price) specific functions for order book updates.update_bid_depth(price, qty, timestamp)- Updates bid side and returns(price_tick, prev_best_bid_tick, best_bid_tick, prev_qty, qty, timestamp)update_ask_depth(price, qty, timestamp)- Updates ask side and returns(price_tick, prev_best_ask_tick, best_ask_tick, prev_qty, qty, timestamp)clear_depth(side, clear_upto_price)- Clears market depth for the specified side
L3MarketDepth
Provides Level-3 (Market-By-Order) specific functions for individual order tracking.add_buy_order(order_id, px, qty, timestamp)- Adds a buy order and returns(prev_best_bid_tick, best_bid_tick)add_sell_order(order_id, px, qty, timestamp)- Adds a sell order and returns(prev_best_ask_tick, best_ask_tick)delete_order(order_id, timestamp)- Removes an order and returns(side, prev_best_tick, best_tick)modify_order(order_id, px, qty, timestamp)- Modifies an order and returns(side, prev_best_tick, best_tick)clear_orders(side)- Clears all orders on the specified sideorders()- Returns all orders in the book
L1MarketDepth
Provides Level-1 (BBO - Best Bid/Offer) specific functions.Implementations
HashMapMarketDepth
AHashMap-based market depth implementation suitable for sparse order books.
- Efficient for sparse order books
- Good performance for market-making strategies
- Implements both
L2MarketDepthandL3MarketDepth
BTreeMarketDepth
ABTreeMap-based market depth implementation with ordered price levels.
- Maintains sorted price levels
- Efficient range queries
- Slightly slower updates than HashMap
ROIVectorMarketDepth
A vector-based implementation optimized for a specific range of interest (ROI).- Extremely fast access within the ROI range
- Fixed memory allocation
- Best for high-frequency strategies with predictable price ranges
roi_lb- Lower bound of the range of interest (in ticks)roi_ub- Upper bound of the range of interest (in ticks)
FusedHashMapMarketDepth
A fused implementation that combines multiple market depth sources.- Merges multiple depth feeds
- Useful for cross-exchange arbitrage
- Maintains synchronized view across sources
Supporting Types
L3Order
Represents a Level-3 order in the order book.Constants
ApplySnapshot Trait
Provides functionality to initialize market depth from snapshot data.apply_snapshot(data)- Initializes the order book from snapshot eventssnapshot()- Exports the current order book as snapshot events