validate_stake_amount should not be a private method

This commit is contained in:
Matthias 2021-11-10 06:38:24 +01:00
parent c9d974d210
commit 23a566b478
4 changed files with 7 additions and 7 deletions

View File

@ -501,7 +501,7 @@ class FreqtradeBot(LoggingMixin):
pair=pair, current_time=datetime.now(timezone.utc), pair=pair, current_time=datetime.now(timezone.utc),
current_rate=enter_limit_requested, proposed_stake=stake_amount, current_rate=enter_limit_requested, proposed_stake=stake_amount,
min_stake=min_stake_amount, max_stake=max_stake_amount) min_stake=min_stake_amount, max_stake=max_stake_amount)
stake_amount = self.wallets._validate_stake_amount(pair, stake_amount, min_stake_amount) stake_amount = self.wallets.validate_stake_amount(pair, stake_amount, min_stake_amount)
if not stake_amount: if not stake_amount:
return False return False

View File

@ -431,7 +431,7 @@ class Backtesting:
default_retval=stake_amount)( default_retval=stake_amount)(
pair=pair, current_time=row[DATE_IDX].to_pydatetime(), current_rate=row[OPEN_IDX], pair=pair, current_time=row[DATE_IDX].to_pydatetime(), current_rate=row[OPEN_IDX],
proposed_stake=stake_amount, min_stake=min_stake_amount, max_stake=max_stake_amount) proposed_stake=stake_amount, min_stake=min_stake_amount, max_stake=max_stake_amount)
stake_amount = self.wallets._validate_stake_amount(pair, stake_amount, min_stake_amount) stake_amount = self.wallets.validate_stake_amount(pair, stake_amount, min_stake_amount)
if not stake_amount: if not stake_amount:
return None return None

View File

@ -238,7 +238,7 @@ class Wallets:
return self._check_available_stake_amount(stake_amount, available_amount) return self._check_available_stake_amount(stake_amount, available_amount)
def _validate_stake_amount(self, pair, stake_amount, min_stake_amount): def validate_stake_amount(self, pair, stake_amount, min_stake_amount):
if not stake_amount: if not stake_amount:
logger.debug(f"Stake amount is {stake_amount}, ignoring possible trade for {pair}.") logger.debug(f"Stake amount is {stake_amount}, ignoring possible trade for {pair}.")
return 0 return 0
@ -258,10 +258,10 @@ class Wallets:
stake_amount = min_stake_amount stake_amount = min_stake_amount
if stake_amount > max_stake_amount: if stake_amount > max_stake_amount:
stake_amount = max_stake_amount
if self._log: if self._log:
logger.info( logger.info(
f"Stake amount for pair {pair} is too big " f"Stake amount for pair {pair} is too big "
f"({stake_amount} > {max_stake_amount}), adjusting to {max_stake_amount}." f"({stake_amount} > {max_stake_amount}), adjusting to {max_stake_amount}."
) )
stake_amount = max_stake_amount
return stake_amount return stake_amount

View File

@ -189,13 +189,13 @@ def test_get_trade_stake_amount_unlimited_amount(default_conf, ticker, balance_r
(1, 15, 10, 0), # Below min stake and min_stake > max_stake (1, 15, 10, 0), # Below min stake and min_stake > max_stake
]) ])
def test__validate_stake_amount(mocker, default_conf, def test_validate_stake_amount(mocker, default_conf,
stake_amount, min_stake_amount, max_stake_amount, expected): stake_amount, min_stake_amount, max_stake_amount, expected):
freqtrade = get_patched_freqtradebot(mocker, default_conf) freqtrade = get_patched_freqtradebot(mocker, default_conf)
mocker.patch("freqtrade.wallets.Wallets.get_available_stake_amount", mocker.patch("freqtrade.wallets.Wallets.get_available_stake_amount",
return_value=max_stake_amount) return_value=max_stake_amount)
res = freqtrade.wallets._validate_stake_amount('XRP/USDT', stake_amount, min_stake_amount) res = freqtrade.wallets.validate_stake_amount('XRP/USDT', stake_amount, min_stake_amount)
assert res == expected assert res == expected