Fix dashboard position limit flicker by unifying active count across APIs.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -69,6 +69,7 @@ from modules.trading.sl_tp_guard import (
|
||||
from risk.account_risk_lib import (
|
||||
assert_can_open,
|
||||
count_active_trade_monitors,
|
||||
effective_active_position_count,
|
||||
get_risk_status,
|
||||
on_mood_journal_freeze,
|
||||
on_user_initiated_close,
|
||||
@@ -972,27 +973,11 @@ def install_trading(app, *, login_required, require_nav, get_db, get_setting, se
|
||||
*,
|
||||
ctp_connected: Optional[bool] = None,
|
||||
) -> int:
|
||||
"""风控持仓数以柜台/快照实际持仓优先,本地监控作兜底。"""
|
||||
monitor_count = count_active_trade_monitors(conn)
|
||||
if ctp_connected is None:
|
||||
ctp_connected = bool(_cached_ctp_status(mode).get("connected"))
|
||||
if not ctp_connected:
|
||||
return monitor_count
|
||||
keys: set[tuple[str, str]] = set()
|
||||
for p in _positions_for_monitor_restore(mode, allow_ctp=False):
|
||||
lots = int(p.get("lots") or 0)
|
||||
if lots <= 0:
|
||||
continue
|
||||
sym = (
|
||||
p.get("symbol")
|
||||
or p.get("symbol_code")
|
||||
or p.get("ths_code")
|
||||
or ""
|
||||
).strip().lower()
|
||||
direction = (p.get("direction") or "long").strip().lower()
|
||||
if sym:
|
||||
keys.add((sym, direction))
|
||||
return max(monitor_count, len(keys))
|
||||
return effective_active_position_count(
|
||||
conn, mode, ctp_connected=ctp_connected,
|
||||
)
|
||||
|
||||
def _build_pending_orders(conn, mode: str) -> list[dict]:
|
||||
pending: list[dict] = []
|
||||
@@ -2175,7 +2160,7 @@ def install_trading(app, *, login_required, require_nav, get_db, get_setting, se
|
||||
capital = _capital(conn)
|
||||
risk = get_risk_status(
|
||||
conn,
|
||||
active_count=count_active_trade_monitors(conn),
|
||||
active_count=_effective_active_position_count(conn, mode),
|
||||
equity=capital,
|
||||
)
|
||||
syncing = bool(ctp_st.get("connected") or ctp_st.get("connecting"))
|
||||
|
||||
Reference in New Issue
Block a user