I printed the datetime of the current bar data been processed in backtrader next(). The live bar data is always 2 minutes, not 1m, late. I used the following code to add data
I understand, that if current timestamp is 10:51, the last finished bar timestamp is 10:50, so i am okay with it being 1m late. but not sure why it’s always consistantly 2m late.
@yann I’m not familiar with backtrader but the issue may be in how bars are labeled? The industry convention is to label bars by their start time. As an example, the bar labeled 9:32 will have trades between 9:32 → 9:33. Alpaca waits 2-3 seconds after the end of the bar to publish it. So, at 9:33:03 (or after) the 9:32 bar would be available. Could that be the issue?
thanks for the reply. I am afraid that’s not the issue. The most recent bar returned is 2m late than the other real time app. I manually check the open close high low price of the latest bar returned by alpaca, it’s 2 bars delayed.
@yann That must be something with how backtrader is fetching data. As mentioned above, Alpaca generates the latest bar 2-3 seconds after each minute and the most ‘delayed’ it would ever be is 1 minute past that (ie the bar doesn’t change until 2-3 seconds after the next minute). This probably isn’t the issue, but note that bars are only generated if there are trades. There can often be ‘missing’ bars simply because there were no trades during that time.