Market Engine

StockMarketABM.MarketEngine provides the public entry points used by agents and simulations. It normalises incoming requests, delegates matching to StockMarketABM.MatchingEngine, and applies the resulting events to portfolio state, expiry tracking, and order-flow logging.

  1. submit_order! validates the request (instrument available, GTT has expire_at), aligns limit prices to the instrument's TickSize, invokes match_order!, updates portfolios via _apply_trade!, records trades in telemetry, logs order flow for each emitted event, and registers GTT orders with the expiry store.
  2. submit_cancel! locates the relevant book/instrument, dispatches the cancel through cancel_order!, updates expiry tracking, and logs the cancel/event to the order-flow buffer.

See also docs/src/market/matching_engine.md for the lower-level matching flow.

StockMarketABM.MarketEngine._apply_trade!Method
_apply_trade!(market, trade, taker_side)

Update maker and taker portfolios to reflect the executed trade. Cash transfers are computed from trade price × quantity, and holdings are adjusted based on the taker's side.

source
StockMarketABM.MarketEngine._locate_bookMethod
_locate_book(market, order_id)

Internal helper that searches for the order's instrument using the expiry store then falls back to scanning all order books. Returns (instrument, book) or (nothing, nothing) when unfound.

source
StockMarketABM.MarketEngine.submit_cancel!Method
submit_cancel!(market, request) -> OrderResponse

Attempt to cancel the specified order. Locates the relevant order book, invokes the matching engine's cancel routine, and updates expiry tracking.

source
StockMarketABM.MarketEngine.submit_order!Method
submit_order!(market, request) -> OrderResponse

Route an OrderRequest through the matching engine, update portfolios according to trades, and record expiries for GTT orders. Returns the aggregated OrderResponse.

source