How to subscribe and unsubscribe symbols in Fyers API Websocket(API v2)

I have 2 trades open and for those 2 trade symbol I have created a websocket. I am running the websocket in background mode.

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 and subscribe the new symbol to the websocket? How do I call the subscribe and unsubscribe function from anywhere in the program?

def subscribe_websocket(symbol):

        #TODO: Call this functon whenever new trade is placed

        ws.subscribe(symbol=symbol, data_type="symbolData")

        ws.keep_running()

    def unsubscribe_websocket(symbol):

        #TODO: Call this function whenever exit trade is called

        ws.unsubscribe(symbol=symbol)

Can anyone please help understanding this process and how do I proceed for the above problem?

I am getting below errors:

1
4 replies