adicionada chamada 'derivatives_exchange_data_by_id()'

This commit is contained in:
2024-06-17 10:23:26 +01:00
parent 62b2ce3278
commit 3b01079786

View File

@ -1378,16 +1378,41 @@ def derivatives_exchange_list_with_data(
# else: # else:
# print(f'erro {codigo}: {dados}') # print(f'erro {codigo}: {dados}')
def derivatives_exchange_data_by_id() -> tuple[str, int, dict]: def derivatives_exchange_data_by_id(
pass id_exchange: str = '',
include_tickers: str = '',
) -> tuple[str, int, dict]:
'''https://docs.coingecko.com/v3.0.1/reference/derivatives-exchanges-id
este endpoint permite obter os dados relativos a uma correctora de derivados (id, nome,
contractos em aberto, etc) a partir do id da correctora)
'''
# dicionario de parametros
api_parameters: dict = {
'id': '',
'include_tickers': '',
}
# 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
# include_tickers
if not isinstance(include_tickers, str):
raise TypeError('\'include_tickers\' tem de ser do tipo \'str\'')
api_parameters['include_tickers'] = include_tickers
return API(f'derivatives/exchanges/{api_parameters['id']}', api_parameters)
# debug (decomentar linhas seguintes para testar funcao) # debug (decomentar linhas seguintes para testar funcao)
# url, codigo, dados = <nome_chamada_api()> # url, codigo, dados = derivatives_exchange_data_by_id('binance_futures')
# print(f'url: {url}') # print(f'url: {url}')
# if codigo == 200: # if codigo == 200:
# for item in dados: # for item in dados:
# print(item) # print(f'{item}: {dados[item]}')
# else: # else:
# print(f'erro {codigo}: {dados}') # print(f'erro {codigo}: {dados}')