Document Git-only deploy workflow and reduce positions page IPC blocking.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-01 14:05:37 +08:00
parent 7748a88219
commit b354d6c701
6 changed files with 247 additions and 65 deletions
+41 -6
View File
@@ -110,15 +110,29 @@ def recommend_cache_needs_refresh(
def _ctp_connected_for_mode(trading_mode: str) -> bool:
try:
from vnpy_bridge import ctp_status
from position_stream import position_hub
return bool(ctp_status(trading_mode).get("connected"))
snap = position_hub.get_snapshot() or {}
st = snap.get("ctp_status")
if isinstance(st, dict) and st:
return bool(st.get("connected"))
except Exception:
return False
pass
del trading_mode
return False
def recommend_margin_used(trading_mode: str) -> float:
"""当前持仓已占用保证金(各持仓 CTP 回报之和,与柜台持仓保证金一致)。"""
try:
from position_stream import position_hub
snap = position_hub.get_snapshot() or {}
raw = snap.get("margin_used")
if raw is not None:
return max(0.0, float(raw or 0))
except Exception:
pass
if not _ctp_connected_for_mode(trading_mode):
return 0.0
try:
@@ -162,6 +176,7 @@ def enrich_recommend_rows(
max_margin_pct: float = 30.0,
trading_mode: str = "simulation",
margin_used: float = 0.0,
use_ctp_margin: bool = True,
) -> list[dict]:
"""用当前权益与保证金比例补算最大可开手数(兼容旧缓存)。"""
cap = float(capital or 0)
@@ -193,7 +208,7 @@ def enrich_recommend_rows(
code_for_margin,
price,
direction="max",
trading_mode=trading_mode if ctp_connected else None,
trading_mode=trading_mode if (ctp_connected and use_ctp_margin) else None,
)
if spec_used.get("mult"):
row["mult"] = spec_used["mult"]
@@ -340,19 +355,39 @@ def recommend_payload(
trading_mode: str = "simulation",
sizing_mode: str = "fixed",
fixed_lots: int = 1,
use_ctp_margin: bool = True,
) -> dict:
"""读取缓存并附带当前权益(展示用,可能与缓存计算时不同)。"""
payload = load_recommend_cache(conn)
cap = float(live_capital or 0)
pct = max(1.0, min(100.0, float(max_margin_pct or 30.0)))
used = recommend_margin_used(trading_mode)
if use_ctp_margin:
used = recommend_margin_used(trading_mode)
else:
used = 0.0
try:
from position_stream import position_hub
snap = position_hub.get_snapshot() or {}
raw = snap.get("margin_used")
if raw is not None:
used = max(0.0, float(raw or 0))
except Exception:
pass
if used <= 0:
used = float(payload.get("margin_used") or 0)
budget_info = margin_budget_info(cap, pct, used)
payload["capital"] = cap
payload["max_margin_pct"] = pct
payload.update(budget_info)
rows = payload.get("rows") or []
rows = enrich_recommend_rows(
rows, cap, max_margin_pct=pct, trading_mode=trading_mode, margin_used=used,
rows,
cap,
max_margin_pct=pct,
trading_mode=trading_mode,
margin_used=used,
use_ctp_margin=use_ctp_margin,
)
rows = filter_rows_for_account_scope(
rows, cap, ctp_connected=_ctp_connected_for_mode(trading_mode),