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: InstrumentIdThe instrument ID for the matching core.
price_increment: PriceThe 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
impl OrderMatchingCore
Sourcepub fn new(instrument_id: InstrumentId, price_increment: Price) -> Self
pub fn new(instrument_id: InstrumentId, price_increment: Price) -> Self
Creates a new OrderMatchingCore for the given instrument.
Sourcepub const fn price_precision(&self) -> u8
pub const fn price_precision(&self) -> u8
Returns the price precision of the instrument’s tick size.
Sourcepub fn get_order(&self, client_order_id: ClientOrderId) -> Option<&RestingOrder>
pub fn get_order(&self, client_order_id: ClientOrderId) -> Option<&RestingOrder>
Returns the order with the given client_order_id, searching both sides.
Sourcepub fn iter_bid_orders(&self) -> impl Iterator<Item = &RestingOrder>
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.
Sourcepub fn iter_ask_orders(&self) -> impl Iterator<Item = &RestingOrder>
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.
Sourcepub fn iter_orders(&self) -> impl Iterator<Item = &RestingOrder>
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.
Sourcepub fn get_orders_bid(&self) -> Vec<RestingOrder>
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.
Sourcepub fn get_orders_ask(&self) -> Vec<RestingOrder>
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.
Sourcepub fn get_orders(&self) -> Vec<RestingOrder>
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.
Sourcepub fn order_exists(&self, client_order_id: ClientOrderId) -> bool
pub fn order_exists(&self, client_order_id: ClientOrderId) -> bool
Returns whether an order with client_order_id is present on either side.
Sourcepub const fn set_last_raw(&mut self, last: Price)
pub const fn set_last_raw(&mut self, last: Price)
Sets the last traded price.
Sourcepub const fn set_bid_raw(&mut self, bid: Price)
pub const fn set_bid_raw(&mut self, bid: Price)
Sets the best bid price.
Sourcepub const fn set_ask_raw(&mut self, ask: Price)
pub const fn set_ask_raw(&mut self, ask: Price)
Sets the best ask price.
Sourcepub const fn update_price_increment(&mut self, price_increment: Price)
pub const fn update_price_increment(&mut self, price_increment: Price)
Updates the price increment (tick size) for the matching core.
Sourcepub fn add_order(&mut self, order: RestingOrder)
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
LIMITorders go to the side’s limit book, keyed by limit price. - Orders with neither price (e.g.
MARKET_TO_LIMITbefore conversion) go to the per-side pending bucket. They remain visible toget_order/order_existsbutiterate_*skips them.
§Panics
Panics in debug builds if the invariant is violated.
Sourcepub fn delete_order(
&mut self,
client_order_id: ClientOrderId,
) -> Result<(), OrderError>
pub fn delete_order( &mut self, client_order_id: ClientOrderId, ) -> Result<(), OrderError>
Sourcepub fn iterate(&self) -> Vec<MatchAction>
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.
Sourcepub fn iterate_bids(&self) -> Vec<MatchAction>
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.
Sourcepub fn iterate_asks(&self) -> Vec<MatchAction>
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.
Sourcepub fn match_order(&self, order: &RestingOrder) -> Option<MatchAction>
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).
Sourcepub fn is_limit_matched(&self, side: OrderSideSpecified, price: Price) -> bool
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).
Sourcepub fn is_stop_matched(&self, side: OrderSideSpecified, price: Price) -> bool
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).
Sourcepub fn is_touch_triggered(
&self,
side: OrderSideSpecified,
trigger_price: Price,
) -> bool
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).
Sourcepub fn set_fill_limit_inside_spread(&mut self, value: bool)
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).
Sourcepub fn is_limit_fillable(&self, side: OrderSideSpecified, price: Price) -> bool
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
impl Clone for OrderMatchingCore
Source§fn clone(&self) -> OrderMatchingCore
fn clone(&self) -> OrderMatchingCore
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more