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
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.
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
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?
What if a1 a2 a3 a4 are all on different exchanges and m1 is a directed market order to a particular exchange?
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).
*Hunsader http://www.zerohedge.com/news/2016-04-19/eric-hunsader-financial-system-absolutely-positively-rigged Thx! :^D
Here is another good article with Eric Honsador which simplifies how orders re picked off by HFTs and a few things traders can do to minimize the hit on your orders. http://www.forbes.com/sites/richard...y-human-traders-and-investors/2/#38c95e3f62e0
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.