Merge pull request #1902 from freqtrade/fix_tsl_offset_on_reason
Trailing stoploss sell reason fixed.
This commit is contained in:
commit
9967df8f45
@ -329,8 +329,9 @@ class IStrategy(ABC):
|
|||||||
(not self.order_types.get('stoploss_on_exchange'))):
|
(not self.order_types.get('stoploss_on_exchange'))):
|
||||||
|
|
||||||
selltype = SellType.STOP_LOSS
|
selltype = SellType.STOP_LOSS
|
||||||
# If Trailing stop (and max-rate did move above open rate)
|
|
||||||
if trailing_stop and trade.open_rate != trade.max_rate:
|
# If initial stoploss is not the same as current one then it is trailing.
|
||||||
|
if trade.initial_stop_loss != trade.stop_loss:
|
||||||
selltype = SellType.TRAILING_STOP_LOSS
|
selltype = SellType.TRAILING_STOP_LOSS
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"HIT STOP: current price at {current_rate:.6f}, "
|
f"HIT STOP: current price at {current_rate:.6f}, "
|
||||||
|
@ -2484,9 +2484,9 @@ def test_trailing_stop_loss(default_conf, limit_buy_order, fee, markets, caplog,
|
|||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
'freqtrade.exchange.Exchange',
|
'freqtrade.exchange.Exchange',
|
||||||
get_ticker=MagicMock(return_value={
|
get_ticker=MagicMock(return_value={
|
||||||
'bid': 0.00000102,
|
'bid': 0.00001099,
|
||||||
'ask': 0.00000103,
|
'ask': 0.00001099,
|
||||||
'last': 0.00000102
|
'last': 0.00001099
|
||||||
}),
|
}),
|
||||||
buy=MagicMock(return_value={'id': limit_buy_order['id']}),
|
buy=MagicMock(return_value={'id': limit_buy_order['id']}),
|
||||||
get_fee=fee,
|
get_fee=fee,
|
||||||
@ -2498,15 +2498,33 @@ def test_trailing_stop_loss(default_conf, limit_buy_order, fee, markets, caplog,
|
|||||||
freqtrade.strategy.min_roi_reached = MagicMock(return_value=False)
|
freqtrade.strategy.min_roi_reached = MagicMock(return_value=False)
|
||||||
|
|
||||||
freqtrade.create_trade()
|
freqtrade.create_trade()
|
||||||
|
|
||||||
trade = Trade.query.first()
|
trade = Trade.query.first()
|
||||||
trade.update(limit_buy_order)
|
assert freqtrade.handle_trade(trade) is False
|
||||||
trade.max_rate = trade.open_rate * 1.003
|
|
||||||
|
# Raise ticker above buy price
|
||||||
|
mocker.patch('freqtrade.exchange.Exchange.get_ticker',
|
||||||
|
MagicMock(return_value={
|
||||||
|
'bid': 0.00001099 * 1.5,
|
||||||
|
'ask': 0.00001099 * 1.5,
|
||||||
|
'last': 0.00001099 * 1.5
|
||||||
|
}))
|
||||||
|
|
||||||
|
# Stoploss should be adjusted
|
||||||
|
assert freqtrade.handle_trade(trade) is False
|
||||||
|
|
||||||
|
# Price fell
|
||||||
|
mocker.patch('freqtrade.exchange.Exchange.get_ticker',
|
||||||
|
MagicMock(return_value={
|
||||||
|
'bid': 0.00001099 * 1.1,
|
||||||
|
'ask': 0.00001099 * 1.1,
|
||||||
|
'last': 0.00001099 * 1.1
|
||||||
|
}))
|
||||||
|
|
||||||
caplog.set_level(logging.DEBUG)
|
caplog.set_level(logging.DEBUG)
|
||||||
# Sell as trailing-stop is reached
|
# Sell as trailing-stop is reached
|
||||||
assert freqtrade.handle_trade(trade) is True
|
assert freqtrade.handle_trade(trade) is True
|
||||||
assert log_has(
|
assert log_has(
|
||||||
f'HIT STOP: current price at 0.000001, stop loss is {trade.stop_loss:.6f}, '
|
f'HIT STOP: current price at 0.000012, stop loss is 0.000015, '
|
||||||
f'initial stop loss was at 0.000010, trade opened at 0.000011', caplog.record_tuples)
|
f'initial stop loss was at 0.000010, trade opened at 0.000011', caplog.record_tuples)
|
||||||
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