Split up tests for adjust_stoploss and adjust_highlow

This commit is contained in:
Matthias 2019-03-16 20:04:55 +01:00
parent 68a9b14eca
commit 01733c94fa

View File

@ -510,7 +510,7 @@ def test_migrate_new(mocker, default_conf, fee, caplog):
assert trade.pair == "ETC/BTC" assert trade.pair == "ETC/BTC"
assert trade.exchange == "binance" assert trade.exchange == "binance"
assert trade.max_rate == 0.0 assert trade.max_rate == 0.0
assert trade.min_rate == 0.0 assert trade.min_rate is None
assert trade.stop_loss == 0.0 assert trade.stop_loss == 0.0
assert trade.initial_stop_loss == 0.0 assert trade.initial_stop_loss == 0.0
assert trade.sell_reason is None assert trade.sell_reason is None
@ -586,7 +586,48 @@ def test_migrate_mid_state(mocker, default_conf, fee, caplog):
caplog.record_tuples) caplog.record_tuples)
def test_adjust_stop_loss(limit_buy_order, limit_sell_order, fee): def test_adjust_stop_loss(fee):
trade = Trade(
pair='ETH/BTC',
stake_amount=0.001,
fee_open=fee.return_value,
fee_close=fee.return_value,
exchange='bittrex',
open_rate=1,
max_rate=1,
)
trade.adjust_stop_loss(trade.open_rate, 0.05, True)
assert trade.stop_loss == 0.95
assert trade.initial_stop_loss == 0.95
# Get percent of profit with a lower rate
trade.adjust_stop_loss(0.96, 0.05)
assert trade.stop_loss == 0.95
assert trade.initial_stop_loss == 0.95
# Get percent of profit with a custom rate (Higher than open rate)
trade.adjust_stop_loss(1.3, -0.1)
assert round(trade.stop_loss, 8) == 1.17
assert trade.initial_stop_loss == 0.95
# current rate lower again ... should not change
trade.adjust_stop_loss(1.2, 0.1)
assert round(trade.stop_loss, 8) == 1.17
assert trade.initial_stop_loss == 0.95
# current rate higher... should raise stoploss
trade.adjust_stop_loss(1.4, 0.1)
assert round(trade.stop_loss, 8) == 1.26
assert trade.initial_stop_loss == 0.95
# Initial is true but stop_loss set - so doesn't do anything
trade.adjust_stop_loss(1.7, 0.1, True)
assert round(trade.stop_loss, 8) == 1.26
assert trade.initial_stop_loss == 0.95
def test_adjust_high_low(fee):
trade = Trade( trade = Trade(
pair='ETH/BTC', pair='ETH/BTC',
stake_amount=0.001, stake_amount=0.001,
@ -596,40 +637,24 @@ def test_adjust_stop_loss(limit_buy_order, limit_sell_order, fee):
open_rate=1, open_rate=1,
) )
trade.adjust_stop_loss(trade.open_rate, 0.05, True) trade.adjust_high_low(trade.open_rate)
assert trade.stop_loss == 0.95
assert trade.max_rate == 1 assert trade.max_rate == 1
assert trade.initial_stop_loss == 0.95 assert trade.min_rate == 1
# Get percent of profit with a lowre rate # check min adjusted, max remained
trade.adjust_stop_loss(0.96, 0.05) trade.adjust_high_low(0.96)
assert trade.stop_loss == 0.95
assert trade.max_rate == 1 assert trade.max_rate == 1
assert trade.initial_stop_loss == 0.95 assert trade.min_rate == 0.96
# Get percent of profit with a custom rate (Higher than open rate) # check max adjusted, min remains
trade.adjust_stop_loss(1.3, -0.1) trade.adjust_high_low(1.05)
assert round(trade.stop_loss, 8) == 1.17 assert trade.max_rate == 1.05
assert trade.max_rate == 1.3 assert trade.min_rate == 0.96
assert trade.initial_stop_loss == 0.95
# current rate lower again ... should not change # current rate "in the middle" - no adjustment
trade.adjust_stop_loss(1.2, 0.1) trade.adjust_high_low(1.03)
assert round(trade.stop_loss, 8) == 1.17 assert trade.max_rate == 1.05
assert trade.max_rate == 1.3 assert trade.min_rate == 0.96
assert trade.initial_stop_loss == 0.95
# current rate higher... should raise stoploss
trade.adjust_stop_loss(1.4, 0.1)
assert round(trade.stop_loss, 8) == 1.26
assert trade.max_rate == 1.4
assert trade.initial_stop_loss == 0.95
# Initial is true but stop_loss set - so doesn't do anything
trade.adjust_stop_loss(1.7, 0.1, True)
assert round(trade.stop_loss, 8) == 1.26
assert trade.max_rate == 1.4
assert trade.initial_stop_loss == 0.95
def test_get_open(default_conf, fee): def test_get_open(default_conf, fee):