Replace market_is_pair() by symbol_is_pair()

This commit is contained in:
hroff-1902 2019-10-17 18:44:25 +03:00
parent e8eb968a6f
commit b6e26c82ea
4 changed files with 27 additions and 26 deletions

View File

@ -11,6 +11,6 @@ from freqtrade.exchange.exchange import (timeframe_to_seconds, # noqa: F401
timeframe_to_next_date, timeframe_to_next_date,
timeframe_to_prev_date) timeframe_to_prev_date)
from freqtrade.exchange.exchange import (market_is_active, # noqa: F401 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.kraken import Kraken # noqa: F401
from freqtrade.exchange.binance import Binance # noqa: F401 from freqtrade.exchange.binance import Binance # noqa: F401

View File

@ -297,7 +297,7 @@ class Exchange:
if quote_currencies: if quote_currencies:
markets = {k: v for k, v in markets.items() if v['quote'] in quote_currencies} markets = {k: v for k, v in markets.items() if v['quote'] in quote_currencies}
if pairs_only: 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: if active_only:
markets = {k: v for k, v in markets.items() if market_is_active(v)} markets = {k: v for k, v in markets.items() if market_is_active(v)}
return markets 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) 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, 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 it also checks that the symbol contains appropriate base and/or quote currency part before
and after the separating character correspondingly. and after the separating character correspondingly.
""" """
symbol_parts = market['symbol'].split('/') symbol_parts = market_symbol.split('/')
return (len(symbol_parts) == 2 and return (len(symbol_parts) == 2 and
(symbol_parts[0] == base_currency if base_currency else len(symbol_parts[0]) > 0) 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)) (symbol_parts[1] == quote_currency if quote_currency else len(symbol_parts[1]) > 0))

View File

@ -14,7 +14,7 @@ from freqtrade.configuration import Configuration, TimeRange
from freqtrade.configuration.directory_operations import create_userdata_dir from freqtrade.configuration.directory_operations import create_userdata_dir
from freqtrade.data.history import refresh_backtest_ohlcv_data from freqtrade.data.history import refresh_backtest_ohlcv_data
from freqtrade.exchange import (available_exchanges, ccxt_exchanges, market_is_active, from freqtrade.exchange import (available_exchanges, ccxt_exchanges, market_is_active,
market_is_pair) symbol_is_pair)
from freqtrade.misc import plural from freqtrade.misc import plural
from freqtrade.resolvers import ExchangeResolver from freqtrade.resolvers import ExchangeResolver
from freqtrade.state import RunMode 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'], tabular_data.append({'Id': v['id'], 'Symbol': v['symbol'],
'Base': v['base'], 'Quote': v['quote'], 'Base': v['base'], 'Quote': v['quote'],
'Active': market_is_active(v), '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 if (args.get('print_one_column', False) or
args.get('list_pairs_print_json', False) or args.get('list_pairs_print_json', False) or

View File

@ -19,7 +19,7 @@ from freqtrade.exchange.exchange import (API_RETRY_COUNT, timeframe_to_minutes,
timeframe_to_next_date, timeframe_to_next_date,
timeframe_to_prev_date, timeframe_to_prev_date,
timeframe_to_seconds, timeframe_to_seconds,
market_is_pair) symbol_is_pair)
from freqtrade.resolvers.exchange_resolver import ExchangeResolver from freqtrade.resolvers.exchange_resolver import ExchangeResolver
from tests.conftest import get_patched_exchange, log_has, log_has_re 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 assert timeframe_to_next_date("5m") > date
@pytest.mark.parametrize("market,base_currency,quote_currency,expected_result", [ @pytest.mark.parametrize("market_symbol,base_currency,quote_currency,expected_result", [
({'symbol': "BTC/USDT"}, None, None, True), ("BTC/USDT", None, None, True),
({'symbol': "USDT/BTC"}, None, None, True), ("USDT/BTC", None, None, True),
({'symbol': "BTCUSDT"}, None, None, False), ("BTCUSDT", None, None, False),
({'symbol': "BTC/USDT"}, None, "USDT", True), ("BTC/USDT", None, "USDT", True),
({'symbol': "USDT/BTC"}, None, "USDT", False), ("USDT/BTC", None, "USDT", False),
({'symbol': "BTCUSDT"}, None, "USDT", False), ("BTCUSDT", None, "USDT", False),
({'symbol': "BTC/USDT"}, "BTC", None, True), ("BTC/USDT", "BTC", None, True),
({'symbol': "USDT/BTC"}, "BTC", None, False), ("USDT/BTC", "BTC", None, False),
({'symbol': "BTCUSDT"}, "BTC", None, False), ("BTCUSDT", "BTC", None, False),
({'symbol': "BTC/USDT"}, "BTC", "USDT", True), ("BTC/USDT", "BTC", "USDT", True),
({'symbol': "BTC/USDT"}, "USDT", "BTC", False), ("BTC/USDT", "USDT", "BTC", False),
({'symbol': "BTC/USDT"}, "BTC", "USD", False), ("BTC/USDT", "BTC", "USD", False),
({'symbol': "BTCUSDT"}, "BTC", "USDT", False), ("BTCUSDT", "BTC", "USDT", False),
({'symbol': "BTC/"}, None, None, False), ("BTC/", None, None, False),
({'symbol': "/USDT"}, None, None, False), ("/USDT", None, None, False),
]) ])
def test_market_is_pair(market, base_currency, quote_currency, expected_result) -> None: def test_symbol_is_pair(market_symbol, base_currency, quote_currency, expected_result) -> None:
assert market_is_pair(market, base_currency, quote_currency) == expected_result assert symbol_is_pair(market_symbol, base_currency, quote_currency) == expected_result