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.
submit_order!validates the request (instrument available, GTT hasexpire_at), aligns limit prices to the instrument'sTickSize, invokesmatch_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.submit_cancel!locates the relevant book/instrument, dispatches the cancel throughcancel_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.
StockMarketABM.MarketEngine._locate_book — Method_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.
StockMarketABM.MarketEngine._response_status — Method_response_status(request_qty, filled, events) -> ResponseStatusDerive the final response classification from the filled quantity and the set of emitted events.
StockMarketABM.MarketEngine.submit_cancel! — Methodsubmit_cancel!(market, request) -> OrderResponseAttempt to cancel the specified order. Locates the relevant order book, invokes the matching engine's cancel routine, and updates expiry tracking.
StockMarketABM.MarketEngine.submit_order! — Methodsubmit_order!(market, request) -> OrderResponseRoute an OrderRequest through the matching engine, update portfolios according to trades, and record expiries for GTT orders. Returns the aggregated OrderResponse.