Skip to content

Commit e26529b

Browse files
committed
feat: Don't run custom_exit_price callback when exiting with price
1 parent bac6219 commit e26529b

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

freqtrade/freqtradebot.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,6 +2054,7 @@ def execute_trade_exit(
20542054
exit_tag: str | None = None,
20552055
ordertype: str | None = None,
20562056
sub_trade_amt: float | None = None,
2057+
skip_custom_exit_price: bool = False,
20572058
) -> bool:
20582059
"""
20592060
Executes a trade exit for the given trade and limit
@@ -2080,26 +2081,29 @@ def execute_trade_exit(
20802081
):
20812082
exit_type = "stoploss"
20822083

2084+
order_type = ordertype or self.strategy.order_types[exit_type]
20832085
# set custom_exit_price if available
20842086
proposed_limit_rate = limit
2087+
custom_exit_price = limit
2088+
20852089
current_profit = trade.calc_profit_ratio(limit)
2086-
custom_exit_price = strategy_safe_wrapper(
2087-
self.strategy.custom_exit_price, default_retval=proposed_limit_rate
2088-
)(
2089-
pair=trade.pair,
2090-
trade=trade,
2091-
current_time=datetime.now(UTC),
2092-
proposed_rate=proposed_limit_rate,
2093-
current_profit=current_profit,
2094-
exit_tag=exit_reason,
2095-
)
2090+
if order_type == "limit" and not skip_custom_exit_price:
2091+
custom_exit_price = strategy_safe_wrapper(
2092+
self.strategy.custom_exit_price, default_retval=proposed_limit_rate
2093+
)(
2094+
pair=trade.pair,
2095+
trade=trade,
2096+
current_time=datetime.now(UTC),
2097+
proposed_rate=proposed_limit_rate,
2098+
current_profit=current_profit,
2099+
exit_tag=exit_reason,
2100+
)
20962101

20972102
limit = self.get_valid_price(custom_exit_price, proposed_limit_rate)
20982103

20992104
# First cancelling stoploss on exchange ...
21002105
trade = self.cancel_stoploss_on_exchange(trade, allow_nonblocking=True)
21012106

2102-
order_type = ordertype or self.strategy.order_types[exit_type]
21032107
if exit_check.exit_type == ExitType.EMERGENCY_EXIT:
21042108
# Emergency exits (default to market!)
21052109
order_type = self.strategy.order_types.get("emergency_exit", "market")

freqtrade/rpc/rpc.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,12 @@ def __exec_force_exit(
992992
sub_amount = amount
993993

994994
self._freqtrade.execute_trade_exit(
995-
trade, current_rate, exit_check, ordertype=order_type, sub_trade_amt=sub_amount
995+
trade,
996+
current_rate,
997+
exit_check,
998+
ordertype=order_type,
999+
sub_trade_amt=sub_amount,
1000+
skip_custom_exit_price=price is not None and ordertype == "limit",
9961001
)
9971002

9981003
return True

0 commit comments

Comments
 (0)