How does order matching happen in stock exchanges?
But how does the quantity matching happen? For example, if I want to buy 1000 shares at $100, but there is only one seller to sell 10 shares at $100, what happens then? This depends on the type of order you've placed. If you placed a fill-or-kill order, your order to buy or sell a certain number of shares is routed to the trading floor for immediate execution. If the order cannot be immediately filled, it is cancelled (killed) automatically. Note that the order must be filled in its entirety. Partial fills are not allowed. In your example, your buy order wouldn't be filled because it couldn't be matched to a sell order of the same volume. This is similar to an all-or-none order, which is an order that contains  A condition instructing the broker to fill the order completely or not at all. If there is insufficient supply to meet the quantity requested by the order then it is canceled at the close of the market. In this case, if your order wasn't matched to an order of the same volume by the time the market closes, it's cancelled. If you simply placed a market/limit order, and (in the case of the limit order), part of your order was matched to another order with the right price, that part of your order will be filled, while the rest will remained unfilled. To answer your question in its entirety there's more information we need (exchange, session, traded security, order type, etc.). Most exchanges support partial fills, that is your order will be partially executed and modified.  In your example, you'd get an execution of 10 shares at $100, and your order ticket will be modified to $100 for 990 shares. Like John Bensin explained, there are ways to prevent partial filling through order modifiers (e.g. Fill-or-Kill). My addition here is, there are also ways to prevent the other bit, i.e. do the partial fill but don't keep a modified order in the system.  You'd have to mark the order Immediate-or-Cancel (IoC).  In your case you'd be partially filled (10 @$100) and that's it.  For the remaining 990 shares you'd have to enter a new order.
This has never really adequately explained it for me, and I've tried reading up on it all over the place. For a long time I thought that in a trade, the market maker pockets the spread *for that trade*, but that's not the case.  The only sensible explanation I've found (which I'm not going to give in full...) is that the market maker will provide liquidity by buying and selling trades they have no actual view on (short or long), and if the spread is higher, that contributes directly to the amount they make over time when they open and close positions they've made.  It would be great to see a single definitive example somewhere that shows how a market maker makes money. the data source is the same as the live market trading. pre and after market trading are active markets and there are actual buyers and sellers getting their orders matched. In the world of stock exchanges, the result depends on the market state of the traded stock. There are two possibilities, (a) a trade occurs or (b) no trade occurs. During the so-called auction phase, bid and ask prices may overlap, actually they usually do. During an open market, when bid and ask match, trades occur. The principle of demand-supply law will not work if spoofing (or layering, fake order) is implemented. However, spoofing stocks is an illegal criminal practice  monitored by SEC. In stock market, aggressive buyer are willing to pay for a higher ask price pushing the price higher even if ask size is considerably larger than bid size, especially when high growth potential with time is expected. Larger bids may attract more buyers, further perpetuating a price increase (positive pile-on effect). Aggressive sellers are willing to accept a lower bid price pushing the price lower even if ask size is considerably smaller than bid size, when a negative situation is expected. Larger asks may attract more sellers, further perpetuating a price fall (negative pile-on effect).  Moreover, seller and buyers considers not only price but also size of shares in their decision-making process, along with marker order and/or limit order. Unlike limit order, market order is not recorded in bid/ask size. Market order, but not limit order, immediately affects the price direction. Thus, ask/bid sizes alone do not give enough information on price direction. If stocks are being sold continuously at the bid price, this could be the beginning of a downward trend; if stocks are being sold continuously at the ask price, this could be the beginning of a upward trend.  This is because ask price is always higher than bid price. In all the cases, both buyers and sellers hope to make a profit in a long-term and short-term view "why do markets sometimes appear in sync, but during other times, not so much By ""markets"" I'm assuming you mean equity indices such as the HSI. Financial products fluctuate with respect to the supply/demand of the traders. There's been a large increase in the number of hedge funds, prop desks who trade relative values between financial products, that partially explains why these products seem to pick up ""sync"" when they get out of line for a while." The situation you're proposing is an over-simplification that wouldn't occur in practice. Orders occur in a sequence over time. Time is an important part of the order matching process. Orders are not processed in parallel; otherwise, the problem of fairness, already heavily regulated, would become even more complex. First, crossed and locked markets are forbidden by regulators.  Crossed orders are where one exchange has a higher bid than another's ask, or a lower ask than another's bid.  A locked market is where a bid on one exchange is equal to the ask on another.  HFTs would be able to make these markets because of the gap between exchange fees. Since these are forbidden, and handling orders in parallel would ensure that a crossed or locked market would occur, orders are serialized (queued up), processed in order of price-time priority. So, the first to cross the market will be filled with the best oldest opposing order. Regulators believe crossed or locked markets are unfair.  They would however eliminate the bid ask spread for many large securities thus the bid-ask cost to the holder. When you place a bid between the bid/ask spread, that means you are raising the bid (or lowering the ask, if you are selling). The NBBO (national best bid and offer) is now changed because of your action, and yes, certain kinds of orders may be set to react to that (a higher bid or lower ask triggering them), also many algorithms (that haven't already queued an order simply waiting for a trigger, like in a stop limit) read the bid and ask and are programmed to then place an order at that point. "A ""stock price"" is nothing but the price at which some shares of that stock were sold on an exchange from someone willing to sell those shares at that price (or more) to someone willing to buy them at that price (or less). Pretty much every question about how stock prices work is answered by the paragraph above, which an astonishingly large number of people don't seem to be aware of. So there is no explicit ""tracking"" mechanism at all. Just people buying and selling, and if the current going price on two exchanges differ, then that is an opportunity for someone to make money by buying on one exchange and selling on the other - until the prices are close enough that the fees and overhead make that activity unprofitable. This is called ""arbitrage"" and a common activity of investment banks or (more recently) hedge funds and specialized trading firms spun off by said banks due to regulation." "I place a trade, a limit order on a thinly traded stock. I want to buy 1000 shares at $10. The current price is $10.50. Someone places a market order for 500 shares. Another trader has a limit order for $10.10 for 400 shares. His order fills, and I get 100 at my price. I wait another day to see if I get any more shares. This is just an example of how it can work. I can place my order as ""all or none"" if I wish to avoid this." Yes, the ADR will trade on a separate exchange from the underlying one, and can (and does) see fluctuations in price that do not match the (exchange corrected) fluctuations that occur in the original market. You are probably exposing yourself to additional risk that is related to: "For any large company, there's a lot of activity, and if you sell at ""market"" your buy or sell will execute in seconds within a penny or two of the real-time ""market"" price.  I often sell at ""limit"" a few cents above market, and those sell within 20 minutes usually.  For much smaller companies, obviously you are beholden to a buyer also wanting that stock, but those are not on major exchanges.  You never see whose buy order you're selling into, that all happens behind the curtain so to speak." "In addition to the other answers it's also noteworthy that the stock exchanges themselves adjust the price quotes via their ex-div mechanism.  All limit orders present in the book when the stock goes ex-div will be adjusted by the dividend. Which means you can't even get ""accidentally"" filled in the very unlikely case that everyone forgot to adjust their quotes." "Just read the book Flash Boys by Michael Lewis.  It describes this process in detail, albeit a bit more dramatically than it has to.  Basically what ""HFTs"" (high frequency traders) do is they set up their line to the exchange so its microseconds faster than everyone else.  Then they test out the market with tiny orders, seeing how fast it's getting filled - if these are getting filled immediately, it probably means there's a big order coming in from an investor.  So the algorithm - and it's all algo-based obviously because no human can remotely hope to catch this - will detect that as soon as there's a spike in volume, it will buy all of the volume at the current price, and sell it back for higher, forcing the big investor to take on higher prices.    Another case is that some HFTs can basically buy the entire trade book from an exchange like Nasdaq.  So every time someone places a market order for 200 shares of a 6.5 stock, the HFT will see it, buy up all the current stock from say 6.5-6.6 and sell it back at 6.7.  Not rocket science if you already get info about the trade coming in, in fact this is basically market making but performed by an ""evil HFT"" instead of a ""trustworthy bank.""    But honestly there are a lot more ways to make money from HFT than front-running, which isn't even possible anymore because exchanges no longer sell their books to HFTs." The original option writer (seller) can close his short position in the contracts he wrote by purchasing back matching contracts (i.e. contracts with the same terms: underlying, option type, strike price, expiration date) from any others who hold long positions, or else who write new matching contract instances. Rather than buyer and seller settling directly, options are settled through a central options clearing house, being the Options Clearing Corporation for exchange-listed options in the U.S. See also Wikipedia - Clearing house (finance). So, the original buyer of the put maintains his position (insurance) and the clearing process ensures he is matched up with somebody else holding a matching obligation, if he chooses to exercise his put. I also answered a similar question but in more detail, here. "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."