# Function: Display the Bitcoin price in the menu item – to assist the user when setting price levels
def updateMenuPrice(self):
# Get the latest Bitcoin info (as a Tick object) from getBitMexPrice(). Name it tickObj.
tickObj = self.getBitMexPrice()
# Update the currentPrice property with the Bitcoin price in tickObj.
import requests from datetime import datetime
# https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD, JPY, EUR
URL = "https://min-api.cryptocompare.com/data/price?fsym={}&tsyms={}"
def get_price(coin, currency):
try:
response = requests.get (URL.format(coin, currency)).json() return response
except:
return False
while True:
date_time = datetime.now()
date_time=date_time.strftime("%d/%m/%Y %H:%M:%S")
currentPrice = get_price("BTC", "USD")
if currentPrice:
print (date_time, "$", currentPrice)
Comments
Leave a comment