Importing and using Yfinance 0.2.3

Question:

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:

code snippet

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)
poetry upgrade packageName

OR

pip install --upgrade packageName

Unless you need the extra RAM and CPU, then you should just disable poetry.

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.

I should make a poll lol.

That is a good idea. I would like to see the results.

When I run this:


import yfinance as yf

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))


I get this:


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

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

Just a tip, try to format your code using three backticks so it’s easier to read:

import yfinance as yf

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)
2 Likes

Use stock.fast_info instead of stock.info?

1 Like