nsepython icon indicating copy to clipboard operation
nsepython copied to clipboard

nse data fetch issue

Open 000-arunkumar opened this issue 1 year ago • 3 comments

Issue: can't able to fetch index history using index_history function

ERROR:

""" KeyError Traceback (most recent call last) in <cell line: 6>() 4 start_date_r = start_date.strftime("%d-%b-%Y") 5 print(end_date_r, start_date_r) ----> 6 df = index_history(symbol,start_date_r,end_date_r) 7 len(df)

/usr/local/lib/python3.10/dist-packages/nsepython/rahu.py in index_history(symbol, start_date, end_date) 746 data = "{'name':'"+symbol+"','startDate':'"+start_date+"','endDate':'"+end_date+"'}" 747 payload = requests.post('https://niftyindices.com/Backpage.aspx/getHistoricaldatatabletoString', headers=niftyindices_headers, data=data).json() --> 748 payload = json.loads(payload["d"]) 749 payload=pd.DataFrame.from_records(payload) 750 return payload

KeyError: 'd' """

note: payload = requests.post('https://niftyindices.com/Backpage.aspx/getHistoricaldatatabletoString', headers=niftyindices_headers, data=data).json()

payload={'Message': 'There was an error processing the request.', 'StackTrace': '', 'ExceptionType': ''}

000-arunkumar avatar Mar 18 '24 15:03 000-arunkumar

I'm running into the same issue @aeron7

andiamvinay avatar Mar 28 '24 17:03 andiamvinay

replace index_history function with below function body in rahu.py

def index_history(symbol,start_date,end_date): data = {"name": symbol, "startDate": start_date, "endDate": end_date, } data={"cinfo":json.dumps(data)}
payload = requests.post('https://www.niftyindices.com/Backpage.aspx/getHistoricaldatatabletoString', timeout=300, headers=niftyindices_headers, json=data,).json()
payload = json.loads(payload["d"]) payload=pd.DataFrame.from_records(payload) return payload

supriyom083 avatar Apr 02 '24 20:04 supriyom083

replace index_history function with below function body in rahu.py

def index_history(symbol,start_date,end_date): data = {"name": symbol, "startDate": start_date, "endDate": end_date, } data={"cinfo":json.dumps(data)} payload = requests.post('https://www.niftyindices.com/Backpage.aspx/getHistoricaldatatabletoString', timeout=300, headers=niftyindices_headers, json=data,).json() payload = json.loads(payload["d"]) payload=pd.DataFrame.from_records(payload) return payload

This is working. Thanks

ghost avatar Apr 10 '24 14:04 ghost

https://github.com/aeron7/nsepython/pull/40 will take care of this @aeron7

buzzvolt avatar Apr 27 '24 06:04 buzzvolt

Support and Beta Functions If you have other doubts or want to check out the beta functions, visit the NSEPython Discussions forum. If you have feature requests, you can submit them at the NSEPython Feature Request forum.

aeron7 avatar Apr 28 '24 07:04 aeron7