Actions after order is created

ashishbajaj
I want to achieve a scenario where I can do certain actions after an order is created from the Kite app directly.

For example, if I create an order from zerodha kite app my backend should automatically know and do certain actions subsequently.

Has anyone tried it? Is it possible? I see that there is a webhook but as per my understanding, it is limited to the webhook's knowledge of the order ID which may not be known for the backend unless we fetch all orders every 10s.
Tagged:
  • MAG
    Anything and everything is possible @ashishbajaj. It all depends on your market knowledge and coding skills.
    You can look at smallcase, streak, coin, sensibull etc. These are all tools/products developed based on the same kiteconnect api.

    You can find out your order status based on
    1. polling the api using the orders / order_history/ order_trades methods or
    2. using webhooks or
    3. using the postback URL endpoint if its defined in your app configuration. From the app configuration page: "The URL where realtime order completion updates for orders placed by you will be POSTed. This has to be an HTTPS url."
    4. Or you can maintain your own orders and positions locally at your end and just poll the API for changes to orders status.

    And once you have this information you can do whatever actions you want.
  • sujith
    @ashishbajaj,
    You won't receive postbacks if order is not originated from your app. You will have to create a websocket and listen to order updates on that. You may use that order update as an event to fetch orderbook and check order status or do anything else.
  • ashishbajaj
    @sujith: Order will be originated from the app itself. I want my server to know that a new order in my account has been created. Websocket will work after the order is created and I know the order ID, right?

    @MAG: I don't want to call the order API to get the new order continuously, that seems unnecessary when we have the concept of webhooks and WebSocket with the API. The requirement can be summed up as "I create a new order from the Kite App, my server should know a new order has been created in my account."


    What I don't see is a way to get this information in the docs or maybe I am missing something. We can subscribe to an order when we know the order ID, this is after the order has been already created by the app.
  • MAG
    @ashishbajaj If the orders are originating from your app; using the API; then you can configure the postback url which points to your server. So when any order actions are completed the Zerodha api servers will send a post request with the order details (including order id) to your server at the configured url. Or listen to the postback messages through the websocket API. And then your server can listen to these postbacks, receive them, parse the JSON and then carry out whatever actions you want to be executed.

    This information is there in the documentation if you care to look.
    Here is the link where information is given - https://kite.trade/docs/connect/v3/postbacks/
    It also mentions in this document that "For individual developers, Postbacks over [WebSocket](websocket.md) is recommended"

    Now coming to postback over websocket, if you look at https://kite.trade/docs/connect/v3/websocket/#postbacks-and-non-binary-updates you have all the information you should need.
    What I don't see is a way to get this information in the docs or maybe I am missing something. We can subscribe to an order when we know the order ID, this is after the order has been already created by the app.
    When an order is created a postback message is sent containing a JSON payload which contains the order id as mentioned in the payload attributes at https://kite.trade/docs/connect/v3/postbacks/#payload-attributes.

    It's unfair to the rest of the forum especially folks that are trying to help others when someone doesn't read the documents properly and then expect others to do their work for them.


  • sujith
    @ashishbajaj,
    You don't need to subscribe to get order updates, it is pushed automatically by the Kite Ticker.
  • sujith
    Order update is not pushed when order is placed on Kite app but it will be pushed only when there is a partial fill or the trigger is hit or order is modified.
Sign In or Register to comment.