market data websocket API issue

I am facing problem with market data websocket for fyers V2

I am able to get live data on the console and the same is getting logged in the log folder path.

But unable to get call for the custom_message function, where I want to process the live data before further usage.

I dont see this **custom_message **function getting called, below is code I am using for this purpose

def custom_message(self):

** print("Custom: " + str(self.response))**

ws.websocket_data = custom_message

feedtoken = app_id + ā€œ:ā€ + access_key

data_type = ā€˜symbolData’

symbol = [ā€˜MCX:CRUDEOIL21NOVFUT’]

fyersSocket = ws.FyersSocket(access_token=feedtoken, run_background=False, log_path=ā€˜C:/python_project’)

fyersSocket.subscribe(symbol=symbol, data_type=data_type)

time.sleep(300)

fyersSocket.keep_running()

facing a similar problem… **custom_***message function is not getting called for *orderUpdate

This worked for me try if it helps you,

custom message is not working with fyers-apiv2=2.0.5

try installing previous version **fyers-apiv2=2.0.4 ā€˜**custom function is working fine with this version’

Even I’m facing this issue with custom_message. However, if you go to 2.0.4 then ModuleNotFoundError: No module named 'fyers_api.Websocket’ will pop up

# use this
import ws from fyers_api.websocket

instead of

Websocket with ā€˜W’ capital

Can you tell me exactly what you want to achive with custom function? May be I can help.

Currently I am using it to insert data into MySQL and I am not facing any issue with using version 2.0.4

For Order Update Websocket,

Data we recieve is in string format, can use json.loads() to convert it to python dictionary.

import json

def custom_message(self):

data = json.loads(self)

After converting to it to dictionary you can insert it into dataframe

What about data websocket?

For data websocket, data is in dictionary format. We have to use for loop, to loop through each symbol we subscribed.

def custom_message(self):

insert_ticks(self.response)

def insert_ticks(ticks):

for tick in ticks:

  ltp = tick['ltp']

  time_stamp = tick['last_traded_time']

I’m aware of this issue sir. I have written to the Fyers team as well that the *def custom_message(self) *is more like a dummy statement.

Thanks for the workaround. Makes sense. Anyway, I’m going to wait for Fyers to do it the right way.

above code to start new thread did not work for me. is it working?

I’m having the same issue. I strictly followed docs but It’s not calling the custom_message( ) functions

Didn’t work for me either. :frowning:

fs = ws.FyersSocket(access_token=access_token, run_background=True, log_path="")

Change run_background to False

and in custom_message(msg) use json.load(msg) and assign it some value and do your parsing.

**import **json

**def **custom_message(msg):

   print(f"Custom:{msg}")

   data = json.loads(msg)

   print(data)

   print(data.get('s'))

   print(data.get('d'))

This works for me…

Hope it helps for you as well…

If run background is false, the code after invoking the WebSocket will not run. The code will stop there itself.

I tried this with orderupdate, when ever there is change in order. scripts works for me.

Note: Created Weebhook for pending, rejected, cancelled, traded

@**Bikram Raj Kapoor **

which Fyers version are you using ? 2.0.4 or 2.0.5?

Hi Vishnu,

Any response from Fyers?

I am still facing this issue.

If you found any work around then please share. Thanks in advance.

I also got this error but I fix it

https://github.com/SHIVANIUM-GIT/fyer_api_websocket

if you face any problem again message me