Unable to exit the order

zuser
def kitePlaceOrder(sym, action, qnt, val, ordertype, target, sl, tagname):
order_id = kite.place_order(tradingsymbol=sym,
exchange=kite.EXCHANGE_NSE,
transaction_type=action,
quantity=qnt,
order_type=ordertype,
variety="bo",
price=val,
tag=tagname,
product="MIS",
squareoff=target,
stoploss=sl)

return order_id #while loop breaks here

order_id = kitePlaceOrder('YESBANK', "BUY", 1, 40.0, "LIMIT",1,1 "")
print order_id
time.sleep(10)
kite.exit_order("BO",order_id)
With the above code I am able to successfully place the order and the order is getting fulfilled as well. But the exit_order function throws the following error.
kite.exit_order("BO",order_id)
File "build/bdist.macosx-10.7-x86_64/egg/kiteconnect/connect.py", line 378, in exit_order
File "build/bdist.macosx-10.7-x86_64/egg/kiteconnect/connect.py", line 373, in cancel_order
File "build/bdist.macosx-10.7-x86_64/egg/kiteconnect/connect.py", line 826, in _delete
File "build/bdist.macosx-10.7-x86_64/egg/kiteconnect/connect.py", line 883, in _request
kiteconnect.exceptions.InputException: Invalid `api_key` or `access_token`.
Please help out.
  • sujith
    To exit a bracket order you need to send variety, order id and parent order id. You seem to be passing a wrong variety, the correct variety is bo.
    You can check out the Python documentation here and API documentation here.
  • zuser
    I tried passing "bo" instead of "BO". The error has changed to the following.
    kite.exit_order("bo",order_id)
    File "build/bdist.macosx-10.7-x86_64/egg/kiteconnect/connect.py", line 378, in exit_order
    File "build/bdist.macosx-10.7-x86_64/egg/kiteconnect/connect.py", line 373, in cancel_order
    File "build/bdist.macosx-10.7-x86_64/egg/kiteconnect/connect.py", line 826, in _delete
    File "build/bdist.macosx-10.7-x86_64/egg/kiteconnect/connect.py", line 883, in _request
    kiteconnect.exceptions.InputException: Order is already executed.
    Below is the output of kite.orders(). Parent order id is None.

    {"exchange_order_id": "1300000002799141", "order_timestamp": datetime.datetime(2020, 2, 3, 10, 1, 14), "market_protection": 0, "tradingsymbol": "YESBANK", "meta": {}, "guid": "7591Xa5nWmkjLklMv", "order_type": "LIMIT", "variety": "bo", "status_message_raw": None, "cancelled_quantity": 0, "instrument_token": 3050241, "status_message": None, "status": "COMPLETE", "product": "BO", "exchange": "NSE", "order_id": "200203000944556", "price": 40, "pending_quantity": 0, "validity": "DAY", "placed_by": "ZN7821", "disclosed_quantity": 0, "exchange_update_timestamp": "2020-02-03 10:01:14", "tags": [""], "parent_order_id": None, "exchange_timestamp": datetime.datetime(2020, 2, 3, 10, 1, 14), "average_price": 36.7, "trigger_price": 0, "transaction_type": "BUY", "tag": None, "filled_quantity": 1, "quantity": 1}

    I tried passing None as parent_id and the error still remains the same.
    kite.exit_order("bo",order_id, None)
    File "build/bdist.macosx-10.7-x86_64/egg/kiteconnect/connect.py", line 378, in exit_order
    File "build/bdist.macosx-10.7-x86_64/egg/kiteconnect/connect.py", line 373, in cancel_order
    File "build/bdist.macosx-10.7-x86_64/egg/kiteconnect/connect.py", line 826, in _delete
    File "build/bdist.macosx-10.7-x86_64/egg/kiteconnect/connect.py", line 883, in _request
    kiteconnect.exceptions.InputException: Order is already executed.
    This might sound like typical developer ;) but indeed the same code had been running well for 6 months and the issue started coming from 13th Jan, 2020.
  • sujith
    If you send only order id and not parent order id then the system will think you are trying to cancel the order.
    One can't cancel an executed order. It looks like you are trying to cancel an executed order.

    The above order looks like a parent order upon whose execution second leg orders are placed.
Sign In or Register to comment.