Fix bug in stake_amount adjustment
This was preventing a DCA order to take the remaining stake
This commit is contained in:
parent
865d678304
commit
772800bf74
@ -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
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user