Document Git-only deploy workflow and reduce positions page IPC blocking.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+24
-6
@@ -118,10 +118,29 @@ def _cached_ctp_account(mode: str) -> dict[str, float]:
|
||||
return {}
|
||||
|
||||
|
||||
def _ctp_status_from_snapshot(mode: str) -> Optional[dict]:
|
||||
"""读持仓快照中的 CTP 状态,避免页面渲染同步 IPC。"""
|
||||
try:
|
||||
from position_stream import position_hub
|
||||
|
||||
snap = position_hub.get_snapshot() or {}
|
||||
st = snap.get("ctp_status")
|
||||
if isinstance(st, dict) and st:
|
||||
return st
|
||||
except Exception:
|
||||
pass
|
||||
del mode
|
||||
return None
|
||||
|
||||
|
||||
def get_account_capital(conn, get_setting: Callable[[str, str], str]) -> float:
|
||||
"""优先 SimNow/期货公司 CTP 权益;未连接时用最近快照或设置中的参考资金。"""
|
||||
"""优先读持仓/Worker 快照权益;无快照时才同步问 CTP。"""
|
||||
del conn
|
||||
mode = get_trading_mode(get_setting)
|
||||
cached = _cached_ctp_account(mode)
|
||||
balance = float(cached.get("balance") or 0)
|
||||
if balance > 0:
|
||||
return balance
|
||||
try:
|
||||
from vnpy_bridge import ctp_status, get_ctp_balance
|
||||
|
||||
@@ -132,10 +151,6 @@ def get_account_capital(conn, get_setting: Callable[[str, str], str]) -> float:
|
||||
return float(bal)
|
||||
except Exception:
|
||||
pass
|
||||
cached = _cached_ctp_account(mode)
|
||||
balance = float(cached.get("balance") or 0)
|
||||
if balance > 0:
|
||||
return balance
|
||||
try:
|
||||
return float(get_setting("live_capital", "0") or 0)
|
||||
except (TypeError, ValueError):
|
||||
@@ -153,10 +168,13 @@ def get_recommend_capital(conn, get_setting: Callable[[str, str], str]) -> float
|
||||
|
||||
def is_ctp_connected(get_setting: Callable[[str, str], str]) -> bool:
|
||||
"""当前交易模式(SimNow / 实盘)是否已连接 CTP。"""
|
||||
mode = get_trading_mode(get_setting)
|
||||
st = _ctp_status_from_snapshot(mode)
|
||||
if st is not None:
|
||||
return bool(st.get("connected"))
|
||||
try:
|
||||
from vnpy_bridge import ctp_status
|
||||
|
||||
mode = get_trading_mode(get_setting)
|
||||
return bool(ctp_status(mode).get("connected"))
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user