kite.exit_order(variety,order_id) is not working for cover orders

Kinsh
I am using the below code to place and exit a cover order.
kite.place_order(variety=variety,
tradingsymbol=tradingsymbol,
exchange=exchange,
transaction_type=transaction_type_buy,
quantity=qyantity,
order_type=order_type,
product='co',
trigger_price = trigger_price)
The order got placed and returned an order_id string.

Now using below code to exit the same order
kite.exit_order(variety=variety, order_id=order_id), which is showing the below error/exception

DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.kite.trade:443
DEBUG:urllib3.connectionpool:https://api.kite.trade:443 "DELETE /orders/co/21050600 HTTP/1.1" 400 135
Traceback (most recent call last):

File "", line 1, in
dfdf = kite.exit_order(variety=variety, order_id=co_buy_order_id)

File "C:\\anaconda3\lib\site-packages\kiteconnect\connect.py", line 387, in exit_order
return self.cancel_order(variety, order_id, parent_order_id=parent_order_id)

File "C\lib\site-packages\kiteconnect\connect.py", line 381, in cancel_order
return self._delete("order.cancel",

File "C:\lib\site-packages\kiteconnect\connect.py", line 838, in _delete
return self._request(route, "DELETE", url_args=url_args, params=params, is_json=is_json)

File "C:\lib\site-packages\kiteconnect\connect.py", line 898, in _request
raise exp(data["message"], code=r.status_code)


InputException: order cannot be cancelled as it is being processed. Try later.


I have tried that several times, it just didn't work.
But at the same time, I am able to exit the order from Zerodha kite web.

  • rakeshr
    kite.exit_order(variety=variety, order_id=order_id)
    InputException: order cannot be cancelled as it is being processed. Try later.
    You are using the wrong order_id here. When you place a CO order, you get 2 legs i.e order_id, 1st leg for limit/market, and the other for pending SL order. You have to use 2nd leg SL order_id here instead of executed limit/market order(1st leg order). You will find that order_id from the complete order book.
    ......
    product='co',
    trigger_price = trigger_price)
    The order got placed and returned an order_id string.
    This is 1st leg market/limit order_id, which must have been executed. You need 2nd leg i.e SL order_id in exit_order.
  • Kinsh
    Thank you @rakeshr for highlighting the issue.
    There is one more thing I want to know,
    Is it necessary that the 2nd leg order_id would be the (1st leg's order_id + 1)?
    same above question for exchange_ids.
  • sujith
    @Kinsh,
    It is not guaranteed that the second leg order will be +1 of the first leg order id.
Sign In or Register to comment.