This is the code available in the api-V2 documentation for accessing RTD
from fyers_api.websocket import ws
accessToken = app_id + ‘:’ + access_token
data_type = “symbolData”
def custom_message(self):
print ("Custom " + str(self.response))
ws.FyersSocket.websocket_data = custom_message
symbol = [“NSE:SBIN-EQ”, “NSE:RELIANCE-EQ”]
fyersSocket = ws.FyersSocket(access_token=accessToken, data_type=data_type,symbol=symbol)
fyersSocket.subscribe()
fyersSocket.unsubscribe(symbol=symbol)
This code is running well, but the process is looping within the custom_message(self) function. Is it possible that the function will run only when I call the function and get the return value from the function? If yes, please help me with the code. Moreover with this code the last line , where to unsubscribe the websocket, never coming as the process is looping over the function.
This is what I want:
def custom_message(self):
return ("Custom " + str(self.response))
If possible, please give me the full code.