Elffuss BraidHub

kikocis/freqtrade public

Merge pull request #4742 from theomart/patch-2

Correct get_min_pair_stake_amount formula
Changesetdc83fdeebe0d7fef581edaac83fd1972559cf268ed12f938c55115f1e02a1139
AuthorMatthias <xmatthias@outlook.com> · 2021-04-16 13:49 +02:00
CommitterGitHub <noreply@github.com> · 2021-04-16 13:49 +02:00
Parents946fd3742da3, 5bdce1b69517

Browse the files at this changeset

3 files changed

modified docs/configuration.md +1 −1
@@ -167,7 +167,7 @@
167167
168168 To guarantee safe execution, freqtrade will not allow buying with a stake-amount of 10.1$, instead, it'll make sure that there's enough space to place a stoploss below the pair (+ an offset, defined by `amount_reserve_percent`, which defaults to 5%).
169169
170-With a stoploss of 10% - we'd therefore end up with a value of ~13.8$ (`12 * (1 + 0.05 + 0.1)`).
170+With a reserve of 5%, the minimum stake amount would be ~12.6$ (`12 * (1 + 0.05)`). If we take in account a stoploss of 10% on top of that - we'd end up with a value of ~14$ (`12.6 / (1 - 0.1)`).
171171
172172 To limit this calculation in case of large stoploss values, the calculated minimum stake-limit will never be more than 50% above the real limit.
173173
modified freqtrade/exchange/exchange.py +3 −1
@@ -539,7 +539,9 @@
539539 # reserve some percent defined in config (5% default) + stoploss
540540 amount_reserve_percent = 1.0 + self._config.get('amount_reserve_percent',
541541 DEFAULT_AMOUNT_RESERVE_PERCENT)
542- amount_reserve_percent += abs(stoploss)
542+ amount_reserve_percent = (
543+ amount_reserve_percent / (1 - abs(stoploss)) if abs(stoploss) != 1 else 1.5
544+ )
543545 # it should not be more than 50%
544546 amount_reserve_percent = max(min(amount_reserve_percent, 1.5), 1)
545547
modified tests/exchange/test_exchange.py +9 −6
@@ -371,7 +371,7 @@
371371 PropertyMock(return_value=markets)
372372 )
373373 result = exchange.get_min_pair_stake_amount('ETH/BTC', 1, stoploss)
374- assert isclose(result, 2 * 1.1)
374+ assert isclose(result, 2 * (1+0.05) / (1-abs(stoploss)))
375375
376376 # min amount is set
377377 markets["ETH/BTC"]["limits"] = {
@@ -383,7 +383,7 @@
383383 PropertyMock(return_value=markets)
384384 )
385385 result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, stoploss)
386- assert isclose(result, 2 * 2 * 1.1)
386+ assert isclose(result, 2 * 2 * (1+0.05) / (1-abs(stoploss)))
387387
388388 # min amount and cost are set (cost is minimal)
389389 markets["ETH/BTC"]["limits"] = {
@@ -395,7 +395,7 @@
395395 PropertyMock(return_value=markets)
396396 )
397397 result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, stoploss)
398- assert isclose(result, max(2, 2 * 2) * 1.1)
398+ assert isclose(result, max(2, 2 * 2) * (1+0.05) / (1-abs(stoploss)))
399399
400400 # min amount and cost are set (amount is minial)
401401 markets["ETH/BTC"]["limits"] = {
@@ -407,10 +407,10 @@
407407 PropertyMock(return_value=markets)
408408 )
409409 result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, stoploss)
410- assert isclose(result, max(8, 2 * 2) * 1.1)
410+ assert isclose(result, max(8, 2 * 2) * (1+0.05) / (1-abs(stoploss)))
411411
412412 result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, -0.4)
413- assert isclose(result, max(8, 2 * 2) * 1.45)
413+ assert isclose(result, max(8, 2 * 2) * 1.5)
414414
415415 # Really big stoploss
416416 result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, -1)
@@ -432,7 +432,10 @@
432432 PropertyMock(return_value=markets)
433433 )
434434 result = exchange.get_min_pair_stake_amount('ETH/BTC', 0.020405, stoploss)
435- assert round(result, 8) == round(max(0.0001, 0.001 * 0.020405) * 1.1, 8)
435+ assert round(result, 8) == round(
436+ max(0.0001, 0.001 * 0.020405) * (1+0.05) / (1-abs(stoploss)),
437+ 8
438+ )
436439
437440
438441 def test_set_sandbox(default_conf, mocker):