Error: Please provide valid Symbol

Error while fetching historic data for Banknifty Index, I am getting this error: Please provide valid Symbol

After updating to fyers v3 api, for logging in code I get this:

session = fyersModel.SessionModel(

^^^^^^^^^^^^^^^^^^^^^^^

AttributeError: module 'fyers_api.fyersModel' has no attribute 'SessionModel'

I had followed the steps as per Git.

Can you please assist me here? Originally, I want to get historical data for Banknifty index from v2 fyers where I am getting Invalid symbol error.

Thanks

Hey @117375893251546738105

We request you to please use API V3 to get the history data .

Please follow our API latest API docs for this
Docs link : https://myapi.fyers.in/docsv3

and follow code from this github repo
Github Repo : https://github.com/FyersDev/fyers-api-sample-code/tree/sample_v3/v3

Hi Abhishek

As I mentioned above, I have installed v3 and post that I am facing this new issue. Below is my code:

session = fyersModel.SessionModel(

client_id=client_id[i],

secret_key=secret_key[i],

redirect_uri=url[i],

response_type='code',

grant_type='authorization_code')

Error:

session = fyersModel.SessionModel(

^^^^^^^^^^^^^^^^^^^^^^^

AttributeError: module 'fyers_api.fyersModel' has no attribute 'SessionModel'

I request to please provide the fix for this or tell me how to continue on v2. Please hurry!!

Could you try to fetch the history data with this code :

https://github.com/FyersDev/fyers-api-sample-code/blob/sample_v3/v3/python/market_data/history.py

Hello

I tried that, actually i was using similar thing. But I am getting this error:

1709661137131 :: history :: {'symbol': 'NSE:NIFTY50-INDEX', 'resolution': 'D', 'date_format': '1', 'range_from': datetime.date(2024, 3, 5), 'range_to': datetime.date(2024, 3, 5), 'cont_flag': '1'} :: 1709661137335 :: {'s': 'error', 'code': -300, 'message': 'Please provide a valid symbol'}

1709661159493 :: history :: {'symbol': 'NSE:NIFTYBANK-INDEX', 'resolution': 'D', 'date_format': '1', 'range_from': datetime.date(2024, 3, 5), 'range_to': datetime.date(2024, 3, 5), 'cont_flag': '1'} :: 1709661159698 :: {'s': 'error', 'code': -300, 'message': 'Please provide a valid symbol'}

Symbol name is correct. I tried above with v2 as with v3 I am not able to login due to above comment’s error

@117375893251546738105 Could you send the complete code used from you’re end

from fyers_apiv3 import fyersModel

from selenium import webdriver

import chromedriver_autoinstaller

import time

import os

import json

import datetime as dt

import pandas as pd

from collections import defaultdict

import pyotp

from datetime import timedelta

chromedriver_autoinstaller.install()

i=4

session = fyersModel.SessionModel(

client_id=client_id[i],

secret_key=secret_key[i],

redirect_uri=url[i],

response_type='code',

grant_type='authorization_code')

auth_code = getAuthCode(session, mob_num[i], GA_KEY[i], key[i])

session.set_token(auth_code)

response = session.generate_token()

accessToken = response["access_token"]

fyers = fyersModel.FyersModel(client_id=client_id[i], token=accessToken, log_path=os.getcwd())

n=dateToday-timedelta(200)

totalDays=200

if n.weekday()==5:

n=dateToday-timedelta(201)

totalDays=201

elif n.weekday()==6:

n=dateToday-timedelt(202)

totalDays=202

resp = getFyersHist("NSE:NIFTYBANK-INDEX", fyers, "5", n, dateToday)

getAuthCode and getFyersHist are internal functions, but i am getting error at login itself, this is working with v2. I hope this is helpful

uninstalling v2 worked
pip uninstall fyers-apiv2