Order Book: Who gets matched first? Order queuing/matching algo question...

Discussion in 'App Development' started by kmiklas, Jan 16, 2017.

  1. kmiklas

    kmiklas

    How is it decided which orders get matched first? In the following example, which limit sell gets matched with m1 and filled at 42.15? a1, a2, a3, or a4?

    Thx, Keith :^)

    Example: the order book for XYZ stands as follows, where bn stands for an active limit buy order (bid), and an (ask) is a limit sell, all for 100 shares. As you can see, bid and ask now stand at 42.14/42.15:


    Code:
                   42.17   a1 a2 a3
                   42.16   a1 a2
                   42.15   a1 a2 a3 a4
    b1 b2 b3       42.14
    b1 b2 b3 b4 b5 42.13
    b1             42.12
    

    Now, market buy order m1, also for 100 shares, is sent to the exchange. With which sell limit is it matched: a1, a2, a3, or a4?

    Code:
                   42.17   a1 a2 a3
                   42.16   a1 a2
    m1             42.15   a1 a2 a3 a4   <- HERE. Who gets matched?
    b1 b2 b3       42.14
    b1 b2 b3 b4 b5 42.13
    b1             42.12
    

    For completeness of the example, let's assume that it's a FIFO (you know what they say when you assume!), and a1 gets matched. The book would then look like this :

    Code:
                   42.17   a1 a2 a3
                   42.16   a1 a2
                   42.15   a2 a3 a4
    b1 b2 b3       42.14
    b1 b2 b3 b4 b5 42.13
    b1             42.12
    





     
    Last edited: Jan 16, 2017
  2. You answered your own question. Market order m1 will be matched with limit order a1 at price level 42.15. If the quantity offered by a1 is less than the quantity of m1, then after the transaction between m1 and a1, m1 will be matched with the next limit order in the FIFO queue, which is limit order a2 at price level 42.15.
     
    Alpha Trader likes this.
  3. comagnum

    comagnum

    You may want to look at some of the detailed work done by Eric Honsador on the market micro structure of order flow, you can find it buried on-line. I believe he is the top dog in this arena.

    http://www.nanex.net/Research/IsNBBOIgnored.html
     
    Last edited: Jan 16, 2017
  4. JackRab

    JackRab

    FIFO, and market orders are always first... Theoretically, you market buy order could be matched with a market sell order if they are at exactly the same time...

    You should look at it this way, more interesting:

    Say the book is this pre opening (opening auction situation)

    5.000 @ mrkt / 2.000 @ mrkt
    1.000 @ 10.20 / 2.000 @ 10.00
    5.000 @ 10.12 / 4.000 @ 10.04
    2.000 @ 10.05 / 6.000 @ 10.07
    8.000 @ 10.01 / 2.000 @ 10.20

    Where does the market open?
     
  5. sprstpd

    sprstpd

    What if a1 a2 a3 a4 are all on different exchanges and m1 is a directed market order to a particular exchange?
     
    TraDaToR likes this.
  6. Tim Smith

    Tim Smith

    Eric is indeed the mutts nuts. Absolutely worth following his work (unless you're an HFT, in which case you've probably got an army of hit-men looking for him).
     
  7. kmiklas

    kmiklas

  8. comagnum

    comagnum

  9. Lee-

    Lee-

    Take NASDAQ as an example. At a particular price, the queue is not strictly FIFO. Whether an order is display or non-display will cause it to jump ahead or fall behind other orders in the queue (non-display is lower priority than display). A newer order type, extended life, will have a higher queue priority.
     
  10. TraDaToR

    TraDaToR

    Not sure because I don't know how market orders work in auctions, but 10.07?
     
    #10     Jan 18, 2017