Best way to source open price right after open

Hi!
How can I source the open price for a given stock right after it becomes available at the same day? I am using Python, but please gimme some general tips if you can.

Thanks in advance!

This works for me:

# Whichever stock you want...
_symbol = 'AAPL'

# Get the bars for the specified ticker, using the Day timeframe and limit to only 1 (today).
_bars = api.get_bars(_symbol, TimeFrame.Day, limit=1)

# Get the 'Open' value from the first item in the array.
_openPrice = _bars[0].o

print(f'Open price for {_symbol}: ${_openPrice}')

Bear in mind, if you run this when the market is closed, it will probably return the open price for the previous day. I wrote and tested this just now (during market hours) so cannot confirm for out of hours.

Actually, there’s a much simpler method. Use the get_snapshot() function and then extract the open price from the daily bar:

_day_open = api.get_snapshot('AAPL').daily_bar.o

print(f'Day open: ${_day_open}')
1 Like