Yes, Zerodha’s WebSocket provides the tick-tick data, we will have to aggregate the ticks and convert that into candle of different timeframes whatever you want.
To do that can refer below code:
from datetime import datetime
CANDLE_STATE = {}
def build_candle(symbol, tick, timeframe=1):
ts = tick["timestamp"]
price = tick["price"]
# Adject timeframe
minute = (ts.minute // timeframe) * timeframe
bucket = ts.replace(minute=minute, second=0, microsecond=0)
if symbol not in CANDLE_STATE:
CANDLE_STATE[symbol] = {}
candles = CANDLE_STATE[symbol]
# Create new candle
if bucket not in candles:
candles[bucket] = {
"open": price,
"high": price,
"low": price,
"close": price
}
else:
c = candles[bucket]
c["high"] = max(c["high"], price)
c["low"] = min(c["low"], price)
c["close"] = price
return candles
# Replace the tick's static data with the live feed
ticks = [
{"timestamp": datetime(2026, 4, 24, 9, 15, 5), "price": 100},
{"timestamp": datetime(2026, 4, 24, 9, 15, 20), "price": 102},
{"timestamp": datetime(2026, 4, 24, 9, 15, 40), "price": 99},
{"timestamp": datetime(2026, 4, 24, 9, 16, 10), "price": 105},
]
symbol = "TEST"
for t in ticks:
candles = build_candle(symbol, t, timeframe=1)
# Print result
for time, candle in candles.items():
print(time, candle)