import time import os # se não houver ficheiro 'modulos/constantes.py' criar ficheiro com 'CHAVE_API_DEMO' if not os.path.exists('modulos/constantes.py'): with open('modulos/constantes.py', 'w') as f: chave_api = input('Introduza a chave da API Demo de CoinGecko: ') f.write(f'CHAVE_API_DEMO = \'{chave_api}\'\n') import modulos.coingecko_api as cgapi criptomoeda: str = 'bitcoin' vs_currency: str = 'eur' dias: str = '30' historico_precos_header = [ "data", "moeda", "preco_abertura", "preco_maximo", "preco_minimo", "preco_fecho" ] portfolio_headers = [ "data", "moeda", "quantidade", "movimento" ] url, codigo, dados_ohlc = cgapi.coin_ohlc_chart_by_id(criptomoeda, vs_currency, dias, precision=3) if codigo == 200: #print(len(dados_ohlc)) for index in range(0, len(dados_ohlc)): data = time.gmtime(dados_ohlc[index][0]/1000) if data.tm_hour == 0 and data.tm_min == 0: date_as_string = time.strftime("%d/%m/%Y", data) price = dados_ohlc[index][4] print(f'{date_as_string} -> {price}') else: print('failed to retrive data')