I noticed something strange with the ccxt fetchohlc() in that sometimes it returns candles up to the last closed candle and sometimes it returns the current live (not yet closed candle).
I used the follow code to get the last 20 candles which uses the same method that the ccxt backtrader uses to get live candle data.
df = pd.DataFrame(gdax.fetchOhlcv('BTC/USD', timeframe='1m', limit=20))
df['Date'] = pd.to_datetime(df[0], unit='ms')
df.set_index('Date', inplace=True)
df.drop(0, axis=1, inplace=True)
df.columns = ['open', 'high','low','close','volume']
df['highlow'] = df['high'] - df['low']; df
This outputs a dataframe:
Date open high low close volume highlow
2018-08-21 09:15:00 6452.99 6453.00 6452.99 6452.99 0.382287 0.01
2018-08-21 09:16:00 6453.00 6453.00 6452.99 6453.00 0.231581 0.01
2018-08-21 09:17:00 6453.00 6453.00 6453.00 6453.00 0.033058 0.00
2018-08-21 09:18:00 6453.00 6453.00 6452.99 6453.00 0.244911 0.01
2018-08-21 09:19:00 6453.00 6453.00 6452.99 6452.99 2.142046 0.01
2018-08-21 09:20:00 6453.00 6453.00 6438.91 6441.62 10.994071 14.09
2018-08-21 09:21:00 6441.62 6445.98 6441.62 6445.98 1.862376 4.36
2018-08-21 09:22:00 6445.97 6445.97 6431.64 6437.10 12.625005 14.33
2018-08-21 09:23:00 6437.10 6445.67 6437.10 6443.40 1.902326 8.57
2018-08-21 09:24:00 6443.39 6443.40 6443.39 6443.39 0.531487 0.01
2018-08-21 09:25:00 6443.40 6443.40 6435.62 6435.62 1.435376 7.78
2018-08-21 09:26:00 6436.35 6437.32 6433.71 6433.71 1.582333 3.61
2018-08-21 09:27:00 6435.23 6435.23 6435.22 6435.22 0.054494 0.01
2018-08-21 09:28:00 6435.22 6436.00 6435.22 6436.00 0.099945 0.78
2018-08-21 09:29:00 6435.99 6435.99 6433.71 6433.71 1.374433 2.28
2018-08-21 09:30:00 6433.71 6433.71 6431.00 6432.77 1.015340 2.71
2018-08-21 09:31:00 6433.62 6433.62 6432.76 6433.00 0.172707 0.86
2018-08-21 09:32:00 6432.99 6433.00 6432.99 6432.99 0.555686 0.01
2018-08-21 09:33:00 6432.99 6432.99 6427.75 6431.62 3.599003 5.24
2018-08-21 09:34:00 6431.63 6431.63 6431.63 6431.63 0.059508 0.00
When I ran this 4 times consecutively within less than 1 second I got the following results (only last 3 lines shown)
2018-08-21 09:32:00 6432.99 6433.00 6432.99 6432.99 0.555686 0.01
2018-08-21 09:33:00 6432.99 6432.99 6427.75 6431.62 3.599003 5.24
2018-08-21 09:34:00 6431.63 6431.63 6431.63 6431.63 0.059508 0.00
2018-08-21 09:31:00 6433.62 6433.62 6432.76 6433.00 0.172707 0.86
2018-08-21 09:32:00 6432.99 6433.00 6432.99 6432.99 0.555686 0.01
2018-08-21 09:33:00 6432.99 6432.99 6427.75 6431.62 3.599003 5.24
2018-08-21 09:32:00 6432.99 6433.00 6432.99 6432.99 0.555686 0.01
2018-08-21 09:33:00 6432.99 6432.99 6427.75 6431.62 3.599003 5.24
2018-08-21 09:34:00 6431.63 6431.63 6431.63 6431.63 0.062508 0.00
2018-08-21 09:32:00 6432.99 6433.00 6432.99 6432.99 0.555686 0.01
2018-08-21 09:33:00 6432.99 6432.99 6427.75 6431.62 3.599003 5.24
2018-08-21 09:34:00 6431.63 6431.63 6431.63 6431.63 0.059508 0.00
As you can see, sometimes it returns the 9:34 candle (which at the time had not closed) and sometimes it returns the 9:33 candle (which has closed) as the most recent.
When I ran this a few minutes later I get
2018-08-21 09:32:00 6432.99 6433.00 6432.99 6432.99 0.555686 0.01
2018-08-21 09:33:00 6432.99 6432.99 6427.75 6431.62 3.599003 5.24
2018-08-21 09:34:00 6431.63 6433.00 6431.62 6433.00 4.551569 1.38
2018-08-21 09:35:00 6433.38 6434.68 6433.38 6434.68 12.601649 1.30
2018-08-21 09:36:00 6436.36 6444.00 6436.36 6443.99 3.252023 7.64
As you can see the 9:34 candle closed at 6433.00 not at 6431.63.
This means that when you are getting 1m live data from backtrader you may actually be getting a live candle instead of the actual data because backtrader/ccxt will record the time of the latest candle and only give candles with timestamps later than the previous.
In fact this actually looks like what I'm getting
***** DATA NOTIF: LIVE
***** NEXT: 2018-08-21 09:04:00 btc_usd_min 6459.99 6460.0 6459.99 6460.0 0.02234232 Minute 3
***** NEXT: 2018-08-21 09:05:00 btc_usd_min 6455.06 6455.06 6455.06 6455.06 0.05325761 Minute 4
***** NEXT: 2018-08-21 09:06:00 btc_usd_min 6455.06 6460.92 6455.06 6460.92 0.75941057 Minute 5
***** NEXT: 2018-08-21 09:07:00 btc_usd_min 6460.95 6460.95 6460.95 6460.95 0.00362068 Minute 6
***** NEXT: 2018-08-21 09:08:00 btc_usd_min 6457.84 6457.84 6457.84 6457.84 0.03702458 Minute 7
***** NEXT: 2018-08-21 09:09:00 btc_usd_min 6452.82 6452.82 6452.82 6452.82 1.21548925 Minute 8
***** NEXT: 2018-08-21 09:10:00 btc_usd_min 6452.81 6452.81 6452.81 6452.81 0.0226 Minute 9
Minute 5 appears to be a full candle whereas Minute 7 (for example) appears to be a partially completed live candle