Skip to main content
Question
FYERS API
Asked a question last year

{'s': 'error', 'code': -96, 'message': ''} Getting above when calling any data api. Can anyone please help? eg: data = {"symbol":"NSE:SBIN-EQ","resolution":"D","date_format":"0","range_from":"1622097600","range_to":"1622097685","cont_flag":"1"} fyers.history(data)

Join FYERS Community to pick others' brains on Trading/Investing

Hey Naga,

try checking if you have given the correct client id (client id is the app id) and access token. Also you can have a look at pip list in which I had installed fyers-apiv2.
 

sample script
------------------------------

uncomment the function calls as needed in the main function and run the python script.

from fyers_api import fyersModel
from fyers_api import accessToken
import webbrowser


def generate_auth_code(client_id, secret_key, redirect_uri, response_type):
	session = accessToken.SessionModel(client_id=client_id, secret_key=secret_key, redirect_uri=redirect_uri, response_type=response_type)
	auth_code_url = session.generate_authcode()
	webbrowser.open17(auth_code_url,new=1)


def generate_access_token(auth_code, client_id, secret_key, redirect_uri, response_type, grant_type):
	session = accessToken.SessionModel(client_id=client_id, secret_key=secret_key, redirect_uri=redirect_uri, response_type=response_type, grant_type=grant_type)
	session.set_token(auth_code)
	response = session.generate_token()
	access_token = response["access_token"]
	print(access_token)

def data_api_call(client_id, access_token):
	fyers = fyersModel.FyersModel(token=access_token,is_async=False, log_path="/home/user/fyers-api",client_id=client_id) # Enter you desired log path store the logs on your system
	
	print(fyers.get_profile())
	print()

	history_data = {"symbol":"NSE:SBIN-EQ","resolution":"D","date_format":"0","range_from":"1622097600","range_to":"1622097685","cont_flag":"1"}
	print(fyers.history(history_data))
	print()

	quotes_data = {"symbols": "NSE:BANKNIFTY21AUGFUT,NSE:SBIN-EQ"}
	print(fyers.quotes(quotes_data))
	print()

	market_depth_data = {"symbol":"NSE:BANKNIFTY21AUGFUT","ohlcv_flag":"1"}
	print(fyers.depth(market_depth_data))


def main():	
	# enter your client ID (i.e., the app ID)
	client_id = ""

	# Enter the secret key of your app 
	secret_key = ""

	redirect_uri = "https://trade.fyers.in/api-login/redirect-uri/index.html18"
	response_type = "code"

	#generate_auth_code(client_id, secret_key, redirect_uri, response_type)

	auth_code = ""
	grant_type = "authorization_code"
	#generate_access_token(auth_code, client_id, secret_key, redirect_uri, response_type, grant_type)

	access_token = ""
	#data_api_call(client_id, access_token)



if __name__ == '__main__':
	main()


{'s': 'error', 'code': -96, 'message': ''}
Getting above when calling any data api. Can anyone please help?  eg: data = {"symbol":"NSE:SBIN-EQ","resolution":"D","date_format":"0","range_from":"1622097600","range_to":"1622097685","cont_flag":"1"}
 
fyers.history(data)
if __name__ == '__main__':
    access_token = get_token()
    print(access_token)
    fyers = fyersModel.FyersModel(client_id=app_id, token=access_token, log_path="../fyers")
    #print(fyers.get_profile())
    monthly_exp = monthly_expiry()
    expiry_month = monthly_exp.strftime("%b").upper()
    expiry_year = monthly_exp.strftime("%y")
    current_fut_contract = "NSE:" + "BANKNIFTY" + expiry_year + expiry_month + "FUT"
    print( f"{current_fut_contract}")
    data = {"symbols": current_fut_contract}
    fut_quote = fyers.quotes(data)
    print(fut_quote)
    if fut_quote['s'] == 'ok':

result: 

{'s': 'error', 'code': -96, 'message': ''}
Getting above when calling any data api. Can anyone please help?  eg: data = {"symbol":"NSE:SBIN-EQ","resolution":"D","date_format":"0","range_from":"1622097600","range_to":"1622097685","cont_flag":"1"}
 
fyers.history(data)

 

@Vikram Sri16, thanks for your prompt response. Here is the screenshot as requested. thanks for your help in advance.