Skip to main content

OrderMatchingCore

Struct OrderMatchingCore 

Source
pub struct OrderMatchingCore {
    pub instrument_id: InstrumentId,
    pub price_increment: Price,
    pub bid: Option<Price>,
    pub ask: Option<Price>,
    pub last: Option<Price>,
    /* private fields */
}
Expand description

A generic order matching core. See module docs for ordering, modify, duplicate, and performance contracts.

Fields§

§instrument_id: InstrumentId

The instrument ID for the matching core.

§price_increment: Price

The price increment for the matching core.

§bid: Option<Price>

The current bid price for the matching core.

§ask: Option<Price>

The current ask price for the matching core.

§last: Option<Price>

The last price for the matching core.

Implementations§

Source§

impl OrderMatchingCore

Source

pub fn new(instrument_id: InstrumentId, price_increment: Price) -> Self

Creates a new OrderMatchingCore for the given instrument.

Source

pub const fn price_precision(&self) -> u8

Returns the price precision of the instrument’s tick size.

Source

pub fn get_order(&self, client_order_id: ClientOrderId) -> Option<&RestingOrder>

Returns the order with the given client_order_id, searching both sides.

Source

pub fn iter_bid_orders(&self) -> impl Iterator<Item = &RestingOrder>

Iterates the bid-side orders in price-time priority without allocating: limits best (highest) first, then stops nearest-trigger (lowest) first, then pending unkeyed orders. Borrowed view; for an owned snapshot use Self::get_orders_bid.

Source

pub fn iter_ask_orders(&self) -> impl Iterator<Item = &RestingOrder>

Iterates the ask-side orders in price-time priority without allocating: limits best (lowest) first, then stops nearest-trigger (highest) first, then pending unkeyed orders. Borrowed view; for an owned snapshot use Self::get_orders_ask.

Source

pub fn iter_orders(&self) -> impl Iterator<Item = &RestingOrder>

Iterates all orders without allocating, bids (best first) then asks (best first). Borrowed view; for an owned snapshot use Self::get_orders.

Source

pub fn get_orders_bid(&self) -> Vec<RestingOrder>

Returns the bid-side orders in price-time priority: limits best (highest) first, then stops nearest-trigger (lowest) first, then pending unkeyed orders. Allocates an owned snapshot; for borrowed iteration use Self::iter_bid_orders.

Source

pub fn get_orders_ask(&self) -> Vec<RestingOrder>

Returns the ask-side orders in price-time priority: limits best (lowest) first, then stops nearest-trigger (highest) first, then pending unkeyed orders. Allocates an owned snapshot; for borrowed iteration use Self::iter_ask_orders.

Source

pub fn get_orders(&self) -> Vec<RestingOrder>

Returns all orders, bids (best first) then asks (best first). Allocates an owned snapshot; for borrowed iteration use Self::iter_orders.

Source

pub fn order_exists(&self, client_order_id: ClientOrderId) -> bool

Returns whether an order with client_order_id is present on either side.

Source

pub const fn set_last_raw(&mut self, last: Price)

Sets the last traded price.

Source

pub const fn set_bid_raw(&mut self, bid: Price)

Sets the best bid price.

Source

pub const fn set_ask_raw(&mut self, ask: Price)

Sets the best ask price.

Source

pub const fn update_price_increment(&mut self, price_increment: Price)

Updates the price increment (tick size) for the matching core.

Source

pub fn reset(&mut self)

Clears all orders and resets bid/ask/last to uninitialized.

Source

pub fn add_order(&mut self, order: RestingOrder)

Adds an order to the matching core.

§Invariant

Each client_order_id must appear at most once across all books. To re-add an order under the same ID (e.g. a price-changing modify), call Self::delete_order first. Inserting duplicates puts two entries in the bucket and the order will match twice.

Routing:

  • is_stop() orders go to the side’s stop book, keyed by trigger price.
  • Pure LIMIT orders go to the side’s limit book, keyed by limit price.
  • Orders with neither price (e.g. MARKET_TO_LIMIT before conversion) go to the per-side pending bucket. They remain visible to get_order / order_exists but iterate_* skips them.
§Panics

Panics in debug builds if the invariant is violated.

Source

pub fn delete_order( &mut self, client_order_id: ClientOrderId, ) -> Result<(), OrderError>

Deletes an order from the matching core by client order ID.

§Errors

Returns an OrderError::NotFound if the order is not present.

§Panics

Panics if the index points at a bucket that is missing or no longer contains the expected order, indicating internal index corruption.

Source

pub fn iterate(&self) -> Vec<MatchAction>

Matches all bid then ask orders against the current market and returns the resulting actions in price-time priority.

Source

pub fn iterate_bids(&self) -> Vec<MatchAction>

Matches bid-side orders: limits best (highest) first, then stops nearest-trigger (lowest) first. FIFO within each price level.

Source

pub fn iterate_asks(&self) -> Vec<MatchAction>

Matches ask-side orders: limits best (lowest) first, then stops nearest-trigger (highest) first. FIFO within each price level.

Source

pub fn match_order(&self, order: &RestingOrder) -> Option<MatchAction>

Returns a MatchAction if the order matches the current market, or None if it does not (or has neither trigger nor limit price).

Source

pub fn is_limit_matched(&self, side: OrderSideSpecified, price: Price) -> bool

Returns whether a limit order at price would cross the opposite side (BUY: ask <= price, SELL: bid >= price).

Source

pub fn is_stop_matched(&self, side: OrderSideSpecified, price: Price) -> bool

Returns whether a stop trigger at price has been reached (BUY: ask >= price, SELL: bid <= price).

Source

pub fn is_touch_triggered( &self, side: OrderSideSpecified, trigger_price: Price, ) -> bool

Returns whether a touch trigger at trigger_price has been reached (BUY: ask <= trigger_price, SELL: bid >= trigger_price).

Source

pub fn set_fill_limit_inside_spread(&mut self, value: bool)

Toggles whether limit orders fill at-or-inside the spread (vs only on cross).

Source

pub fn is_limit_fillable(&self, side: OrderSideSpecified, price: Price) -> bool

Returns whether a limit order is fillable at the given price.

Checks is_limit_matched first (crosses the spread). When fill_limit_inside_spread is set, also checks at-or-inside spread (BUY >= bid, SELL <= ask), requiring both sides initialized.

Trait Implementations§

Source§

impl Clone for OrderMatchingCore

Source§

fn clone(&self) -> OrderMatchingCore

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 OrderMatchingCore

Source§

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

Formats the value using the given formatter. Read more

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

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

impl<T> Ungil for T
where T: Send,