More sofisticated market_is_pair(), taken from #1989

This commit is contained in:
hroff-1902 2019-10-17 17:49:04 +03:00
parent bd08874f1f
commit 1e61263a28

View File

@ -937,12 +937,17 @@ 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): def market_is_pair(market, base_currency: str = None, quote_currency: str = None):
""" """
Return True if the market is a pair. Check if the market is a pair, i.e. that its symbol consists of the base currency and the
Currently pairs are defined as markets containing '/' character in its symbol. 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
and after the separating character correspondingly.
""" """
return '/' in market.get('symbol', '') symbol_parts = market['symbol'].split('/')
return (len(symbol_parts) == 2 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))
def market_is_active(market): def market_is_active(market):