Skip to content

Instantly share code, notes, and snippets.

@sovietspy2
Forked from mattvukas/bitcoinShellTicker.py
Created August 18, 2018 14:47
Show Gist options
  • Save sovietspy2/5b668739197e6fb6e21bffb638f76408 to your computer and use it in GitHub Desktop.
Save sovietspy2/5b668739197e6fb6e21bffb638f76408 to your computer and use it in GitHub Desktop.
A simple Python script that queries the Bitstamp API every 5 seconds and prints the last USD/Bitcoin price to the shell. Requires the Python Requests library.
import requests, json
from time import sleep
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"
while True:
print "Bitstamp last price: $" + str(getBitcoinPrice()) + "/BTC"
sleep(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment