diff --git a/freqtrade/commands/list_commands.py b/freqtrade/commands/list_commands.py index 2970c1fc3..dcb102ce5 100644 --- a/freqtrade/commands/list_commands.py +++ b/freqtrade/commands/list_commands.py @@ -1,7 +1,7 @@ import csv import logging import sys -from typing import Any, Dict, List +from typing import Any, Dict, List, Union import rapidjson from colorama import Fore, Style @@ -14,6 +14,7 @@ from freqtrade.exceptions import OperationalException from freqtrade.exchange import list_available_exchanges, market_is_active from freqtrade.misc import parse_db_uri_for_logging, plural from freqtrade.resolvers import ExchangeResolver, StrategyResolver +from freqtrade.types import ValidExchangesType logger = logging.getLogger(__name__) @@ -38,13 +39,16 @@ def start_list_exchanges(args: Dict[str, Any]) -> None: 'comment': 'Reason', } - def build_entry(exchange, valid): + def build_entry(exchange: ValidExchangesType, valid: bool): valid_entry = {'valid': exchange['valid']} if valid else {} - result = { + result: Dict[str, Union[str, bool]] = { 'name': exchange['name'], **valid_entry, 'supported': 'Official' if exchange['supported'] else '', - 'trade_modes': ', '.join(exchange['trade_modes']), + 'trade_modes': ', '.join( + (f"{a['margin_mode']} " if a['margin_mode'] else '') + a['trading_mode'] + for a in exchange['trade_modes'] + ), 'comment': exchange['comment'], } diff --git a/freqtrade/exchange/exchange_utils.py b/freqtrade/exchange/exchange_utils.py index 1f1e926ee..fe7264dd9 100644 --- a/freqtrade/exchange/exchange_utils.py +++ b/freqtrade/exchange/exchange_utils.py @@ -65,11 +65,11 @@ def _build_exchange_list_entry( 'valid': valid, 'supported': exchange_name.lower() in SUPPORTED_EXCHANGES, 'comment': comment, - 'trade_modes': ['spot'], + 'trade_modes': [{'trading_mode': 'spot', 'margin_mode': ''}], } if resolved := exchangeClasses.get(exchange_name.lower()): - supported_modes = ['spot'] + [ - f"{mm.value} {tm.value}" + supported_modes = [{'trading_mode': 'spot', 'margin_mode': ''}] + [ + {'trading_mode': tm.value, 'margin_mode': mm.value} for tm, mm in resolved['class']._supported_trading_mode_margin_pairs ] result.update({ diff --git a/freqtrade/exchange/types.py b/freqtrade/exchange/types.py index 1247e5754..5568e4336 100644 --- a/freqtrade/exchange/types.py +++ b/freqtrade/exchange/types.py @@ -26,6 +26,5 @@ class OrderBook(TypedDict): Tickers = Dict[str, Ticker] - # pair, timeframe, candleType, OHLCV, drop last?, OHLCVResponse = Tuple[str, str, CandleType, List, bool] diff --git a/freqtrade/types/valid_exchanges_type.py b/freqtrade/types/valid_exchanges_type.py index f40c3fb30..0f02b1f5d 100644 --- a/freqtrade/types/valid_exchanges_type.py +++ b/freqtrade/types/valid_exchanges_type.py @@ -2,9 +2,14 @@ from typing import List, TypedDict +class TradeModeType(TypedDict): + trading_mode: str + margin_mode: str + + class ValidExchangesType(TypedDict): name: str valid: bool supported: bool comment: str - trade_modes: List[str] + trade_modes: List[TradeModeType] diff --git a/tests/rpc/test_rpc_apiserver.py b/tests/rpc/test_rpc_apiserver.py index 8377de547..ac7904515 100644 --- a/tests/rpc/test_rpc_apiserver.py +++ b/tests/rpc/test_rpc_apiserver.py @@ -1593,8 +1593,14 @@ def test_api_exchanges(botclient): "supported": True, "comment": "", "trade_modes": [ - "spot", - "isolated futures", + { + "trading_mode": "spot", + "margin_mode": "" + }, + { + "trading_mode": "futures", + "margin_mode": "isolated" + } ] } @@ -1605,8 +1611,11 @@ def test_api_exchanges(botclient): "supported": False, "comment": "", "trade_modes": [ - "spot", - ] + { + "trading_mode": "spot", + "margin_mode": "" + } + ] }