Fix target-exit mismatch: correct close reason and executable PnL gate.
Locked premium exits no longer label as fixed_usdt; mark/book optimism no longer triggers close into a realized loss. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -882,6 +882,17 @@ class StrategyEngine:
|
||||
locked_exit_target=locked_exit,
|
||||
)
|
||||
pending_close = st["phase"] in ("liquidity_wait", "closing")
|
||||
# 曾因达标进入流动性等待,但当前估价已跌破目标:取消挂起,避免硬平出亏损却仍记「达标」
|
||||
if (
|
||||
pending_close
|
||||
and not expired.should_close
|
||||
and not decision.should_close
|
||||
):
|
||||
self._set_state(
|
||||
phase="open",
|
||||
last_error="达标后流动性等待期间浮盈回落,已取消平仓挂起",
|
||||
)
|
||||
return
|
||||
if expired.should_close or decision.should_close or pending_close:
|
||||
is_oo = (
|
||||
str(upl.get("hedge_mode") or "") == "option_option"
|
||||
|
||||
@@ -110,16 +110,17 @@ def check_exits(
|
||||
locked_exit_target: float | None = None,
|
||||
) -> ExitDecision:
|
||||
"""净盈利(预估全平后)≥ 所选模式目标则全平。持仓锁定目标优先。"""
|
||||
# 模式始终按设置解析(权利金倍数 vs 固定),勿因锁定目标就改成 fixed_usdt
|
||||
_resolved_target, mode = resolve_exit_target(
|
||||
exit_mode=exit_mode,
|
||||
net_profit_target=net_profit_target,
|
||||
premium_exit_multiple=premium_exit_multiple,
|
||||
initial_premium=initial_premium,
|
||||
)
|
||||
if locked_exit_target is not None and float(locked_exit_target) > 0:
|
||||
target = float(locked_exit_target)
|
||||
mode = EXIT_MODE_FIXED
|
||||
else:
|
||||
target, mode = resolve_exit_target(
|
||||
exit_mode=exit_mode,
|
||||
net_profit_target=net_profit_target,
|
||||
premium_exit_multiple=premium_exit_multiple,
|
||||
initial_premium=initial_premium,
|
||||
)
|
||||
target = float(_resolved_target)
|
||||
if target > 0 and net_pnl + 1e-9 >= target:
|
||||
reason = "premium_multiple" if mode == EXIT_MODE_PREMIUM else "fixed_usdt"
|
||||
return ExitDecision(True, reason, target)
|
||||
|
||||
Reference in New Issue
Block a user