From 78a1551798abb05687822050be8efa08774cce56 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 2 Apr 2023 16:45:42 +0200 Subject: [PATCH] Reorder get_stake_limit --- freqtrade/exchange/exchange.py | 36 ++++++++++++++-------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 437ed4289..2d2fa3354 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -788,27 +788,6 @@ class Exchange: except KeyError: raise ValueError(f"Can't get market information for symbol {pair}") - stake_limits = [] - limits = market['limits'] - if (limits['cost'][limit] is not None): - stake_limits.append( - self._contracts_to_amount( - pair, - limits['cost'][limit] - ) - ) - - if (limits['amount'][limit] is not None): - stake_limits.append( - self._contracts_to_amount( - pair, - limits['amount'][limit] * price - ) - ) - - if not stake_limits: - return None if isMin else float('inf') - # reserve some percent defined in config (5% default) + stoploss amount_reserve_percent = 1.0 + self._config.get('amount_reserve_percent', DEFAULT_AMOUNT_RESERVE_PERCENT) @@ -818,6 +797,21 @@ class Exchange: # it should not be more than 50% amount_reserve_percent = max(min(amount_reserve_percent, 1.5), 1) + stake_limits = [] + limits = market['limits'] + if (limits['cost'][limit] is not None): + stake_limits.append( + self._contracts_to_amount(pair, limits['cost'][limit]) + ) + + if (limits['amount'][limit] is not None): + stake_limits.append( + self._contracts_to_amount(pair, limits['amount'][limit] * price) + ) + + if not stake_limits: + return None if isMin else float('inf') + # The value returned should satisfy both limits: for amount (base currency) and # for cost (quote, stake currency), so max() is used here. # See also #2575 at github.