I'm trying to use the alpaca API to retrieve some stock prices and I get this error:
for bar in bars[symbol]:
TypeError: list indices must be integers or slices, not Bar
My code:
api = tradeapi.REST(config.API_KEY, config.SECRET_KEY,
base_url=config.BASE_URL)
chunk_size = 200
for i in range(0, len(symbols), chunk_size):
symbol_chunk = symbols[i:i+chunk_size]
bars = api.get_bars(symbol_chunk, TimeFrame.Day,
"2022-01-01", "2022-08-08")
for symbol in bars:
print(f"processing symbol {symbol}")
for bar in bars[symbol]:
stock_id = stock_dict[symbol]
cursor.execute("""
INSERT INTO stock Price (stock id, datetime, open, high, low, close, volume)
VALUES (?,?,?,?,?,?,?)
""", (stock_id, bar.t.date(), bar.o, bar.h, bar.l, bar.c, bar.v))