diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 99670d612..2225ddd89 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -1399,9 +1399,13 @@ class FreqtradeBot(LoggingMixin): Check if the custom price is of the good type if not return proposed_price :return: valid price for the order """ - if custom_price and (isinstance(custom_price, int) - or isinstance(custom_price, float)): - valid_price = custom_price + if custom_price: + if isinstance(custom_price, int): + valid_price = float(custom_price) + elif isinstance(custom_price, float): + valid_price = custom_price + else: + valid_price = proposed_price else: valid_price = proposed_price diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index 69a4fa530..a67f5b290 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -4588,3 +4588,27 @@ def test_refind_lost_order(mocker, default_conf, fee, caplog): freqtrade.refind_lost_order(trades[4]) assert log_has(f"Error updating {order['id']}.", caplog) + + +def test_get_valid_price(mocker, default_conf) -> None: + patch_RPCManager(mocker) + patch_exchange(mocker) + freqtrade = FreqtradeBot(default_conf) + + custom_price_string = "10" + custom_price_float = 10.0 + custom_price_int = 10 + + proposed_price = 12.2 + + valid_price_from_string = freqtrade.get_valid_price(custom_price_string, proposed_price) + valid_price_from_int = freqtrade.get_valid_price(custom_price_int, proposed_price) + valid_price_from_float = freqtrade.get_valid_price(custom_price_float, proposed_price) + + assert isinstance(valid_price_from_string, float) + assert isinstance(valid_price_from_int, float) + assert isinstance(valid_price_from_float, float) + + assert valid_price_from_string == proposed_price + assert valid_price_from_int == custom_price_int + assert valid_price_from_float == custom_price_float