Show position-limit freeze on hub and instance risk badges.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -12,11 +12,14 @@ from account_risk_lib import (
|
||||
STATUS_DAILY,
|
||||
STATUS_FREEZE_1H,
|
||||
STATUS_FREEZE_4H,
|
||||
STATUS_FREEZE_POSITION,
|
||||
STATUS_NORMAL,
|
||||
account_risk_blocks_trading,
|
||||
apply_position_limit_risk,
|
||||
compute_account_risk_status,
|
||||
enrich_risk_status_countdown,
|
||||
ensure_account_risk_schema,
|
||||
max_active_positions_from_env,
|
||||
on_journal_saved,
|
||||
on_manual_close,
|
||||
on_user_initiated_close,
|
||||
@@ -489,6 +492,33 @@ class AccountRiskLibTests(unittest.TestCase):
|
||||
ok, _ = account_risk_blocks_trading(conn, trading_day="2026-06-14", now=now)
|
||||
self.assertTrue(ok)
|
||||
|
||||
def test_position_limit_freeze_from_env(self):
|
||||
os.environ["MAX_ACTIVE_POSITIONS"] = "2"
|
||||
st = apply_position_limit_risk({"status": STATUS_NORMAL, "can_trade": True}, 2)
|
||||
self.assertEqual(st["status"], STATUS_FREEZE_POSITION)
|
||||
self.assertEqual(st["status_label"], "仓位上限冻结")
|
||||
self.assertFalse(st["can_trade"])
|
||||
self.assertIn("2/2", st["reason"])
|
||||
self.assertEqual(st["max_active_positions"], 2)
|
||||
|
||||
def test_position_limit_normal_when_under_cap(self):
|
||||
st = apply_position_limit_risk({"status": STATUS_NORMAL, "can_trade": True}, 0, max_active_positions=1)
|
||||
self.assertEqual(st["status"], STATUS_NORMAL)
|
||||
self.assertTrue(st["can_trade"])
|
||||
|
||||
def test_time_freeze_takes_priority_over_position_limit(self):
|
||||
st = apply_position_limit_risk(
|
||||
{"status": STATUS_FREEZE_4H, "status_label": "4h冻结", "can_trade": False},
|
||||
5,
|
||||
max_active_positions=1,
|
||||
)
|
||||
self.assertEqual(st["status"], STATUS_FREEZE_4H)
|
||||
self.assertEqual(st["active_count"], 5)
|
||||
|
||||
def test_max_active_positions_from_env(self):
|
||||
os.environ["MAX_ACTIVE_POSITIONS"] = "3"
|
||||
self.assertEqual(max_active_positions_from_env(), 3)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user