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:
@@ -150,6 +150,34 @@ class AccountRiskLibTests(unittest.TestCase):
|
||||
st = compute_account_risk_status(conn, trading_day="2026-06-14", now=now)
|
||||
self.assertEqual(st["status"], STATUS_FREEZE_1H)
|
||||
|
||||
def test_journal_reduces_when_manual_count_cleared_but_cooloff_active(self):
|
||||
conn = _mem_conn()
|
||||
now = datetime(2026, 6, 15, 10, 0, 0)
|
||||
now_ms = int(now.replace(tzinfo=timezone.utc).timestamp() * 1000)
|
||||
close_ms = now_ms - 3600 * 1000
|
||||
until_ms = close_ms + 4 * 3600 * 1000
|
||||
conn.execute(
|
||||
"""UPDATE account_risk_state SET
|
||||
trading_day='2026-06-15',
|
||||
manual_close_count=0,
|
||||
cooloff_until_ms=?,
|
||||
cooloff_hours=4,
|
||||
last_close_at_ms=?,
|
||||
daily_frozen=0
|
||||
WHERE id=1""",
|
||||
(until_ms, close_ms),
|
||||
)
|
||||
on_journal_saved(
|
||||
conn,
|
||||
early_exit_trigger="手动平仓",
|
||||
early_exit_note="切日后补复盘",
|
||||
mood_issues_raw="",
|
||||
trading_day="2026-06-15",
|
||||
now=now,
|
||||
)
|
||||
st = compute_account_risk_status(conn, trading_day="2026-06-15", now=now)
|
||||
self.assertEqual(st["status"], STATUS_FREEZE_1H)
|
||||
|
||||
def test_journal_late_save_still_gets_1h_from_now(self):
|
||||
conn = _mem_conn()
|
||||
close_at = datetime(2026, 6, 14, 12, 0, 0)
|
||||
|
||||
Reference in New Issue
Block a user