Python - API: Historical data is not giving latest candle (OHLC) data

Problem Definition:
Not getting the complete last candle (OHLC) data of 5 mins at the end of the 5 minute interval, in live market. The issue is I get say 10:15 data only at the end of 10:20 with the following code, that I have been running this as part of the overall code:

Code for Reference
While True:
if ( == 30) and ( % 5 == 0):
from_date = datetime.strftime( - timedelta(100), '%Y-%m-%d')
to_date ='%Y-%m-%d')
records = kite.historical_data(instrument_token=256265, from_date=from_date, to_date=to_date, interval=interval1)
df = pd.DataFrame(records)

I have tried the following both with this line added and without df.drop(df.tail(1).index, inplace=True), but I do not get the correct OHLC for 5 min data, even though I have given 30 seconds more, just in case.

Where am I going wrong?
  • sujith
    The historical data API is provided for backtesting purposes only. For live market strategies, you can generate candles at your end using the Websocket API data.
    You can get started from here.
Sign In or Register to comment.