updated a test, put in TODO-lev
This commit is contained in:
parent
362c29c315
commit
7f7f377a90
@ -840,6 +840,7 @@ class IStrategy(ABC, HyperStrategyMixin):
|
|||||||
else:
|
else:
|
||||||
logger.warning("CustomStoploss function did not return valid stoploss")
|
logger.warning("CustomStoploss function did not return valid stoploss")
|
||||||
|
|
||||||
|
# TODO-lev: short
|
||||||
if self.trailing_stop and trade.stop_loss < (low or current_rate):
|
if self.trailing_stop and trade.stop_loss < (low or current_rate):
|
||||||
# trailing stoploss handling
|
# trailing stoploss handling
|
||||||
sl_offset = self.trailing_stop_positive_offset
|
sl_offset = self.trailing_stop_positive_offset
|
||||||
@ -861,6 +862,7 @@ class IStrategy(ABC, HyperStrategyMixin):
|
|||||||
# evaluate if the stoploss was hit if stoploss is not on exchange
|
# evaluate if the stoploss was hit if stoploss is not on exchange
|
||||||
# in Dry-Run, this handles stoploss logic as well, as the logic will not be different to
|
# in Dry-Run, this handles stoploss logic as well, as the logic will not be different to
|
||||||
# regular stoploss handling.
|
# regular stoploss handling.
|
||||||
|
# TODO-lev: short
|
||||||
if ((trade.stop_loss >= (low or current_rate)) and
|
if ((trade.stop_loss >= (low or current_rate)) and
|
||||||
(not self.order_types.get('stoploss_on_exchange') or self.config['dry_run'])):
|
(not self.order_types.get('stoploss_on_exchange') or self.config['dry_run'])):
|
||||||
|
|
||||||
|
@ -3565,11 +3565,13 @@ def test_trailing_stop_loss(default_conf_usdt, limit_order_open,
|
|||||||
assert trade.sell_reason == SellType.TRAILING_STOP_LOSS.value
|
assert trade.sell_reason == SellType.TRAILING_STOP_LOSS.value
|
||||||
|
|
||||||
|
|
||||||
@ pytest.mark.parametrize("is_short", [False, True])
|
@ pytest.mark.parametrize('offset,trail_if_reached,second_sl,is_short', [
|
||||||
@ pytest.mark.parametrize('offset,trail_if_reached,second_sl', [
|
# (0, False, 2.0394, False),
|
||||||
(0, False, 2.0394),
|
# (0.011, False, 2.0394, False),
|
||||||
(0.011, False, 2.0394),
|
# (0.055, True, 1.8, False),
|
||||||
(0.055, True, 1.8),
|
(0, False, 2.1606, True),
|
||||||
|
(0.011, False, 2.1606, True),
|
||||||
|
(0.055, True, 2.4, True),
|
||||||
])
|
])
|
||||||
def test_trailing_stop_loss_positive(
|
def test_trailing_stop_loss_positive(
|
||||||
default_conf_usdt, limit_order, limit_order_open,
|
default_conf_usdt, limit_order, limit_order_open,
|
||||||
@ -3581,9 +3583,9 @@ def test_trailing_stop_loss_positive(
|
|||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
'freqtrade.exchange.Exchange',
|
'freqtrade.exchange.Exchange',
|
||||||
fetch_ticker=MagicMock(return_value={
|
fetch_ticker=MagicMock(return_value={
|
||||||
'bid': enter_price - 0.01,
|
'bid': enter_price - (-0.01 if is_short else 0.01),
|
||||||
'ask': enter_price - 0.01,
|
'ask': enter_price - (-0.01 if is_short else 0.01),
|
||||||
'last': enter_price - 0.01
|
'last': enter_price - (-0.01 if is_short else 0.01),
|
||||||
}),
|
}),
|
||||||
create_order=MagicMock(side_effect=[
|
create_order=MagicMock(side_effect=[
|
||||||
limit_order_open[enter_side(is_short)],
|
limit_order_open[enter_side(is_short)],
|
||||||
@ -3614,9 +3616,9 @@ def test_trailing_stop_loss_positive(
|
|||||||
mocker.patch(
|
mocker.patch(
|
||||||
'freqtrade.exchange.Exchange.fetch_ticker',
|
'freqtrade.exchange.Exchange.fetch_ticker',
|
||||||
MagicMock(return_value={
|
MagicMock(return_value={
|
||||||
'bid': enter_price + 0.06,
|
'bid': enter_price + (-0.06 if is_short else 0.06),
|
||||||
'ask': enter_price + 0.06,
|
'ask': enter_price + (-0.06 if is_short else 0.06),
|
||||||
'last': enter_price + 0.06
|
'last': enter_price + (-0.06 if is_short else 0.06),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
# stop-loss not reached, adjusted stoploss
|
# stop-loss not reached, adjusted stoploss
|
||||||
@ -3634,9 +3636,9 @@ def test_trailing_stop_loss_positive(
|
|||||||
mocker.patch(
|
mocker.patch(
|
||||||
'freqtrade.exchange.Exchange.fetch_ticker',
|
'freqtrade.exchange.Exchange.fetch_ticker',
|
||||||
MagicMock(return_value={
|
MagicMock(return_value={
|
||||||
'bid': enter_price + 0.125,
|
'bid': enter_price + (-0.125 if is_short else 0.125),
|
||||||
'ask': enter_price + 0.125,
|
'ask': enter_price + (-0.125 if is_short else 0.125),
|
||||||
'last': enter_price + 0.125,
|
'last': enter_price + (-0.125 if is_short else 0.125),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
assert freqtrade.handle_trade(trade) is False
|
assert freqtrade.handle_trade(trade) is False
|
||||||
@ -3649,17 +3651,17 @@ def test_trailing_stop_loss_positive(
|
|||||||
mocker.patch(
|
mocker.patch(
|
||||||
'freqtrade.exchange.Exchange.fetch_ticker',
|
'freqtrade.exchange.Exchange.fetch_ticker',
|
||||||
MagicMock(return_value={
|
MagicMock(return_value={
|
||||||
'bid': enter_price + 0.02,
|
'bid': enter_price + (-0.02 if is_short else 0.02),
|
||||||
'ask': enter_price + 0.02,
|
'ask': enter_price + (-0.02 if is_short else 0.02),
|
||||||
'last': enter_price + 0.02
|
'last': enter_price + (-0.02 if is_short else 0.02),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
# Lower price again (but still positive)
|
# Lower price again (but still positive)
|
||||||
assert freqtrade.handle_trade(trade) is True
|
assert freqtrade.handle_trade(trade) is True
|
||||||
assert log_has(
|
assert log_has(
|
||||||
f"ETH/USDT - HIT STOP: current price at {enter_price + 0.02:.6f}, "
|
f"ETH/USDT - HIT STOP: current price at {enter_price + (-0.02 if is_short else 0.02):.6f}, "
|
||||||
f"stoploss is {trade.stop_loss:.6f}, "
|
f"stoploss is {trade.stop_loss:.6f}, "
|
||||||
f"initial stoploss was at 1.800000, trade opened at 2.000000", caplog)
|
f"initial stoploss was at {2.2 if is_short else 1.8}00000, trade opened at 2.000000", caplog)
|
||||||
assert trade.sell_reason == SellType.TRAILING_STOP_LOSS.value
|
assert trade.sell_reason == SellType.TRAILING_STOP_LOSS.value
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user