From 72bd4e816d78a0f8976cb8d42e0a4d8f7ba3f537 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 12 Aug 2023 16:10:37 +0200 Subject: [PATCH] Simplify code, no longer log "could not find rate" closes #9031 --- freqtrade/exchange/exchange.py | 4 ++-- freqtrade/rpc/rpc.py | 18 +++++++----------- tests/exchange/test_exchange.py | 2 +- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index afbcff3b6..3f36bd16c 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -568,7 +568,7 @@ class Exchange: for pair in [f"{curr_1}/{curr_2}", f"{curr_2}/{curr_1}"]: if pair in self.markets and self.markets[pair].get('active'): return pair - raise ExchangeError(f"Could not combine {curr_1} and {curr_2} to get a valid pair.") + raise ValueError(f"Could not combine {curr_1} and {curr_2} to get a valid pair.") def validate_timeframes(self, timeframe: Optional[str]) -> None: """ @@ -1864,7 +1864,7 @@ class Exchange: tick = self.fetch_ticker(comb) fee_to_quote_rate = safe_value_fallback2(tick, tick, 'last', 'ask') - except ExchangeError: + except (ValueError, ExchangeError): fee_to_quote_rate = self._config['exchange'].get('unknown_fee_rate', None) if not fee_to_quote_rate: return None diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index 466c99aa1..61f4384b7 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -605,17 +605,13 @@ class RPC: est_stake = balance.free est_bot_stake = amount else: - try: - pair = self._freqtrade.exchange.get_valid_pair_combination(coin, stake_currency) - rate: Optional[float] = tickers.get(pair, {}).get('last', None) - if rate: - if pair.startswith(stake_currency) and not pair.endswith(stake_currency): - rate = 1.0 / rate - est_stake = rate * balance.total - est_bot_stake = rate * amount - except (ExchangeError): - logger.warning(f"Could not get rate for pair {coin}.") - raise ValueError() + pair = self._freqtrade.exchange.get_valid_pair_combination(coin, stake_currency) + rate: Optional[float] = tickers.get(pair, {}).get('last', None) + if rate: + if pair.startswith(stake_currency) and not pair.endswith(stake_currency): + rate = 1.0 / rate + est_stake = rate * balance.total + est_bot_stake = rate * amount return est_stake, est_bot_stake diff --git a/tests/exchange/test_exchange.py b/tests/exchange/test_exchange.py index 85d30a9cd..236576747 100644 --- a/tests/exchange/test_exchange.py +++ b/tests/exchange/test_exchange.py @@ -3522,7 +3522,7 @@ def test_get_valid_pair_combination(default_conf, mocker, markets): assert ex.get_valid_pair_combination("ETH", "BTC") == "ETH/BTC" assert ex.get_valid_pair_combination("BTC", "ETH") == "ETH/BTC" - with pytest.raises(DependencyException, match=r"Could not combine.* to get a valid pair."): + with pytest.raises(ValueError, match=r"Could not combine.* to get a valid pair."): ex.get_valid_pair_combination("NOPAIR", "ETH")