Problem accessing RTD with websocket.

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.

Hi Partha,

Let me clarify something before you proceed further. Websocket is a 2-way communication to the server you are accessing. Once you subscribe to a symbol through websocket, you get its stream of data, in this case the symbols tick data every second. So, to run this perfectly you need to place it in a while loop.

At present the documentation on fyers for websocket is crude, so give it some time for the developers to update the code documentation.

I tired websockets in Nodejs with and without while loop. nothing seems to work