adicionada chamada 'coin_historical_chart_data_within_time_range_by_token_address()'
This commit is contained in:
@ -956,19 +956,91 @@ def coin_historical_chart_data_by_token_address(
|
||||
# print(f'erro {codigo}: {dados}')
|
||||
|
||||
|
||||
def coin_historical_chart_data_within_time_range_by_token_address() -> tuple[str, int, dict]:
|
||||
pass
|
||||
def coin_historical_chart_data_within_time_range_by_token_address(
|
||||
id_plataforma: str = '',
|
||||
contract_address: str = '',
|
||||
vs_currency: str = '',
|
||||
from_unix: int = -1,
|
||||
to_unix: int = -1,
|
||||
precision: str | int = 'full'
|
||||
) -> tuple[str, int, dict]:
|
||||
'''https://docs.coingecko.com/v3.0.1/reference/contract-address-market-chart-range
|
||||
|
||||
est endpoint permite obter dados historicos graficos compreendidos num determinado
|
||||
periodo de tempo UNIX, tais como preco, capitalizacao de mercado e volume 24hrs a
|
||||
partir da plataforma do activo e o seu endereco de contrato
|
||||
'''
|
||||
# dicionario de parametros
|
||||
api_parameters: dict = {
|
||||
'id': '',
|
||||
'contract_address': '',
|
||||
'vs_currency': '',
|
||||
'from': '',
|
||||
'to': '',
|
||||
'precision': '',
|
||||
}
|
||||
# validacao de parametros
|
||||
# id_platform (como 'id' é nome reservado, foi usado outro nome)
|
||||
if not isinstance(id_plataforma, str):
|
||||
raise TypeError('\'id_plataforma\' tem de ser do tipo \'str\'')
|
||||
if id_plataforma == '':
|
||||
raise ValueError('\'id_plataforma\' tem de ser definido')
|
||||
api_parameters['id'] = id_plataforma
|
||||
# contract_address
|
||||
if not isinstance(contract_address, str):
|
||||
raise TypeError('\'contract_address\' tem de ser do tipo \'str\'')
|
||||
if contract_address == '':
|
||||
raise ValueError('\'contract_address\' tem de ser definido')
|
||||
api_parameters['contract_address'] = contract_address
|
||||
# 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\' tem de ser definido')
|
||||
api_parameters['from'] = str(from_unix)
|
||||
# to_unix ('to' não é nome reservado, mas foi usado para manter logica)
|
||||
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, (str, int)):
|
||||
raise TypeError('\'precision\' tem de ser do tipo \'(str, int)\'')
|
||||
if isinstance(precision, str):
|
||||
if precision != 'full':
|
||||
precision = 'full'
|
||||
if precision == 'full':
|
||||
precision = '18'
|
||||
precision = int(precision)
|
||||
if isinstance(precision, int):
|
||||
if precision < 0:
|
||||
precision = 0
|
||||
if precision > 18:
|
||||
precision = 18
|
||||
precision = str(precision)
|
||||
api_parameters['precision'] = precision
|
||||
|
||||
|
||||
return API(f'coins/{api_parameters['id']}/contract/{api_parameters['contract_address']}/market_chart/range', api_parameters)
|
||||
|
||||
|
||||
# debug (decomentar linhas seguintes para testar funcao)
|
||||
# url, codigo, dados = <nome_chamada_api()>
|
||||
# url, codigo, dados = coin_historical_chart_data_within_time_range_by_token_address('ethereum','0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48','eur',1711929600,1712275200)
|
||||
# print(f'url: {url}')
|
||||
# if codigo == 200:
|
||||
# for item in dados:
|
||||
# print(item)
|
||||
# print(f'{item}: {dados[item]}')
|
||||
# else:
|
||||
# print(f'erro {codigo}: {dados}')
|
||||
|
||||
|
||||
def assets_platforms_list() -> tuple[str, int, dict]:
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user