fix(risk): allow journal to reduce 4h cooloff to 1h without pending trade id
Hub closes and late journal saves now shorten active manual cooloffs when exit trigger and note are filled in. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -128,6 +128,55 @@ 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_hub_close_without_pending_reduces_to_1h(self):
|
||||
conn = _mem_conn()
|
||||
now = datetime(2026, 6, 14, 12, 0, 0)
|
||||
close_ms = int(now.replace(tzinfo=timezone.utc).timestamp() * 1000)
|
||||
on_user_initiated_close(
|
||||
conn,
|
||||
source=CLOSE_SOURCE_USER_HUB,
|
||||
closed_at_ms=close_ms,
|
||||
trading_day="2026-06-14",
|
||||
now=now,
|
||||
)
|
||||
on_journal_saved(
|
||||
conn,
|
||||
early_exit_trigger="手动平仓",
|
||||
early_exit_note="中控全平后复盘说明",
|
||||
mood_issues_raw="",
|
||||
trading_day="2026-06-14",
|
||||
now=now,
|
||||
)
|
||||
st = compute_account_risk_status(conn, trading_day="2026-06-14", 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)
|
||||
close_ms = int(close_at.replace(tzinfo=timezone.utc).timestamp() * 1000)
|
||||
on_user_initiated_close(
|
||||
conn,
|
||||
source=CLOSE_SOURCE_USER_INSTANCE,
|
||||
closed_at_ms=close_ms,
|
||||
trading_day="2026-06-14",
|
||||
now=close_at,
|
||||
)
|
||||
journal_at = datetime(2026, 6, 14, 14, 0, 0)
|
||||
on_journal_saved(
|
||||
conn,
|
||||
early_exit_trigger="手动平仓",
|
||||
early_exit_note="补写复盘说明",
|
||||
mood_issues_raw="",
|
||||
trading_day="2026-06-14",
|
||||
now=journal_at,
|
||||
)
|
||||
st = compute_account_risk_status(conn, trading_day="2026-06-14", now=journal_at)
|
||||
self.assertEqual(st["status"], STATUS_FREEZE_1H)
|
||||
self.assertEqual(
|
||||
st["cooloff_until_ms"],
|
||||
int(journal_at.replace(tzinfo=timezone.utc).timestamp() * 1000) + 3600 * 1000,
|
||||
)
|
||||
|
||||
def test_journal_mood_issues_daily_freeze(self):
|
||||
conn = _mem_conn()
|
||||
now = datetime(2026, 6, 14, 12, 0, 0)
|
||||
|
||||
Reference in New Issue
Block a user