Bitcoin Price Query
Query the Bitcoin Price
Here is a very simple and quick function to get the spot bitcoin price in USD ($) in Python. It querys the API of an exchange called Bitstamp:
import requests
import json
def getBitcoinPrice():
URL = "https://www.bitstamp.net/api/ticker/"
try:
r = requests.get(URL)
priceFloat = float(json.loads(r.text)["last"])
return priceFloat
except requests.ConnectionError:
print("Error querying Bitstamp API")
How to Use It
Once you have it coded up, simply run getBitcoinPrice()
and voila!