I have placed below two orders and they are yet to be executed. P1=kite.place_order('bo','NSE','YESBANK','BUY',1,product='MIS',order_type='SL',trigger_price=393, price=395,stoploss=5,squareoff=5) P2=kite.place_order('bo','NSE','YESBANK','SELL',1,product='MIS',order_type='SL',trigger_price=375, price=373,stoploss=5,squareoff=5)
Now P1 is executed and if P1 is executed, I need to cancel P2 automatically. In this case I don't want to know order number of P2 through kite trade login.
Request you to let me know what should I do to cancel P2?
Do you close your application after placing 2 orders or your application will be running? If you close your application, then no way to cancel one another..
If your application will be running, then you can write simple logic to do that.
You can try the below logic; Assuming, 1.You know python well 2.Using Web-sockets to listen for ticks and order updates.
Step1: Place Order P1=kite.place_order('bo','NSE','YESBANK','BUY',1,product='MIS',order_type='SL',trigger_price=393, price=395,stoploss=5,squareoff=5) P2=kite.place_order('bo','NSE','YESBANK','SELL',1,product='MIS',order_type='SL',trigger_price=375, price=373,stoploss=5,squareoff=5)
Step2: Store the OrderId's in Dictionary orderDict = { P1: P2, P2: P1} Here is the main trick We store 2 keys, In the 1st dict, P1 as Key & P2 as Value In the 2nd dict, P2 as Key & P1 as Value
Step3: Cancel order in Websocket Order Update orderId = 'Id frm websocket update' orderStatus = 'Status frm Webscoket Update'
if orderId in orderDict: if orderStatus = "COMPLETE" orderToCancel = orderDict[orderId] kite.cancel_order(self, "bo", orderToCancel)
Since the order updates are pushed to you automatically, with few lines of code, you can cancel the other order automatically, you no need to check for order status every sec.
Do you close your application after placing 2 orders or your application will be running?
If you close your application, then no way to cancel one another..
If your application will be running, then you can write simple logic to do that.
I just need api command to cancel second order if first got executed. And also want to know how to check order got executed or not.
Regards,
Better way to know,order executed status for any specific order, by it's
order_id
param, have a look here.You can try the below logic;
Assuming,
1.You know python well
2.Using Web-sockets to listen for ticks and order updates. Since the order updates are pushed to you automatically, with few lines of code, you can cancel the other order automatically, you no need to check for order status every sec.
Thank you for your detailed support.
I will revert in case of further query.
Regards,