Getting error in websocket

I’m new to fyers API, I installed API through pip install fyers-apiv2 and going through the documentation but I’m getting an error : ModuleNotFoundError: No module named ‘fyers_api.Websocket’

when I tried from fyers_api.websocket import ws then it is working but I’m getting an error in the custom message function

pong received

Exception is custom_message() missing 1 required positional argument: ‘msg’

Thanks

Hi Ajay can you let me know your python version(python --version)
and your SDK version (output of pip list)
and code you are using to try to connect to websocket
to let me replicate the enviroment

Hi Nihal,

Thanks for your reply. I tried both ways.

#------------------------------
from fyers_api.Websocket import ws

data_type = "symbolData"
symbol= ["NSE:SBIN-EQ"]

def custom_message(msg):
     print ("Custome Message " + str(msg.response))

# ws.websocket_data = custom_message
fyersSocket = ws.FyersSocket(access_token=access_token,run_background=False)
fyersSocket.websocket_data = custom_message
fyersSocket.subscribe(symbol=symbol,data_type=data_type)

#------------------------------
from fyers_api.websocket import ws

data_type = "symbolData"
symbol= ["NSE:SBIN-EQ"]

def custom_message(msg):
     print ("Custome Message " + str(msg.response))
     
fyersSocket = ws.FyersSocket(access_token=access_token,symbol=symbol,data_type=data_type)
ws.websocket_data = custom_message
fyersSocket.subscribe()

python --version
Python 3.10.11

pip list
Package           Version
----------------- ---------
asyncio           3.4.3
certifi           2022.12.7
chardet           4.0.0
fyers-api-builder 0.3.8
fyers-apiv2       2.0.4
idna              2.10
pip               23.1.2
pprintpp          0.4.0
pyotp             2.8.0
requests          2.25.1
setuptools        67.7.2
tornado           6.1
urllib3           1.26.15
websocket-client  1.2.1
websockets        8.1

Please try installing the latest SDK version which is 2.0.5
then you will be able to import as
pip install fyers-apiv2==2.0.5

and incase you get a error like this while running ws = websocket.WebSocketApp(

AttributeError: module ‘websocket’ has no attribute ‘WebSocketApp’

try:
pip uninstall websocket-client(as both can be imported with same names and can cause issues)

I installed the latest version now I’m getting error

from fyers_api.Websocket import ws
ModuleNotFoundError: No module named 'fyers_api.Websocket'
C:\Users\verma> pip show fyers-apiv2
Name: fyers-apiv2
Version: 2.0.5
Summary: Fyers trading APIs.
Home-page: https://github.com/FyersDev/fyers-api-py
Author: Fyers-Tech
Author-email: [email protected]
License: UNKNOWN
Location: c:\python310\lib\site-packages
Requires: asyncio, requests, tornado, websocket-client, websockets
Required-by:

Hi @xGEOiW2SHe

I there any way to fix this??

I have been trying to replicate the error but not able to few things you can try

  1. if you are using pyenv make sure the python version set by pyenv and your IDE are running on same version(specially if you run your code with run button rather than ‘python file.py or python3 file.py’).
  2. upgrade pip(pip install --upgrade pip) try uninstalling and reinstalling fyers-apiv2(pip uninstall fyers-apiv2,pip install fyers-apiv2) should install v2.0.5 by default.
    Meanwhile I will try to find if there is other reason causing this

thanks, I will try these steps and let u know.