Verify sell-rate got a value - otherwise downstream code does not work.

Using PricingException here will cease operation for this pair for this
iteration - postponing handling to the next iteration - where hopefully
a price is again present.
This commit is contained in:
Matthias 2020-06-01 19:45:37 +02:00
parent 84c50bf16c
commit c35f9f8d39
2 changed files with 22 additions and 0 deletions

View File

@ -676,6 +676,8 @@ class FreqtradeBot:
raise PricingError from e raise PricingError from e
else: else:
rate = self.exchange.fetch_ticker(pair)[ask_strategy['price_side']] rate = self.exchange.fetch_ticker(pair)[ask_strategy['price_side']]
if rate is None:
raise PricingError(f"Sell-Rate for {pair} was empty.")
self._sell_rate_cache[pair] = rate self._sell_rate_cache[pair] = rate
return rate return rate

View File

@ -3931,6 +3931,26 @@ def test_get_sell_rate_orderbook_exception(default_conf, mocker, caplog):
assert log_has("Sell Price at location from orderbook could not be determined.", caplog) assert log_has("Sell Price at location from orderbook could not be determined.", caplog)
def test_get_sell_rate_exception(default_conf, mocker, caplog):
# Ticker on one side can be empty in certain circumstances.
default_conf['ask_strategy']['price_side'] = 'ask'
pair = "ETH/BTC"
mocker.patch('freqtrade.exchange.Exchange.fetch_ticker', return_value={'ask': None, 'bid': 0.12})
ft = get_patched_freqtradebot(mocker, default_conf)
with pytest.raises(PricingError, match=r"Sell-Rate for ETH/BTC was empty."):
ft.get_sell_rate(pair, True)
ft.config['ask_strategy']['price_side'] = 'bid'
assert ft.get_sell_rate(pair, True) == 0.12
# Reverse sides
mocker.patch('freqtrade.exchange.Exchange.fetch_ticker', return_value={'ask': 0.13, 'bid': None})
with pytest.raises(PricingError, match=r"Sell-Rate for ETH/BTC was empty."):
ft.get_sell_rate(pair, True)
ft.config['ask_strategy']['price_side'] = 'ask'
assert ft.get_sell_rate(pair, True) == 0.13
def test_startup_state(default_conf, mocker): def test_startup_state(default_conf, mocker):
default_conf['pairlist'] = {'method': 'VolumePairList', default_conf['pairlist'] = {'method': 'VolumePairList',
'config': {'number_assets': 20} 'config': {'number_assets': 20}