Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nse data fetch issue #38

Closed
000-arunkumar opened this issue Mar 18, 2024 · 5 comments
Closed

nse data fetch issue #38

000-arunkumar opened this issue Mar 18, 2024 · 5 comments

Comments

@000-arunkumar
Copy link

000-arunkumar commented Mar 18, 2024

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': ''}

@andiamvinay
Copy link

I'm running into the same issue @aeron7

@supriyom083
Copy link

supriyom083 commented Apr 2, 2024

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

@000-arunkumar
Copy link
Author

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

@buzzvolt
Copy link

#40 will take care of this @aeron7

@aeron7
Copy link
Owner

aeron7 commented Apr 28, 2024

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 aeron7 closed this as completed Apr 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants