I cannot get quotes from YFinance since the new 0.2.3 version came out. Something to do with a new key I think. The YFinance site addresses this but nothing there seems to work for me. I get something like this — KeyError: ‘regularMarketPreviousClose’ Repl link:
To use an older version of a package, specify it in the install. You can use poetry add or pip install. In shell, type (or use Ctrl Shift V to paste):
poetry add whateverPackage==0.2.2
I personally am not familiar with the YFinance package, but this is how to install a package for Python Repls. Replace whateverPackage with your package name (YFinance I assume).
Other useful package commands:
Remove package (it's possible you'll need to do this)
poetry remove packageName
OR
pip remove packageName
Upgrade package (you may want to do this once the bug is fixed)
Interesting. I hear conflicting reports about whether or not to use pip. I think I should just not give an opinion since I clearly don’t know enough about pip VS poetry.
WARNING: No decryption keys could be extracted from JS file. Falling back to backup decrypt methods.
Price data removed from info (key='previousClose'). Use Ticker.fast_info or history() instead
Exchange data removed from info (key='currency'). Use Ticker.fast_info or Ticker.get_history_metadata() instead
Vanguard Total Stock Market ETF previously closed at None None
Price data removed from info (key='previousClose'). Use Ticker.fast_info or history() instead
Traceback (most recent call last):
File "main.py", line 10, in <module>
vti = float(info['previousClose'])
TypeError: float() argument must be a string or a real number, not 'NoneType'
Sorry for taking up your time-- thanking you in advance for any advise you can give
Roger
Hw can I get Yfinance to import stock quotes now? Is there a new key
that is used in Python? Can you find an example of where someone is
importing quotes from Yfinance to a Python program?
Just for the record I have found the answer to my problem and here
is the code that I have written using it:
import yfinance as yf
df = yf.download('VTI')
print(df['Close'].iloc[-1])
ticker = yf.Ticker('VTI')
VTI = round(df['Close'].iloc[-1])
VTIsh = 68
VTIval = VTI * VTIsh
stock = yf.Ticker('VTI')
info = stock.info
print(info['shortName'], "previously closed at", info['previousClose'],
info['currency'])
VTI = float(info['previousClose'])
VTIsh = 68
VTIval = VTI * VTIsh
print(("value of vti stock bucket ="), (VTIval))
The new code that is needed seems to be the:
print(df['Close'].iloc[-1])
VTI = round(df['Close'].iloc[-1])
I am sincerely grateful to anyone who tried to help me.o