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:
@@ -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:
|
||||
try:
|
||||
from modules.ctp.ctp_trading_state import trading_state
|
||||
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
|
||||
keys |= _position_keys_from_rows(trading_state.get_positions())
|
||||
except Exception:
|
||||
pass
|
||||
if not keys:
|
||||
try:
|
||||
from modules.trading.position_stream import position_hub
|
||||
|
||||
|
||||
Reference in New Issue
Block a user