Partially executed order, modify order, pending qty

This is something which I thought was working fine until last week, but today surprisingly is NOT with my MIS LIMIT order scripts.

Lets say I place an order for selling some NIFTY instrument option for 900 Quantity, refer attached pic (I have blocked unwanted details here).

As you can see the order got executed couple of time for 75 quantity once at 2:09 and another at 2:11, after which the order was modified to the remaining "pending" quantity, which I get the details from the order_history and modify the order for the remaining "pending" quantity using modify_order. This was working fine, when I modified the order for pending quantity, but today, if you see, eventually the executed quantity became 750 from initial 900 quantity.

  • kiteapi
    This happened with 4 of my orders, the total quantity when order was "complete" was not the same when submitted. And there was one order, which got cancelled "for no reason" :(
  • sujith
    Can you private message your client id? We will check and get back to you.
  • sujith
    And make sure to mention the order ids as well.
  • kiteapi
    @sujith DM'd you the details. Thanks!
  • sujith
    When you modify an order, you will be modifying the orders total quantity, not the pending quantity.
  • kiteapi
    kiteapi edited August 2020
    Yes, I modified the total quantity, as you know there is nothing called as pending quantity in the modify_order, there is just quantity.

    The quantity data which is passed in modify_order I am getting from pending_quantity in the order_history, if there are some lots executed, you cannot have same original quantity mentioned in the modified order as well, which is the same we do on Kite web as well.

    But, in the orders shared if you see, it is NOT what was expected quantity wise + there was an issue with cancelled order, what were these about?
  • kiteapi
    Below is the code:

    while not (order_history_status == "COMPLETE"):
    except Exception as e:
    print("Order Error:", orig_order_id, "Exception", e)

    order_hist = kite.order_history(orig_order_id)
    order_history_status = order_hist[-1]["status"]
    pending_qty = order_hist[-1]["pending_quantity"]


    We cannot have the original quantity in the kite.place_order in the modify_order as some quantity is executed, so we need to pass the pending_quantity in the quantity of the kite.modify_order, which is what I have done.

    I am looking for solution for below queries from you/team:

    1. What went wrong with my orders which I shared in my DM for the quantity?
    2. What went wrong with the order which got cancelled on its own?

    For 1 and 2, I have shared order ID's with you/team in DM earlier in the day.
  • kiteapi
    Apart from the above issue with partial order fill, I just now have DM'd you @sujith and @themohammedfaisal 3 (yes three) more orders which got cancelled for no reason on MCX.

    Can you get someone to look into this (before I escalate this issue) and get a fix for this? I am NOT AT ALL HAPPY with what I am seeing/facing. Definitely not what I expected, beats the purpose of automation with what I am seeing with Kite API.
  • kiteapi
    All these cancelled orders were partially filled before it got cancelled on its own by the system without any reasons!!!!
  • kiteapi
    kiteapi edited August 2020
    Something that I will try from my side:

    I will try without sending quantity in the modify_order (as quantity is optional in modify_order) and check if that works, while your team checks on the two issues.
  • sujith
    Everything seems fine. I think you got confused about the behavior of modifying the order quantity.
    When one tries to modify the quantity of an order, it is important to note that you are modifying the order's total quantity and not the pending quantity.
    Let us say you place an order for 4 qty and 2 gets filled, you modify the order to 2 qty then order status gets changed to canceled after modification is successful. This is how OMS behaves.
  • kiteapi
    @sujith like you have seen the logic in my above code, this worked fine for 2 weeks (which is what we manually do for partially filled orders, where we see pending qty in quantity while modifying partially filled order), with partial filled orders and logic was the same.

    As of now I have removed quantity in the modify_order since yesterday morning, but all my orders have got full fill since then, will update this thread, most like this should work (similar to how we dont touch quantity on kite web) fine. But will keep you posted on this.

    Thanks for looking into this. Appreciate it.
  • kiteapi
    @sujith you can close this thread, finally one of my orders was modified and got executed on Friday and I could see the order went fine with no "quantity" in modify_order.
This discussion has been closed.