It looks like you're new here. If you want to get involved, click one of these buttons!
2017-10-25 09:36:00,349 - root - DEBUG - [{'last_price': 578.6, 'volume': 1089551, 'sell_quantity': 325896, 'last_quantity': 26, 'change': 1.0478519035976248, 'average_price': 581.93, 'ohlc': {'high': 587.7, 'close': 572.6, 'open': 579.8, 'low': 574.55}, 'depth': {'sell': [], 'buy': []}, 'mode': 'quote', 'tradeable': True, 'buy_quantity': 184671, 'instrument_token': 737793}]
2017-10-25 09:36:01,429 - root - DEBUG - [{'last_price': 578.65, 'volume': 1089677, 'sell_quantity': 329105, 'last_quantity': 1, 'change': 1.0565840027942637, 'average_price': 581.93, 'ohlc': {'high': 587.7, 'close': 572.6, 'open': 579.8, 'low': 574.55}, 'depth': {'sell': [], 'buy': []}, 'mode': 'quote', 'tradeable': True, 'buy_quantity': 185751, 'instrument_token': 737793}]
Live calls to Historical API (3m TF) - Symbol:PETRONET, Close:266.7,vol-1:36277.0,ts:2017-10-24 13:48:00
End of day calls to Historical API (3m TF) - Symbol:PETRONET, Close:267.6,vol-1:3106.0,ts:2017-10-24 13:48:00
I think you have swapped the historical data fetched during market and end of the day candles.
3minute candles are generated using three 1minute candles. If the last candle is not there then the last 3minute candle is generated based on two candles.
During market hours, the system will listen to each tick and generates a candle at the end of the minute and writes it to the database. This keeps happening simultaneously for all the instruments that are being traded for the day. Hence there can be a random delay in the database write.
In this case, the solution would be adding some 10 to 15 seconds delay to fetch data.
If your algorithm can't afford delay then I would suggest generating candles at your end.