Order matching questions

Discussion in 'Order Execution' started by Spaghetti Code, Dec 11, 2024.

  1. I have some questions about how orders are matched. I am trying to write a simple simulator that tries to match orders.

    1. After a trading halt, how are limit orders matched with each other? Do all orders get the same price like in the opening/closing cross?

    2. After a trading halt, are market orders executed before or after other limit orders?

    3. Does a Market order convert into a limit order at execution time? If I wanted to market buy, does the exchange just enter a limit order with a price equal to the top of the book price?

    4. What happens if a market order is placed where there are no active bids / asks? Does it just sit there until someone picks an insanely high / low price and the order executes?
     
  2. MrMuppet

    MrMuppet

    It is very, very sad that the majority of the posters here doesn´t realize that this probably one of the best questions of the year.

    You are not writing a simulator, you are writing a matching engine. The reason why your question is so important is the fact that the way how orders are matched differs from exchange to exchange and sometimes from product to product.
    And understanding how it is done offers a ginormous edge once you´ve learned to exploit it.

    In order for you to go ahead you have to get your hands dirty and read the rulebooks of the exchanges you want to simulate. CBOT should be easy, CME has a couple of different matching algos and exception handlings, US Equities...boy you´re in for some nasty surprises. And then there is crypto which basically is an undiscovered goldmine.

    I would advise to press forward and get a proper understanding of where your order goes to, how it is matched, what happens during exceptions such as volatility triggers, SSR, halts and other circuit breakers, say good bye to charts and finally start to make money.
     
    spy and Baron like this.
  3. lx008

    lx008

    for a simple matching algo:

    1,matching by price
    2,if price the same, ranking by order submit time
    3,for simple reason, make the market order price the limit up or limit down price