Error while fetching order id

kapilaggr
Hi All,

I sent some orders on Friday around 15.20 pm.Some conditions are checked in a loop and based on certain criteria,the orders are sent and the order status is checked just after that.In the first run of the loop,the orders were sent out but I got an exception saying "Order request timed out" and the call to kite.order_history() function also gave an error saying"Invalid order_id" -

in get_sell_price
future1 price 22403.6
Order request timed out.
in get_order_status
Invalid `order_id`.

I checked my order log in Zerodha and confirmed that no order was sent from this run of the loop(by matching the order price).Could this be because there was some lag while sending the order from Zerodha to the exchange and the order request timed out in this interval.

In the next run of the loop,there was no error in the place order try catch block but the kite.order_history() call right after that again gave an error-

in get_sell_price
future1 price 22403.25
in get_order_status
Couldn't find that `order_id`.

From the order log in Zerodha I can confirm that this order was sent from this run of the loop(by matching the order price).I can not understand why the order_id could not be found when the order was sent.From the logs,I can see that there was a lag of 1 second when the status changed from "PUT ORDER REQ RECEIVED" to "VALIDATION PENDING" and then again a delay of one second from "VALIDATION PENDING" to "REJECTED".Could this error be because the code moved from the place order statement to the get status statement before the order id was generated,.....but i can see that the order id appears even when the status is "PUT ORDER REQ RECEIVED".
The same case was repeated in the next 3 runs of the loop,the placed orders are visible in the order log but the kite.order_history call gave the same error-Invalid `order_id`.

The next two runs of the loop worked fine,the orders were placed and the correct status was returned by the function.

In the last run of the loop,the place order statement again an error saying-"Order request timed out".But this time there was no error in the kite.order_history() function and it returned the correct order status-

in get_sell_price
future1 price 22416.95
Order request timed out.
in get_order_status
order_status1 REJECTED

When I checked for this in my order log,I can see that this order was placed and there was no delay in the status changes of this order,everything happened in the same second.I am not able to understand this behaviour.

These are the order ids-

'order_id': '191227002518502'
'order_id': '191227002517430'
'order_id': '191227002519623'
'order_id': '191227002520248'
'order_id': '191227002520861'
'order_id': '191227002521352'
'order_id': '191227002521641'
'order_id': '191227002521949'

I sent the order 9 times,and orders were placed 8 times(the first one where the error-"Order request timed out" was sent,no order was placed).

Request you to kindly help me understand the logic behind these errors.

How can i handle such situations in the code when there is a lag in sending the order and when the order is placed.

What is the best approach to check the status after the place order statement is executed.



Thanks and Regards,
Kapil

  • sujith
    Hi @kapilaggr,
    There are multiple hops in the system. It is not a single server doing everything. There are multiple hops(layers) of the complex systems in place which are used when a user places an order. An order can move from one hop to another in a second or more than that. It depends on the traffic and network conditions at any point in time.
    If any of the hops fail then you will receive a timeout exception.

    A timeout exception doesn't guarantee either order is placed or it is not placed. You will be able to know this after fetching orderbook.

    A correct way to listen to order updates is from the websockets on_order_update which gets all the order updates.
Sign In or Register to comment.