Member-only story
How to download Historical data from NSE using Python
4 min readAug 29, 2023
How to download Historical data from NSE using Python
Historical Data is the most important thing if You’re backtesting. NSE provides Historical Data for free in various time frames. To scrap that data, We have designed a function named equity_history()
NSEPython Library. The documentation follows –
Syntax:
equity_history(symbol,series,start_date,end_date)
Program Structure:
def equity_history(symbol,series,start_date,end_date):
payload = nsefetch("https://www.nseindia.com/api/historical/cm/equity?symbol="+symbol+"&series=[%22"+series+"%22]&from="+start_date+"&to="+end_date+"")
return pd.DataFrame.from_records(payload["data"])
Example:
symbol = "SBIN"
series = "EQ"
start_date = "08-06-2021"
end_date ="14-06-2021"
print(equity_history(symbol,series,start_date,end_date))
Problem
It will return a Pandas Dataframe
as output. Anyways it is huge, So We are not pasting here. But there is a huge limitation –
- Error or Empty data if You search beyond
365 days.
- It will return only 50 days of data even if you ask for the last 90 days and discard the rest!
So, How to improvise this function?