diff --git a/README.md b/README.md index df44cf6..598d758 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ quando houver parametros 'vazios' passados como argumentos, estes não devem ser * ✅ coin historical chart data by id - * ❌⬛ coin historical chart data within time range by id + * ✅ coin historical chart data within time range by id * ❌⬛ coin ohlc chart by id * **contract** diff --git a/modulos/coingecko_api.py b/modulos/coingecko_api.py index fcbbc85..6a190b0 100644 --- a/modulos/coingecko_api.py +++ b/modulos/coingecko_api.py @@ -692,17 +692,75 @@ def coin_historical_chart_data_by_id( # print(f'erro {codigo}: {dados}') -def coin_historical_chart_data_within_time_range_by_id() -> tuple: - pass +# temos de criar outra abordagem, este noma de chamada api é enorme... +def coin_historical_chart_data_within_time_range_by_id( + id_criptomoeda: str = '', + vs_currency: str = '', + from_unix: int = -1, + to_unix: int = -1, + precision: str | int = 'full' +) -> tuple: + '''https://docs.coingecko.com/v3.0.1/reference/coins-id-market-chart-range + + este endpoint permite obter dados historicos graficos compreendidos num periodo de tempo + unix com preco, capitalizacao de mercado e volume 24hrs a partir de um id de moeda + ''' + # dicionario parametros + api_parameters = { + 'id': '', + 'vs_currency': '', + 'from': '', + 'to': '', + 'precision': '', + } + # validacao parametros + # id_criptomoeda (como 'id' é nome reservado, foi usado outro nome) + if not isinstance(id_criptomoeda, str): + raise TypeError('\'id_criptomoeda\' tem de ser do tipo \'str\'') + if id_criptomoeda == '': + raise ValueError('\'id_criptomoeda\' tem de ser definido') + api_parameters['id'] = id_criptomoeda + # vs_currency + if not isinstance(vs_currency, str): + raise TypeError('\'vs_currency\' tem de ser do tipo \'str\'') + if vs_currency == '': + raise ValueError('\'vs_currency\' tem de ser definido') + api_parameters['vs_currency'] = vs_currency + # from_unix (como 'from' é nome reservado, foi usado outro nome) + if not isinstance(from_unix, int): + raise TypeError('\'from_unix\' tem de ser do tipo \'int\'') + if from_unix == -1: + raise ValueError('\'from_unix\' tm de ser definido') + api_parameters['from'] = str(from_unix) + # to_unix ('to' não é nome reservado, mas foi usado este nome para manter relação) + if not isinstance(to_unix, int): + raise TypeError('\'to_unix\' tem de ser do tipo \'int\'') + if to_unix == -1: + raise ValueError('\'to_unix\' tem de ser definido') + api_parameters['to'] = str(to_unix) + # precision + if not isinstance(precision, (int, str)): + raise TypeError('\'precision\' tem de ser do tipo \'(int, str)\'') + if isinstance(precision, str): + if precision == 'full': + precision = '18' + precision = int(precision) + if isinstance(precision, int): + if precision < 0: + precision = 0 + if precision > 18: + precision = 18 + api_parameters['precision'] = str(precision) + + return API(f'coins/{api_parameters['id']}/market_chart/range', api_parameters) # debug (decomentar linhas seguintes para testar funcao) -# url, codigo, dados = coins_list_with_market_data('eur', 'bitcoin') +# url, codigo, dados = coin_historical_chart_data_within_time_range_by_id('bitcoin','eur',1711929600,1712275200) # print(f'url: {url}') -# if codigo == 200: -# print(f'codigo: {codigo}') +# if codigo == 200: # for item in dados: -# print(item) +# print(f'{item}: {dados[item]}') # else: # print(f'erro {codigo}: {dados}')