pub struct OrderMatchingEngine {
pub venue: Venue,
pub instrument: InstrumentAny,
pub raw_id: u32,
pub book_type: BookType,
pub oms_type: OmsType,
pub account_type: AccountType,
pub market_status: MarketStatus,
pub config: OrderMatchingEngineConfig,
/* private fields */
}Expand description
An order matching engine for a single market.
Fields§
§venue: VenueThe venue for the matching engine.
instrument: InstrumentAnyThe instrument for the matching engine.
raw_id: u32The instruments raw integer ID for the venue.
book_type: BookTypeThe order book type for the matching engine.
oms_type: OmsTypeThe order management system (OMS) type for the matching engine.
account_type: AccountTypeThe account type for the matching engine.
market_status: MarketStatusThe market status for the matching engine.
config: OrderMatchingEngineConfigThe config for the matching engine.
Implementations§
Source§impl OrderMatchingEngine
impl OrderMatchingEngine
Sourcepub fn new(
instrument: InstrumentAny,
raw_id: u32,
fill_model: FillModelAny,
fee_model: FeeModelAny,
book_type: BookType,
oms_type: OmsType,
account_type: AccountType,
clock: Rc<RefCell<dyn Clock>>,
cache: Rc<RefCell<Cache>>,
config: OrderMatchingEngineConfig,
) -> Self
pub fn new( instrument: InstrumentAny, raw_id: u32, fill_model: FillModelAny, fee_model: FeeModelAny, book_type: BookType, oms_type: OmsType, account_type: AccountType, clock: Rc<RefCell<dyn Clock>>, cache: Rc<RefCell<Cache>>, config: OrderMatchingEngineConfig, ) -> Self
Creates a new OrderMatchingEngine instance.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Resets the matching engine to its initial state.
Clears the order book, execution state, cached data, and resets all internal components. This is typically used for backtesting scenarios where the engine needs to be reset between test runs.
Sourcepub fn set_fill_model(&mut self, fill_model: FillModelAny)
pub fn set_fill_model(&mut self, fill_model: FillModelAny)
Sets the fill model for the matching engine.
Sourcepub fn best_bid_price(&self) -> Option<Price>
pub fn best_bid_price(&self) -> Option<Price>
Returns the best bid price from the order book.
Sourcepub fn best_ask_price(&self) -> Option<Price>
pub fn best_ask_price(&self) -> Option<Price>
Returns the best ask price from the order book.
Sourcepub const fn get_open_bid_orders(&self) -> &[OrderMatchInfo]
pub const fn get_open_bid_orders(&self) -> &[OrderMatchInfo]
Returns all open bid orders managed by the matching core.
Sourcepub const fn get_open_ask_orders(&self) -> &[OrderMatchInfo]
pub const fn get_open_ask_orders(&self) -> &[OrderMatchInfo]
Returns all open ask orders managed by the matching core.
Sourcepub fn get_open_orders(&self) -> Vec<OrderMatchInfo>
pub fn get_open_orders(&self) -> Vec<OrderMatchInfo>
Returns all open orders from both bid and ask sides.
Sourcepub fn order_exists(&self, client_order_id: ClientOrderId) -> bool
pub fn order_exists(&self, client_order_id: ClientOrderId) -> bool
Returns true if an order with the given client order ID exists in the matching engine.
pub const fn get_core(&self) -> &OrderMatchingCore
pub fn get_core_mut(&mut self) -> &mut OrderMatchingCore
pub fn set_fill_at_market(&mut self, value: bool)
Sourcepub fn process_order_book_delta(&mut self, delta: &OrderBookDelta) -> Result<()>
pub fn process_order_book_delta(&mut self, delta: &OrderBookDelta) -> Result<()>
Process the venues market for the given order book delta.
§Errors
- If delta order price precision does not match the instrument (for Add/Update actions).
- If delta order size precision does not match the instrument (for Add/Update actions).
- If applying the delta to the book fails.
Sourcepub fn process_order_book_deltas(
&mut self,
deltas: &OrderBookDeltas,
) -> Result<()>
pub fn process_order_book_deltas( &mut self, deltas: &OrderBookDeltas, ) -> Result<()>
Process the venues market for the given order book deltas.
§Errors
- If any delta order price precision does not match the instrument (for Add/Update actions).
- If any delta order size precision does not match the instrument (for Add/Update actions).
- If applying the deltas to the book fails.
Sourcepub fn process_order_book_depth10(
&mut self,
depth: &OrderBookDepth10,
) -> Result<()>
pub fn process_order_book_depth10( &mut self, depth: &OrderBookDepth10, ) -> Result<()>
Process the venues market for the given order book depth10.
§Errors
- If any bid/ask price precision does not match the instrument.
- If any bid/ask size precision does not match the instrument.
- If applying the depth to the book fails.
- If updating the L1 order book with the top-of-book quote fails.
Sourcepub fn process_quote_tick(&mut self, quote: &QuoteTick)
pub fn process_quote_tick(&mut self, quote: &QuoteTick)
Processes a quote tick to update the market state.
§Panics
- If updating the order book with the quote tick fails.
- If bid/ask price precision does not match the instrument.
- If bid/ask size precision does not match the instrument.
Sourcepub fn process_bar(&mut self, bar: &Bar)
pub fn process_bar(&mut self, bar: &Bar)
Processes a bar and simulates market dynamics by creating synthetic ticks.
For L1 books with bar execution enabled, generates synthetic trade or quote ticks from bar OHLC data to drive order matching.
§Panics
- If the bar type configuration is missing a time delta.
- If bar OHLC price precision does not match the instrument.
- If bar volume precision does not match the instrument.
Sourcepub fn process_trade_tick(&mut self, trade: &TradeTick)
pub fn process_trade_tick(&mut self, trade: &TradeTick)
Processes a trade tick to update the market state.
For L1 books, always updates the order book with the trade tick to maintain
market state. When trade_execution is disabled, order matching and maintenance
operations (GTD order expiry, trailing stop activation, instrument expiration)
are skipped. These maintenance operations will run on the next quote tick or bar.
§Panics
- If updating the order book with the trade tick fails.
- If trade price precision does not match the instrument.
- If trade size precision does not match the instrument.
Sourcepub fn process_status(&mut self, action: MarketStatusAction)
pub fn process_status(&mut self, action: MarketStatusAction)
Processes a market status action to update the market state.
Sourcepub fn process_instrument_close(&mut self, close: InstrumentClose)
pub fn process_instrument_close(&mut self, close: InstrumentClose)
Processes an instrument close event.
For ContractExpired close types, stores the close and triggers expiration
processing which cancels all open orders and closes all open positions.
Sourcepub fn process_order(&mut self, order: &mut OrderAny, account_id: AccountId)
pub fn process_order(&mut self, order: &mut OrderAny, account_id: AccountId)
Processes a new order submission.
Validates the order against instrument precision, expiration, and contingency rules before accepting or rejecting it.
§Panics
Panics if an OTO child order references a missing or non-OTO parent.
Sourcepub fn process_modify(&mut self, command: &ModifyOrder, account_id: AccountId)
pub fn process_modify(&mut self, command: &ModifyOrder, account_id: AccountId)
Processes an order modify command to update quantity, price, or trigger price.
Sourcepub fn process_cancel(&mut self, command: &CancelOrder, account_id: AccountId)
pub fn process_cancel(&mut self, command: &CancelOrder, account_id: AccountId)
Processes an order cancel command.
Sourcepub fn process_cancel_all(
&mut self,
command: &CancelAllOrders,
account_id: AccountId,
)
pub fn process_cancel_all( &mut self, command: &CancelAllOrders, account_id: AccountId, )
Processes a cancel all orders command for an instrument.
Sourcepub fn process_batch_cancel(
&mut self,
command: &BatchCancelOrders,
account_id: AccountId,
)
pub fn process_batch_cancel( &mut self, command: &BatchCancelOrders, account_id: AccountId, )
Processes a batch cancel orders command.
Sourcepub fn iterate(
&mut self,
timestamp_ns: UnixNanos,
aggressor_side: AggressorSide,
)
pub fn iterate( &mut self, timestamp_ns: UnixNanos, aggressor_side: AggressorSide, )
Iterate the matching engine by processing the bid and ask order sides
and advancing time up to the given UNIX timestamp_ns.
The aggressor_side parameter is used for trade execution processing.
When not NoAggressor, the book-based bid/ask reset is skipped to preserve
transient trade price overrides.
Sourcepub fn fill_market_order(&mut self, client_order_id: ClientOrderId)
pub fn fill_market_order(&mut self, client_order_id: ClientOrderId)
Fills a market order against the current order book.
The order is filled as a taker against available liquidity. Reduce-only orders are canceled if no position exists.
Sourcepub fn fill_limit_order(&mut self, client_order_id: ClientOrderId)
pub fn fill_limit_order(&mut self, client_order_id: ClientOrderId)
Attempts to fill a limit order against the current order book.
Determines fill prices and quantities based on available liquidity, then applies the fills to the order.
§Panics
Panics if the order has no price (design error).
Sourcepub fn trigger_stop_order(&mut self, client_order_id: ClientOrderId)
pub fn trigger_stop_order(&mut self, client_order_id: ClientOrderId)
Triggers a stop order, converting it to an active market or limit order.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for OrderMatchingEngine
impl !RefUnwindSafe for OrderMatchingEngine
impl !Send for OrderMatchingEngine
impl !Sync for OrderMatchingEngine
impl Unpin for OrderMatchingEngine
impl UnsafeUnpin for OrderMatchingEngine
impl !UnwindSafe for OrderMatchingEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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