Skip to main content

OrderBookHandle

Struct OrderBookHandle 

Source
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§

Source§

impl OrderBookHandle

Source

pub fn new(book: OrderBook) -> Self

Wraps book in a boundary-owned handle.

Source

pub fn book(&self) -> &OrderBook

Returns a reference to the wrapped book.

Source

pub fn into_inner(self) -> OrderBook

Consumes the wrapper and returns the inner book.

Methods from Deref<Target = OrderBook>§

Source

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.

Source

pub fn bids(&self, depth: Option<usize>) -> impl Iterator<Item = &BookLevel>

Returns an iterator over bid price levels.

Source

pub fn asks(&self, depth: Option<usize>) -> impl Iterator<Item = &BookLevel>

Returns an iterator over ask price levels.

Source

pub fn bids_as_map(&self, depth: Option<usize>) -> IndexMap<Decimal, Decimal>

Returns bid price levels as a map of price to size.

Source

pub fn asks_as_map(&self, depth: Option<usize>) -> IndexMap<Decimal, Decimal>

Returns ask price levels as a map of price to size.

Source

pub fn group_bids( &self, group_size: Decimal, depth: Option<usize>, ) -> IndexMap<Decimal, Decimal>

Groups bid quantities by price into buckets, limited by depth.

Source

pub fn group_asks( &self, group_size: Decimal, depth: Option<usize>, ) -> IndexMap<Decimal, Decimal>

Groups ask quantities by price into buckets, limited by depth.

Source

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).

Source

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).

Source

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.

Source

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.

Source

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).

Source

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).

Source

pub fn has_bid(&self) -> bool

Returns true if the book has any bid orders.

Source

pub fn has_ask(&self) -> bool

Returns true if the book has any ask orders.

Source

pub fn best_bid_price(&self) -> Option<Price>

Returns the best bid price if available.

Source

pub fn best_ask_price(&self) -> Option<Price>

Returns the best ask price if available.

Source

pub fn best_bid_size(&self) -> Option<Quantity>

Returns the size at the best bid price if available.

Source

pub fn best_ask_size(&self) -> Option<Quantity>

Returns the size at the best ask price if available.

Source

pub fn spread(&self) -> Option<f64>

Returns the spread between best ask and bid prices if both exist.

Source

pub fn midpoint(&self) -> Option<f64>

Returns the midpoint between best ask and bid prices if both exist.

Source

pub fn get_avg_px_for_quantity( &self, qty: Quantity, order_side: OrderSide, ) -> f64

Calculates the average price to fill the specified quantity.

Source

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.

Source

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).

Source

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.

Source

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.

Source

pub fn simulate_fills(&self, order: &BookOrder) -> Vec<(Price, Quantity)>

Simulates fills for an order, returning list of (price, quantity) tuples.

Source

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.

Source

pub fn pprint(&self, num_levels: usize, group_size: Option<Decimal>) -> String

Return a formatted string representation of the order book.

Trait Implementations§

Source§

impl Clone for OrderBookHandle

Source§

fn clone(&self) -> OrderBookHandle

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OrderBookHandle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for OrderBookHandle

Source§

type Target = OrderBook

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.