The right way to place trading orders using Zerodha Kite API

How to place trade orders properly using Zerodha Kite API, and things that you need to understand about order execution flow.

By

Few days ago, I attended a Twitter space by Ankur_Quant and came across an interesting discussion. Quite a few users were complaining about the fact that after firing an order, even though Zerodha server responds back with a 200-Suceess message, the actual orders often do not get executed.

This is not an issue with Zerodha. On the contrary, this is due to a misunderstanding about how the order API flow actually works. Let me explain.

Order Stages

Once an order is fired from your computer via the Zerodha API, the order is not sent to the exchange immediately. There are number of checks that need to happen at Zerodha's end to validate the order and evaluate the risk parameters.

These checks and validations take time. Albeit a very short span of time (measured in milli- or micro seconds), but it still takes time.

Then, once the order is sent to the exchange, it takes additional time to get executed. Why? Well, if it is a limit order, the order waits until the limit price is not reached. But even if it is a market order, there could be other orders in the queue before it.

In short, there is always a delay between you sending the order and the actual execution of the order.

However, Zerodha will send you a 200-SUCCESS response the moment your order is reached to their server.

Asynchronous Server Response

{
  "status": "success",
  "data": {
    "order_id": "151220000000000"
  }
}

Above is a typical response from the Zerodha server. This is called asynchronous server response. In stead of waiting for the entire order execution to take effect, Zerodha will send you a 200-SUCCESS HTTP response the moment your order reach their server.

This 200 status code does not mean your order is executed. It does not even mean that your order has been accepted. It just means that they have received your order. 

They can still reject the order (if it fails validation checks). Exchanges can still reject the order. And even if everyone accepts the order, it may still not get executed.

How the heck do I know if my order is actually executed?

Good question. For that, you have 2 choices - 

  • Use order status API to check the status of your order periodically
  • Use Web Socket as Zerodha server will intimate you over socket as soon as the order is executed.

 

Terms Privacy Feed