From d3d17f9f8b19b1ff87bcb4cb705d49363593c49c Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 10 Nov 2021 06:57:22 +0100 Subject: [PATCH] Only allow min-stake adjustments of up to 30% fix #5856 --- docs/configuration.md | 2 +- freqtrade/wallets.py | 9 +++++++++ tests/test_freqtradebot.py | 2 +- tests/test_wallets.py | 3 ++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index f2958f725..6c810fba2 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -214,7 +214,7 @@ With a reserve of 5%, the minimum stake amount would be ~12.6$ (`12 * (1 + 0.05) To limit this calculation in case of large stoploss values, the calculated minimum stake-limit will never be more than 50% above the real limit. !!! Warning - Since the limits on exchanges are usually stable and are not updated often, some pairs can show pretty high minimum limits, simply because the price increased a lot since the last limit adjustment by the exchange. + Since the limits on exchanges are usually stable and are not updated often, some pairs can show pretty high minimum limits, simply because the price increased a lot since the last limit adjustment by the exchange. Freqtrade adjusts the stake-amount to this value, unless it's > 30% more than the calculated/desired stake-amount - in which case the trade is rejected. #### Tradable balance diff --git a/freqtrade/wallets.py b/freqtrade/wallets.py index 4357f2a95..1a124d1bb 100644 --- a/freqtrade/wallets.py +++ b/freqtrade/wallets.py @@ -255,6 +255,15 @@ class Wallets: f"Stake amount for pair {pair} is too small " f"({stake_amount} < {min_stake_amount}), adjusting to {min_stake_amount}." ) + if stake_amount * 1.3 < min_stake_amount: + # Top-cap stake-amount adjustments to +30%. + if self._log: + logger.info( + f"Adjusted stake amount for pair {pair} is more than 30% bigger than " + f"the desired stake ({stake_amount} * 1.3 > {max_stake_amount}), " + f"ignoring trade." + ) + return 0 stake_amount = min_stake_amount if stake_amount > max_stake_amount: diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index a417a46eb..0b3c76736 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -321,7 +321,7 @@ def test_create_trade_no_stake_amount(default_conf_usdt, ticker_usdt, fee, mocke @pytest.mark.parametrize('stake_amount,create,amount_enough,max_open_trades', [ (5.0, True, True, 99), - (0.00005, True, False, 99), + (0.04, True, False, 99), # Amount will be adjusted to min - which is 0.051 (0, False, True, 99), (UNLIMITED_STAKE_AMOUNT, False, True, 0), ]) diff --git a/tests/test_wallets.py b/tests/test_wallets.py index c223a9dd1..3e02cdb09 100644 --- a/tests/test_wallets.py +++ b/tests/test_wallets.py @@ -185,8 +185,9 @@ def test_get_trade_stake_amount_unlimited_amount(default_conf, ticker, balance_r (100, 11, 500, 100), (1000, 11, 500, 500), # Above max-stake (20, 15, 10, 0), # Minimum stake > max-stake - (1, 11, 100, 11), # Below min stake + (9, 11, 100, 11), # Below min stake (1, 15, 10, 0), # Below min stake and min_stake > max_stake + (20, 50, 100, 0), # Below min stake and stake * 1.3 > min_stake ]) def test_validate_stake_amount(mocker, default_conf,