Prefer monitor slots for position limit and fix dashboard sticky count.

When active monitors exist, use their deduped symbol+direction slots so roll does not inflate the limit; only hold previous active_count on SSE when incoming drops to zero during sync.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-02 23:01:50 +08:00
parent 6710692dfb
commit 93bdce3568
2 changed files with 15 additions and 10 deletions
+8 -3
View File
@@ -322,8 +322,10 @@ def effective_active_position_count(
*,
ctp_connected: Optional[bool] = None,
) -> int:
"""风控持仓数:品种+方向槽位去重;滚仓不计入新仓位"""
keys = active_position_slots_from_monitors(conn)
"""风控持仓数:品种+方向槽位去重;滚仓/加仓共用监控,不额外占槽"""
monitor_keys = active_position_slots_from_monitors(conn)
if monitor_keys:
return len(monitor_keys)
if ctp_connected is None:
try:
from modules.ctp.vnpy_bridge import ctp_status
@@ -331,13 +333,16 @@ def effective_active_position_count(
ctp_connected = bool(ctp_status(mode).get("connected"))
except Exception:
ctp_connected = False
if ctp_connected:
if not ctp_connected:
return 0
keys: set[tuple[str, str]] = set()
try:
from modules.ctp.ctp_trading_state import trading_state
keys |= _position_keys_from_rows(trading_state.get_positions())
except Exception:
pass
if not keys:
try:
from modules.trading.position_stream import position_hub
+2 -2
View File
@@ -424,8 +424,8 @@
: 0;
if (
!isNaN(incN) && !isNaN(prevN)
&& incN < prevN
&& (marginUsed > 0 || prevN > 0)
&& incN === 0 && prevN > 0
&& marginUsed > 0
) {
risk.status.active_count = prevN;
}