diff --git a/freqtrade/exchange/__init__.py b/freqtrade/exchange/__init__.py index 470091181..7545bff6a 100644 --- a/freqtrade/exchange/__init__.py +++ b/freqtrade/exchange/__init__.py @@ -11,6 +11,6 @@ from freqtrade.exchange.exchange import (timeframe_to_seconds, # noqa: F401 timeframe_to_next_date, timeframe_to_prev_date) from freqtrade.exchange.exchange import (market_is_active, # noqa: F401 - market_is_pair) + symbol_is_pair) from freqtrade.exchange.kraken import Kraken # noqa: F401 from freqtrade.exchange.binance import Binance # noqa: F401 diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 164f21ac6..193982b74 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -297,7 +297,7 @@ class Exchange: if quote_currencies: markets = {k: v for k, v in markets.items() if v['quote'] in quote_currencies} if pairs_only: - markets = {k: v for k, v in markets.items() if market_is_pair(v)} + markets = {k: v for k, v in markets.items() if symbol_is_pair(v['symbol'])} if active_only: markets = {k: v for k, v in markets.items() if market_is_active(v)} return markets @@ -937,14 +937,14 @@ def timeframe_to_next_date(timeframe: str, date: datetime = None) -> datetime: return datetime.fromtimestamp(new_timestamp, tz=timezone.utc) -def market_is_pair(market, base_currency: str = None, quote_currency: str = None): +def symbol_is_pair(market_symbol: str, base_currency: str = None, quote_currency: str = None): """ - Check if the market is a pair, i.e. that its symbol consists of the base currency and the + Check if the market symbol is a pair, i.e. that its symbol consists of the base currency and the quote currency separated by '/' character. If base_currency and/or quote_currency is passed, it also checks that the symbol contains appropriate base and/or quote currency part before and after the separating character correspondingly. """ - symbol_parts = market['symbol'].split('/') + symbol_parts = market_symbol.split('/') return (len(symbol_parts) == 2 and (symbol_parts[0] == base_currency if base_currency else len(symbol_parts[0]) > 0) and (symbol_parts[1] == quote_currency if quote_currency else len(symbol_parts[1]) > 0)) diff --git a/freqtrade/utils.py b/freqtrade/utils.py index 90140f6ba..e00b0739e 100644 --- a/freqtrade/utils.py +++ b/freqtrade/utils.py @@ -14,7 +14,7 @@ from freqtrade.configuration import Configuration, TimeRange from freqtrade.configuration.directory_operations import create_userdata_dir from freqtrade.data.history import refresh_backtest_ohlcv_data from freqtrade.exchange import (available_exchanges, ccxt_exchanges, market_is_active, - market_is_pair) + symbol_is_pair) from freqtrade.misc import plural from freqtrade.resolvers import ExchangeResolver from freqtrade.state import RunMode @@ -173,7 +173,8 @@ def start_list_pairs(args: Dict[str, Any], pairs_only: bool = False) -> None: tabular_data.append({'Id': v['id'], 'Symbol': v['symbol'], 'Base': v['base'], 'Quote': v['quote'], 'Active': market_is_active(v), - **({'Is pair': market_is_pair(v)} if not pairs_only else {})}) + **({'Is pair': symbol_is_pair(v['symbol'])} + if not pairs_only else {})}) if (args.get('print_one_column', False) or args.get('list_pairs_print_json', False) or diff --git a/tests/exchange/test_exchange.py b/tests/exchange/test_exchange.py index d61748d1d..20449bd6b 100644 --- a/tests/exchange/test_exchange.py +++ b/tests/exchange/test_exchange.py @@ -19,7 +19,7 @@ from freqtrade.exchange.exchange import (API_RETRY_COUNT, timeframe_to_minutes, timeframe_to_next_date, timeframe_to_prev_date, timeframe_to_seconds, - market_is_pair) + symbol_is_pair) from freqtrade.resolvers.exchange_resolver import ExchangeResolver from tests.conftest import get_patched_exchange, log_has, log_has_re @@ -1558,22 +1558,22 @@ def test_timeframe_to_next_date(): assert timeframe_to_next_date("5m") > date -@pytest.mark.parametrize("market,base_currency,quote_currency,expected_result", [ - ({'symbol': "BTC/USDT"}, None, None, True), - ({'symbol': "USDT/BTC"}, None, None, True), - ({'symbol': "BTCUSDT"}, None, None, False), - ({'symbol': "BTC/USDT"}, None, "USDT", True), - ({'symbol': "USDT/BTC"}, None, "USDT", False), - ({'symbol': "BTCUSDT"}, None, "USDT", False), - ({'symbol': "BTC/USDT"}, "BTC", None, True), - ({'symbol': "USDT/BTC"}, "BTC", None, False), - ({'symbol': "BTCUSDT"}, "BTC", None, False), - ({'symbol': "BTC/USDT"}, "BTC", "USDT", True), - ({'symbol': "BTC/USDT"}, "USDT", "BTC", False), - ({'symbol': "BTC/USDT"}, "BTC", "USD", False), - ({'symbol': "BTCUSDT"}, "BTC", "USDT", False), - ({'symbol': "BTC/"}, None, None, False), - ({'symbol': "/USDT"}, None, None, False), +@pytest.mark.parametrize("market_symbol,base_currency,quote_currency,expected_result", [ + ("BTC/USDT", None, None, True), + ("USDT/BTC", None, None, True), + ("BTCUSDT", None, None, False), + ("BTC/USDT", None, "USDT", True), + ("USDT/BTC", None, "USDT", False), + ("BTCUSDT", None, "USDT", False), + ("BTC/USDT", "BTC", None, True), + ("USDT/BTC", "BTC", None, False), + ("BTCUSDT", "BTC", None, False), + ("BTC/USDT", "BTC", "USDT", True), + ("BTC/USDT", "USDT", "BTC", False), + ("BTC/USDT", "BTC", "USD", False), + ("BTCUSDT", "BTC", "USDT", False), + ("BTC/", None, None, False), + ("/USDT", None, None, False), ]) -def test_market_is_pair(market, base_currency, quote_currency, expected_result) -> None: - assert market_is_pair(market, base_currency, quote_currency) == expected_result +def test_symbol_is_pair(market_symbol, base_currency, quote_currency, expected_result) -> None: + assert symbol_is_pair(market_symbol, base_currency, quote_currency) == expected_result