pub struct OrderBookSide { /* private fields */ }Expand description
One side of a level 2 book.
Levels are kept best first — descending for bids, ascending for asks — so the best level, the n-th level and the depth cut are all index arithmetic.
Implementations§
Source§impl OrderBookSide
impl OrderBookSide
Sourcepub fn max_depth(&self) -> Option<usize>
pub fn max_depth(&self) -> Option<usize>
The level cap this side was built with, or None when uncapped.
Sourcepub fn iter(&self) -> Iter<'_, PriceAmount> ⓘ
pub fn iter(&self) -> Iter<'_, PriceAmount> ⓘ
Iterate every level, best first.
Sourcepub fn find(&self, price: Dec) -> Option<&PriceAmount>
pub fn find(&self, price: Dec) -> Option<&PriceAmount>
The level at exactly price, if the side holds one.
Keyed by price, where OrderBookSide::at is keyed by depth.
Sourcepub fn best(&self) -> Option<&PriceAmount>
pub fn best(&self) -> Option<&PriceAmount>
The best level: highest bid, lowest ask.
Sourcepub fn best_price(&self) -> Option<Dec>
pub fn best_price(&self) -> Option<Dec>
The price of the best level.
Sourcepub fn worst(&self) -> Option<&PriceAmount>
pub fn worst(&self) -> Option<&PriceAmount>
The worst level held, which is the deepest one, not the worst possible.
Sourcepub fn worst_price(&self) -> Option<Dec>
pub fn worst_price(&self) -> Option<Dec>
The price of the worst level held.
Sourcepub fn at(&self, n: usize) -> Option<&PriceAmount>
pub fn at(&self, n: usize) -> Option<&PriceAmount>
The n-th level from the best, counting from zero.
Sourcepub fn set(&mut self, entry: PriceAmount) -> Option<Dec>
pub fn set(&mut self, entry: PriceAmount) -> Option<Dec>
Set a level, returning the amount it replaced. A zero amount removes it.
A level failing PriceAmount::is_valid is rejected and the book left
untouched. None therefore covers four cases: the level was inserted,
it was rejected as invalid, it was refused for sitting past
max_depth, or a zero amount asked to remove a price that was absent.
Sourcepub fn set_price_amount(&mut self, price: Dec, amount: Dec) -> Option<Dec>
pub fn set_price_amount(&mut self, price: Dec, amount: Dec) -> Option<Dec>
OrderBookSide::set taking the price and amount separately.
Sourcepub fn trim(&mut self, depth: usize)
pub fn trim(&mut self, depth: usize)
Retain at most depth levels, dropping the worst ones beyond that.
Sourcepub fn range(&self, low: Dec, high: Dec) -> Iter<'_, PriceAmount> ⓘ
pub fn range(&self, low: Dec, high: Dec) -> Iter<'_, PriceAmount> ⓘ
Iterate levels within [low, high] in best-first order.
An empty iterator when no level falls inside, low above high
included.
Sourcepub fn volume_at(&self, level: usize) -> Option<Dec>
pub fn volume_at(&self, level: usize) -> Option<Dec>
Get the volume up to a given level in the orderbook side
Sourcepub fn price_for_quantity(&self, quantity: f64) -> Option<f64>
pub fn price_for_quantity(&self, quantity: f64) -> Option<f64>
Volume weighted price paid to fill quantity, or None if the side is
too thin.
Sourcepub fn amount_mean(&self) -> Option<f64>
pub fn amount_mean(&self) -> Option<f64>
Mean level amount, or None when the side is empty.
Summed on demand rather than kept as a running total. A running one
would have to be corrected on every set, which is the hot path, to
save an addition per level here, which is not; and one non-finite amount
would poison it for good, since the subtraction that removes the level
cannot take a NaN back out again.
Sourcepub fn amount_std_dev(&self) -> Option<f64>
pub fn amount_std_dev(&self) -> Option<f64>
Population standard deviation of the level amounts, or None when the
side is empty.
Computed from the levels rather than from a running sum of squares. A
running one drifts: adding and removing a level far larger than the
rest cancels badly enough to report no dispersion at all on a book that
has some, and the clamp that hid it turned corruption into a plausible
number. The mean comes from the exact Dec total, so only the
deviations are floating point, and their squares cannot go negative.
Two passes, then: the mean has to be known before a deviation can be measured against it, which is the same reason the one-pass form is the one that drifts.