From b58e4129827cf6d46675d43f2e2629227e89662e Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 3 Jul 2024 13:34:00 +0200 Subject: [PATCH] feat: Add "DEX" output for `list- exchanges` subcommand --- freqtrade/commands/list_commands.py | 3 ++- freqtrade/exchange/check_exchange.py | 2 +- freqtrade/exchange/exchange_utils.py | 14 +++++++++----- freqtrade/types/valid_exchanges_type.py | 1 + 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/freqtrade/commands/list_commands.py b/freqtrade/commands/list_commands.py index 257166f9c..3a542226c 100644 --- a/freqtrade/commands/list_commands.py +++ b/freqtrade/commands/list_commands.py @@ -45,7 +45,8 @@ def start_list_exchanges(args: Dict[str, Any]) -> None: "name": exchange["name"], **valid_entry, "supported": "Official" if exchange["supported"] else "", - "trade_modes": ", ".join( + "trade_modes": ("DEX: " if exchange["dex"] else "") + + ", ".join( (f"{a['margin_mode']} " if a["margin_mode"] else "") + a["trading_mode"] for a in exchange["trade_modes"] ), diff --git a/freqtrade/exchange/check_exchange.py b/freqtrade/exchange/check_exchange.py index 73b1c8a97..6d82bae04 100644 --- a/freqtrade/exchange/check_exchange.py +++ b/freqtrade/exchange/check_exchange.py @@ -47,7 +47,7 @@ def check_exchange(config: Config, check_for_bad: bool = True) -> bool: f'{", ".join(available_exchanges())}' ) - valid, reason = validate_exchange(exchange) + valid, reason, _ = validate_exchange(exchange) if not valid: if check_for_bad: raise OperationalException( diff --git a/freqtrade/exchange/exchange_utils.py b/freqtrade/exchange/exchange_utils.py index dcae1ab3b..15555248b 100644 --- a/freqtrade/exchange/exchange_utils.py +++ b/freqtrade/exchange/exchange_utils.py @@ -53,16 +53,19 @@ def available_exchanges(ccxt_module: Optional[CcxtModuleType] = None) -> List[st return [x for x in exchanges if validate_exchange(x)[0]] -def validate_exchange(exchange: str) -> Tuple[bool, str]: +def validate_exchange(exchange: str) -> Tuple[bool, str, bool]: """ returns: can_use, reason with Reason including both missing and missing_opt """ ex_mod = getattr(ccxt, exchange.lower())() + + if not ex_mod or not ex_mod.has: + return False, "", False + result = True reason = "" - if not ex_mod or not ex_mod.has: - return False, "" + is_dex = getattr(ex_mod, "dex", False) missing = [ k for k, v in EXCHANGE_HAS_REQUIRED.items() @@ -81,18 +84,19 @@ def validate_exchange(exchange: str) -> Tuple[bool, str]: if missing_opt: reason += f"{'. ' if reason else ''}missing opt: {', '.join(missing_opt)}. " - return result, reason + return result, reason, is_dex def _build_exchange_list_entry( exchange_name: str, exchangeClasses: Dict[str, Any] ) -> ValidExchangesType: - valid, comment = validate_exchange(exchange_name) + valid, comment, is_dex = validate_exchange(exchange_name) result: ValidExchangesType = { "name": exchange_name, "valid": valid, "supported": exchange_name.lower() in SUPPORTED_EXCHANGES, "comment": comment, + "dex": is_dex, "trade_modes": [{"trading_mode": "spot", "margin_mode": ""}], } if resolved := exchangeClasses.get(exchange_name.lower()): diff --git a/freqtrade/types/valid_exchanges_type.py b/freqtrade/types/valid_exchanges_type.py index c01149455..9de05b964 100644 --- a/freqtrade/types/valid_exchanges_type.py +++ b/freqtrade/types/valid_exchanges_type.py @@ -14,4 +14,5 @@ class ValidExchangesType(TypedDict): valid: bool supported: bool comment: str + dex: bool trade_modes: List[TradeModeType]