From 2fbbeb970bb768de7c7efb3ed6b1ca2b0c922363 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 4 Dec 2020 07:42:16 +0100 Subject: [PATCH] Gracefully handle cases where no buy price was found closes #4030 --- freqtrade/freqtradebot.py | 3 +++ tests/test_freqtradebot.py | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 7416d8236..c8d281852 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -616,6 +616,9 @@ class FreqtradeBot: # Calculate price buy_limit_requested = self.get_buy_rate(pair, True) + if not buy_limit_requested: + raise PricingError('Could not determine buy price.') + min_stake_amount = self._get_min_pair_stake_amount(pair, buy_limit_requested) if min_stake_amount is not None and min_stake_amount > stake_amount: logger.warning( diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index 64dfb016e..6adef510f 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -1074,6 +1074,12 @@ def test_execute_buy(mocker, default_conf, fee, limit_buy_order, limit_buy_order mocker.patch('freqtrade.exchange.Exchange.buy', MagicMock(return_value=limit_buy_order)) assert not freqtrade.execute_buy(pair, stake_amount) + # Fail to get price... + mocker.patch('freqtrade.freqtradebot.FreqtradeBot.get_buy_rate', MagicMock(return_value=0.0)) + + with pytest.raises(PricingError, match="Could not determine buy price."): + freqtrade.execute_buy(pair, stake_amount) + def test_execute_buy_confirm_error(mocker, default_conf, fee, limit_buy_order) -> None: freqtrade = get_patched_freqtradebot(mocker, default_conf)