Skip to content
All library documents

How Matching Engines Handle Market Orders and Opposing Order Flow

Article Quant Q&A · Author: olivia

Summary

The document explains, at a simplified level, how an exchange may process market orders when buy and sell orders arrive close together. In the described model, market orders execute against resting limit orders on the opposite side of the book; market orders do not directly match one another. A market order with no available opposing limit liquidity may be rejected or constrained by exchange safeguards such as a volatility threshold.

The answers emphasize that actual behavior depends on the exchange’s matching rules. One explanation describes separate market buy and market sell queues, while another models matching as an atomic check against resting orders, after which an unmatched immediate order is discarded. These are illustrative descriptions, not a universal specification. The example of an empty book highlights why matching two market orders would leave the execution price undefined, and why an exchange needs explicit rules for empty-book cases.

Key ideas

  • Market orders generally execute against resting limit orders on the opposite side.
  • An unmatched immediate order may be rejected or removed, depending on exchange rules.
  • Market buy and sell orders may be handled in separate queues.
  • Matching behavior and safeguards vary among exchanges.

Tags

Full text
# How is market buy order executed when meeting both market sell order and limit sell order?


# How is market buy order executed when meeting both market sell order and limit sell order?












Currently, we all know how market buy order is executed when meeting only limit sell order for time-priority rule.

## Answer by amdopt (score 4)

https://quant.stackexchange.com/a/50507

Two (or more) orders arriving at the same time makes no difference for an exchange's matching engine, the buy orders execute against sell limit orders, and the sell orders execute against buy limit orders. If no limit orders exist, market orders may be rejected by the exchange, or the price will be restricted to a 'volatility threshold' based on the last trade price to maintain an 'orderly' market (see section 7.3 (amongst others) of the Eurex link below).

Not to overly complicate the answer, but some understanding of matching engines and HFT is what you are really looking for here. Matching engines have several different queues to handle orders--the queues have a priority order. One of those queues is the 'Market Order Queue.' Within the 'Market Order Queue,' there will be two sub-queues -- 'market buy' and 'market sell.' The 'market buy' queue is handled independently of the 'market sell' queue.

A functional reference guide for the Eurex matching engine can be downloaded here Eurex.

Some additional resources you may learn from are:

Quote setting and price formation in an order driven market

Google Search: "Limit order book models and optimal trading strategies" will yield dozens of results.

## Answer by Bob Jansen (score 1)

https://quant.stackexchange.com/a/50513

@amdopt's answer emphasises there is a lot of depth to this topic and that the actual behaviour of the order matching depends on exchange particulars. In this answer, I give a simplified view of an exchange where market orders also don't match other market orders.

Orders can be split into two types: resting orders and immediate orders. All resting orders that have not been executed are kept by the exchange until they are completely executed or otherwise removed (for example: cancelled by the sender). Immediate orders, such as market orders, are either instantly executed or immediately removed.

So, if a market order arrives at the exchange, the matching engine of the exchange will atomically check whether the order can be matched and if it can not be matched discard the order. So it can never be that the matching engine considers more than one market order at one moment and therefore also can't match two market orders.

## Answer by wildbunny (score 0)

https://quant.stackexchange.com/a/50506

Market orders cannot be matched against other market orders. Consider this case:

1) Limit book is empty on both sides

2) Market sell arrives at same time as market buy with matching sizes

What price do you fill this trade at?

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.