Enhance dashboard with exchange labels, split SL/TP columns, and daily risk limits.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+23
-9
@@ -37,13 +37,17 @@ def build_risk_overview(
|
||||
margin_used: Optional[float] = None,
|
||||
) -> dict[str, Any]:
|
||||
from risk.account_risk_lib import (
|
||||
cooling_hours_manual,
|
||||
cooling_hours_manual_journal,
|
||||
count_daily_opens,
|
||||
daily_position_limit,
|
||||
daily_trading_risk_pct_limit,
|
||||
daily_trading_risk_used_pct,
|
||||
ensure_account_risk_schema,
|
||||
get_risk_status,
|
||||
manual_close_daily_limit,
|
||||
max_active_positions,
|
||||
risk_control_enabled,
|
||||
cooling_hours_manual,
|
||||
cooling_hours_manual_journal,
|
||||
trading_day_label,
|
||||
trading_day_reset_hour,
|
||||
)
|
||||
@@ -52,12 +56,11 @@ def build_risk_overview(
|
||||
get_fixed_lots,
|
||||
get_max_margin_pct,
|
||||
get_roll_max_margin_pct,
|
||||
get_risk_percent,
|
||||
get_sizing_mode,
|
||||
)
|
||||
|
||||
ensure_account_risk_schema(conn)
|
||||
risk = dict(get_risk_status(conn) or {})
|
||||
risk = dict(get_risk_status(conn, equity=equity) or {})
|
||||
row = conn.execute("SELECT * FROM account_risk_state WHERE id=1").fetchone()
|
||||
td = trading_day_label()
|
||||
stored_td = str(row["trading_day"] or "") if row else ""
|
||||
@@ -71,20 +74,28 @@ def build_risk_overview(
|
||||
sizing = get_sizing_mode(get_setting)
|
||||
sizing_label = "固定金额" if sizing == "amount" else "固定手数"
|
||||
|
||||
daily_opens = int(risk.get("daily_open_count") or count_daily_opens(conn))
|
||||
daily_risk_used = risk.get("daily_risk_used_pct")
|
||||
if daily_risk_used is None and equity and equity > 0:
|
||||
daily_risk_used = daily_trading_risk_used_pct(conn, float(equity))
|
||||
|
||||
return {
|
||||
"enabled": risk_control_enabled(),
|
||||
"status": risk,
|
||||
"manual_close_count_today": manual_count,
|
||||
"margin_pct_used": margin_pct_used,
|
||||
"daily_open_count": daily_opens,
|
||||
"daily_risk_used_pct": daily_risk_used,
|
||||
"limits": {
|
||||
"max_active_positions": max_active_positions(),
|
||||
"daily_position_limit": daily_position_limit(),
|
||||
"daily_trading_risk_pct_limit": daily_trading_risk_pct_limit(),
|
||||
"manual_close_daily_limit": manual_close_daily_limit(),
|
||||
"cooling_hours_manual": cooling_hours_manual(),
|
||||
"cooling_hours_manual_journal": cooling_hours_manual_journal(),
|
||||
"trading_day_reset_hour": trading_day_reset_hour(),
|
||||
"max_margin_pct": max_margin,
|
||||
"roll_max_margin_pct": get_roll_max_margin_pct(get_setting),
|
||||
"risk_percent": get_risk_percent(get_setting),
|
||||
"sizing_mode": sizing,
|
||||
"sizing_label": sizing_label,
|
||||
"fixed_lots": get_fixed_lots(get_setting),
|
||||
@@ -167,11 +178,12 @@ def build_dashboard_payload(
|
||||
dist_upper = round(upper - float(price), 2)
|
||||
dist_lower = round(float(price) - lower, 2)
|
||||
mtype = r["monitor_type"] or ""
|
||||
sf = _symbol_fields(sym)
|
||||
keys.append({
|
||||
"id": r["id"],
|
||||
"symbol": sym,
|
||||
"symbol_name": r["symbol_name"] or sym,
|
||||
**_symbol_fields(sym),
|
||||
**sf,
|
||||
"symbol_name": r["symbol_name"] or sf.get("symbol_name") or sym,
|
||||
"monitor_type": mtype,
|
||||
"direction": r["direction"] or "",
|
||||
"direction_label": _direction_label(r["direction"] or "long")
|
||||
@@ -200,11 +212,13 @@ def build_dashboard_payload(
|
||||
closes: list[dict[str, Any]] = []
|
||||
for r in close_rows:
|
||||
sym_code = r["symbol"] or ""
|
||||
sf = _symbol_fields(sym_code)
|
||||
closes.append({
|
||||
"id": r["id"],
|
||||
"symbol": r["symbol_name"] or sym_code,
|
||||
"symbol": r["symbol_name"] or sf.get("symbol_name") or sym_code,
|
||||
"symbol_code": sym_code,
|
||||
**_symbol_fields(sym_code),
|
||||
**sf,
|
||||
"symbol_name": r["symbol_name"] or sf.get("symbol_name") or sym_code,
|
||||
"direction": r["direction"] or "long",
|
||||
"direction_label": _direction_label(r["direction"] or "long"),
|
||||
"lots": float(r["lots"] or 0),
|
||||
|
||||
Reference in New Issue
Block a user