Code for extracting live 5 minute data for bank nifty. Dera team I am getting multiple errors while developing the code for extracting the live market data for bank nifty. Can you please send me one sample code for Python?
Hi Preeti,
can you check this,
import datetime
import time
from fyers_api import fyersModel
def getHistoryData(fyers):
current_day = [datetime.datetime.now](http://datetime.datetime.now)().day
current_month = [datetime.datetime.now](http://datetime.datetime.now)().month
current_year = [datetime.datetime.now](http://datetime.datetime.now)().year
current_date = f"{current_year}-{current_month}-{current_day}"
while True:
data = {
"symbol":"NSE:NIFTYBANK-INDEX",
"resolution":"5",
"date_format":"1",
"range_from":current_date,
"range_to":current_date,
"cont_flag":"1"
}
response = fyers.history(data=data)
print(response)
time.sleep(1)
def main():
client_id = "SPXXXXE7-100"
access_token = "eyJ0eXAiOiJK***.eyJpc3MiOiJhcGkuZnllcnM***.IzcuRxg4tnXiULCx3***"
fyers = fyersModel.FyersModel(client_id=client_id, token=access_token, log_path="/home/user/logs")
getHistoryData(fyers)
if __name__ == "__main__":
main()
Hi Nikhil
Thanks for the response..thats really helpful..
I am now getting this error
ERR: logEntryFunc: history : [Errno 13] Permission denied: ‘/2022-12-14.txt’
{‘s’: ‘error’, ‘code’: -17, ‘message’: ‘Could not authenticate the user’}
Thanks
Preeti
Hi Vikram Apologies I addressed you as Nikhil by mistake.
Hey preeti,
Would suggest you to go through the docs,
See how to create an app and create and access token to hit the APIs
Hi Vikram Thanks for your response..I have followed the process and I have just tested another code which is giving me perfect ping..but in your code I am getting error for user authentificatin..please help..Thanks Preeti
Hi Vikram..issue resolved.I guess the issue was , may be related to access_token generated. I can see now the data on console. Thanks for your help !! Much appreciated. Thanks Preeti . But I see that script you provided is different to the steps and data feilds provided in API documentation. So API documentation needs updation. Thanks