How the Stock Exchange Matches Your Buy Order
Understand the mechanics of price-time priority and the order book to make smarter, cost-effective trades.
When you click the 'Buy' button on your broker's app, your order vanishes into the digital network. In a fraction of a second, a confirmation screen pops up: 'Order Executed.' Have you ever wondered who actually sold those shares to you?
It was not your broker, and it was not a random guess by a computer. Instead, the stock exchange ran your order through a highly organized, ultra-fast matchmaking system called the order book.
Meet the Matchmaker: The Order Book
Every stock traded on the exchange has its own digital ledger called an order book. This ledger contains two lists: people who want to buy (the bids) and people who want to sell (the asks).
The exchange does not match people randomly. It follows a strict, fair rulebook known as Price-Time Priority:
- Price Priority: The exchange always rewards the most competitive prices. The buyer willing to pay the highest price (the Best Bid) and the seller willing to accept the lowest price (the Best Ask) are put at the front of the queue.
- Time Priority: If two investors want to buy at the exact same price, the one who submitted their order first gets served first.
Inside a Live Order Book
Let us look at a simplified order book for a fictional company, Astra Paints. This table shows the pending orders waiting to be matched at the exchange:
| Side | Price (₹) | Quantity | Queue Position |
|---|---|---|---|
| Sell (Ask) | 150.20 | 150 | 3rd in line to sell |
| Sell (Ask) | 150.10 | 100 | 2nd in line to sell |
| Sell (Ask) | 150.05 | 50 | 1st in line to sell (Best Ask) |
| Buy (Bid) | 149.90 | 200 | 1st in line to buy (Best Bid) |
| Buy (Bid) | 149.80 | 150 | 2nd in line to buy |
| Buy (Bid) | 149.70 | 300 | 3rd in line to buy |
Step-by-Step: Walking a Trade Through the Book
Imagine you want to buy shares of Astra Paints. You place a Limit Order to buy 80 shares at a maximum price of ₹150.10. Here is exactly how the exchange matches your order, step by step:
- Step 1: The exchange receives your buy order for 80 shares with a limit price of ₹150.10.
- Step 2: It checks the best available sell price. The first seller in line is offering 50 shares at ₹150.05. Since ₹150.05 is lower than your maximum limit of ₹150.10, the exchange matches you with this seller.
- Step 3: You successfully buy 50 shares at ₹150.05. Your order still needs 30 more shares to be complete (80 - 50 = 30).
- Step 4: The exchange looks at the next seller in line, who is offering 100 shares at ₹150.10. Since this matches your limit price, the exchange buys the remaining 30 shares from this seller.
- Step 5: Your order of 80 shares is now fully complete. The second seller now has 70 shares left waiting in the queue (100 - 30 = 70).
Because of price priority, you actually saved money on your first 50 shares by getting them at ₹150.05 instead of your maximum limit of ₹150.10.
Why This Matters for Your Trades
Knowing how the order book works helps you make smarter trading decisions. If you place a 'Market Order' instead of a 'Limit Order,' you tell the exchange to buy immediately at whatever price is available. If you wanted 500 shares, a market order would sweep through multiple sellers, buying at ₹150.05, then ₹150.10, and then ₹150.20, driving up your average cost. This is called slippage.
Always use limit orders when trading stocks with low volume to prevent the order book matching engine from filling your order at unexpectedly high prices.
When you search for any stock on stock-analyze.com, you can view the live bid-ask spread and liquidity metrics directly on the stock's real-time analysis page to ensure you always trade at the best possible price.
