Show position-limit freeze on hub and instance risk badges.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -9,12 +9,14 @@ STATUS_NORMAL = "normal"
|
||||
STATUS_FREEZE_1H = "freeze_1h"
|
||||
STATUS_FREEZE_4H = "freeze_4h"
|
||||
STATUS_DAILY = "freeze_daily"
|
||||
STATUS_FREEZE_POSITION = "freeze_position"
|
||||
|
||||
STATUS_LABELS = {
|
||||
STATUS_NORMAL: "正常",
|
||||
STATUS_FREEZE_1H: "1h冻结",
|
||||
STATUS_FREEZE_4H: "4h冻结",
|
||||
STATUS_DAILY: "日冻结",
|
||||
STATUS_FREEZE_POSITION: "仓位上限冻结",
|
||||
}
|
||||
|
||||
MOOD_ISSUE_OPTIONS = (
|
||||
@@ -84,6 +86,13 @@ def manual_close_daily_limit() -> int:
|
||||
return 2
|
||||
|
||||
|
||||
def max_active_positions_from_env(default: int = 1) -> int:
|
||||
try:
|
||||
return max(1, int(os.getenv("MAX_ACTIVE_POSITIONS", str(default))))
|
||||
except (TypeError, ValueError):
|
||||
return max(1, default)
|
||||
|
||||
|
||||
def mood_issues_daily_freeze_enabled() -> bool:
|
||||
return _env_bool("RISK_MOOD_ISSUES_DAILY_FREEZE", True)
|
||||
|
||||
@@ -688,6 +697,39 @@ def enrich_risk_status_countdown(
|
||||
return st
|
||||
|
||||
|
||||
def apply_position_limit_risk(
|
||||
st: dict[str, Any],
|
||||
active_count: int,
|
||||
*,
|
||||
max_active_positions: Optional[int] = None,
|
||||
) -> dict[str, Any]:
|
||||
"""持仓达 env MAX_ACTIVE_POSITIONS 时叠加「仓位上限冻结」(时间冻结优先展示)。"""
|
||||
out = dict(st or {})
|
||||
try:
|
||||
mx = max(1, int(max_active_positions if max_active_positions is not None else max_active_positions_from_env()))
|
||||
except (TypeError, ValueError):
|
||||
mx = max_active_positions_from_env()
|
||||
try:
|
||||
ac = max(0, int(active_count))
|
||||
except (TypeError, ValueError):
|
||||
ac = 0
|
||||
out["max_active_positions"] = mx
|
||||
out["active_count"] = ac
|
||||
if out.get("status") != STATUS_NORMAL:
|
||||
return out
|
||||
if ac >= mx:
|
||||
out["status"] = STATUS_FREEZE_POSITION
|
||||
out["status_label"] = STATUS_LABELS[STATUS_FREEZE_POSITION]
|
||||
out["can_trade"] = False
|
||||
out["reason"] = f"已达最大持仓数({ac}/{mx}),平仓前不可新开"
|
||||
out["position_limit_frozen"] = True
|
||||
out["freeze_until_ms"] = None
|
||||
out["freeze_remaining_sec"] = 0
|
||||
else:
|
||||
out["position_limit_frozen"] = False
|
||||
return out
|
||||
|
||||
|
||||
def compute_account_risk_status(
|
||||
conn,
|
||||
*,
|
||||
|
||||
Reference in New Issue
Block a user