fix(risk): shorten cooloff on review save and when count was reset

Allow 1h reduction for any active 4h-tier cooloff, hook trade record review updates, and fix freeze label thresholds.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-18 16:35:51 +08:00
parent f0a158686e
commit 0280b4f065
7 changed files with 99 additions and 11 deletions
+32 -10
View File
@@ -206,23 +206,23 @@ def _cooloff_until_ms(row) -> Optional[int]:
return None
def _in_active_manual_cooloff(row, now_ms: int) -> bool:
def _journal_can_reduce_cooloff(row, pending, now_ms: int) -> bool:
if int(_row_get(row, "daily_frozen") or 0) == 1:
return False
if int(_row_get(row, "manual_close_count") or 0) < 1:
return False
until_ms = _cooloff_until_ms(row)
return until_ms is not None and until_ms > now_ms
def _journal_can_reduce_cooloff(row, pending, now_ms: int) -> bool:
if until_ms is None or until_ms <= now_ms:
return False
journal_h = cooling_hours_manual_journal()
cooloff_h = float(_row_get(row, "cooloff_hours") or cooling_hours_manual())
if cooloff_h <= journal_h + 1e-6:
return False
if pending is not None:
try:
if int(pending) != 0:
return True
except (TypeError, ValueError):
return True
return _in_active_manual_cooloff(row, now_ms)
return True
def _journal_cooloff_until_ms(row, now_ms: int, journal_hours: float) -> int:
@@ -384,6 +384,27 @@ def on_journal_saved(
)
def apply_manual_close_journal_cooloff(
conn,
*,
early_exit_note: str,
trading_day: str,
now: Optional[datetime] = None,
) -> None:
"""核对修改或复盘:手动平仓 + 说明后尝试将 4h 冷静期降为 1h。"""
note = (early_exit_note or "").strip()
if not note:
return
on_journal_saved(
conn,
early_exit_trigger="手动平仓",
early_exit_note=note,
mood_issues_raw="",
trading_day=trading_day,
now=now,
)
def compute_account_risk_status(
conn,
*,
@@ -420,8 +441,9 @@ def compute_account_risk_status(
status = STATUS_DAILY
reason = f"账户今日已冻结(手动平仓 {manual_close_count} 次或复盘情绪标签)"
elif cooloff_until_ms is not None and cooloff_until_ms > now_ms:
h = int(cooloff_hours or cooling_hours_manual())
status = STATUS_FREEZE_1H if h <= 1 else STATUS_FREEZE_4H
h = float(cooloff_hours or cooling_hours_manual())
journal_h = cooling_hours_manual_journal()
status = STATUS_FREEZE_1H if h <= journal_h + 1e-6 else STATUS_FREEZE_4H
until_str = _ms_to_local_str(cooloff_until_ms, fmt_local_ms) if fmt_local_ms else None
label = STATUS_LABELS[status]
reason = f"账户{label}"