Use dict for symbol_is_pair
This commit is contained in:
parent
9f8b21de4a
commit
f3824d970b
@ -163,7 +163,7 @@ def start_list_markets(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': symbol_is_pair(v['symbol'])}
|
**({'Is pair': symbol_is_pair(v)}
|
||||||
if not pairs_only else {})})
|
if not pairs_only else {})})
|
||||||
|
|
||||||
if (args.get('print_one_column', False) or
|
if (args.get('print_one_column', False) or
|
||||||
|
@ -214,7 +214,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 symbol_is_pair(v['symbol'])}
|
markets = {k: v for k, v in markets.items() if symbol_is_pair(v)}
|
||||||
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
|
||||||
@ -1210,7 +1210,7 @@ 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 symbol_is_pair(market_symbol: str, base_currency: str = None,
|
def symbol_is_pair(market_symbol: Dict[str, Any], base_currency: str = None,
|
||||||
quote_currency: str = None) -> bool:
|
quote_currency: str = None) -> bool:
|
||||||
"""
|
"""
|
||||||
Check if the market symbol 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
|
||||||
@ -1218,10 +1218,12 @@ def symbol_is_pair(market_symbol: str, base_currency: str = None,
|
|||||||
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['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
|
(market_symbol.get('base') == base_currency
|
||||||
(symbol_parts[1] == quote_currency if quote_currency else len(symbol_parts[1]) > 0))
|
if base_currency else len(symbol_parts[0]) > 0) and
|
||||||
|
(market_symbol.get('quote') == quote_currency
|
||||||
|
if quote_currency else len(symbol_parts[1]) > 0))
|
||||||
|
|
||||||
|
|
||||||
def market_is_active(market: Dict) -> bool:
|
def market_is_active(market: Dict) -> bool:
|
||||||
|
Loading…
Reference in New Issue
Block a user