real time price of crypto with datetime on a loop

PHOTO EMBED

Thu Mar 24 2022 13:37:13 GMT+0000 (Coordinated Universal Time)

Saved by @Taylor #python #datetime #cryptoprice

import requests
from datetime import datetime

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["USD"])
content_copyCOPY