ranaroussi / yfinance

Download market data from Yahoo! Finance's API
https://aroussi.com/post/python-yahoo-finance
Apache License 2.0
14.64k stars 2.43k forks source link

Ticker.history() doesn't include pre-market data if the stock market hasn't opened yet #581

Open psbj opened 3 years ago

psbj commented 3 years ago

If you use Ticker.history() before the market officially opens but while pre-market trading is happening, with the following code:

>>> yfinance.Ticker("amzn").history(prepost=True, interval="1m", period="1d")
                              Open     High      Low    Close  Volume  Dividends  Stock Splits
Datetime                                                                                      
2021-02-02 04:00:00-05:00  3369.61  3369.61  3362.87  3362.87       0          0             0
2021-02-02 04:01:00-05:00  3369.79  3372.05  3369.79  3372.05       0          0             0
2021-02-02 04:02:00-05:00  3370.57  3373.70  3370.57  3373.70       0          0             0
2021-02-02 04:03:00-05:00  3373.70  3376.95  3373.70  3376.95       0          0             0
2021-02-02 04:04:00-05:00  3375.99  3378.33  3375.00  3375.00       0          0             0
...                            ...      ...      ...      ...     ...        ...           ...
2021-02-02 19:55:00-05:00  3398.00  3398.00  3396.00  3396.00       0          0             0
2021-02-02 19:56:00-05:00  3397.00  3397.00  3393.00  3393.00       0          0             0
2021-02-02 19:57:00-05:00  3394.06  3395.00  3394.00  3394.00       0          0             0
2021-02-02 19:58:00-05:00  3394.00  3394.89  3393.67  3394.00       0          0             0
2021-02-02 19:59:00-05:00  3394.00  3394.00  3388.88  3389.10       0          0             0

The data returned does not include the pre-market data for the current day. Even if you set the period to "1h" it only includes the pervious day's post-market data as the latest.

I'm not sure if this is intended or not, but if it is, how do you get the pre-market data for the day with the Ticker.history() function before the market opens?

silvavn commented 3 years ago

Yahoo does not offer 1m anymore, only daily or higher granularity, closing

ssvetli commented 1 year ago

I see that post-market move is available in the yahoo finance app, but can this data be pulled in the API? Maybe .history() should return an additional 'PostMktClose' column?