KiteConnect Websocket(subscribing to new token and unsubscribe old token)

Siddhant_Mohanty
I have 2 trades open and for those 2 trade symbol/token I have created a websocket. Keeping(kws.connect(threaded=True))
Lets say 1 of my trade hits a stop loss and I need to close that trade and open 1 new trade.

How to unsubscribe the old symbol/token and subscribe the new symbol/token to the websocket? How do I call the subscribe and unsubscribe function from anywhere in the program?

def subscribe_websocket(new_trade_token):
#TODO: Call this function whenever new trade is placed
ws.subscribe(new_trade_token)

def unsubscribe_websocket(unsubscribe_token):
#TODO: Call this function whenever exit a trade
ws.unsubscribe(unsubscribe_token)

Can anyone please help understanding this process and how do I proceed for the above problem?
Sign In or Register to comment.