From 1283f8cfd4585c8fef9d68b87fcf3903b7c96605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Martin?= <33117460+theomart@users.noreply.github.com> Date: Thu, 15 Apr 2021 00:33:05 +0100 Subject: [PATCH] Correct get_min_pair_stake_amount formula If I understand well, the goal is to have stoploss price above the minimum required by the exchange, which is not what has been achieved so far. Only if amount_reserve_percent = (1 + pad) / (1 - abs(stoploss)) we get final stake amount * (1 - abs(stoploss)) > minimum required. Here is a code example, with numbers from the example in the doc for this function: stoploss = 0.1 padding = 0.05 min_required_exchange_cost = 10 min_required_exchange_amount = 12 min_required_exchange = max(min_required_exchange_cost, min_required_exchange_amount) min_required_with_padding = min_required_exchange * (1 + padding) min_stake_amount = min_required_exchange * max(min(padding + stoploss + 1, 1.5), 1) stoploss_price = min_stake_amount*(1-stoploss) print(f'[OLD LOGIC] stoploss_price ({stoploss_price}) < min_required_with_padding ({min_required_with_padding})') min_stake_amount = min_required_exchange * max(min((1+padding) / (1-stoploss), 1.5), 1) stoploss_price = min_stake_amount*(1-stoploss) print(f'[NEW LOGIC] stoploss_price ({stoploss_price}) > min_required_with_padding ({min_required_with_padding})') --- freqtrade/exchange/exchange.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 3958f6838..627bdcf32 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -539,7 +539,7 @@ class Exchange: # reserve some percent defined in config (5% default) + stoploss amount_reserve_percent = 1.0 + self._config.get('amount_reserve_percent', DEFAULT_AMOUNT_RESERVE_PERCENT) - amount_reserve_percent += abs(stoploss) + amount_reserve_percent /= 1 - abs(stoploss) # it should not be more than 50% amount_reserve_percent = max(min(amount_reserve_percent, 1.5), 1)