Cancel an open order which has not yet been executed in 1 seconds of placement

sensexboy
Hi All,

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')

The error I get is too many arguments regular

  • SRIJAN
    SRIJAN edited July 27
    Is this error occuring in the place_order API or the cancel order API?? It seems the error is in your custom order function.

    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
  • sensexboy
    Hi Srijan, it is the cancel order that is giving error:
    the exact error is:

    "cancel_order() got multiple values for argument 'variety'"
  • SRIJAN
    You are passing the variety parameter more than once in the cancel_order function.

    Do it properly and it will work.
  • sensexboy
    Actually got it and thanks for replying. I just gave the variable and name explicitly and it worked!:

    cancel_order = kite.cancel_order(order_id = placed_order_id, variety='regular', parent_order_id = None)
  • SRIJAN
    Variety is by default the first parameter in the cancel _order function.

    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.
  • sensexboy
    aah! i also suspected it. Makes sense. Thanks a ton for clearing this doubt! Cheers
This discussion has been closed.