Using websocket to save daily open prices to variable, then exit

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 import Stream
from alpaca_trade_api.common import URL

import nest_asyncio

async def bar_callback(t):
    print('bar', t)
stream = Stream(alpaca_key,

stream.subscribe_daily_bars(bar_callback, 'AAPL')

Why do you need streaming for such a simple task? Just request a snapshot for a single symbol (or for several symbols at once) and check/use current/previous daily bars available instantly.

That’s much more sensible, yes. I was under the mistaken impression that real-time data was accessible only through the websocket. Thank you!