diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index a92bc4a90..0fd1bb120 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -7,6 +7,7 @@ import traceback from datetime import datetime, timezone from math import isclose from threading import Lock +from decimal import Decimal from typing import Any, Dict, List, Optional, Tuple from freqtrade import __version__, constants @@ -481,7 +482,8 @@ class FreqtradeBot(LoggingMixin): if stake_amount is not None and stake_amount < 0.0: # We should decrease our position - amount = abs(stake_amount) / current_exit_rate + # Strategy should return value as Decimal. + amount = abs(float(Decimal(stake_amount) / Decimal(current_exit_rate))) if trade.amount - amount < min_stake_amount: logger.info('Remaining amount would be too small') return diff --git a/tests/exchange/test_exchange.py b/tests/exchange/test_exchange.py index 61fd55e49..157f4c3a8 100644 --- a/tests/exchange/test_exchange.py +++ b/tests/exchange/test_exchange.py @@ -2055,8 +2055,9 @@ def test_get_sell_rate_orderbook_exception(default_conf, mocker, caplog): exchange = get_patched_exchange(mocker, default_conf) with pytest.raises(PricingError): exchange.get_rate(pair, refresh=True, side="sell") - assert log_has_re(rf"{pair} - Sell Price at location 1 from orderbook could not be determined\..*", - caplog) + assert log_has_re( + rf"{pair} - Sell Price at location 1 from orderbook " + rf"could not be determined\..*", caplog) def test_get_sell_rate_exception(default_conf, mocker, caplog):