KeyError: ['high'] backtrader + alpaca_trader_api exception when running cerebro

HI Folks,

I recently opened an account with Alpaca, so that I can live trade my backtrader strategies,
I am using Python 3.8 and both my backtrader as well as alpaca_backtrader_api packages are up to date
however , when I am Trying to run even the most basic ‘README’ example from the alpaca-backtrader-api githup page (also available PyPl) , I am getting this exception:

the script is as follows:

import alpaca_backtrader_api
import backtrader as bt
from datetime import datetime
from local_settings import alpaca_paper

ALPACA_API_KEY = alpaca_paper['api_key']
ALPACA_SECRET_KEY = alpaca_paper['api_secret']

class SmaCross(bt.SignalStrategy):
  def __init__(self):
    sma1, sma2 = bt.ind.SMA(period=10), bt.ind.SMA(period=30)
    crossover = bt.ind.CrossOver(sma1, sma2)
    self.signal_add(bt.SIGNAL_LONG, crossover)

cerebro = bt.Cerebro()

store = alpaca_backtrader_api.AlpacaStore(

  broker = store.getbroker()  # or just alpaca_backtrader_api.AlpacaBroker()

DataFactory = store.getdata  # or use alpaca_backtrader_api.AlpacaData
data0 = DataFactory(dataname='AAPL', historical=True, fromdate=datetime(
    2015, 1, 1), timeframe=bt.TimeFrame.Days)

print('Starting Portfolio Value: %.2f' %
print('Final Portfolio Value: %.2f' %
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/", line 932, in _bootstrap_inner
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/alpaca_backtrader_api/", line 414, in _t_candles
    cdl = cdl.loc[
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/", line 5162, in dropna
    raise KeyError(list(np.compress(check, subset)))
KeyError: ['high']

could it be that Alpaca is returning the wrong data format? could it be that perhaps there is missing date?

FYI I did not fund my account yet. if this is funding related ,what is the minimum amount of money that I have deposit to be able to have this capability?


Same here with python 3.9

This annoying error means that Pandas can not find your column name in your dataframe. Before doing anything with the data frame, use print(df.columns) to see column exist or not.


I was getting a similar kind of error in one of my codes. Turns out, that particular index was missing from my data frame as I had dropped the empty dataframe 2 rows. If this is the case, you can do df.reset_index(inplace=True) and the error should be resolved.