@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.