Add short-exit logic to backtesting

This commit is contained in:
Matthias
2021-08-24 19:55:00 +02:00
parent eb71ee847c
commit b40f985b13
4 changed files with 42 additions and 22 deletions

View File

@@ -452,27 +452,39 @@ def test_custom_sell(default_conf, fee, caplog) -> None:
)
now = arrow.utcnow().datetime
res = strategy.should_sell(trade, 1, now, False, False, None, None, 0)
res = strategy.should_exit(trade, 1, now,
enter_long=False, enter_short=False,
exit_long=False, exit_short=False,
low=None, high=None)
assert res.sell_flag is False
assert res.sell_type == SellType.NONE
strategy.custom_sell = MagicMock(return_value=True)
res = strategy.should_sell(trade, 1, now, False, False, None, None, 0)
res = strategy.should_exit(trade, 1, now,
enter_long=False, enter_short=False,
exit_long=False, exit_short=False,
low=None, high=None)
assert res.sell_flag is True
assert res.sell_type == SellType.CUSTOM_SELL
assert res.sell_reason == 'custom_sell'
strategy.custom_sell = MagicMock(return_value='hello world')
res = strategy.should_sell(trade, 1, now, False, False, None, None, 0)
res = strategy.should_exit(trade, 1, now,
enter_long=False, enter_short=False,
exit_long=False, exit_short=False,
low=None, high=None)
assert res.sell_type == SellType.CUSTOM_SELL
assert res.sell_flag is True
assert res.sell_reason == 'hello world'
caplog.clear()
strategy.custom_sell = MagicMock(return_value='h' * 100)
res = strategy.should_sell(trade, 1, now, False, False, None, None, 0)
res = strategy.should_exit(trade, 1, now,
enter_long=False, enter_short=False,
exit_long=False, exit_short=False,
low=None, high=None)
assert res.sell_type == SellType.CUSTOM_SELL
assert res.sell_flag is True
assert res.sell_reason == 'h' * 64