What is the order execution process on Stock Exchange?
The Stock Exchanges are a place where different market participants come to get their buy or sell orders matched with a counter party. Thanks to the technical advancements, the Stock Exchanges have an automated order matching system for the execution of orders and trades.
All investors should know about the pending Order Book of the stock that they are trading in. This allows investors to judge how their order execution will happen after submission. This is important because the trades now get executed in fractions of seconds after it is received by the exchange. So if a mistake is made at submission time, then the investor might not get a chance to modify the order.
The order execution process is different in the pre open session and the normal market timings. As explained in What is Pre opening session in stock market, a Call Auction mechanism is used to calculate the Open Price of the stock.
On this page, we try to explain how the order matching algorithm works in the normal trading window (from 09:15 AM to 03:30 PM).
Best Price
Before we can explain how the order processing on Stock exchange works, some important points need to be mentioned about the order priority in stock market.
- It is assumed that a seller would like to sell at the highest price and the buyer would like to buy at the lowest price
- So the ‘Best Buy order‘ refers to the Buy order with the highest price (That means a buyer at INR 101 will get higher priority than a buyer at INR 100)
- And the “Best Sell order” refers to the Sell order with the lowest price (That means a seller at INR 99 will get higher priority than a seller at INR 100)
- If the price is same for 2 orders, then priority is given to the order that was submitted earlier on the exchange
- Orders that are not yet traded and are pending in the Order Book, are known as Passive orders
- When an order is submitted and it immediately matches an existing pending order, then it is known as an Active order
- Market Orders are traded against the best available price at the submission time itself. In some cases, they might be converted to a Limit Order.
Order Submission and Matching
In simple terms, the following steps are followed by the Stock Exchange when processing the orders:
Step 1: After an order is received, validation is done to check if the data in the order is correct
Step 2: If the order is accepted by the exchange, then an Order Number and Order Time Stamp is generated
Step 3: The order is immediately taken up for processing against the pending orders
Step 4: If the order can be executed (fully or partially) against any pending order, then a trade will be executed
Step 5: If the order cannot be matched (fully or partially), then the pending quantity will be added to the Order Book. The order execution will happen when future order are received.
Step 6: If any orders matched and a trade was executed, then a Trade Number will be generated. (It is possible for one order to have multiple trades)
The below image explains the general order matching system in stock markets.
Depending on the type of orders received and the supply and demand, there are different scenarios that could be applicable. We will now explain them and provide examples to better explain how are the orders matched in different cases.
Case 1: Immediate execution of full order
Let us look at some cases to understand the order execution process for the new submitted orders against the existing orders.
Example: Suppose at any instant, the market depth for a stock looks like this in the Order Book:
| Order ID | Buy quantity | Buy Price | Sell Price | Sell quantity | Order ID |
| B1 | 25 | 1,004 | 1,005 | 10 | S1 |
| B2 | 40 | 1,004 | 1,006 | 50 | S2 |
| B3 | 125 | 1,003 | 1,007 | 25 | S3 |
| B4 | 100 | 1,002 | 1,008 | 150 | S4 |
| B5 | 150 | 1,001 | 1,009 | 120 | S5 |
Here are some examples to explain how are the orders matched when a new order is placed:
Example 1: Buy 10 shares at INR 1,005
Order will be matched against order S1
Example 2: Sell 100 shares at Market price
65 shares will be sold at INR 1,004 against order ID B1 and B2
35 shares will be sold at INR 1,003 against order ID B3 (B3 gets partially executed and the remaining quantity of 90 shares will still be pending in the Order Book)
Example 3: Buy 40 shares at INR 1,008
Order will be matched against the best Sell order.
So, 10 shares will be bought at INR 1,005 against order ID S1.
30 shares will be bought at INR 1,006 against order ID S2 (S2 gets partially executed as the remaining quantity of 20 shares will still be pending in the Order Book)
Example 4: Sell 20 shares at INR 1,004
20 shares will be sold at INR 1,004 against order ID B1 (B1 gets partially executed and the remaining quantity of 5 shares will still be pending in the Order Book)
Case 2: Execution of partial order
Let us look at some cases of partial execution of order on stock Exchange.
Example: Suppose that at any instant, the market depth looks like this in the Order Book for a stock:
| Order ID | Buy quantity | Buy Price | Sell Price | Sell quantity | Order ID |
| B1 | 10 | 1,004 | 1,005 | 20 | S1 |
| B2 | 25 | 1,003 | 1,006 | 50 | S2 |
| B3 | 50 | 1,002 | 1,007 | 30 | S3 |
| B4 | 40 | 1,001 | 1,008 | 100 | S4 |
| B5 | 120 | 1,000 | 1,009 | 210 | S5 |
Here are some examples to explain how are the orders matched when a new order will be placed:
Example 1: Buy 25 shares at INR 1,005
20 shares will be bought at INR 1,005 against order ID S1.
The remaining quantity will be added in the Order Book as a Limit Order of: Buy 5 shares at INR 1,005.
Example 2: Sell 100 shares at INR 1,002
Order will be matched against the best Buy orders.
So, 10 shares will be sold at INR 1,004 against order ID B1.
25 shares will be sold at INR 1,003 against order ID B2.
50 shares will be sold at INR 1,002 against order ID B3.
The remaining quantity will be added in the Order Book as a Limit Order of: Sell 15 shares at INR 1,002.
Example 3: Buy 30 shares at Market price
Order will be matched against the best Sell orders.
20 shares will be bought at INR 1,005 against order ID S1.
10 shares will be bought at INR 1,006 against order ID S2.
S1 gets fully executed, but S2 gets partially executed. So, the remaining quantity of S2 will be updated in the Order Book as: Sell 40 shares at INR 1,006.
Case 3: When order can not be traded
Let us look at an example where the new order cannot be matched against existing orders. This usually happens when there are no buyers/sellers at the requested price.
Example: Suppose the market depth looks like this in the Order Book:
| Order ID | Buy quantity | Buy Price | Sell Price | Sell quantity | Order ID |
| B1 | 15 | 1,005 | 1,008 | 75 | S1 |
| B2 | 40 | 1,002 | 1,009 | 60 | S2 |
| B3 | 90 | 1,001 | 1,010 | 30 | S3 |
| B4 | 80 | 1,000 | 1,013 | 210 | S4 |
Example: Buy 50 shares at INR 1,007
In this case, there is no seller available at INR 1,007.
So, the order will not get matched immediately and it will be added in the Order Book as a pending limit order of: Buy 50 shares at INR 1,007.
Case 4: When there are no buyers or sellers
Let us look at an example where there are no orders on Sell side. This can happen when there are no sellers left for a stock with less liquidity or if a share has hit an Upper Circuit.
Example: Suppose the market depth looks like this in the Order Book:
| Order ID | Buy quantity | Buy Price | Sell Price | Sell quantity | Order ID |
| B1 | 150 | 1,006 | |||
| B2 | 210 | 1,005 | |||
| B3 | 290 | 1,002 |
Here are some examples about what will happen when new orders are submitted:
Example 1: Buy 20 shares at INR 1,007
In this case, there is no seller available at INR 1,007.
So the order will not get executed and it will be added in the OrderBook as a pending limit order.
Example 2: Buy 100 shares at Market Price
Again, the Market Order cannot be executed as there are no sellers at any price.
In this case, the order will be added in the Order Book as a pending Limit Order at the Last Traded Price (LTP).
So, if the last trade in the share happened at INR 1,010 for example, then the above market order will be converted to a limit order of: Buy 100 shares at INR 1,010.
Case 5: Stop loss orders
The Stop Loss Orders are added to a separate Order Book on the Stock exchange and the order execution process is different from the normal orders. These type of orders get activated when the Last Traded Price (LTP) of the share hits the Trigger Price that was mentioned in the Stop Loss order.
When the trigger is hit, the order gets converted to a normal order and it is added to the regular Order Book for normal execution. For more details about how these orders work, refer: How to use Stop Loss orders when trading?
Disclaimer
- This page is for education purpose only
- Some information could be outdated / inaccurate
- Investors should always consult with certified advisors and experts before taking final decision
- Some images and screenshots on this page might not be owned by FinLib
