No output from WebSocket

Hello,

Please help providing your inputs on the below issue:

Executing the below code after successful authentication, is not streaming any data and the program just continue to run until I terminate the session with ALT + CTR + DEL.

Removing fs.keep_running() from the code is not making any difference.

def custom_function(msg):
    print(f'custom function: {msg}')

symbol=["NSE:NIFTYBANK-INDEX","NSE:TCS-EQ"]
fs = ws.FyersSocket(access_token=access_token,run_background=False,log_path="D:\\code\\fyers\\logs")
fs.websocket_data = custom_function
fs.subscribe(symbol=symbol, data_type="symbolUpdate")
fs.keep_running()

Hey try the below code,

from fyers_api.Websocket import ws

def run_process_symbol_data(access_token):

data_type = “symbolData”

symbol = [“NSE:SBIN-EQ”]

fs = ws.FyersSocket(access_token=access_token,log_path=“/home/user/logs”)

fs.websocket_data = custom_message

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

fs.keep_running()

def custom_message(msg):

print (f"Custom:{msg}")

def main():

access_token = “SPXXXXE7-100:eyJ0eXAiOiJK***.eyJpc3MiOiJhcGkuZnllcnM***.IzcuRxg4tnXiULCx3***”

run_process_symbol_data(access_token)

if name == ‘main’:

main()

Tried above code am getting below error

ModuleNotFoundError: No module named ‘fyers_api.Websocket’

Thank you Vikram. Your input is much appreciated. I have corrected the data_type in my code as per your code and it works now.

4Sudhakar can you share your code am unable to fetch data.

TypeError: init() got an unexpected keyword argument ‘log_path’

Hi, Can you please update to the latest version of fyers api

Hi

I am running below code but i am getting error - Can someone pls guide me.

ERR: logEntryFunc: get_profile : [Errno 30] Read-only file system: ‘/2022-12-31.txt’

{‘s’: ‘error’, ‘code’: 500, ‘message’: ‘Looks like you are passing an invalid entry’}

ERR: logEntryFunc: orderBook : [Errno 30] Read-only file system: ‘/2022-12-31.txt’

{‘s’: ‘error’, ‘code’: 500, ‘message’: ‘Looks like you are passing an invalid entry’}

Code

from fyers_api.Websocket import ws

from fyers_api import fyersModel

from fyers_api.Websocket import ws

import datetime

import time

import threading

import pandas as pd

from fyers_api import accessToken

from fyers_api import fyersModel

from datetime import datetime

import time

import threading

import pandas as pd

from fyers_api import accessToken

from fyers_api import fyersModel

from datetime import datetime

import pytz

from zoneinfo import ZoneInfo

from datetime import datetime, timedelta

import pandas as pd

import numpy as np

from datetime import datetime

import math

import fyers_api

import requests

import threading

import requests

import urllib.request, urllib.response

from urllib.request import Request, urlopen

import json

import ast

import fyers_api

import re

import requests

import threading

import csv

import fyerscred

fyers = fyersModel.FyersModel(token=“access_token as defined in main block”,is_async=False,client_id=“client_id(APP_ID)”) ## Create a fyersModel object if in any scenario you want to call the trading and data apis when certain condiiton in websocket data is met so that can be triggered by calling the method/object after subscribing and before the keep_running method as shown in run_process_background_symbol_data

def run_process_background_symbol_data(access_token):

data_type = “symbolData”

symbol =[“NSE:SBIN-EQ”,“NSE:HDFC-EQ”,“NSE:IOC-EQ”]

fs = ws.FyersSocket(access_token=access_token,run_background=False,log_path=“/Users/nitinbakshi/Downloads/python/New”)

fs.websocket_data = custom_message

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

print(fyers.get_profile())

print(fyers.orderbook())

fs.keep_running()

def run_process_background_order_update(access_token):

data_type = “orderUpdate”

fs = ws.FyersSocket(access_token=access_token,run_background=False,log_path=“/Users/nitinbakshi/Downloads/python/New”)

fs.websocket_data = custom_message

fs.subscribe(data_type=data_type)

fs.keep_running()

def custom_message(msg): ### This function can be anything which you want to configure at your end

print (f"Custom:{msg}")

def main():

access_token = “eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJhcGkuZnllcnMuaW4iLCJpYXQiOjE2NzI0NjA2OTYsImV4cCI6MTY3MjUzMzA1NiwibmJmIjoxNjcyNDYwNjk2LCJhdWQiOlsieDowIiwieDoxIiwieDoyIiwiZDoxIiwiZDoyIiwieDoxIiwieDowIl0sInN1YiI6ImFjY2Vzc190b2tlbiIsImF0X2hhc2giOiJnQUFBQUFCanI3bVlDR3g2WmtmRVRhRVhRWTJveENLNFJLNG1UQ3lWbEQ5WEhpOTRWb0NXalpMd2Uzb1pIeXMzMWlPMHlFbUhXR0YwV2RUb2tkNHU0VXQzYnFPbFRmMlFyTE5hTWtadjFwOVp5anFfZ2tFSXZRUT0iLCJkaXNwbGF5X25hbWUiOiJOSVRJTiBCQUtTSEkiLCJvbXMiOm51bGwsImZ5X2lkIjoiWE4xNjU0NSIsImFwcFR5cGUiOjEwMCwicG9hX2ZsYWciOiJOIn0.hwwvcrlYQReycmXn9MNOy-svucYrlTuZHfEAWCqz2G8”

For regular api calls you the access_token as mentioned above

Insert the accessToken and app_id over here in the following format for subscribing the websocket data (APP_ID:access_token)

access_token_websocket= “HA******ZB5-100:eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJhcGkuZnllcnMuaW4iLCJpYXQiOjE2NzI0NjA2OTYsImV4cCI6MTY3MjUzMzA1NiwibmJmIjoxNjcyNDYwNjk2LCJhdWQiOlsieDowIiwieDoxIiwieDoyIiwiZDoxIiwiZDoyIiwieDoxIiwieDowIl0sInN1YiI6ImFjY2Vzc190b2tlbiIsImF0X2hhc2giOiJnQUFBQUFCanI3bVlDR3g2WmtmRVRhRVhRWTJveENLNFJLNG1UQ3lWbEQ5WEhpOTRWb0NXalpMd2Uzb1pIeXMzMWlPMHlFbUhXR0YwV2RUb2tkNHU0VXQzYnFPbFRmMlFyTE5hTWtadjFwOVp5anFfZ2tFSXZRUT0iLCJkaXNwbGF5X25hbWUiOiJOSVRJTiBCQUtTSEkiLCJvbXMiOm51bGwsImZ5X2lkIjoiWE4xNjU0NSIsImFwcFR5cGUiOjEwMCwicG9hX2ZsYWciOiJOIn0.hwwvcrlYQReycmXn9MNOy-svucYrlTuZHfEAWCqz2G8”

run_process_background_symbol_data(access_token_websocket)

run_process_background_order_update(access_token_websocket)

if name == ‘main’:

main()

Hi Can someone pls help me with my query. thanks.