Not able to fetch any market data using api v2

Hi All,

can anyone please resolve this issue of fetching marketdata.

I am using the pip version 2.0.4

code:
def getMarketData(self):

    access_token=client_id+':'+self.access_token

    print('access_token>>>>',access_token)

    data_type='symbolData'

    symbol = ['NSE:TATAMOTORS-EQ', 'NSE:ITC-EQ']

    def custom_message(ticks):

        print (ticks.response)

    ws.FyersSocket.websocket_data=custom_message

    fs=ws.FyersSocket(access_token,data_type,symbol)

    fs.subscribe ()

can anyone please help me , why this is not working

and the output is like this:

any help and answers would be helpful, if anyone else is facing the same issue please comment.

thank you.

I am also facing the same issue. I am getting the below error.

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

is Fyers API really working?

Hi Thanna, try running this,

from fyers_api.Websocket import ws

def run_process_foreground_symbol_data(access_token):
    '''This function is used for running the symbolData in foreground 
    1. log_path here is configurable this specifies where the output will be stored for you
    2. data_type == symbolData this specfies while using this function you will be able to connect to symbolwebsocket to get the symbolData
    3. run_background = False specifies that the process will be running in foreground'''
    data_type = "symbolData"
    symbol = ["NSE:SBIN-EQ","NSE:ONGC-EQ"]   ##NSE,BSE sample symbols
    #symbol =["MCX:SILVERMIC22FEBFUT"]
    # symbol =["MCX:SILVERMIC21NOVFUT","MCX:GOLDPETAL21SEPTFUT"]
    fs = ws.FyersSocket(access_token=access_token,run_background=False,log_path="")
    fs.websocket_data = custom_message
    fs.subscribe(symbol=symbol,data_type=data_type)
    fs.keep_running()

def run_process_foreground_order_update(access_token):
    '''This function is used for running the order_update in background 
    1. log_path here is configurable this specifies where the output will be stored for you.
    2. data_type == orderUpdate this specfies while using this function you will be able to connect to orderwebsocket to get the orderUpdate
    3. run_background = False specifies that the process will be running in foreground '''
    data_type = "orderUpdate"
    fs = ws.FyersSocket(access_token=access_token,run_background=False,log_path="")
    fs.websocket_data = custom_message
    fs.subscribe(data_type=data_type)
    fs.keep_running()

def custom_message(msg):
    print (f"Custom:{msg}") 

def main():
    ### Insert the accessToken and app_id over here in the following format (APP_ID:access_token) 
    access_token= ""

    ## run a specific process you need to connect to get the updates on
    run_process_foreground_symbol_data(access_token)

    # run_process_foreground_order_update(access_token)
    
if __name__ == '__main__':
	main()

Hi Vikram Sri,

Please find the above screenshot error.

Can you please tell me how to resolve this error.

changed the first import line to:

from fyers_api.websocket import ws

and also installed 2.0.4 version

!pip install fyers_apiv2==2.0.4

Thank you.

Please you the latest fyers apiv2, its 2.0.5
and then the above code should work.

Can you please tell me how to resolve this error.

Thank you.

updated as you said in previous comment

If there is another file called websocket.py or a directory called websocket in your current directory, it will cause issues. Also i think there is some install errors, can you create a new virtual environment and install the latest version of fyers apiv2?

Hi Vikram Sri,

1.I opened a new colab

  1. !pip install fyers_apiv2

  2. execute the code with the access token

!pip install fyers_apiv2

from fyers_api.Websocket import ws

def run_process_foreground_symbol_data(access_token):

'''This function is used for running the symbolData in foreground 

1. log_path here is configurable this specifies where the output will be stored for you

2. data_type == symbolData this specfies while using this function you will be able to connect to symbolwebsocket to get the symbolData

3. run_background = False specifies that the process will be running in foreground'''

data_type = "symbolData"

symbol = ["NSE:SBIN-EQ","NSE:ONGC-EQ"]   ##NSE,BSE sample symbols

#symbol =["MCX:SILVERMIC22FEBFUT"]

# symbol =["MCX:SILVERMIC21NOVFUT","MCX:GOLDPETAL21SEPTFUT"]

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

fs.websocket_data = custom_message

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

fs.keep_running()

def run_process_foreground_order_update(access_token):

'''This function is used for running the order_update in background 

1. log_path here is configurable this specifies where the output will be stored for you.

2. data_type == orderUpdate this specfies while using this function you will be able to connect to orderwebsocket to get the orderUpdate

3. run_background = False specifies that the process will be running in foreground '''

data_type = "orderUpdate"

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

fs.websocket_data = custom_message

fs.subscribe(data_type=data_type)

fs.keep_running()

def custom_message(msg):

print (f"Custom:{msg}") 

def main():

### Insert the accessToken and app_id over here in the following format (APP_ID:access_token) 

access_token= "your access token"



## run a specific process you need to connect to get the updates on

run_process_foreground_symbol_data(access_token)



# run_process_foreground_order_update(access_token)

if name == ‘main’:

main()

Finally it works . Thank you so much

Have a good day