Fyers_Api v3 websocket is not working

Hi, i am using fyers Api V3 for web socket connection.

Earlier it was working fine to get the live tick data.

But now i am not able to get the data neither any error logs are recorded.

Even when i try sample code mentioned in the fyers docsv3 “Market Data Lite-Mode”

I am not able to get the live feed.

Is the problem same with all the users or i am missing something.

Thanks in advance!

Hi @srikanta.6nzpjldt

Please share your code so that I can check it.

hi here is the code:-
from fyers_apiv3.FyersWebsocket import data_ws

def onmessage(message):

"""

Callback function to handle incoming messages from the FyersDataSocket WebSocket.

Parameters:

    message (dict): The received message from the WebSocket.

"""

print("Response:", message)

def onerror(message):

"""

Callback function to handle WebSocket errors.

Parameters:

    message (dict): The error message received from the WebSocket.

"""

print("Error:", message)

def onclose(message):

"""

Callback function to handle WebSocket connection close events.

"""

print("Connection closed:", message)

def onopen():

"""

Callback function to subscribe to data type and symbols upon WebSocket connection.

"""

# Specify the data type and symbols you want to subscribe to

data_type = "SymbolUpdate"

# Subscribe to the specified symbols and data type

symbols = ['NSE:BANKNIFTY23SEP44400CE']

fyers.subscribe(symbols=symbols, data_type=data_type, channel = 15)

# Keep the socket running to receive real-time data

fyers.keep_running()

Replace the sample access token with your actual access token obtained from Fyers

access_token = “accesstoken.eyJpc3MiOiJhcGkubG9naW4uZnllcnMuaW4iLCJpYXQiOjE2OTU2MjI3NTEsImV4cCI6MTY5NTY1Mjc1MSwibmJmIjoxNjk1NjIyMTUxLCJhdWQiOiJbXCJ4OjBcIiwgXCJ4OjFcIiwgXCJ4OjJcIiwgXCJkOjFcIiwgXCJkOjJcIiwgXCJ4OjFcIiwgXCJ4OjBcIl0iLCJzdWIiOiJhdXRoX2NvZGUiLCJkaXNwbGF5X25hbWUiOiJYSzI1NzY1Iiwib21zIjoiSzEiLCJoc21fa2V5IjoiOTg1N2IwOWMzOWM0MWExOWI5YTlhNTk1MTllZjIyMzA0MTM4ZmIwOGE0MjViMmRjZWMxMjVmYWUiLCJub25jZSI6IiIsImFwcF9pZCI6IjhER0tLOEpaVTQiLCJ1dWlkIjoiMzI4NDEzMTBlNmJjNDNmNTljM2U0NWY0NDkzNjQ2OWQiLCJpcEFkZHIiOiIwLjAuMC4wIiwic2NvcGUiOiIifQ.ZBUx9QsINKoidrawHvyzERaufeT7SiG22ybenErEZYU”

Create a FyersDataSocket instance with the provided parameters

fyers = data_ws.FyersDataSocket(

access_token=access_token,       # Access token in the format "appid:accesstoken"

log_path="",                     # Path to save logs. Leave empty to auto-create logs in the current directory.

litemode=True,                  # Lite mode disabled. Set to True if you want a lite response.

write_to_file=False,              # Save response in a log file instead of printing it.

reconnect=True,                  # Enable auto-reconnection to WebSocket on disconnection.

on_connect=onopen,               # Callback function to subscribe to data upon connection.

on_close=onclose,                # Callback function to handle WebSocket connection close events.

on_error=onerror,                # Callback function to handle WebSocket errors.

on_message=onmessage             # Callback function to handle incoming messages from the WebSocket.

)

Establish a connection to the Fyers WebSocket

fyers.connect()

outcome:-

Response: {‘type’: ‘cn’, ‘code’: 200, ‘message’: ‘Authentication done’, ‘s’: ‘ok’}

Response: {‘type’: ‘lit’, ‘code’: 200, ‘message’: ‘Lite Mode On’, ‘s’: ‘ok’}

no ticks afterwards

Hi @srikanta.6nzpjldt

Don’t put your access token publicly. If something goes wrong you will be only responsible for that.

Hi ,

I understand the access token is not correct.
Please help me with the issue i am facing.

HI @srikanta.6nzpjldt

Can you try this code once and let me know

https://github.com/FyersDev/fyers-api-sample-code/blob/sample_v3/v3/python/websocket/data_socket/data_websocket_foreground.py

hi,
Wow surprisingly it is working.
may i know where i am getting wrong?

Thank you

Hi @srikanta.6nzpjldt

Glad to know it is working for you now.
Thank you

Hi Pankaj,

Again getting the same error with the code you provided.

I dont know where i am lagging?

Can you please help me ?

do i have some compatibility issue?

Hi @srikanta.6nzpjldt

Can you check now.

Hi Pankaj,
yes checked same issue no ticks

Hi @srikanta.6nzpjldt,

Could you please send me your Client ID via DM? Our team will use your registered details to assist you promptly.