Unable to cancel orders

manishratnani1
Sir,
I entered short sell order, with 2 buy orders. First is buy order as stoploss and second buy order as target.
While sl order is triggered, target order must be cancelled and vice versa.
But unable to cancel order.
I am coading in python.
Tagged:
  • rjamitsharma
    For that you can either use kite.orders and check if sl or target hit if yes then cancel opposit order


    Or use postback url to track everything and do it
  • manishratnani1
    Yes, target is achieved. As well as cancel order code is entered. but it is not triggered.
  • rakeshr
    While sl order is triggered, target order must be cancelled and vice versa.
    As you have entered two individual orders. You need to specifically cancel other order, when other one is achieved.
    As well as cancel order code is entered. but it is not triggered.
    Are you sure, you are sending correct order_id to cancel required pending order. You can check complete cancel_order, param detail here.
    First is buy order as stoploss and second buy order as target.
    If you are looking to place a single order for both as One Cancels Other(OCO). You can try out two-leg GTT orders. Refer to the documentation here.
  • manishratnani1
    # this will cancel target order
    if (sl_status == 'COMPLETE'):

    send_rev_order_status = pd.DataFrame(kite.order_history(order_id=status['send_rev_order'])).iloc[-1]['status']

    cancel_send_reverse_order = kite.cancel_order(variety = kite.VARIETY_REGULAR, order_id = status['send_rev_order'], parent_order_id=status['send_rev_order'])

    # this will cancel stoploss order
    if (send_rev_order_status == 'COMPLETE'):

    sl_status = pd.DataFrame(kite.order_history(order_id=status['sl_order'])).iloc[-1]['status']
    cancel_sl_order = kite.cancel_order(variety = kite.VARIETY_REGULAR, order_id = status['sl_order'], parent_order_id=status['sl_order'])


    above is my code for cancel order.

    Sir, i am unable to understand "complete cancel_order, param" pls give me example code if any.
    Thank you
  • rakeshr
    kite.cancel_order(variety = kite.VARIETY_REGULAR, order_id = status['send_rev_order'], parent_order_id=status['send_rev_order'])
    kite.cancel_order(variety = kite.VARIETY_REGULAR, order_id = status['sl_order'], parent_order_id=status['sl_order'])
    Can you re-check, if you are sending correct variety and order_id?
    "complete cancel_order, param"
    We meant, you can know all input params required for cancel_order like variety, order_id and parent_order_id.
    Also, you can enable debug log and paste here your complete log for the required request made. Use the below code to enable debug logs:
    import logging
    logging.basicConfig(level=logging.DEBUG)
  • manishratnani1
    Yes variety and order_id is correct.
    Is there any mail id? I want to send my code file.
    Thank you
  • rakeshr
    Also, you can enable debug log and paste here your complete log for the required request made. Use the below code to enable debug logs:
    import logging
    logging.basicConfig(level=logging.DEBUG)
    As said above, can you paste debug log here? Will help us to debug more on this.
  • sujith
    @manishratnani1,
    You need to give us the complete logs for helping you out.
Sign In or Register to comment.