From 772800bf749ecc08a3f082683e111a504e695c01 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 21 Jan 2023 08:52:10 +0100 Subject: [PATCH] Fix bug in stake_amount adjustment This was preventing a DCA order to take the remaining stake --- freqtrade/wallets.py | 14 +++++++------- tests/test_wallets.py | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/freqtrade/wallets.py b/freqtrade/wallets.py index 97db3fba5..8dcc92af4 100644 --- a/freqtrade/wallets.py +++ b/freqtrade/wallets.py @@ -297,16 +297,16 @@ class Wallets: logger.debug(f"Stake amount is {stake_amount}, ignoring possible trade for {pair}.") return 0 - max_stake_amount = min(max_stake_amount, self.get_available_stake_amount()) + max_allowed_stake = min(max_stake_amount, self.get_available_stake_amount()) if trade_amount: # if in a trade, then the resulting trade size cannot go beyond the max stake # Otherwise we could no longer exit. - max_stake_amount = min(max_stake_amount, max_stake_amount - trade_amount) + max_allowed_stake = min(max_allowed_stake, max_stake_amount - trade_amount) - if min_stake_amount is not None and min_stake_amount > max_stake_amount: + if min_stake_amount is not None and min_stake_amount > max_allowed_stake: if self._log: logger.warning("Minimum stake amount > available balance. " - f"{min_stake_amount} > {max_stake_amount}") + f"{min_stake_amount} > {max_allowed_stake}") return 0 if min_stake_amount is not None and stake_amount < min_stake_amount: if self._log: @@ -325,11 +325,11 @@ class Wallets: return 0 stake_amount = min_stake_amount - if stake_amount > max_stake_amount: + if stake_amount > max_allowed_stake: if self._log: logger.info( f"Stake amount for pair {pair} is too big " - f"({stake_amount} > {max_stake_amount}), adjusting to {max_stake_amount}." + f"({stake_amount} > {max_allowed_stake}), adjusting to {max_allowed_stake}." ) - stake_amount = max_stake_amount + stake_amount = max_allowed_stake return stake_amount diff --git a/tests/test_wallets.py b/tests/test_wallets.py index 0117f7427..61e8f279d 100644 --- a/tests/test_wallets.py +++ b/tests/test_wallets.py @@ -190,7 +190,7 @@ def test_get_trade_stake_amount_unlimited_amount(default_conf, ticker, balance_r (1, 15, 10, 10000, None, 0), # Below min stake and min_stake > stake_available (20, 50, 100, 10000, None, 0), # Below min stake and stake * 1.3 > min_stake (1000, None, 1000, 10000, None, 1000), # No min-stake-amount could be determined - (2000, 15, 2000, 3000, 1500, 500), # Rebuy - resulting in too high stake amount. Adjusting. + (2000, 15, 2000, 3000, 1500, 1500), # Rebuy - resulting in too high stake amount. Adjusting. ]) def test_validate_stake_amount( mocker,