Improve emergency_exit handling
This commit is contained in:
parent
b23cea6e59
commit
5c280d5649
@ -1122,8 +1122,7 @@ class FreqtradeBot(LoggingMixin):
|
|||||||
trade.stoploss_order_id = None
|
trade.stoploss_order_id = None
|
||||||
logger.error(f'Unable to place a stoploss order on exchange. {e}')
|
logger.error(f'Unable to place a stoploss order on exchange. {e}')
|
||||||
logger.warning('Exiting the trade forcefully')
|
logger.warning('Exiting the trade forcefully')
|
||||||
self.execute_trade_exit(trade, stop_price, exit_check=ExitCheckTuple(
|
self.emergency_exit(trade, stop_price)
|
||||||
exit_type=ExitType.EMERGENCY_EXIT))
|
|
||||||
|
|
||||||
except ExchangeError:
|
except ExchangeError:
|
||||||
trade.stoploss_order_id = None
|
trade.stoploss_order_id = None
|
||||||
@ -1281,13 +1280,16 @@ class FreqtradeBot(LoggingMixin):
|
|||||||
if canceled and max_timeouts > 0 and canceled_count >= max_timeouts:
|
if canceled and max_timeouts > 0 and canceled_count >= max_timeouts:
|
||||||
logger.warning(f'Emergency exiting trade {trade}, as the exit order '
|
logger.warning(f'Emergency exiting trade {trade}, as the exit order '
|
||||||
f'timed out {max_timeouts} times.')
|
f'timed out {max_timeouts} times.')
|
||||||
try:
|
self.emergency_exit(trade, order['price'])
|
||||||
self.execute_trade_exit(
|
|
||||||
trade, order['price'],
|
def emergency_exit(self, trade: Trade, price: float) -> None:
|
||||||
exit_check=ExitCheckTuple(exit_type=ExitType.EMERGENCY_EXIT))
|
try:
|
||||||
except DependencyException as exception:
|
self.execute_trade_exit(
|
||||||
logger.warning(
|
trade, price,
|
||||||
f'Unable to emergency sell trade {trade.pair}: {exception}')
|
exit_check=ExitCheckTuple(exit_type=ExitType.EMERGENCY_EXIT))
|
||||||
|
except DependencyException as exception:
|
||||||
|
logger.warning(
|
||||||
|
f'Unable to emergency exit trade {trade.pair}: {exception}')
|
||||||
|
|
||||||
def replace_order(self, order: Dict, order_obj: Optional[Order], trade: Trade) -> None:
|
def replace_order(self, order: Dict, order_obj: Optional[Order], trade: Trade) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -2724,21 +2724,21 @@ def test_manage_open_orders_exit_usercustom(
|
|||||||
assert freqtrade.strategy.check_exit_timeout.call_count == 1
|
assert freqtrade.strategy.check_exit_timeout.call_count == 1
|
||||||
assert freqtrade.strategy.check_entry_timeout.call_count == 0
|
assert freqtrade.strategy.check_entry_timeout.call_count == 0
|
||||||
|
|
||||||
# 2nd canceled trade - Fail execute sell
|
# 2nd canceled trade - Fail execute exit
|
||||||
caplog.clear()
|
caplog.clear()
|
||||||
open_trade_usdt.open_order_id = limit_sell_order_old['id']
|
open_trade_usdt.open_order_id = limit_sell_order_old['id']
|
||||||
mocker.patch('freqtrade.persistence.Trade.get_exit_order_count', return_value=1)
|
mocker.patch('freqtrade.persistence.Trade.get_exit_order_count', return_value=1)
|
||||||
mocker.patch('freqtrade.freqtradebot.FreqtradeBot.execute_trade_exit',
|
mocker.patch('freqtrade.freqtradebot.FreqtradeBot.execute_trade_exit',
|
||||||
side_effect=DependencyException)
|
side_effect=DependencyException)
|
||||||
freqtrade.manage_open_orders()
|
freqtrade.manage_open_orders()
|
||||||
assert log_has_re('Unable to emergency sell .*', caplog)
|
assert log_has_re('Unable to emergency exit .*', caplog)
|
||||||
|
|
||||||
et_mock = mocker.patch('freqtrade.freqtradebot.FreqtradeBot.execute_trade_exit')
|
et_mock = mocker.patch('freqtrade.freqtradebot.FreqtradeBot.execute_trade_exit')
|
||||||
caplog.clear()
|
caplog.clear()
|
||||||
# 2nd canceled trade ...
|
# 2nd canceled trade ...
|
||||||
open_trade_usdt.open_order_id = limit_sell_order_old['id']
|
open_trade_usdt.open_order_id = limit_sell_order_old['id']
|
||||||
|
|
||||||
# If cancelling fails - no emergency sell!
|
# If cancelling fails - no emergency exit!
|
||||||
with patch('freqtrade.freqtradebot.FreqtradeBot.handle_cancel_exit', return_value=False):
|
with patch('freqtrade.freqtradebot.FreqtradeBot.handle_cancel_exit', return_value=False):
|
||||||
freqtrade.manage_open_orders()
|
freqtrade.manage_open_orders()
|
||||||
assert et_mock.call_count == 0
|
assert et_mock.call_count == 0
|
||||||
|
Loading…
Reference in New Issue
Block a user