Changesets · Branches · Tags · Compare
| Changeset | dc83fdeebe0d7fef581edaac83fd1972559cf268ed12f938c55115f1e02a1139 |
|---|---|
| Author | Matthias <xmatthias@outlook.com> · 2021-04-16 13:49 +02:00 |
| Committer | GitHub <noreply@github.com> · 2021-04-16 13:49 +02:00 |
| Parents | 946fd3742da3, 5bdce1b69517 |
3 files changed
modified docs/configuration.md +1 −1
| @@ -167,7 +167,7 @@ | ||
| 167 | 167 | |
| 168 | 168 | 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%). |
| 169 | 169 | |
| 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)`). | |
| 171 | 171 | |
| 172 | 172 | 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. |
| 173 | 173 |
modified freqtrade/exchange/exchange.py +3 −1
| @@ -539,7 +539,9 @@ | ||
| 539 | 539 | # reserve some percent defined in config (5% default) + stoploss |
| 540 | 540 | amount_reserve_percent = 1.0 + self._config.get('amount_reserve_percent', |
| 541 | 541 | 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 | + ) | |
| 543 | 545 | # it should not be more than 50% |
| 544 | 546 | amount_reserve_percent = max(min(amount_reserve_percent, 1.5), 1) |
| 545 | 547 |
modified tests/exchange/test_exchange.py +9 −6
| @@ -371,7 +371,7 @@ | ||
| 371 | 371 | PropertyMock(return_value=markets) |
| 372 | 372 | ) |
| 373 | 373 | 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))) | |
| 375 | 375 | |
| 376 | 376 | # min amount is set |
| 377 | 377 | markets["ETH/BTC"]["limits"] = { |
| @@ -383,7 +383,7 @@ | ||
| 383 | 383 | PropertyMock(return_value=markets) |
| 384 | 384 | ) |
| 385 | 385 | 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))) | |
| 387 | 387 | |
| 388 | 388 | # min amount and cost are set (cost is minimal) |
| 389 | 389 | markets["ETH/BTC"]["limits"] = { |
| @@ -395,7 +395,7 @@ | ||
| 395 | 395 | PropertyMock(return_value=markets) |
| 396 | 396 | ) |
| 397 | 397 | 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))) | |
| 399 | 399 | |
| 400 | 400 | # min amount and cost are set (amount is minial) |
| 401 | 401 | markets["ETH/BTC"]["limits"] = { |
| @@ -407,10 +407,10 @@ | ||
| 407 | 407 | PropertyMock(return_value=markets) |
| 408 | 408 | ) |
| 409 | 409 | 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))) | |
| 411 | 411 | |
| 412 | 412 | 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) | |
| 414 | 414 | |
| 415 | 415 | # Really big stoploss |
| 416 | 416 | result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, -1) |
| @@ -432,7 +432,10 @@ | ||
| 432 | 432 | PropertyMock(return_value=markets) |
| 433 | 433 | ) |
| 434 | 434 | 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 | + ) | |
| 436 | 439 | |
| 437 | 440 | |
| 438 | 441 | def test_set_sandbox(default_conf, mocker): |