pbrissaud / suivi-bourse

Monitor the stock shares you own with Python and Prometheus !
https://pbrissaud.github.io/suivi-bourse/
MIT License
60 stars 26 forks source link

KeyError: 'currentPrice' for crypto currencies #92

Closed vutsalsinghal closed 1 year ago

vutsalsinghal commented 1 year ago

Describe the bug Hi There

I'm getting python KeyError: 'currentPrice' in the logs. I'm using the latest arm64 image (this). I see this error only for crypto currencies (tried a few like BTC-USD, BTC-EUR, ETH-USD). Upon further digging, looks like the issue is in the yfinance library.

import yfinance as yf

ticker_info = yf.Ticker("BTC-USD").info
last_quote = ticker_info['currentPrice']
print(last_quote)

Traceback (most recent call last):
  File "main.py", line 13, in <module>
    last_quote = ticker_info['currentPrice']
KeyError: 'currentPrice'

There is no key called "currentPrice" for cryptos. Will have to handle that

Installation mode: (choose one)

Additional comments I had worked on something similar (python finance/portfolio dashboard) and I cant recall but there were several inconsistency issues with the data ingestion from yfinance but things might've changed for better since I last used. I had decided to use yahoo_fin instead. Worked fine for cypto/non-crypto.

I'm in no way/shape/form have any association with yahoo_fin. Cheers! 😄

pbrissaud commented 1 year ago

Hi, Thanks for submitting this issue. I will try to find an other way to get the current price and I will open a PR associated to this .

pbrissaud commented 1 year ago

@vutsalsinghal PR is merged and I created a 3.3.0 release with the fixes