Python : Getting current Bitcoin price from Yahoo finance with yfinance module

420 views Asked by At

I'm trying to read and display the current Bitcoin market price in Python, using the yfinance module/library.
It works fine for currency pairs or market indices but BTC-USD doesn't seem to have any returned data which contains the current price.

For other indices there's a bid/ask price and I just take the average but I guess BTC has no spread...but I can't figure out which field has the 'current market price'
Suggestions please.

Thanks,

This code works but it's showing the opening price, not the current market price:

BTC = yF.Ticker("BTC-GBP")
print("Bitcoin Current : ", round(BTC.info['open'],0))
print("        Day     : ", round(BTC.info['dayLow'], 0), "-", round(BTC.info['dayHigh'], 0))
print("        52 Week : ", round(BTC.info['fiftyTwoWeekLow'], 0), "-", round(BTC.info['fiftyTwoWeekHigh'], 0))
2

There are 2 answers

1
S.D. On

Did you try/check regularMarketPrice?

print("Bitcoin Current : ", round(BTC.info['regularMarketPrice'], 0))
0
Miles On

Looks like Yahoo change their API regularly. I found a solution. I have to use fast_info instead of info and then there's a key called 'lastPrice':

CurrentPrice = Commod.fast_info['lastPrice']