From fcdbe846e51a9c76f86c97b84dec28680d857a71 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 3 Jul 2019 20:06:50 +0200 Subject: [PATCH] Fix #1981 - Detect reverted currency pairs --- freqtrade/exchange/exchange.py | 11 ++++++++++- freqtrade/rpc/rpc.py | 7 ++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index c3171b961..536a707cd 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -270,6 +270,15 @@ class Exchange(object): f'Pair {pair} is not available on {self.name}. ' f'Please remove {pair} from your whitelist.') + def get_valid_pair_combination(self, paira, pairb) -> str: + """ + Get valid combination of paira and pairb by trying both combinations. + """ + for pair in [f"{paira}/{pairb}", f"{pairb}/{paira}"]: + if pair in self._api.markets and self._api.markets[pair].get('active'): + return pair + raise DependencyException(f"Could not combine {paira} and {pairb} to get a valid pair.") + def validate_timeframes(self, timeframe: List[str]) -> None: """ Checks if ticker interval from config is a supported timeframe on the exchange @@ -501,7 +510,7 @@ class Exchange(object): def get_ticker(self, pair: str, refresh: Optional[bool] = True) -> dict: if refresh or pair not in self._cached_ticker.keys(): try: - if pair not in self._api.markets: + if pair not in self._api.markets or not self._api.markets[pair].get('active'): raise DependencyException(f"Pair {pair} not available") data = self._api.fetch_ticker(pair) try: diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index f5adffc65..f77e0eddb 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -281,10 +281,11 @@ class RPC(object): rate = 1.0 else: try: - if coin in('USDT', 'USD', 'EUR'): - rate = 1.0 / self._freqtrade.get_sell_rate('BTC/' + coin, False) + pair = self._freqtrade.exchange.get_valid_pair_combination(coin, "BTC") + if pair.startswith("BTC"): + rate = 1.0 / self._freqtrade.get_sell_rate(pair, False) else: - rate = self._freqtrade.get_sell_rate(coin + '/BTC', False) + rate = self._freqtrade.get_sell_rate(pair, False) except (TemporaryError, DependencyException): logger.warning(f" Could not get rate for pair {coin}.") continue