NSEpy Library to Extract Historical Data from NSE’s Website

Hello Everyone, as we know from previous video tutorial of NSEPY mentioned below where we are able to fetch historical data so now i'm here to guide the updated and simpler version of it which will fetch our data as required here we mention a start as from date and end as to date.First we fetch an equity stock then we move towards spot price and then further future and options can be fetched as mentioned with fewer input details.Mostly we see historical data in the form of EOD candle of that particular day.The historical data always combined with realtime data to perform programmatic trading or algorithmic trading or it serves the data analysis purpose.To get the realtime data and perform the programmatic trading you can open an alice blue account and you can get Free API through our refferal link as follows Alice Blue Free API Register Here



from nsepy import get_history
from datetime import datetime
import dateutil.relativedelta
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
to_date=datetime.now()
to_date=datetime.strftime(to_date,'%Y,%m,%d')
to_date=datetime.strptime(to_date,'%Y,%m,%d')
from_date=to_date-dateutil.relativedelta.relativedelta(month=1)
data=get_history(symbol='RELIANCE',start=from_date,end=to_date)
print(data)
data['Close'].plot()
plt.show()


Updated and Simpler Version:



from nsepy import get_history as gh
import datetime as dt
import dateutil.relativedelta as dr
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
tradingsymbol='NIFTY BANK'
end=dt.date.today()
start=end-dr.relativedelta(days=30)
data=gh(tradingsymbol,start,end,index=True)
data['Close'].plot()
plt.show()