#get dump of all NSE instruments instrument_dump = kite.instruments("NSE") instrument_df = pd.DataFrame(instrument_dump) instrument_df.to_csv("NSE_Instruments_14052024.csv",index=False)
def instrumentLookup(instrument_df,symbol): """Looks up instrument token for a given script from instrument dump""" try: return instrument_df[instrument_df.tradingsymbol==symbol].instrument_token.values[0] except: return -1 instrumentLookup(instrument_df,"INFY")
def fetchOHLC(ticker,interval,duration): """extracts historical data and outputs in the form of dataframe""" instrument = instrumentLookup(instrument_df,ticker) data = pd.DataFrame(kite.historical_data(instrument,dt.date.today()-dt.timedelta(duration), dt.date.today(),interval)) data.set_index("date",inplace=True) return data
You need to invalidate your access token and retry, you can check this thread for the solution.