diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index e55e01186..363fa4e39 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -19,7 +19,7 @@ from pandas import DataFrame from freqtrade import (DependencyException, InvalidOrderException, OperationalException, TemporaryError, constants) from freqtrade.data.converter import parse_ticker_dataframe -from freqtrade.misc import deep_merge_dicts +from freqtrade.misc import deep_merge_dicts, symbol_is_pair logger = logging.getLogger(__name__) @@ -208,7 +208,7 @@ class Exchange(object): if quote_currency: markets = {k: v for k, v in markets.items() if v['quote'] == quote_currency} if pairs_only: - markets = {k: v for k, v in markets.items() if '/' in v['symbol']} + 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 v['active']} return markets diff --git a/freqtrade/misc.py b/freqtrade/misc.py index 7196338cf..9deb0ece6 100644 --- a/freqtrade/misc.py +++ b/freqtrade/misc.py @@ -137,3 +137,16 @@ def deep_merge_dicts(source, destination): def plural(num, singular: str, plural: str = None) -> str: return singular if (num == 1 or num == -1) else plural or singular + 's' + + +def symbol_is_pair(symbol: str, base_currency: str = None, quote_currency: str = None): + """ + Check if the symbol is a pair, i.e. 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 = 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))