Answer to Question #240228 in Python for saksham

Question #240228

# 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.

       . . .



1
Expert's answer
2021-09-22T00:00:39-0400
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)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS