Historical Data changing on 30th Second of every minute for past 1 candle's data

amitjet
Hello Zerodha Support team,

I am seeing a strange issue where historical data api is giving me changing data at 30th second of the minute.

e.g. below is a code which is fetching 2 mins of data every second (for repro purpose) for NIFTY25JUL24800PE.
Observation is at time = 13:06:29, 13:05 candle shows close of 142 with volume 1131300, but very next second 13:06:30, it changes to 141.65 & 1149150.

this happens every single minute when clock moves past 30 second mark. Post this the candle never changes.

Why is this important to me: when i do EOD backtest vs my realtime trades using same api on same day, trades are different as the close values and volume (which matter most to my strategy) are not same. This is not helping us to automate our trades.

Please guide on what is cause of this behaviour and how do i get consistent results for candles ?

PS: I have also tried to change end-date of historical fetch to 59th second, but didnt help.

here is sample code:

import pandas as pd
import datetime
import time, os
from kiteconnect import KiteConnect
from authentication.authenticator import authenticator_zerodha

kite = authenticator_zerodha().authenticate()

token = '14282754' # Hard Coded token for NIFTY25JUL24800PE

while True:
fetch_timestamp = datetime.datetime.now() # Capture fetch timestamp
start_date = fetch_timestamp - datetime.timedelta(minutes=2)
end_date = fetch_timestamp


start_date = start_date.replace(second=0, microsecond=0)
end_date = end_date.replace(second=0, microsecond=0)

print(f"Fetch Timestamp: {fetch_timestamp}")
print(f"start_date={start_date}, end_date={end_date}")

try:
df = pd.DataFrame(kite.historical_data(token, start_date, end_date, "minute"))

# Add fetch timestamp to the DataFrame for comparison
df['fetch_timestamp'] = fetch_timestamp

# Save to CSV for analysis
df.to_csv('historical_data_log.csv', mode='a', header=False if os.path.exists('historical_data_log.csv') else True, index=False)

print(df)

except Exception as e:
print(f"Error fetching data: {e}")

time.sleep(1)


here is output (Truncated)


Fetch Timestamp: 2025-07-28 13:06:28.576068
start_date=2025-07-28 13:04:00, end_date=2025-07-28 13:05:59
date open high low close volume fetch_timestamp
0 2025-07-28 13:04:00+05:30 151.0 153.7 146.40 153.2 1272825 2025-07-28 13:06:28.576068
1 2025-07-28 13:05:00+05:30 152.9 152.9 141.85 142.0 1131300 2025-07-28 13:06:28.576068

Fetch Timestamp: 2025-07-28 13:06:29.716982
start_date=2025-07-28 13:04:00, end_date=2025-07-28 13:05:59
date open high low close volume fetch_timestamp
0 2025-07-28 13:04:00+05:30 151.0 153.7 146.40 153.2 1272825 2025-07-28 13:06:29.716982
1 2025-07-28 13:05:00+05:30 152.9 152.9 141.85 142.0 1131300 2025-07-28 13:06:29.716982

Fetch Timestamp: 2025-07-28 13:06:30.871542
start_date=2025-07-28 13:04:00, end_date=2025-07-28 13:05:59
date open high low close volume fetch_timestamp
0 2025-07-28 13:04:00+05:30 151.0 153.7 146.40 153.20 1272825 2025-07-28 13:06:30.871542
1 2025-07-28 13:05:00+05:30 152.9 152.9 141.65 141.65 1149150 2025-07-28 13:06:30.871542

Fetch Timestamp: 2025-07-28 13:06:31.985011
start_date=2025-07-28 13:04:00, end_date=2025-07-28 13:05:59
date open high low close volume fetch_timestamp
0 2025-07-28 13:04:00+05:30 151.0 153.7 146.40 153.20 1272825 2025-07-28 13:06:31.985011
1 2025-07-28 13:05:00+05:30 152.9 152.9 141.65 141.65 1149150 2025-07-28 13:06:31.985011

Fetch Timestamp: 2025-07-28 13:06:33.098897
start_date=2025-07-28 13:04:00, end_date=2025-07-28 13:05:59
date open high low close volume fetch_timestamp
0 2025-07-28 13:04:00+05:30 151.0 153.7 146.40 153.20 1272825 2025-07-28 13:06:33.098897
1 2025-07-28 13:05:00+05:30 152.9 152.9 141.65 141.65 1149150 2025-07-28 13:06:33.098897
  • salim_chisty
    You may refer to the similar discussion here.
  • amitjet
    This happens on 30th second for every single minute candle.

    I have also observed the kite chartIQ Charts. you leave any chart on. and switch to the data table. take a snap on 29th second , force refresh chart, take one more snap on 31st second of data table, you will also see it.

    The last candle's volume and close changes. High/low could also change but rarely (depending on close).
  • amitjet
    for those who are wondering, look at above sample code and output.

    for candle of time 13:05:00, at Timestamp 13:06:29.716982 close is 142.0 & 1 second later, at 13:06:30.871542 it is 141.65.

    I am not looking at current ongoing candle. i am looking at the one which is already completed.
  • amitjet
    anyone from Zerodha Support who can update? I dont want to look at websocket to construct candles. I have seen lot of differences in OHLC from Websocket vs Historical.
  • salim_chisty
    We are looking into this and will share an update soon.
Sign In or Register to comment.