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,
pub core: OrderMatchingCore,
/* 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.
core: OrderMatchingCoreImplementations§
Source§impl OrderMatchingEngine
impl OrderMatchingEngine
Sourcepub fn new(
instrument: InstrumentAny,
raw_id: u32,
fill_model: FillModel,
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: FillModel, 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 const fn set_fill_model(&mut self, fill_model: FillModel)
pub const fn set_fill_model(&mut self, fill_model: FillModel)
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) -> &[PassiveOrderAny]
pub const fn get_open_bid_orders(&self) -> &[PassiveOrderAny]
Returns all open bid orders managed by the matching core.
Sourcepub const fn get_open_ask_orders(&self) -> &[PassiveOrderAny]
pub const fn get_open_ask_orders(&self) -> &[PassiveOrderAny]
Returns all open ask orders managed by the matching core.
Sourcepub fn get_open_orders(&self) -> Vec<PassiveOrderAny>
pub fn get_open_orders(&self) -> Vec<PassiveOrderAny>
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.
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_quote_tick(&mut self, quote: &QuoteTick)
pub fn process_quote_tick(&mut self, quote: &QuoteTick)
§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, updates the order book with the trade. When trade execution is enabled, allows resting orders to fill against the trade price.
§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_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 the instrument activation timestamp is missing.
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.
§Panics
Panics if the best bid or ask price is unavailable when iterating.
Sourcepub fn fill_market_order(&mut self, order: &mut OrderAny)
pub fn fill_market_order(&mut self, order: &mut OrderAny)
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, order: &mut OrderAny)
pub fn fill_limit_order(&mut self, order: &mut OrderAny)
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, or if fill price or quantity precision mismatches occur.
Sourcepub fn trigger_stop_order(&mut self, order: &mut OrderAny)
pub fn trigger_stop_order(&mut self, order: &mut OrderAny)
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 !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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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