← Go Back
You must first install the Requests library using
How to Fetch Bitcoin Price in Real Time
import requests
url = "https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=bitcoin"
r = requests.get(url)
btc = r.json()[0]["current_price"]
# btc contains US dollar equivalent of one bitcoin.
print(btc)
You must first install the Requests library using
pip install requests
.🐍 You might also find interesting: