Allow --base and --quote be lists of currencies

This commit is contained in:
hroff-1902 2019-10-17 02:09:19 +03:00
parent d72d388726
commit 92fda0f76c
4 changed files with 25 additions and 19 deletions

View File

@ -35,7 +35,7 @@ ARGS_LIST_EXCHANGES = ["print_one_column", "list_exchanges_all"]
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"]

View File

@ -273,13 +273,15 @@ AVAILABLE_CLI_OPTIONS = {
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',

View File

@ -280,7 +280,7 @@ class Exchange:
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
@ -292,10 +292,10 @@ class Exchange:
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:

View File

@ -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:
@ -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 [])]