Where is 'candles' defined in the function that gives us historical data?

def fetchOHLC(ticker,interval,duration):
    """extracts historical data and outputs in the form of dataframe"""
    instrument = ticker
    data = {"symbol":instrument,"resolution":interval,"date_format":"1","range_from":dt.date.today()-dt.timedelta(duration),"range_to":dt.date.today(),"cont_flag":"1"}
    sdata=fyers.history(data)
    sdata=pd.DataFrame(sdata['candles'])
    sdata.columns=['date','open','high','low','close','volume']
    sdata['date']=pd.to_datetime(sdata['date'], unit='s')
    sdata.date=(sdata.date.dt.tz_localize('UTC').dt.tz_convert('Asia/Kolkata'))
    sdata['date'] = sdata['date'].dt.tz_localize(None)
    sdata=sdata.set_index('date')
    return sdata

ticker='NSE:NIFTYBANK-INDEX'
data=fetchOHLC(ticker,'1',60)
print(data)

Can someone explain me how the sdata['candles'] work? Because sometimes I get error that nothing named 'candles' is defined. But sometimes it works - after all - that's how it is in the documentation.

I feel like I'm missing something here. This is the error I get sometimes.

2 replies