diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 534fa8425..f2aca0d09 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -976,7 +976,7 @@ class FreqtradeBot(LoggingMixin): trade.stoploss_order_id = None logger.error(f'Unable to place a stoploss order on exchange. {e}') logger.warning('Exiting the trade forcefully') - self.execute_trade_exit(trade, trade.stop_loss, sell_reason=SellCheckTuple( + self.execute_trade_exit(trade, trade.stop_loss, exit_check=SellCheckTuple( sell_type=SellType.EMERGENCY_SELL)) except ExchangeError: @@ -1158,7 +1158,7 @@ class FreqtradeBot(LoggingMixin): try: self.execute_trade_exit( trade, order.get('price'), - sell_reason=SellCheckTuple(sell_type=SellType.EMERGENCY_SELL)) + exit_check=SellCheckTuple(sell_type=SellType.EMERGENCY_SELL)) except DependencyException as exception: logger.warning( f'Unable to emergency sell trade {trade.pair}: {exception}') @@ -1333,7 +1333,7 @@ class FreqtradeBot(LoggingMixin): self, trade: Trade, limit: float, - sell_reason: SellCheckTuple, + exit_check: SellCheckTuple, *, exit_tag: Optional[str] = None, ordertype: Optional[str] = None, @@ -1342,7 +1342,7 @@ class FreqtradeBot(LoggingMixin): Executes a trade exit for the given trade and limit :param trade: Trade instance :param limit: limit rate for the sell order - :param sell_reason: Reason the sell was triggered + :param exit_check: CheckTuple with signal and reason :return: True if it succeeds (supported) False (not supported) """ trade.funding_fees = self.exchange.get_funding_fees( @@ -1352,7 +1352,7 @@ class FreqtradeBot(LoggingMixin): open_date=trade.open_date, ) exit_type = 'exit' - if sell_reason.sell_type in (SellType.STOP_LOSS, SellType.TRAILING_STOP_LOSS): + if exit_check.sell_type in (SellType.STOP_LOSS, SellType.TRAILING_STOP_LOSS): exit_type = 'stoploss' # if stoploss is on exchange and we are on dry_run mode, @@ -1376,7 +1376,7 @@ class FreqtradeBot(LoggingMixin): trade = self.cancel_stoploss_on_exchange(trade) order_type = ordertype or self.strategy.order_types[exit_type] - if sell_reason.sell_type == SellType.EMERGENCY_SELL: + if exit_check.sell_type == SellType.EMERGENCY_SELL: # Emergency sells (default to market!) order_type = self.strategy.order_types.get("emergencyexit", "market") @@ -1385,8 +1385,8 @@ class FreqtradeBot(LoggingMixin): if not strategy_safe_wrapper(self.strategy.confirm_trade_exit, default_retval=True)( pair=trade.pair, trade=trade, order_type=order_type, amount=amount, rate=limit, - time_in_force=time_in_force, exit_reason=sell_reason.sell_reason, - sell_reason=sell_reason.sell_reason, # sellreason -> compatibility + time_in_force=time_in_force, exit_reason=exit_check.sell_reason, + sell_reason=exit_check.sell_reason, # sellreason -> compatibility current_time=datetime.now(timezone.utc)): logger.info(f"User requested abortion of exiting {trade.pair}") return False @@ -1415,7 +1415,7 @@ class FreqtradeBot(LoggingMixin): trade.open_order_id = order['id'] trade.sell_order_status = '' trade.close_rate_requested = limit - trade.sell_reason = exit_tag or sell_reason.sell_reason + trade.sell_reason = exit_tag or exit_check.sell_reason # Lock pair for one candle to prevent immediate re-trading self.strategy.lock_pair(trade.pair, datetime.now(timezone.utc), diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index 753db0d25..2c61c39ad 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -707,12 +707,12 @@ class RPC: # Get current rate and execute sell current_rate = self._freqtrade.exchange.get_rate( trade.pair, refresh=False, side=trade.exit_side) - sell_reason = SellCheckTuple(sell_type=SellType.FORCE_SELL) + exit_check = SellCheckTuple(sell_type=SellType.FORCE_SELL) order_type = ordertype or self._freqtrade.strategy.order_types.get( "forceexit", self._freqtrade.strategy.order_types["exit"]) self._freqtrade.execute_trade_exit( - trade, current_rate, sell_reason, ordertype=order_type) + trade, current_rate, exit_check, ordertype=order_type) # ---- EOF def _exec_forcesell ---- if self._freqtrade.state != State.RUNNING: diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index ebc1a7b2d..feed74a49 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -3100,7 +3100,7 @@ def test_execute_trade_exit_up(default_conf_usdt, ticker_usdt, fee, ticker_usdt_ freqtrade.execute_trade_exit( trade=trade, limit=(ticker_usdt_sell_down()['ask'] if is_short else ticker_usdt_sell_up()['bid']), - sell_reason=SellCheckTuple(sell_type=SellType.ROI) + exit_check=SellCheckTuple(sell_type=SellType.ROI) ) assert rpc_mock.call_count == 0 assert freqtrade.strategy.confirm_trade_exit.call_count == 1 @@ -3112,7 +3112,7 @@ def test_execute_trade_exit_up(default_conf_usdt, ticker_usdt, fee, ticker_usdt_ freqtrade.execute_trade_exit( trade=trade, limit=(ticker_usdt_sell_down()['ask'] if is_short else ticker_usdt_sell_up()['bid']), - sell_reason=SellCheckTuple(sell_type=SellType.ROI) + exit_check=SellCheckTuple(sell_type=SellType.ROI) ) assert freqtrade.strategy.confirm_trade_exit.call_count == 1 @@ -3173,7 +3173,7 @@ def test_execute_trade_exit_down(default_conf_usdt, ticker_usdt, fee, ticker_usd ) freqtrade.execute_trade_exit( trade=trade, limit=(ticker_usdt_sell_up if is_short else ticker_usdt_sell_down)()['bid'], - sell_reason=SellCheckTuple(sell_type=SellType.STOP_LOSS)) + exit_check=SellCheckTuple(sell_type=SellType.STOP_LOSS)) assert rpc_mock.call_count == 2 last_msg = rpc_mock.call_args_list[-1][0][0] @@ -3248,7 +3248,7 @@ def test_execute_trade_exit_custom_exit_price( freqtrade.execute_trade_exit( trade=trade, limit=ticker_usdt_sell_up()['ask' if is_short else 'bid'], - sell_reason=SellCheckTuple(sell_type=SellType.SELL_SIGNAL) + exit_check=SellCheckTuple(sell_type=SellType.SELL_SIGNAL) ) # Sell price must be different to default bid price @@ -3319,7 +3319,7 @@ def test_execute_trade_exit_down_stoploss_on_exchange_dry_run( trade.stop_loss = 2.0 * 1.01 if is_short else 2.0 * 0.99 freqtrade.execute_trade_exit( trade=trade, limit=(ticker_usdt_sell_up if is_short else ticker_usdt_sell_down())['bid'], - sell_reason=SellCheckTuple(sell_type=SellType.STOP_LOSS)) + exit_check=SellCheckTuple(sell_type=SellType.STOP_LOSS)) assert rpc_mock.call_count == 2 last_msg = rpc_mock.call_args_list[-1][0][0] @@ -3379,7 +3379,7 @@ def test_execute_trade_exit_sloe_cancel_exception( trade.stoploss_order_id = "abcd" freqtrade.execute_trade_exit(trade=trade, limit=1234, - sell_reason=SellCheckTuple(sell_type=SellType.STOP_LOSS)) + exit_check=SellCheckTuple(sell_type=SellType.STOP_LOSS)) assert create_order_mock.call_count == 2 assert log_has('Could not cancel stoploss order abcd', caplog) @@ -3434,7 +3434,7 @@ def test_execute_trade_exit_with_stoploss_on_exchange( freqtrade.execute_trade_exit( trade=trade, limit=ticker_usdt_sell_up()['ask' if is_short else 'bid'], - sell_reason=SellCheckTuple(sell_type=SellType.STOP_LOSS) + exit_check=SellCheckTuple(sell_type=SellType.STOP_LOSS) ) trade = Trade.query.first() @@ -3579,7 +3579,7 @@ def test_execute_trade_exit_market_order( freqtrade.execute_trade_exit( trade=trade, limit=ticker_usdt_sell_up()['ask' if is_short else 'bid'], - sell_reason=SellCheckTuple(sell_type=SellType.ROI) + exit_check=SellCheckTuple(sell_type=SellType.ROI) ) assert not trade.is_open @@ -3647,7 +3647,7 @@ def test_execute_trade_exit_insufficient_funds_error(default_conf_usdt, ticker_u assert not freqtrade.execute_trade_exit( trade=trade, limit=ticker_usdt_sell_up()['ask' if is_short else 'bid'], - sell_reason=sell_reason + exit_check=sell_reason ) assert mock_insuf.call_count == 1 @@ -3816,7 +3816,7 @@ def test_locked_pairs(default_conf_usdt, ticker_usdt, fee, freqtrade.execute_trade_exit( trade=trade, limit=ticker_usdt_sell_down()['ask' if is_short else 'bid'], - sell_reason=SellCheckTuple(sell_type=SellType.STOP_LOSS) + exit_check=SellCheckTuple(sell_type=SellType.STOP_LOSS) ) trade.close(ticker_usdt_sell_down()['bid']) assert freqtrade.strategy.is_pair_locked(trade.pair) @@ -5145,7 +5145,7 @@ def test_update_funding_fees( trade=trade, # The values of the next 2 params are irrelevant for this test limit=ticker_usdt_sell_up()['bid'], - sell_reason=SellCheckTuple(sell_type=SellType.ROI) + exit_check=SellCheckTuple(sell_type=SellType.ROI) ) assert trade.funding_fees == pytest.approx(sum( trade.amount *