I am trying to cancel an order that has been open for 1 second and not yet executed. Below is the code i am using but I guess I am not using the cancel order correctly, checked the documentation but didnt get it completely.
placed_order_id = placeOrder(trading_symbol,"buy",quant, trading_price) current_order_status = getstatus(placed_order_id). (get status of the order using a function) if current_order_status != 'COMPLETE': cancel_order = kite.cancel_order(placed_order_id, variety='REGULAR')
Exchange,order_type etc. fields are missing in your custom order placing function. That might be the cause of the error.
Paste the exact exception message from KiteConnect here .
Also,variety should be small case and not upper case. Please read the documentation properly.
https://kite.trade/docs/connect/v3/orders/#glossary-of-constants
the exact error is:
"cancel_order() got multiple values for argument 'variety'"
Do it properly and it will work.
cancel_order = kite.cancel_order(order_id = placed_order_id, variety='regular', parent_order_id = None)
https://github.com/zerodha/pykiteconnect/blob/e1c2776dcecf630a7fe2a04209a3ef273d4070c8/kiteconnect/connect.py#L386
If you don't specify the name,python considers the order_id as value of variety,and then when you pass variety again ,it throws error.
If you want to do it without names of parameters,pass the variety first and then the order_id.