When exactly does on_order_update gets triggered?

AAAAAAAAAA
AAAAAAAAAA edited February 2022 in Python client
Is it triggered on every update to an order status of a particular order? So all the way from pending, to open to complete, I will get an update for every status - immidiately after it happens?

This can also be used to get the latest positions, and order_ids without any risk of getting the "HTTPSConnectionPool(host='api.kite.trade', port=443): Read timed out. (read timeout=7)" error as with polling kite.positions() right?
  • SRIJAN
    It's triggered whenever an order's status changes. But beware,the order updates are asynchronous,you need to handle them at your end.
  • sujith
    You will receive order update only when there is a partial fill, or trigger is hit or order is modified. You can use that as an event to fetch and update orderbook and positions.
  • AAAAAAAAAA
    @SRIJAN When you say its asynchronous, do you mean that an order is placed, its open and then complete, I might get complete as an update first and then open?
  • AAAAAAAAAA
    @sujith I see. Will the 'status' also update itself to these values as mentioned here?

  • AAAAAAAAAA
    AAAAAAAAAA edited February 2022
    I see. If thats the case then just calling kite.order_history(order_id) seems easier? @SRIJAN
    And following this, this means that it still cant be fully relied upon as a position tracker, am I right?
  • SRIJAN
    SRIJAN edited February 2022
    At the end,it's your choice. In your case,you said you place limit orders,then websocket updates would be better beacuse it will update you directly when the order is filled,but through order_history(),you have to call it every few seconds to check if order is filled. Also,as Sujith Sir said,you should use websocket update as an event to fetch orderbook and update positions.
  • AAAAAAAAAA
    AAAAAAAAAA edited February 2022
    Since you're recommending websockets @SRIJAN as a viable alternative (which I will be happy to use btw, since it has less chance to throw the timeout error), kindly explain how do I go about actually implementing it when it is asynchronous? My algo does different things depending upon what the order status is and if the incoming value is not accurate, you can see how its of no point? Or is it that I just have a limited understanding of the websocket update?

    Please guide :s
  • SRIJAN
    Sujith Sir already told. Use websocket update as an event to fetch orderbook and update positions. Whenever you get an update, instead of looking at it's status ,call order history and check the latest status from there.
  • AAAAAAAAAA
    AAAAAAAAAA edited February 2022
    Got it.


    I did place this in the algo today and initialised it with this
    kws.on_order_update = on_order_update.
    Yet there's nothing. No log entered in my log file as the "data" and on_order_update_list is empty. What could have happened here?
  • sujith
    It is an event that is triggered when there is a change in order like partial fill, order modified, trigger is hit etc.
    It is not an orderbook fetch. So you won't receive a orderbook response on connecting to Kite Ticker.
  • sujith
    You will receive order update for an order when it is executed also so, if you place an order that gets rejected will also trigger this on_order_update.
    But make sure you won't abuse it (place too many rejected orders continuously) otherwise RMS might get flag your app as spam.
  • AAAAAAAAAA
    @sujith
    This is my on_order_update. I have also initialised it with buts not been working since the last time posted here. You have said that I will receive an update when its executed, but I am still getting nothing. There is no "data" from the on_order_update in my logs and on_order_update_list remains empty.

    I want to check the order_history(order_id) when there is an update via the on_order_update(), as you recommended earlier, but this is making be unable to. Please help.
  • sujith
    Why don't you just print the data as is?
    And make sure you are connected to Kite Ticker with the same client id.
  • SRIJAN
    SRIJAN edited February 2022
    The callback would not be indented properly.
Sign In or Register to comment.