Struggling with API V2 for get_barset

I recreated this two years ago which is what turned me on to Alpaca in the first place. It worked fine at the time.

Then I got distracted for two years. I’m starting again recreating this, but I have no formal programming education so it’s a slog.

I managed to get through a few issues with changes between 2018 and now, but I’m stuck on this particular section of code:

returned_data = api.get_bars(

    # Processes all data into numpy arrays for use by talib
    timeList = np.array(returned_data.index)
    openList = np.array(, dtype=np.float64)
    highList = np.array(returned_data.high, dtype=np.float64)
    lowList = np.array(returned_data.low, dtype=np.float64)
    closeList = np.array(returned_data.close, dtype=np.float64)
    volumeList = np.array(returned_data.volume, dtype=np.float64)

get_bars is now get_barset - and I’ve managed to make that part work by changing to the below.

api.get_barset(ticker, barTimeframe, limit=None, start=trainStartDate, end=evalEndDate).df

However, only the timeList line beneath it executes, everything else chokes (doesn’t error, just won’t even execute a print statement beneath that line). Any help greatly appreciated.

This is a ping please help

Please keep in mind get_barset().df returns a multi-level column with (symbol, OHLCV), so you likely need to slice columns by symbol first.

Hi, i’m happy to share my function, the trick is that the dataframe is 3dimensional with the symbo, not just 2 dimensional.

def alpaca_get_15Min_bars(_symbol,_number):
if _number<1000:
    _df = api.get_barset(_symbol, '15Min', limit=_number, start=None, end=None, after=None, until=None).df
    _num_cycles, _residual = divmod(_number, 1000)
    if _residual == 0:
        _df = api.get_barset(_symbol, '15Min', limit=1000, start=None, end=None, after=None, until=None).df
        _num_cycles -=1
        _df = api.get_barset(_symbol, '15Min', limit=_residual, start=None, end=None, after=None, until=None).df    
    for i in range(1,_num_cycles+1):
        _temp = api.get_barset(_symbol, '15Min', limit=1000, start=None, end=None, after=None, until=_df.first_valid_index().isoformat()).df
        _df= pd.concat([_temp,_df,])
return _df[_symbol]