pythonstockquotes

Download Historic NSE Futures Data


I need to download NSE Futures data since 2012 for my strategy backtesting. I tried NSEpy and jugaad-data libraries but they are giving one day's data at a time.

I tried Getbhavcopy as well but the data is not accurate there.

Is there any other free source to download the same.

Thanks, Mohit


Solution

  • You can get as follows .....

    from datetime import timedelta, date
    from nsepy import get_history
    
    def importdata(stock):
        stock_fut = get_history(symbol=stock,
               start=date.today() - timedelta(days = 14),           end=date.today(),
               futures=True,
               expiry_date=date(2022,11,24)) 
                                  
        #print(stock_fut.columns)
        print(stock_fut[["Open","Close","Change in OI","Open Interest"]])
            
    a = ["AARTIIND","ABB","ABBOTINDIA","ABCAPITAL","ABFRL","ACC","ADANIENT"]
        
    for i in range(0,len(a)):
            print(a[i])
            importdata(a[i])