def get_usdt_symbols(): usdt_symbols = [] generic_client = GenericClient() list_obj = generic_client.get_exchange_symbols() if len(list_obj): for symb in list_obj: if symb.quote_currency == 'usdt': usdt_symbols.append(symb.symbol) return usdt_symbols
def get_all_symbols(): try: generic_client = GenericClient(url=settings.config['COMMON']['host']) symbols = generic_client.get_exchange_symbols() ret_val = {} for sym in symbols: ret_val[sym.symbol] = sym return ret_val except Exception as e: print(e) return None
def test_generic(self): generic_client = GenericClient(api_key=g_api_key, secret_key=g_secret_key, performance_test=True) # case get_exchange_symbol_list tc = TimeCost( function_name=generic_client.get_exchange_timestamp.__name__) result, tc.server_req_cost, tc.server_api_cost = generic_client.get_exchange_timestamp( ) tc.run_status = RunStatus.SUCCESS if result and result > 0 else RunStatus.FAILED tc.add_record() # case get_exchange_currencies tc = TimeCost( function_name=generic_client.get_exchange_currencies.__name__) result, tc.server_req_cost, tc.server_api_cost = generic_client.get_exchange_currencies( ) tc.run_status = RunStatus.SUCCESS if result and len( result) else RunStatus.FAILED tc.add_record() # case get_exchange_symbols tc = TimeCost( function_name=generic_client.get_exchange_symbols.__name__) result, tc.server_req_cost, tc.server_api_cost = generic_client.get_exchange_symbols( ) tc.run_status = RunStatus.SUCCESS if result and len( result) else RunStatus.FAILED tc.add_record() # case get_reference_currencies tc = TimeCost( function_name=generic_client.get_reference_currencies.__name__) result, tc.server_req_cost, tc.server_api_cost = generic_client.get_reference_currencies( ) tc.run_status = RunStatus.SUCCESS if result and len( result) else RunStatus.FAILED tc.add_record() # case get_system_status tc = TimeCost(function_name=generic_client.get_system_status.__name__) result, tc.server_req_cost, tc.server_api_cost = generic_client.get_system_status( ) tc.run_status = RunStatus.SUCCESS if result and result.get( "page") and result.get("components") else RunStatus.FAILED tc.add_record()
class MarketClient(_MarketClient): exclude_list = [ 'htusdt', 'btcusdt', 'bsvusdt', 'bchusdt', 'etcusdt', 'ethusdt', 'botusdt','mcousdt','lendusdt','venusdt', 'yamv2usdt', 'bttusdt', 'dogeusdt' ] def __init__(self, **kwargs): super().__init__(**kwargs) self.generic_client = GenericClient() self.symbols_info: 'dict[str, Symbol]' = {} self.mark_price: 'dict[str, float]' = {} self.update_symbols_info() def exclude(self, infos, base_price) -> 'dict[str, Symbol]': return { symbol: info for symbol, info in infos.items() if symbol not in self.exclude_list and not re.search('\d', symbol) and symbol in base_price and base_price[symbol] < 10 } def update_symbols_info(self) -> 'tuple[list[str], list[str]]': new_symbols_info = { info.symbol: info for info in self.generic_client.get_exchange_symbols() if info.symbol.endswith('usdt') } price = self.get_price() symbols_info = self.exclude(new_symbols_info, price) new_symbols = [symbol for symbol in symbols_info.keys() if symbol not in self.symbols_info] removed_symbols = [symbol for symbol in self.symbols_info.keys() if symbol not in symbols_info] self.symbols_info = symbols_info self.mark_price = price return new_symbols, removed_symbols @timeout_handle({}) def get_price(self) -> 'dict[str, float]': return { pair.symbol: pair.close for pair in self.get_market_tickers() }
def get_symbol_info(symbol): generic_client = GenericClient() while (1): try: list_obj = generic_client.get_exchange_symbols() break except requests.exceptions.ProxyError as e: print(e) continue except requests.exceptions.ConnectionError as e: print(e) continue except requests.exceptions.ReadTimeout as e: print(e) continue if len(list_obj): for symbol_info_obj in list_obj: if symbol_info_obj.symbol == symbol: return symbol_info_obj
from huobi.client.account import AccountClient from huobi.client.generic import CandlestickInterval, GenericClient from huobi.client.market import LogInfo, MarketClient from huobi.client.trade import TradeClient generic_client = GenericClient() list_symbol = generic_client.get_exchange_symbols() list_currency = generic_client.get_reference_currencies() print(list_symbol[0]) print(list_currency[0].print_object()) a = c access_key = " " secret_key = " " # Create generic client instance and get the timestamp generic_client = GenericClient() timestamp = generic_client.get_exchange_timestamp() print(timestamp) # Create the market client instance and get the latest btcusdt‘s candlestick market_client = MarketClient() list_obj = market_client.get_candlestick("btcusdt", CandlestickInterval.MIN5, 10) LogInfo.output_list(list_obj) # // Create an AccountClient instance with APIKey account_client = AccountClient(api_key=access_key, secret_key=secret_key) # // Create a TradeClient instance with API Key and customized host trade_client = TradeClient(api_key=access_key,