Order Status

milli
Hi

Ref. https://kite.trade/forum/discussion/2749/how-to-find-the-status-of-an-order

Suppose I have placed an AMO order, the status is shown as AMO REQUEST RECEIVED . But as per the documentation present at https://kite.trade/docs/connect/v3/orders/#order-statuses , the status could be OPEN, COMPLETE, CANCELLED and REJECTED amongst others.

Does the status 'become' OPEN once the order is sent to the exchange and is pending execution?

Also, if I only want to know whether the order is fully executed or not, would it not be better to simply check the value of 'pending_quantity' to be non-zero?

Thanks
  • neel2323
    neel2323 edited January 2021
    Hey!

    My 2 cents on your question.

    1) Yes it will show as "AMO REQUEST RECEIVED" if it is an AMO. If you place a REG order, you will get statuses as per the documentation.

    2) Order becomes OPEN once it is sent to the exchange and is waiting a response from the exchange.

    3) Yes. Either pending quantity or check if qty-filled_qty == 0. Below is the function I use to get a list of all orders and pending_orders.

    def get_all_and_pending_orders():
    run = 1
    while run == 1:
    try:
    all_orders = pd.DataFrame(kite.orders()).set_index("order_id")
    pending_orders = all_orders[['tradingsymbol', 'transaction_type','instrument_token', 'quantity', 'pending_quantity', 'price', 'average_price', 'order_timestamp', 'status', 'status_message']]
    pending_orders = pending_orders[pending_orders['pending_quantity']>0]
    pending_orders = pending_orders[~pending_orders['status'].str.contains("COMPLETE")]
    pending_orders = pending_orders[~pending_orders['status'].str.contains("CANCELLED")]
    pending_orders = pending_orders[~pending_orders['status'].str.contains("REJECTED")]
    run = 0
    except:
    time.sleep(1)
    print("Error in Kite.Orders(), sleeping for 1 second")
    return all_orders, pending_orders

    ##Disclaimer: ##
    ##The code is given only for the purpose of giving an understanding.
    ##Please use it after testing and at your own discretion.
    ##I am not liable for any losses you incur because of this code.

  • milli
    Hi @neel2323 ,

    Thanks for your help.

    I am assuming that the status would be 'COMPLETE' if the position i.e. order is closed (sold / bought) or the pending_quantity is zero. Am I correct?

    One more query:

    Say I short BNF, I am using the code below in a loop to check if the order is complete



    order_id_details = kite.order_history(order_id=order_id)
    while (order_id_details[0]["pending_quantity"]) > 0:
    time.sleep(1) # Wait for order to get executed.
    print('waiting for order', order_id, 'to get executed')
    order_id_details = kite.order_history(order_id=order_id)
    print(order_id_details[0]["pending_quantity"])



    but, the order is never reported as complete.

    Can you advise why?

    Thanks
  • sujith
    @milli,
    We don't recommend polling order history. We suggest using postbacks or order updates on websockets as an event to fetch orderbook or order history.

    Order history is a list of statuses the order has gone through on the system. You can know more here.
    You need to look for the status and pending quantity of the last item on the list.
  • milli
    milli edited February 2021
    @sujith

    The order_history is only used ones to read the orders placed.

    Does this mean that I should check the "status" ? If yes, then what would be the value if the order has been placed, but full quantity not yet fully purchased / sold?

    What I want: I want to place stop loss over a short option.
    What I am doing right now: I am currently checking only the pending quantity, but this keeps checking and does not ever get out of the loop

    This is the code

    order_id_details = kite.order_history(order_id=order_id)

    while (order_id_details[0]["pending_quantity"]) > 0:
    time.sleep(1) # Wait for order to get executed.
    print('waiting for order', order_id, 'to get executed')
    order_id_details = kite.order_history(order_id=order_id)
    print(order_id_details[0]["pending_quantity"])

    I cannot do trial and error testing as the amounts involved are huge

    Would appreciate any help.

    Thanks

  • sujith
    In case of MARKET and LIMIT orders, order status remains as OPEN once it reaches exchange and is waiting to be executed. If there is a partial fill then also order status remains as OPEN only.
    In case of SL and SL-M orders, order status remains TRIGGER PENDING once it reaches the exchange (passive orderbook of the exchange). Once the trigger is hit, status changes to OPEN, and order type changes to LIMIT or MARKET, based on SL or SL-M order.

    I would suggest doing the trial with minimum quantity, you may come across different scenarios that need to be handled. In your case, the first item in the list of order history is always PUT ORDER REQUEST RECEIVED, so it will never be true.
This discussion has been closed.