pub struct OrderBookState { /* private fields */ }Expand description
Local order book, reconstructed from a depth snapshot and a stream of diffs.
All internal bookkeeping (buffered diffs, sync state, book contents) is
private. Feed data in with apply_snapshot,
apply_diff or apply, in any order,
and inspect the book with bids, asks,
best_bid and best_ask once
is_synced is true.
Implementations§
Source§impl OrderBookState
impl OrderBookState
Sourcepub fn apply_snapshot(&mut self, snapshot: Orderbook) -> ApplyOutcome
pub fn apply_snapshot(&mut self, snapshot: Orderbook) -> ApplyOutcome
Feed a REST depth snapshot (Client::get_orderbook).
Sourcepub fn apply_diff(&mut self, diff: OrderbookDataMsg) -> ApplyOutcome
pub fn apply_diff(&mut self, diff: OrderbookDataMsg) -> ApplyOutcome
Feed a live diff from the orderbook.{depth}.{symbol} WebSocket topic.
If the book is not synced yet, the diff is buffered. Otherwise it
must extend the live book by exactly one update_id; anything else
(a stale diff or a gap) is reported via ApplyOutcome::Ignored /
ApplyOutcome::ResyncRequired.
Sourcepub fn apply(&mut self, msg: OrderbookMsg) -> ApplyOutcome
pub fn apply(&mut self, msg: OrderbookMsg) -> ApplyOutcome
Feed any message from the orderbook.{depth}.{symbol} WebSocket
topic, dispatching to apply_snapshot or
apply_diff as appropriate.
Sourcepub fn last_update_id(&self) -> Option<i64>
pub fn last_update_id(&self) -> Option<i64>
The update_id of the last applied snapshot or diff, once synced.
Sourcepub fn bids(&self) -> Option<&BTreeMap<Decimal, Decimal>>
pub fn bids(&self) -> Option<&BTreeMap<Decimal, Decimal>>
The live bid side (price -> size, ascending by price), once synced.
Sourcepub fn asks(&self) -> Option<&BTreeMap<Decimal, Decimal>>
pub fn asks(&self) -> Option<&BTreeMap<Decimal, Decimal>>
The live ask side (price -> size, ascending by price), once synced.