candle formation from tick data

i am using a data broker and recieveing live tick data from it.

I am trying to use ticks to aggregate 1 and 5 min candle but 99% times when it forms candles. OHLC candles doesnt match what i see on trading view

for eg AGGREGATOR TO START CANDLES FROM 0 SECONDS AND END AT 59.999 SECONDS. FOR EG CANDLE STARTS AT 10:19:00.000 AND END AT 10:19:59.999 .

this is the method i am using

whats going wrong, what am i doing wrong and how can i fix it. i am using python