pub struct OrderBookHandle(/* private fields */);Expand description
Boundary-owned wrapper that lets OrderBook cross the cdylib FFI
boundary by reference.
The host constructs an instance from a cloned book, hands a
*const OrderBookHandle to the plug-in for the duration of the
callback, and drops the handle when the call returns. The plug-in
only borrows the handle and never owns it.
Implementations§
Methods from Deref<Target = OrderBook>§
Sourcepub fn to_deltas(
&self,
ts_event: UnixNanos,
ts_init: UnixNanos,
) -> OrderBookDeltas
pub fn to_deltas( &self, ts_event: UnixNanos, ts_init: UnixNanos, ) -> OrderBookDeltas
Creates an OrderBookDeltas snapshot from the current order book state.
This is the reverse operation of apply_deltas: it converts the current book state
back into a snapshot format with a Clear delta followed by Add deltas for all orders.
§Parameters
ts_event- UNIX timestamp (nanoseconds) when the book event occurred.ts_init- UNIX timestamp (nanoseconds) when the instance was created.
§Returns
An OrderBookDeltas containing a snapshot of the current order book state.
Sourcepub fn bids(&self, depth: Option<usize>) -> impl Iterator<Item = &BookLevel>
pub fn bids(&self, depth: Option<usize>) -> impl Iterator<Item = &BookLevel>
Returns an iterator over bid price levels.
Sourcepub fn asks(&self, depth: Option<usize>) -> impl Iterator<Item = &BookLevel>
pub fn asks(&self, depth: Option<usize>) -> impl Iterator<Item = &BookLevel>
Returns an iterator over ask price levels.
Sourcepub fn bids_as_map(&self, depth: Option<usize>) -> IndexMap<Decimal, Decimal>
pub fn bids_as_map(&self, depth: Option<usize>) -> IndexMap<Decimal, Decimal>
Returns bid price levels as a map of price to size.
Sourcepub fn asks_as_map(&self, depth: Option<usize>) -> IndexMap<Decimal, Decimal>
pub fn asks_as_map(&self, depth: Option<usize>) -> IndexMap<Decimal, Decimal>
Returns ask price levels as a map of price to size.
Sourcepub fn group_bids(
&self,
group_size: Decimal,
depth: Option<usize>,
) -> IndexMap<Decimal, Decimal>
pub fn group_bids( &self, group_size: Decimal, depth: Option<usize>, ) -> IndexMap<Decimal, Decimal>
Groups bid quantities by price into buckets, limited by depth.
Sourcepub fn group_asks(
&self,
group_size: Decimal,
depth: Option<usize>,
) -> IndexMap<Decimal, Decimal>
pub fn group_asks( &self, group_size: Decimal, depth: Option<usize>, ) -> IndexMap<Decimal, Decimal>
Groups ask quantities by price into buckets, limited by depth.
Sourcepub fn bids_filtered_as_map(
&self,
depth: Option<usize>,
own_book: Option<&OwnOrderBook>,
status: Option<&AHashSet<OrderStatus>>,
accepted_buffer_ns: Option<u64>,
now: Option<u64>,
) -> IndexMap<Decimal, Decimal>
pub fn bids_filtered_as_map( &self, depth: Option<usize>, own_book: Option<&OwnOrderBook>, status: Option<&AHashSet<OrderStatus>>, accepted_buffer_ns: Option<u64>, now: Option<u64>, ) -> IndexMap<Decimal, Decimal>
Maps bid prices to total public size per level, excluding own orders up to a depth limit.
With own_book, subtracts own order sizes, filtered by status if provided.
Uses accepted_buffer_ns to include only orders accepted at least that many
nanoseconds before now (defaults to now).
Sourcepub fn asks_filtered_as_map(
&self,
depth: Option<usize>,
own_book: Option<&OwnOrderBook>,
status: Option<&AHashSet<OrderStatus>>,
accepted_buffer_ns: Option<u64>,
now: Option<u64>,
) -> IndexMap<Decimal, Decimal>
pub fn asks_filtered_as_map( &self, depth: Option<usize>, own_book: Option<&OwnOrderBook>, status: Option<&AHashSet<OrderStatus>>, accepted_buffer_ns: Option<u64>, now: Option<u64>, ) -> IndexMap<Decimal, Decimal>
Maps ask prices to total public size per level, excluding own orders up to a depth limit.
With own_book, subtracts own order sizes, filtered by status if provided.
Uses accepted_buffer_ns to include only orders accepted at least that many
nanoseconds before now (defaults to now).
Sourcepub fn filtered_view(
&self,
own_book: Option<&OwnOrderBook>,
depth: Option<usize>,
status: Option<&AHashSet<OrderStatus>>,
accepted_buffer_ns: Option<u64>,
now: Option<u64>,
) -> OrderBook
pub fn filtered_view( &self, own_book: Option<&OwnOrderBook>, depth: Option<usize>, status: Option<&AHashSet<OrderStatus>>, accepted_buffer_ns: Option<u64>, now: Option<u64>, ) -> OrderBook
Returns a filtered OrderBook view with own sizes subtracted from public levels.
§Panics
Panics if self and own_book have different instrument IDs.
Self::filtered_view_checked for fallible construction.
Sourcepub fn filtered_view_checked(
&self,
own_book: Option<&OwnOrderBook>,
depth: Option<usize>,
status: Option<&AHashSet<OrderStatus>>,
accepted_buffer_ns: Option<u64>,
now: Option<u64>,
) -> Result<OrderBook, BookViewError>
pub fn filtered_view_checked( &self, own_book: Option<&OwnOrderBook>, depth: Option<usize>, status: Option<&AHashSet<OrderStatus>>, accepted_buffer_ns: Option<u64>, now: Option<u64>, ) -> Result<OrderBook, BookViewError>
Fallible version of Self::filtered_view.
§Errors
Returns BookViewError::InstrumentMismatch if self and own_book have different
instrument IDs.
§Panics
Panics if Price::from_decimal or Quantity::from_decimal fails when
reconstructing filtered levels.
Sourcepub fn group_bids_filtered(
&self,
group_size: Decimal,
depth: Option<usize>,
own_book: Option<&OwnOrderBook>,
status: Option<&AHashSet<OrderStatus>>,
accepted_buffer_ns: Option<u64>,
now: Option<u64>,
) -> IndexMap<Decimal, Decimal>
pub fn group_bids_filtered( &self, group_size: Decimal, depth: Option<usize>, own_book: Option<&OwnOrderBook>, status: Option<&AHashSet<OrderStatus>>, accepted_buffer_ns: Option<u64>, now: Option<u64>, ) -> IndexMap<Decimal, Decimal>
Groups bid quantities into price buckets, truncating to a maximum depth, excluding own orders.
With own_book, subtracts own order sizes, filtered by status if provided.
Uses accepted_buffer_ns to include only orders accepted at least that many
nanoseconds before now (defaults to now).
Sourcepub fn group_asks_filtered(
&self,
group_size: Decimal,
depth: Option<usize>,
own_book: Option<&OwnOrderBook>,
status: Option<&AHashSet<OrderStatus>>,
accepted_buffer_ns: Option<u64>,
now: Option<u64>,
) -> IndexMap<Decimal, Decimal>
pub fn group_asks_filtered( &self, group_size: Decimal, depth: Option<usize>, own_book: Option<&OwnOrderBook>, status: Option<&AHashSet<OrderStatus>>, accepted_buffer_ns: Option<u64>, now: Option<u64>, ) -> IndexMap<Decimal, Decimal>
Groups ask quantities into price buckets, truncating to a maximum depth, excluding own orders.
With own_book, subtracts own order sizes, filtered by status if provided.
Uses accepted_buffer_ns to include only orders accepted at least that many
nanoseconds before now (defaults to now).
Sourcepub fn best_bid_price(&self) -> Option<Price>
pub fn best_bid_price(&self) -> Option<Price>
Returns the best bid price if available.
Sourcepub fn best_ask_price(&self) -> Option<Price>
pub fn best_ask_price(&self) -> Option<Price>
Returns the best ask price if available.
Sourcepub fn best_bid_size(&self) -> Option<Quantity>
pub fn best_bid_size(&self) -> Option<Quantity>
Returns the size at the best bid price if available.
Sourcepub fn best_ask_size(&self) -> Option<Quantity>
pub fn best_ask_size(&self) -> Option<Quantity>
Returns the size at the best ask price if available.
Sourcepub fn spread(&self) -> Option<f64>
pub fn spread(&self) -> Option<f64>
Returns the spread between best ask and bid prices if both exist.
Sourcepub fn midpoint(&self) -> Option<f64>
pub fn midpoint(&self) -> Option<f64>
Returns the midpoint between best ask and bid prices if both exist.
Sourcepub fn get_avg_px_for_quantity(
&self,
qty: Quantity,
order_side: OrderSide,
) -> f64
pub fn get_avg_px_for_quantity( &self, qty: Quantity, order_side: OrderSide, ) -> f64
Calculates the average price to fill the specified quantity.
Sourcepub fn get_worst_px_for_quantity(
&self,
qty: Quantity,
order_side: OrderSide,
) -> Option<Price>
pub fn get_worst_px_for_quantity( &self, qty: Quantity, order_side: OrderSide, ) -> Option<Price>
Calculates the worst (last-touched) price to fill the specified quantity.
Sourcepub fn get_avg_px_qty_for_exposure(
&self,
target_exposure: Quantity,
order_side: OrderSide,
) -> (f64, f64, f64)
pub fn get_avg_px_qty_for_exposure( &self, target_exposure: Quantity, order_side: OrderSide, ) -> (f64, f64, f64)
Calculates average price and quantity for target exposure. Returns (price, quantity, executed_exposure).
Sourcepub fn get_quantity_for_price(&self, price: Price, order_side: OrderSide) -> f64
pub fn get_quantity_for_price(&self, price: Price, order_side: OrderSide) -> f64
Returns the cumulative quantity available at or better than the specified price.
For a BUY order, sums ask levels at or below the price. For a SELL order, sums bid levels at or above the price.
Sourcepub fn get_quantity_at_level(
&self,
price: Price,
order_side: OrderSide,
size_precision: u8,
) -> Quantity
pub fn get_quantity_at_level( &self, price: Price, order_side: OrderSide, size_precision: u8, ) -> Quantity
Returns the quantity at a specific price level only, or 0 if no level exists.
Unlike get_quantity_for_price which returns cumulative quantity across
multiple levels, this returns only the quantity at the exact price level.
Sourcepub fn simulate_fills(&self, order: &BookOrder) -> Vec<(Price, Quantity)>
pub fn simulate_fills(&self, order: &BookOrder) -> Vec<(Price, Quantity)>
Simulates fills for an order, returning list of (price, quantity) tuples.
Sourcepub fn get_all_crossed_levels(
&self,
order_side: OrderSide,
price: Price,
size_precision: u8,
) -> Vec<(Price, Quantity)>
pub fn get_all_crossed_levels( &self, order_side: OrderSide, price: Price, size_precision: u8, ) -> Vec<(Price, Quantity)>
Returns all price levels crossed by an order at the given price and side.
Unlike simulate_fills, this returns ALL crossed levels regardless of
order quantity. Used when liquidity consumption tracking needs visibility
into all available levels.
Trait Implementations§
Source§impl Clone for OrderBookHandle
impl Clone for OrderBookHandle
Source§fn clone(&self) -> OrderBookHandle
fn clone(&self) -> OrderBookHandle
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more