Skip to content

Commit

Permalink
Allow --base and --quote be lists of currencies
Browse files Browse the repository at this point in the history
  • Loading branch information
hroff-1902 committed Oct 16, 2019
1 parent d72d388 commit 92fda0f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion freqtrade/configuration/arguments.py
Expand Up @@ -35,7 +35,7 @@
ARGS_LIST_TIMEFRAMES = ["exchange", "print_one_column"]

ARGS_LIST_PAIRS = ["exchange", "print_list", "list_pairs_print_json", "print_one_column",
"print_csv", "base_currency", "quote_currency", "active_only"]
"print_csv", "base_currencies", "quote_currencies", "active_only"]

ARGS_CREATE_USERDIR = ["user_data_dir"]

Expand Down
14 changes: 8 additions & 6 deletions freqtrade/configuration/cli_options.py
Expand Up @@ -273,13 +273,15 @@ def __init__(self, *args, **kwargs):
help='Print exchange pair or market data in the csv format.',
action='store_true',
),
"quote_currency": Arg(
'--quote-currency',
help='Select quote currency.',
"quote_currencies": Arg(
'--quote',
help='Specify quote currency(-ies). Space-separated list.',
nargs='+',
),
"base_currency": Arg(
'--base-currency',
help='Select base currency.',
"base_currencies": Arg(
'--base',
help='Specify base currency(-ies). Space-separated list.',
nargs='+',
),
"active_only": Arg(
'--active-only',
Expand Down
10 changes: 5 additions & 5 deletions freqtrade/exchange/exchange.py
Expand Up @@ -280,7 +280,7 @@ def markets(self) -> Dict:
self._load_markets()
return self._api.markets

def get_markets(self, base_currency: str = None, quote_currency: str = None,
def get_markets(self, base_currencies: List[str] = None, quote_currencies: List[str] = None,
pairs_only: bool = False, active_only: bool = False) -> Dict:
"""
Return exchange ccxt markets, filtered out by base currency and quote currency
Expand All @@ -292,10 +292,10 @@ def get_markets(self, base_currency: str = None, quote_currency: str = None,
if not markets:
raise OperationalException("Markets were not loaded.")

if base_currency:
markets = {k: v for k, v in markets.items() if v['base'] == base_currency}
if quote_currency:
markets = {k: v for k, v in markets.items() if v['quote'] == quote_currency}
if base_currencies:
markets = {k: v for k, v in markets.items() if v['base'] in base_currencies}
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)}
if active_only:
Expand Down
18 changes: 11 additions & 7 deletions freqtrade/utils.py
Expand Up @@ -137,12 +137,12 @@ def start_list_pairs(args: Dict[str, Any], pairs_only: bool = False) -> None: #
exchange = ExchangeResolver(config['exchange']['name'], config).exchange

active_only = args.get('active_only', False)
base_currency = args.get('base_currency', '')
quote_currency = args.get('quote_currency', '')
base_currencies = args.get('base_currencies', [])
quote_currencies = args.get('quote_currencies', [])

try:
pairs = exchange.get_markets(base_currency=base_currency,
quote_currency=quote_currency,
pairs = exchange.get_markets(base_currencies=base_currencies,
quote_currencies=quote_currencies,
pairs_only=pairs_only,
active_only=active_only)
except Exception as e:
Expand All @@ -152,9 +152,13 @@ def start_list_pairs(args: Dict[str, Any], pairs_only: bool = False) -> None: #
summary_str = ((f"Exchange {exchange.name} has {len(pairs)} ") +
("active " if active_only else "") +
(plural(len(pairs), "pair" if pairs_only else "market")) +
(f" with {base_currency} as base currency" if base_currency else "") +
(" and" if base_currency and quote_currency else "") +
(f" with {quote_currency} as quote currency" if quote_currency else ""))
(f" with {', '.join(base_currencies)} as base "
f"{plural(len(base_currencies), 'currency', 'currencies')}"
if base_currencies else "") +
(" and" if base_currencies and quote_currencies else "") +
(f" with {', '.join(quote_currencies)} as quote "
f"{plural(len(quote_currencies), 'currency', 'currencies')}"
if quote_currencies else ""))

headers = ["Id", "Symbol", "Base", "Quote", "Active",
*(['Is pair'] if not pairs_only else [])]
Expand Down

0 comments on commit 92fda0f

Please sign in to comment.