from alpaca.data.timeframe import TimeFrame, TimeFrameUnit
from alpaca.data.requests import StockBarsRequest
from alpaca.data.historical import StockHistoricalDataClient
current_datetime = datetime.now()
yesterday = current_datetime - timedelta(days=1)
#symbols = [“SPY”,“XLC”, “XLY”, “XLP”, “XLE”,“XLF”, “XLV”, “XLI”, “XLB”, “XLRE”, “XLK”, “XLU”]
symbols = [“SPY”]
client = StockHistoricalDataClient(API_KEY, SECRET_KEY)
request_params = StockBarsRequest(
symbol_or_symbols=symbols,
timeframe=TimeFrame(5,TimeFrameUnit.Minute),
feed=“sip”,
adjustment=‘split’,
start=yesterday
)
bars = client.get_stock_bars(request_params)
bars_df = bars.df
bars_df
1 Like