How do exchanges match limit orders?
The Limit Order are matched based on amount and time. The orders are listed Highest to Lowest on the Buy Side. The orders are listed Lowest to Highest on the Sell Side. If there are 2 Sell orders for same amount the order which is first in time [fractions of milliseconds] is first.  The about is the example as to how the orders would look like on any exchange.  Now the highest price the buyer is ready to pay is 20.21 and the lowest price a seller is ready to sell for is 20.25. Hence there is no trade. Now if a new Buy order comes in at 20.25, it matches with the sell and the deal is made. If a new Buy order comes in at 20.30, it still matches at 20.25. Similarly if a Sell order come in at 20.21, it matches and a deal is made. If a Sell order come in at 20.11, it still matches 20.21.   Incase of market order, with the above example if there is a Buy order, it would match with the lowest sell order at 20.25, if there is not enough quantity , it would match the remaining quantity to the next highest at 20.31 and continue down. Similarly if there is a Sell market order, the it would match to the maximum a seller is ready to buy, ie 20.21, if there is not sufficient buy quantity at 20.21, it will match with next for 20.19   If say there are new buy order at 20.22 and sell orders at 20.24, these will sit first the the above queue to be matched. In your above example the Lowest Sell order was at 20.10 at time t1 and hence any buy order after time t1 for amount 20.10 or greater would match to this and the price would be 20.10. However if the Buy order was first ie at t1 there was a buy order for 20.21 and then at time later than t1, there is a sell order for say 20.10 [amount less than or equal to 20.21] it would match for 20.21. Essentially the market looks at who was the first to sell at lower price or who was the first to buy at higher price and then decide the trade.  Edit [To Clarify xyz]: Say if there is an Sell order at $10 Qty 100. There is a buyer who is willing to pay Max $20 and is looking for Qty 500. Your key assumption that the Buyer does not know the current SELL price of $10 is incorrect. Now there are multiple things, the Buyer knows the lowest Sell order is at $10, he can put a matching Buy order at $10 Qty 100, and say $11 Qty 100 etc. This is painful. Second, lets say he puts a Buy order at $10 Qty 100, by the time the order hits the system someone else has put the trade at $10 and his order is fulfilled. So this buyer has to keep looking at booking and keep making adjustments, if its a large order, it would be extremely difficult and frustrating for this Buyer. Hence the logic of giving preference. The later Buy order says ... The Max I can pay is $20, match eveything at the current price and get the required shares. The total limit book is a composite of all the orders on all of the exchanges. While it's uncommon for a limit order posted beyond the NBBO to fill outside of the NBBO, it does occur. For example, the best ask may be on exchange X, but for some reason the smart order routing algorithm may select exchange Y if it judges the net trade to be less costly, malfunctions, etc, and HFTs will immediately arbitrage the order between two exchanges, or the best order on exchange X disappears causing the order to fill above the NBBO. The system isn't perfect because there are multiple exchanges, but that eventuality is extremely rare with equities since nearly every exchange will have orders posted at the NBBO because exchange equity fee and rebate schedules are extremely competitive, nearly identical.  It is however more common with options since less exchanges as a percentage of the total will have orders posted at the NBBO because of very wide exchange rebate and fee schedules. How a single exchange handles a new order that crosses an existing limit order is already addressed here: How do exchanges match limit orders?
"You might consider learning how the ""matching"" or ""pairing"" system in the market operates.  The actual exchange only happens when both a buyer and a seller overlap their respect quotes.   Sometimes orders ""go to market"" for a particular volume.  Eg get me 10,000 Microsoft shares now.  which means that the price starts at the current lowest seller, and works up the price list until the volume is met.  Like all market it trades, it has it's advantages, and it's dangers.  If you are confident Microsoft is going to bull, you want those shares now, confident you'll recoup the cost.  Where if you put in a priced order, you might get only none or some shares. Same as when you sell.  If you see the price (which is the price of the last completed ""successful"" trade.  and think ""I'm going to sell 1000 shares"". then you give the order to the market (or broker), and then the same as what happened as before.  the highest bidder gets as much as they asked for, if there's still shares left over, they go to the next bidder, and so on down the price... and the last completed ""successful"" trade is when your last sale is made at the lowest price of your batch. If you're selling, and selling 100,000 shares. And the highest bidder wants 1,000,000 shares you'll only see the price drop to that guys bid.  Why will it drop (off the quoted price?).  Because the quoted price is the LAST sale, clearly if there's someone still with an open bid on the market...then either he wants more shares than were available (the price stays same), or his bid wasn't as high as the last bid (so when you sale goes through, it will be at the price he's offering).   Which is why being able to see the price queues is important on large traders. It is also why it can be important put stops and limits on your trades, een through you can still get gapped if you're unlucky.  However putting prices (""Open Orders"" vs ""(at)Market Orders"") can mean that you're sitting there waiting for a bounce/spike while the action is all going on without you). safer but not as much gain (maybe ;) ) that's the excitement of the market, for every option there's advantages...and risks... (eg missing out) There are also issues with stock movement, shadowing, and stop hunting, which can influence the price. But the stuff in the long paragraphs is the technical reasons." Futures exchanges are essentially auction houses facilitating a two-way auction. While they provide a venue for buyers and sellers to come together and transact (be that a physical venue such as a pit at the CME or an electronic network such as Globex), they don't actively seek out or find buyers and sellers to pair them together. The exchanges enable this process through an order book. As a futures trader you may submit one of two types of order to an exchange: Market Order - this is sent to the exchange and is filled immediately by being paired with a limit order.   Limit Order - this is placed on the books of the exchange at the price you specify. If other participants enter opposing market orders at this price, then their market order will be paired with your limit order. In your example, trader B wishes to close his long position. To do this he may enter a market sell order, which will immediately close his position at the lowest possible buy limit price, or he may enter a limit sell order, specifying the price at or above which he is willing to sell. In the case of the limit order, he will only sell and successfully close his position if his order becomes the lowest sell order on the book. All this may be a lot easier to understand by looking at a visual image of an order book such as the one given in the explanation that I have published here: Stop Orders for Futures Finally, not that as far as the exchange is concerned, there is no difference between an order to open and an order to close a position. They're all just 'buy' or 'sell' orders. Whether they cause you to reduce/exit a position or increase/establish a position is relative to the position you currently hold; if you're flat a buy order establishes a new position, if you're short it closes your position and leaves you flat. &gt; we make a trade-off between time to execute and market impact.  Is your time frame any longer than intraday? I imagine you wouldn't want to carry that risk overnight if you're a broker or selling a route..  &gt; we will join the bid for some fraction of our size, and also hit the offer when it looks like the price might be moving away from us  So, say for instance you join a bid a few levels down, you aren't really get filled, you start hitting the offer and eventually you realize you're competing with someone for the shares offered, so you take out the price level and bid on all the exchanges so that you're first on the bid at that level, then repeat until someone that can match your appetite starts to fill you on the bid?  &gt; In some certain situations we will even sweep the book several levels deep to avoid tipping off market makers and having them adjust in anticipation of the rest of our order.  Right, so say you need 100k shares, there are 10k offered at 9.98, 25k offered at 9.99, and 65k at 10.00, you might just enter an intermarket sweep order of 100k @ 10 limit and hope that you can get most of the shares off before everyone can cancel?  I imagine there has to be a lot of bidding it up to attract sellers and then letting people take out your bids all day...  I have a few other questions I would appreciate your insight on. Just trying to ascertain how orders are filled when, as you put it, time is more important than market impact to the client - when they need to take a large amount of liquidity as quickly as possible and as orderly as possible.  Let me know if you'd rather I pm you about this or the additional questions, I work in the industry as well so I know privacy is paramount. "I can address what it means to ""pick off"" all those trades... As quantycuenta & littleadv have said, it is absolutely true that professionals ""prey"" on less-sophisticated market participants. They aren't in the market for charity's sake.  If you're not familiar with the definition of the word ""arbitrage"", look it up.  One possible strategy that can be employed with HFT machinery in order to arbitrage successfully in the stock market is to 'intercept' orders that are placed on various exchanges. In order to do this, an HFT organization watches all the transactions at once to find opportunities to buy low and sell high.  A good explanation of it is described here in this NY Times article; I'll paraphrase what that article lays out.  Stocks are traded through multiple exchanges The first key point to understand is that stocks listed on one exchange (i.e. the NYSE) can be sold on multiple exchanges. That's where the actual ""I would like to sell 100 shares of Ford stock"" is matched with ""I would like to buy 100 shares of Ford stock."" There are multiple clearinghouses on the various exchanges. Your order gets presented to one exchange at a Time An ideal market maker would like to look at the order books for a given stock, say Ford, and see that in exchange A there's a sell order for 100 shares of F at $15.85, and in exchange B there's a buy order for 100 shares of F at $15.90.  Arbitrage Market maker buys from A, sells in B, and pockets $0.05 * 100... $5. It's not much, but it was relatively risk free. Also, scale this up to the scale of the US' multiple stock exchanges, and there are lots of opportunities to make $5 every second.  Computers are (of course) faster than people To tie it in completely with your question about 'picking off trades', HFT rigs can be set up and programmed to go faster than an average retail investor's order.  Let's say you execute the trade to buy 100 shares @ $15.85 as a retail investor. The HFT rigs see your order starting to make the rounds of the different exchanges that your brokerage works through, and go out in front in a matter of milliseconds, finding the orders that are less than $15.85 and less than or equal to 100 shares. They execute a transaction, buy them up, sell to you, and pocket the difference.  You have been ""picked off"".  It's admittedly not the only way to use HFT equipment to make money, but it's definitely one way to do it." Stop orders and stop limit orders typically do not execute during extended hours after the general market session has closed. Stop orders are market orders and market orders especially are not executed during extended hours. Although there are exceptions because a broker can say one thing and do another thing with the way order types are presented to customers vs what their programming actually does. The regulatory burden is a slap on the wrist, so you need to ask the broker what their practices are. Orders created during normal market hours do not execute in extended sessions, different orders would have to be made during the extended session. Your stop order should execute if the normal market hour price stays below your stop price. So a stop limit would actually be worse here, because a stop limit will create a limit order which may never get hit (since it is above the best bid best ask) If the buyside was showing demand, what's wrong with HFT for reacting with supply?  The example you gave is akin to me going from car dealership to car dealership yelling loudly about what car I want and the price I'd like it at - would you be upset if someone heard you and decided to sell their car to you later down the line? In this case, the buy side trader is being **stupid**. This is a major critique many people have with Brad K. Instead of serially going from exchange to exchange, he could have sent orders to all exchanges at the same time (parallel!) and likely received much better prices. In my opinion, the HFT player here is simply facilitating price discovery by reacting to demand - as a market maker that's his job.   [Here's a good article. Let me know what you think.](http://www.cnbc.com/id/101551570) There are people whose strategy revolves around putting orders at the bid and ask and making money off people who cross the spread.  If you put an order in between the current bid/ask, people running that type of strategy will usually pick it off, viewing it as a discount to the orders that they already have on the bid/ask.  Often these people are trading by computer, so your limit order may get hit so quickly that it appears instantaneous to you.  In reality, you were probably hit by a limit order placed specifically to fill against yours. This is to protect your position in specific highly volatile market conditions.  If the stock is free falling and you only have a stop order at $90, it's possible that this order could be filled at $50 or even less. The limit is to protect you from that, as there are certain very specific times where it's better to just hold the stock instead of taking a huge loss (ie when price is whipsawing).