def fee_overrides_dict(): all_dict = {} # all_connector_types = get_exchanges_and_derivatives() for connector_type, connectors in ALL_CONNECTORS.items(): for connector in connectors: maker_key = f"{connector}_maker_fee_amount" if connector in DEXES else f"{connector}_maker_fee" taker_key = f"{connector}_taker_fee_amount" if connector in DEXES else f"{connector}_taker_fee" all_dict.update({maker_key: new_fee_config_var(maker_key)}) all_dict.update({taker_key: new_fee_config_var(taker_key)}) return all_dict
async def fetch_all(self): tasks = [] fetched_connectors = [] for connector_type, connectors in ALL_CONNECTORS.items(): if connector_type != "connector": for connector in connectors: module_name = f"{connector}_api_order_book_data_source" class_name = "".join([ o.capitalize() for o in connector.split("_") ]) + "APIOrderBookDataSource" module_path = f"hummingbot.connector.{connector_type}.{connector}.{module_name}" module = getattr(importlib.import_module(module_path), class_name) tasks.append(module.fetch_trading_pairs()) fetched_connectors.append(connector) results = await safe_gather(*tasks, return_exceptions=True) self.trading_pairs = dict(zip(fetched_connectors, results)) self.ready = True
def get_mid_price(exchange: str, trading_pair: str) -> Optional[Decimal]: mid_price = None for connector_type, connectors in ALL_CONNECTORS.items(): if exchange in connectors: try: module_name = f"{exchange}_api_order_book_data_source" class_name = "".join([o.capitalize() for o in exchange.split("_")]) + "APIOrderBookDataSource" module_path = f"hummingbot.connector.{connector_type}.{exchange}.{module_name}" module = getattr(importlib.import_module(module_path), class_name) mid_price = module.get_mid_price(trading_pair) except Exception: pass if mid_price is None: module_name = "binance_api_order_book_data_source" class_name = "BinanceAPIOrderBookDataSource" module_path = f"hummingbot.connector.exchange.binance.{module_name}" module = getattr(importlib.import_module(module_path), class_name) mid_price = module.get_mid_price(trading_pair) return mid_price
def estimate_fee(exchange: str, is_maker: bool) -> Decimal: override_config_name_suffix = "_maker_fee" if is_maker else "_taker_fee" override_config_name = exchange + override_config_name_suffix s_decimal_0 = Decimal("0") s_decimal_100 = Decimal("100") for connector_type, connectors in ALL_CONNECTORS.items(): if exchange in connectors: try: path = f"hummingbot.connector.{connector_type}.{exchange}.{exchange}_utils" is_cex = getattr(__import__(path, fromlist=["CENTRALIZED"]), "CENTRALIZED") fee = getattr(__import__(path, fromlist=["DEFAULT_FEES"]), "DEFAULT_FEES") except Exception: pass if is_maker: if is_cex: if fee_overrides_config_map[override_config_name].value is not None: return TradeFee(percent=fee_overrides_config_map[override_config_name].value / s_decimal_100) else: return TradeFee(percent=Decimal(fee[0]) / s_decimal_100) else: override_config_name += "_amount" if fee_overrides_config_map[override_config_name].value is not None: return TradeFee(percent=s_decimal_0, flat_fees=[("ETH", fee_overrides_config_map[override_config_name].value)]) else: return TradeFee(percent=s_decimal_0, flat_fees=[("ETH", Decimal(fee[0]))]) else: if is_cex: if fee_overrides_config_map[override_config_name].value is not None: return TradeFee(percent=fee_overrides_config_map[override_config_name].value / s_decimal_100) else: return TradeFee(percent=Decimal(fee[1]) / s_decimal_100) else: override_config_name += "_amount" if fee_overrides_config_map[override_config_name].value is not None: return TradeFee(percent=s_decimal_0, flat_fees=[("ETH", fee_overrides_config_map[override_config_name].value)]) else: return TradeFee(percent=s_decimal_0, flat_fees=[("ETH", Decimal(fee[1]))])