"Couldn't find that `order_id`" exception when order_info is queried immediately after placing order

chethanthewarrior
I placed an order through python API order_id = kite.place_order() and immediately after returning, tried to fetch order_info
order_info = kite.order_history(order_id)
to check for
if order_info[order_info_index]['status'] == 'COMPLETE':
print("Order Execution is success, Time now:", datetime.now().time(), flush=True)

This code flow has been working alright but today got an exception: Couldn't find that `order_id` though the order was placed successfully at the exchange

What is the workaround for this?

As I see in this thread,
https://kite.trade/forum/discussion/2668/order-placement-errors-9-00-am-to-9-05-am#latest

"It could be because the order record is not propagated to all the systems yet. You can add some milliseconds delay and check"

Is this the accepted solution even now?

Order Details:
order_id = 210917200813146

Log:
Time when order_id, is called: 2021-09-17 09:44:59.820198
Time when order_id is returned: 2021-09-17 09:45:00.070870
Time taken:
0:00:00.250672
Time when order_info, is called: 2021-09-17 09:45:00.071371
kiteconnect.exceptions.GeneralException: Couldn't find that `order_id`.
  • sujith
    You can add a couple of seconds delay and then try fetching the order history.
    Order goes through a lot of systems before reaching the exchange, it takes a while for a record to be created at the OMS.
  • chethanthewarrior
    is adding a couple of seconds the only accepted solution? how about waiting in milliseconds?
    currently running with 50ms.

    time.sleep(0.05)
    order_info = kite.order_history(order_id)
  • sujith
    It is up to you, you can try with few milliseconds and if it works our for you then it is ok. There is no definite timeline that OMS has given us after which order history will show up. There are a lot of states involved and lot of systems. It may work in certain scenarios but it may not in certain scenarios. Hence I would suggest do some trial and error with adding few milliseconds delay.
Sign In or Register to comment.