ranaroussi / yfinance

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

Patch keyError in #2027 #2029

Closed aleksfasting closed 1 month ago

aleksfasting commented 3 months ago

Solves ´KeyError´ occurrence in #2027.

Adds Try/Except statement to find keyerror and return to old code if the keyerror is triggered.

ValueRaider commented 3 months ago

That's not the solution. Look at the metadata.

aleksfasting commented 3 months ago

The same information as in the original PR, #2026, can be fetched from the 'currentTradingPeriod' key in the metadata. The metadata from the code that triggered the KeyError,

dat = yf.Ticker('0001.HK')
dat.history(start=1719763200, end=1720540800, interval='30m', prepost=True)

will have the same format as most other stocks for this key.

I don't know if Yahoo Finance may give differently formated metadata for the ´'currentTradingPeriod'´ key.

ValueRaider commented 3 months ago

Just add 2 unit tests: one with prepost=False, other with True. Then rebase to dev branch #1084