feat: Add "DEX" output for list- exchanges subcommand

This commit is contained in:
Matthias 2024-07-03 13:34:00 +02:00
parent d8eb6e59fa
commit b58e412982
4 changed files with 13 additions and 7 deletions

View File

@ -45,7 +45,8 @@ def start_list_exchanges(args: Dict[str, Any]) -> None:
"name": exchange["name"], "name": exchange["name"],
**valid_entry, **valid_entry,
"supported": "Official" if exchange["supported"] else "", "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"] (f"{a['margin_mode']} " if a["margin_mode"] else "") + a["trading_mode"]
for a in exchange["trade_modes"] for a in exchange["trade_modes"]
), ),

View File

@ -47,7 +47,7 @@ def check_exchange(config: Config, check_for_bad: bool = True) -> bool:
f'{", ".join(available_exchanges())}' f'{", ".join(available_exchanges())}'
) )
valid, reason = validate_exchange(exchange) valid, reason, _ = validate_exchange(exchange)
if not valid: if not valid:
if check_for_bad: if check_for_bad:
raise OperationalException( raise OperationalException(

View File

@ -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]] 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 returns: can_use, reason
with Reason including both missing and missing_opt with Reason including both missing and missing_opt
""" """
ex_mod = getattr(ccxt, exchange.lower())() ex_mod = getattr(ccxt, exchange.lower())()
if not ex_mod or not ex_mod.has:
return False, "", False
result = True result = True
reason = "" reason = ""
if not ex_mod or not ex_mod.has: is_dex = getattr(ex_mod, "dex", False)
return False, ""
missing = [ missing = [
k k
for k, v in EXCHANGE_HAS_REQUIRED.items() for k, v in EXCHANGE_HAS_REQUIRED.items()
@ -81,18 +84,19 @@ def validate_exchange(exchange: str) -> Tuple[bool, str]:
if missing_opt: if missing_opt:
reason += f"{'. ' if reason else ''}missing opt: {', '.join(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( def _build_exchange_list_entry(
exchange_name: str, exchangeClasses: Dict[str, Any] exchange_name: str, exchangeClasses: Dict[str, Any]
) -> ValidExchangesType: ) -> ValidExchangesType:
valid, comment = validate_exchange(exchange_name) valid, comment, is_dex = validate_exchange(exchange_name)
result: ValidExchangesType = { result: ValidExchangesType = {
"name": exchange_name, "name": exchange_name,
"valid": valid, "valid": valid,
"supported": exchange_name.lower() in SUPPORTED_EXCHANGES, "supported": exchange_name.lower() in SUPPORTED_EXCHANGES,
"comment": comment, "comment": comment,
"dex": is_dex,
"trade_modes": [{"trading_mode": "spot", "margin_mode": ""}], "trade_modes": [{"trading_mode": "spot", "margin_mode": ""}],
} }
if resolved := exchangeClasses.get(exchange_name.lower()): if resolved := exchangeClasses.get(exchange_name.lower()):

View File

@ -14,4 +14,5 @@ class ValidExchangesType(TypedDict):
valid: bool valid: bool
supported: bool supported: bool
comment: str comment: str
dex: bool
trade_modes: List[TradeModeType] trade_modes: List[TradeModeType]