import requests
import time
import datetime
from datetime import datetime, timedelta, timezone
headers = {
'Accept': 'application/json'
}
for i in range (10):
# Get current UTC time
now_utc = datetime.now(timezone.utc)
# Calculate seconds until the next minute boundary for accurate sleep
seconds_until_next_candle = (60) - (now_utc.timestamp() % (60))
# Calculate start and end timestamps (UTC) for the API request to get the last COMPLETED 1-minute candle.
current_minute_start_dt = now_utc.replace(second=0, microsecond=0)
end_time_ts = current_minute_start_dt.timestamp() # End of the window (exclusive) will be start of current minute
start_time_ts = (current_minute_start_dt - timedelta(minutes=2)).timestamp() # Start of the window (inclusive)
print (f"Requesting from {datetime.fromtimestamp(start_time_ts, tz=timezone.utc)} to {datetime.fromtimestamp(end_time_ts, tz=timezone.utc)}")
print (f"Start Timestamp: {start_time_ts}")
print (f"End Timestamp: {end_time_ts}")
r = requests.get('https://api.india.delta.exchange/v2/history/candles', params={
'resolution': '1m', 'symbol': 'ETHUSD', 'start' : start_time_ts, 'end' : end_time_ts
}, headers = headers)
response_json = r.json()
if response_json and response_json.get('result'):
print(f"Successfully fetched {len(response_json['result'])} candlesticks.")
# Print the last available candle, which should be the last completed 1-minute candle
print(f"Last Candle: {response_json['result'][-1]}")
else:
print("No candlesticks data found for the given parameters, or response is empty.")
print(f"API Response: {response_json}")
time.sleep(seconds_until_next_candle)
time.sleep(2)
this is my code and it is getting few points mismatch mostly in close and open of candlesticks.
what are the ways to resolve it . as it will affect the calculation of supertrend and other indicators leading to wrong entry and exits.

