pub struct OrderBook {Show 13 fields
pub symbol: String,
pub timestamp: i64,
pub datetime: Option<String>,
pub nonce: Option<i64>,
pub bids: Vec<OrderBookEntry>,
pub asks: Vec<OrderBookEntry>,
pub info: HashMap<String, Value>,
pub buffered_deltas: VecDeque<OrderBookDelta>,
pub bids_map: BTreeMap<String, Decimal>,
pub asks_map: BTreeMap<String, Decimal>,
pub is_synced: bool,
pub needs_resync: bool,
pub last_resync_time: i64,
}Expand description
Complete order book structure
Fields§
§symbol: StringExchange symbol
timestamp: i64Timestamp in milliseconds
datetime: Option<String>ISO8601 datetime string
nonce: Option<i64>Nonce/sequence number for updates
bids: Vec<OrderBookEntry>Bid side (buyers) - sorted descending by price
asks: Vec<OrderBookEntry>Ask side (sellers) - sorted ascending by price
info: HashMap<String, Value>Raw exchange info
buffered_deltas: VecDeque<OrderBookDelta>Buffered delta messages waiting for snapshot
bids_map: BTreeMap<String, Decimal>BTree map for efficient bid updates (price -> amount)
asks_map: BTreeMap<String, Decimal>BTree map for efficient ask updates (price -> amount)
is_synced: boolWhether orderbook is synchronized
needs_resync: boolRequest resync flag (set when sequence gap detected)
last_resync_time: i64Last resync timestamp (for rate limiting resync attempts)
Implementations§
Source§impl OrderBook
impl OrderBook
Sourcepub fn best_bid(&self) -> Option<&OrderBookEntry>
pub fn best_bid(&self) -> Option<&OrderBookEntry>
Get best bid (highest buy price)
Sourcepub fn best_ask(&self) -> Option<&OrderBookEntry>
pub fn best_ask(&self) -> Option<&OrderBookEntry>
Get best ask (lowest sell price)
Sourcepub fn spread_percentage(&self) -> Option<Decimal>
pub fn spread_percentage(&self) -> Option<Decimal>
Calculate spread percentage
Sourcepub fn bid_volume(&self) -> Amount
pub fn bid_volume(&self) -> Amount
Get total bid volume
Sourcepub fn ask_volume(&self) -> Amount
pub fn ask_volume(&self) -> Amount
Get total ask volume
Sourcepub fn update(
&mut self,
bids: Vec<OrderBookEntry>,
asks: Vec<OrderBookEntry>,
timestamp: i64,
)
pub fn update( &mut self, bids: Vec<OrderBookEntry>, asks: Vec<OrderBookEntry>, timestamp: i64, )
Update order book with new entries
Sourcepub fn reset_from_snapshot(
&mut self,
bids: Vec<OrderBookEntry>,
asks: Vec<OrderBookEntry>,
timestamp: i64,
nonce: Option<i64>,
)
pub fn reset_from_snapshot( &mut self, bids: Vec<OrderBookEntry>, asks: Vec<OrderBookEntry>, timestamp: i64, nonce: Option<i64>, )
Reset orderbook from snapshot
Sourcepub fn buffer_delta(&mut self, delta: OrderBookDelta)
pub fn buffer_delta(&mut self, delta: OrderBookDelta)
Buffer a delta update for later processing
Sourcepub fn apply_delta(
&mut self,
delta: &OrderBookDelta,
is_futures: bool,
) -> Result<(), String>
pub fn apply_delta( &mut self, delta: &OrderBookDelta, is_futures: bool, ) -> Result<(), String>
Apply a delta update (incremental update)
Sourcepub fn process_buffered_deltas(
&mut self,
is_futures: bool,
) -> Result<usize, String>
pub fn process_buffered_deltas( &mut self, is_futures: bool, ) -> Result<usize, String>
Process buffered deltas after receiving snapshot
Sourcepub fn clear_buffer(&mut self)
pub fn clear_buffer(&mut self)
Clear all buffered deltas
Sourcepub fn buffered_count(&self) -> usize
pub fn buffered_count(&self) -> usize
Get number of buffered deltas
Sourcepub fn reset_for_resync(&mut self)
pub fn reset_for_resync(&mut self)
Reset orderbook state for resync Clears all data but keeps symbol and preserves buffered deltas
Sourcepub fn should_resync(&self, current_time: i64) -> bool
pub fn should_resync(&self, current_time: i64) -> bool
Check if resync is needed and rate limit is satisfied Rate limit: minimum 1 second between resyncs
Sourcepub fn mark_resync_initiated(&mut self, current_time: i64)
pub fn mark_resync_initiated(&mut self, current_time: i64)
Mark that resync has been initiated