Error in cancelling AMO orders

cryptonoob321
When I place an AMO order after market close, and retrieve the pending orders during market timing, the AMO order's variety is shown as 'amo'.

Now after fetching the order using kite.orders(), when I try to cancel pending amo orders using the following code:

variety = order['variety']
order_id = order['order_id']
kite.cancel_order(variety=variety,order_id=order_id) ,

I am getting the following error :
kiteconnect.exceptions.NetworkException: request VHCxnyPX61oLTA678SWVJF9nIHSyZsQ7 timed out

However, when i manually pass 'regular' as the variety param and do kite.cancel_order(variety='regular',order_id=order_id) , the pending amo order is successfully cancelled.

Seems to be a bug? Either the variety of AMO orders must change to 'regular' once market opens, or cancel_order must take 'amo' as variety when cancelling pending amo orders
  • sujith
    sujith edited August 2022
    The amo's variety changes once OMS places the order at the exchange after market opens. You will have to send variety as 'regular', if after market order is placed at the exchange after market opens.
  • cryptonoob321
    But when i pull list of pending orders using kite.orders() during market hours, the variety change is not being reflected. The variety of amo orders is still shown as amo even after OMS places the order at exchange.

    I want to run a code that can cancel orders both during market hours and after market hours. Best way is to take the variety of order from kite.orders() and plug it in cancel_order but if the change of variety is not reflected once OMS places order, then it is not possible for me to parse the correct current variety of order.
  • rakeshr
    But when i pull list of pending orders using kite.orders() during market hours, the variety change is not being reflected
    The variety field can't be modified once the user places the order. So, variety remains the same in the order book through. But, as @sujith mentioned above, once the order is placed on the exchange all normal order becomes of regular variety. So, you need to keep a regular variety for all such order modifications and cancellations.
  • cryptonoob321
    I understood that. But how do i write a code that works for both market hours and after market hours?
  • rakeshr
    For now, you will have to add a time-based condition for this. We will see if we can do anything about this in the future.
Sign In or Register to comment.