Advertisement
DamonShekari

BTC Price Index - V1

May 23rd, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. #Updates the price of BTC in any time interval you request
  2. #Can overflow
  3. #V1
  4. #Thank you MarshallCat94 For Your Help, You Helped Me Learn A Lot!
  5. import requests
  6. import time
  7. while True:
  8.     time.sleep(1)
  9.     response = requests.get("http://api.coindesk.com/v1/bpi/currentprice.json")
  10.     bitcoin_data = response.json()
  11.  
  12.     bitcoin_price = bitcoin_data['bpi']['USD']['rate_float']
  13.     updated_epoch = bitcoin_data['time']['updated']
  14.     updated_epoch = time.mktime(time.strptime(updated_epoch, "%b %d, %Y %H:%M:%S UTC"))
  15.     updated_time = time.strftime("%H:%M:%S %d/%m/%Y", time.gmtime(updated_epoch))
  16.    
  17.     print("Bitcoin Price: {price:.2f} $\r\nThis information was updated on {time} UTC".format(price=bitcoin_price, time=updated_time))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement