import requests import time # import datetime baseURL = 'https://api.coingecko.com/api/v3/' coin = 'bitcoin' vs_currency = 'eur' days = '30' precision = '3' ohlc_endpoint = baseURL + 'coins/' + coin + '/ohlc?vs_currency=' + vs_currency + '&days=' + days + '&precision=' + precision APY_KEY = "CG-K5RS5VXsdFDip2UvY3z8VjQP" headers = { 'accept': 'application/json', 'x-cg-demo-api-key': APY_KEY } #print(ohlc_endpoint) response = requests.get(ohlc_endpoint, headers= headers) if response.status_code == 200: data = response.json() print(len(data)) date = time.ctime(data[0][0]/1000) date_as_string = time.strftime("%d/%m/%Y", time.gmtime(data[0][0]/1000)) ohlc = [ data[0][1], data[0][2], data[0][3], data[0][4] ] print(f'price of bitcoin in {date_as_string}:\nopen: {ohlc[0]}\nhigh: {ohlc[1]}\nlow: {ohlc[2]}\nclose: {ohlc[3]}') else: print('failed to retrive data')