Allow --base and --quote be lists of currencies
This commit is contained in:
parent
d72d388726
commit
92fda0f76c
@ -35,7 +35,7 @@ ARGS_LIST_EXCHANGES = ["print_one_column", "list_exchanges_all"]
|
|||||||
ARGS_LIST_TIMEFRAMES = ["exchange", "print_one_column"]
|
ARGS_LIST_TIMEFRAMES = ["exchange", "print_one_column"]
|
||||||
|
|
||||||
ARGS_LIST_PAIRS = ["exchange", "print_list", "list_pairs_print_json", "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"]
|
ARGS_CREATE_USERDIR = ["user_data_dir"]
|
||||||
|
|
||||||
|
@ -273,13 +273,15 @@ AVAILABLE_CLI_OPTIONS = {
|
|||||||
help='Print exchange pair or market data in the csv format.',
|
help='Print exchange pair or market data in the csv format.',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
),
|
),
|
||||||
"quote_currency": Arg(
|
"quote_currencies": Arg(
|
||||||
'--quote-currency',
|
'--quote',
|
||||||
help='Select quote currency.',
|
help='Specify quote currency(-ies). Space-separated list.',
|
||||||
|
nargs='+',
|
||||||
),
|
),
|
||||||
"base_currency": Arg(
|
"base_currencies": Arg(
|
||||||
'--base-currency',
|
'--base',
|
||||||
help='Select base currency.',
|
help='Specify base currency(-ies). Space-separated list.',
|
||||||
|
nargs='+',
|
||||||
),
|
),
|
||||||
"active_only": Arg(
|
"active_only": Arg(
|
||||||
'--active-only',
|
'--active-only',
|
||||||
|
@ -280,7 +280,7 @@ class Exchange:
|
|||||||
self._load_markets()
|
self._load_markets()
|
||||||
return self._api.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:
|
pairs_only: bool = False, active_only: bool = False) -> Dict:
|
||||||
"""
|
"""
|
||||||
Return exchange ccxt markets, filtered out by base currency and quote currency
|
Return exchange ccxt markets, filtered out by base currency and quote currency
|
||||||
@ -292,10 +292,10 @@ class Exchange:
|
|||||||
if not markets:
|
if not markets:
|
||||||
raise OperationalException("Markets were not loaded.")
|
raise OperationalException("Markets were not loaded.")
|
||||||
|
|
||||||
if base_currency:
|
if base_currencies:
|
||||||
markets = {k: v for k, v in markets.items() if v['base'] == base_currency}
|
markets = {k: v for k, v in markets.items() if v['base'] in base_currencies}
|
||||||
if quote_currency:
|
if quote_currencies:
|
||||||
markets = {k: v for k, v in markets.items() if v['quote'] == quote_currency}
|
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 market_is_pair(v)}
|
||||||
if active_only:
|
if active_only:
|
||||||
|
@ -137,12 +137,12 @@ def start_list_pairs(args: Dict[str, Any], pairs_only: bool = False) -> None: #
|
|||||||
exchange = ExchangeResolver(config['exchange']['name'], config).exchange
|
exchange = ExchangeResolver(config['exchange']['name'], config).exchange
|
||||||
|
|
||||||
active_only = args.get('active_only', False)
|
active_only = args.get('active_only', False)
|
||||||
base_currency = args.get('base_currency', '')
|
base_currencies = args.get('base_currencies', [])
|
||||||
quote_currency = args.get('quote_currency', '')
|
quote_currencies = args.get('quote_currencies', [])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pairs = exchange.get_markets(base_currency=base_currency,
|
pairs = exchange.get_markets(base_currencies=base_currencies,
|
||||||
quote_currency=quote_currency,
|
quote_currencies=quote_currencies,
|
||||||
pairs_only=pairs_only,
|
pairs_only=pairs_only,
|
||||||
active_only=active_only)
|
active_only=active_only)
|
||||||
except Exception as e:
|
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)} ") +
|
summary_str = ((f"Exchange {exchange.name} has {len(pairs)} ") +
|
||||||
("active " if active_only else "") +
|
("active " if active_only else "") +
|
||||||
(plural(len(pairs), "pair" if pairs_only else "market")) +
|
(plural(len(pairs), "pair" if pairs_only else "market")) +
|
||||||
(f" with {base_currency} as base currency" if base_currency else "") +
|
(f" with {', '.join(base_currencies)} as base "
|
||||||
(" and" if base_currency and quote_currency else "") +
|
f"{plural(len(base_currencies), 'currency', 'currencies')}"
|
||||||
(f" with {quote_currency} as quote currency" if quote_currency else ""))
|
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",
|
headers = ["Id", "Symbol", "Base", "Quote", "Active",
|
||||||
*(['Is pair'] if not pairs_only else [])]
|
*(['Is pair'] if not pairs_only else [])]
|
||||||
|
Loading…
Reference in New Issue
Block a user