yfinance: Unable to get open price of a stock on the current day itself, getting yesterday instead

I have the latest version of yfinance installed.

I tried the following query, ohlcv = yf.Ticker(‘AAPL’).history(period=‘1d’), to get the open price of a stock 1 second after the market open at 9:30:01.

I even did

ohlcv = yf.Ticker('AAPL').history(period='1d')
while ohlcv.index[0].date() != datetime.datetime.now(pytz.timezone('US/Eastern'))).date():
    ohlcv = yf.Ticker('AAPL').history(period='1d')
    time.sleep(0.5)

because i wanted to make sure that the date was correct.

I tried this with 6 tickers today, GOOGL, NOW, BABA, BX, APD and SEDG.

Using the code above, and asserting that I get todays date (12 July 2023), I got the following open prices which are actually 11 July 2023. Even though i used datetime.datetime.now(pytz.timezone(‘US/Eastern’))).date() to assert the date.

GOOGL 116.29 supposed to be 118.80 NOW 567.21 supposed to be 570.86 BABA 91.02 supposed to be 94.11 BX 93.80 supposed to be 99.60 APD 291.28 supposed to be 291.70 SEDG 266.00 supposed to be 272.10

I have no idea why I get yesterdays open even though I am forcing the program to check the date as today. Any idea why it’s behaving like this and what I can do to solve this? I am trying to get the open price of a stock on that day itself.

It seems that the date is today’s date but the price is yestedays open. I tried it again like an hour later and it showed the correct price.

I have tried this everyday for a week already and it’s the same during the market open.

I have tried it on BP.L and RELIANCE.NS during their respective market opens but they seem to work fine. This problem only seems to happen on the US market opens.

About this issue

Most upvoted comments