Simplify code, no longer log "could not find rate"

closes #9031
This commit is contained in:
Matthias
2023-08-12 16:10:37 +02:00
parent 716b1cd002
commit 72bd4e816d
3 changed files with 10 additions and 14 deletions
+2 -2
View File
@@ -568,7 +568,7 @@ class Exchange:
for pair in [f"{curr_1}/{curr_2}", f"{curr_2}/{curr_1}"]: for pair in [f"{curr_1}/{curr_2}", f"{curr_2}/{curr_1}"]:
if pair in self.markets and self.markets[pair].get('active'): if pair in self.markets and self.markets[pair].get('active'):
return pair 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: def validate_timeframes(self, timeframe: Optional[str]) -> None:
""" """
@@ -1864,7 +1864,7 @@ class Exchange:
tick = self.fetch_ticker(comb) tick = self.fetch_ticker(comb)
fee_to_quote_rate = safe_value_fallback2(tick, tick, 'last', 'ask') 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) fee_to_quote_rate = self._config['exchange'].get('unknown_fee_rate', None)
if not fee_to_quote_rate: if not fee_to_quote_rate:
return None return None
+7 -11
View File
@@ -605,17 +605,13 @@ class RPC:
est_stake = balance.free est_stake = balance.free
est_bot_stake = amount est_bot_stake = amount
else: else:
try: pair = self._freqtrade.exchange.get_valid_pair_combination(coin, stake_currency)
pair = self._freqtrade.exchange.get_valid_pair_combination(coin, stake_currency) rate: Optional[float] = tickers.get(pair, {}).get('last', None)
rate: Optional[float] = tickers.get(pair, {}).get('last', None) if rate:
if rate: if pair.startswith(stake_currency) and not pair.endswith(stake_currency):
if pair.startswith(stake_currency) and not pair.endswith(stake_currency): rate = 1.0 / rate
rate = 1.0 / rate est_stake = rate * balance.total
est_stake = rate * balance.total est_bot_stake = rate * amount
est_bot_stake = rate * amount
except (ExchangeError):
logger.warning(f"Could not get rate for pair {coin}.")
raise ValueError()
return est_stake, est_bot_stake return est_stake, est_bot_stake
+1 -1
View File
@@ -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("ETH", "BTC") == "ETH/BTC"
assert ex.get_valid_pair_combination("BTC", "ETH") == "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") ex.get_valid_pair_combination("NOPAIR", "ETH")