I tried grab 300 symbols last 650 hour bars at a time. Every time there are some symbols with wrong candle time:
I added the hour by 1 in the log
symbol ABMD candle time wrong: last candle time 2022-12-21 21:00:00 current time 2023-01-20 20:30:31.903852
symbol FBC candle time wrong: last candle time 2022-11-30 21:00:00 current time 2023-01-20 20:30:31.903852
symbol CLVS candle time wrong: last candle time 2022-12-20 21:00:00 current time 2023-01-20 20:30:31.903852
symbol WTBA candle time wrong: last candle time 2023-01-20 19:00:00 current time 2023-01-20 20:30:31.903852
symbol FBHS candle time wrong: last candle time 2022-12-14 21:00:00 current time 2023-01-20 20:30:37.976257
symbol ESQ candle time wrong: last candle time 2023-01-20 19:00:00 current time 2023-01-20 20:30:37.976257
symbol MNRL candle time wrong: last candle time 2022-12-28 21:00:00 current time 2023-01-20 20:30:37.976257
symbol GSIT candle time wrong: last candle time 2023-01-20 18:00:00 current time 2023-01-20 20:30:37.976257
symbol LPI candle time wrong: last candle time 2023-01-06 21:00:00 current time 2023-01-20 20:30:37.976257
symbol PEI candle time wrong: last candle time 2022-12-15 21:00:00 current time 2023-01-20 20:30:37.976257
symbol BATRA candle time wrong: last candle time 2023-01-20 19:00:00 current time 2023-01-20 20:30:37.976257
@sheep From what it appears, you are fetching hour bars at 2023-01-20 20:30:37.976257 and then expecting the latest bar for each symbol to be 2023-01-20 20:00 (ie the current hour with the bar labeled as the beginning of the hour).
This will not always be the case (as you noticed). Bars are only created if there are “valid” trades to calculate the bar. No valid trades no bar. That is probably what you are seeing. You can verify this by fetching all the trades during the timespan for a “missing” bar. What you will probably see is either 1) there are no trades or 2) if there are trades they will all have trade conditions excluding them from a bar calculation. You may want to check out this post on how bars are calculated (if you haven’t already).