feat: improve structure of list_exchange endpoints
This commit is contained in:
@@ -53,9 +53,9 @@ 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, bool]:
|
def validate_exchange(exchange: str) -> Tuple[bool, str, Optional[ccxt.Exchange]]:
|
||||||
"""
|
"""
|
||||||
returns: can_use, reason
|
returns: can_use, reason, exchange_object
|
||||||
with Reason including both missing and missing_opt
|
with Reason including both missing and missing_opt
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
@@ -64,11 +64,10 @@ def validate_exchange(exchange: str) -> Tuple[bool, str, bool]:
|
|||||||
ex_mod = getattr(ccxt.async_support, exchange.lower())()
|
ex_mod = getattr(ccxt.async_support, exchange.lower())()
|
||||||
|
|
||||||
if not ex_mod or not ex_mod.has:
|
if not ex_mod or not ex_mod.has:
|
||||||
return False, "", False
|
return False, "", None
|
||||||
|
|
||||||
result = True
|
result = True
|
||||||
reason = ""
|
reason = ""
|
||||||
is_dex = getattr(ex_mod, "dex", False)
|
|
||||||
missing = [
|
missing = [
|
||||||
k
|
k
|
||||||
for k, v in EXCHANGE_HAS_REQUIRED.items()
|
for k, v in EXCHANGE_HAS_REQUIRED.items()
|
||||||
@@ -87,19 +86,21 @@ def validate_exchange(exchange: str) -> Tuple[bool, str, bool]:
|
|||||||
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, is_dex
|
return result, reason, ex_mod
|
||||||
|
|
||||||
|
|
||||||
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, is_dex = validate_exchange(exchange_name)
|
valid, comment, ex_mod = validate_exchange(exchange_name)
|
||||||
result: ValidExchangesType = {
|
result: ValidExchangesType = {
|
||||||
"name": exchange_name,
|
"name": getattr(ex_mod, "name", exchange_name),
|
||||||
|
"classname": 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,
|
"dex": getattr(ex_mod, "dex", False),
|
||||||
|
"is_alias": getattr(ex_mod, "alias", False),
|
||||||
"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()):
|
||||||
|
|||||||
@@ -11,8 +11,10 @@ class TradeModeType(TypedDict):
|
|||||||
|
|
||||||
class ValidExchangesType(TypedDict):
|
class ValidExchangesType(TypedDict):
|
||||||
name: str
|
name: str
|
||||||
|
classname: str
|
||||||
valid: bool
|
valid: bool
|
||||||
supported: bool
|
supported: bool
|
||||||
comment: str
|
comment: str
|
||||||
dex: bool
|
dex: bool
|
||||||
|
is_alias: bool
|
||||||
trade_modes: List[TradeModeType]
|
trade_modes: List[TradeModeType]
|
||||||
|
|||||||
Reference in New Issue
Block a user