It’s more or less in the title: I’m looking only to get the daily open prices of the constituent stocks in the S&P 500. I can subscribe to daily bars via the below, but I’m not quite sure how to save the results to a variable and then terminate the loop.
I should mention that I’m running this in a Jupyter notebook.
from alpaca_trade_api.stream import Stream
from alpaca_trade_api.common import URL
import nest_asyncio
nest_asyncio.apply()
async def bar_callback(t):
print('bar', t)
stream = Stream(alpaca_key,
alpaca_secret,
raw_data=True,
data_feed='iex')
stream.subscribe_daily_bars(bar_callback, 'AAPL')
stream.run()