adicionada chamada 'exchange_tickers_by_id()'
This commit is contained in:
@ -1206,18 +1206,71 @@ def exchange_data_by_id(id_exchange: str = '') -> tuple[str, int, dict]:
|
||||
# else:
|
||||
# print(f'erro {codigo}: {dados}')
|
||||
|
||||
def exchange_tickers_by_id() -> tuple[str, int, dict]:
|
||||
pass
|
||||
def exchange_tickers_by_id(
|
||||
id_exchange: str = '',
|
||||
coin_ids: str = '',
|
||||
include_exchange_logo: bool = False,
|
||||
page: int = -1,
|
||||
depth: bool = False,
|
||||
order: str = ''
|
||||
) -> tuple[str, int, dict]:
|
||||
'''https://docs.coingecko.com/v3.0.1/reference/exchanges-id-tickers
|
||||
|
||||
este endpoint permite obter os tickers de uma correctora a partir
|
||||
da id da correctora
|
||||
'''
|
||||
# dicionario de parametros
|
||||
api_parameters: dict = {
|
||||
'id': '',
|
||||
'coin_ids': '',
|
||||
'include_exchange_logo': '',
|
||||
'page': '',
|
||||
'depth': '',
|
||||
'order': '',
|
||||
}
|
||||
# validacao de parametros
|
||||
# id_exchange (como 'id' é nome reservado, foi usado outro nome )
|
||||
if not isinstance(id_exchange, str):
|
||||
raise TypeError('\'id_exchange\' tem de ser do tipo \'str\'')
|
||||
if id_exchange == '':
|
||||
raise ValueError('\'id_exchange\' tem de ser definido')
|
||||
api_parameters['id'] = id_exchange
|
||||
# coin_ids
|
||||
if not isinstance(coin_ids, str):
|
||||
raise TypeError('\'coin_ids\' tem de ser do tipo \'str\'')
|
||||
if coin_ids == '':
|
||||
raise ValueError('\'coin_ids\' tem de ser definido')
|
||||
api_parameters['coin_ids'] = coin_ids
|
||||
# include_exchange_logo
|
||||
if not isinstance(include_exchange_logo, bool):
|
||||
raise TypeError('\'include_exchange_logo\' tem de ser do tipo \'bool\'')
|
||||
if include_exchange_logo != False:
|
||||
api_parameters['include_exchange_logo'] = str(True)
|
||||
# page
|
||||
if not isinstance(page, int):
|
||||
raise TypeError('\'page\' tem de ser do tipo \'int\'')
|
||||
api_parameters['page'] = str(page)
|
||||
# depth
|
||||
if not isinstance(depth, bool):
|
||||
raise TypeError('\'depth\' tem de ser do tipo \'bool\'')
|
||||
if depth != False:
|
||||
api_parameters['depth'] = str(True)
|
||||
# order
|
||||
if not isinstance(order, str):
|
||||
raise TypeError('\'order\' tem de ser do tipo \'str\'')
|
||||
api_parameters['order'] = order
|
||||
|
||||
return API(f'exchanges/{api_parameters["id"]}/tickers', api_parameters)
|
||||
|
||||
|
||||
# debug (decomentar linhas seguintes para testar funcao)
|
||||
# url, codigo, dados = <nome_chamada_api()>
|
||||
# print(f'url: {url}')
|
||||
# if codigo == 200:
|
||||
# for item in dados:
|
||||
# print(item)
|
||||
# else:
|
||||
# print(f'erro {codigo}: {dados}')
|
||||
url, codigo, dados = exchange_tickers_by_id('binance', 'bitcoin,dogecoin')
|
||||
print(f'url: {url}')
|
||||
if codigo == 200:
|
||||
for item in dados:
|
||||
print(f'{item}: {dados[item]}')
|
||||
else:
|
||||
print(f'erro {codigo}: {dados}')
|
||||
|
||||
def exchange_colume_chart_by_id() -> tuple[str, int, dict]:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user