Merge orders and positions into one card and hide stale pending when CTP is off.
Stop showing DB pending orders while disconnected, invalidate session cache when CTP is down, and add a local DB clear script without embedded credentials. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+21
-20
@@ -1281,11 +1281,12 @@ def install_trading(app, *, login_required, require_nav, get_db, get_setting, se
|
||||
capital: float,
|
||||
now_iso: str,
|
||||
) -> list[dict]:
|
||||
"""当前委托:以 CTP 柜台为准,本地 pending 开仓单合并展示。"""
|
||||
"""当前委托:CTP 已连接时读柜台;未连接时不展示本地 pending。"""
|
||||
orders: list[dict] = []
|
||||
seen_keys: set[str] = set()
|
||||
connected = ctp_status(mode).get("connected")
|
||||
|
||||
if ctp_status(mode).get("connected"):
|
||||
if connected:
|
||||
ctp_orders = trading_state.get_active_orders()
|
||||
if not ctp_orders:
|
||||
ctp_orders = _ctp_active_orders(mode)
|
||||
@@ -1304,25 +1305,25 @@ def install_trading(app, *, login_required, require_nav, get_db, get_setting, se
|
||||
except Exception as exc:
|
||||
logger.warning("compose ctp order row failed: %s", exc)
|
||||
|
||||
for r in conn.execute(
|
||||
"SELECT * FROM trade_order_monitors WHERE status='pending' ORDER BY id DESC"
|
||||
).fetchall():
|
||||
mon = dict(r)
|
||||
try:
|
||||
prow = _compose_pending_row(
|
||||
mon, mode=mode, capital=capital, now_iso=now_iso,
|
||||
)
|
||||
if prow and prow.get("key") not in seen_keys:
|
||||
pk = f"{prow.get('symbol_code') or ''}:{prow.get('direction') or ''}"
|
||||
dup = any(
|
||||
(x.get("symbol_code") or "") + ":" + (x.get("direction") or "") == pk
|
||||
and x.get("order_state") == "pending"
|
||||
for x in orders
|
||||
for r in conn.execute(
|
||||
"SELECT * FROM trade_order_monitors WHERE status='pending' ORDER BY id DESC"
|
||||
).fetchall():
|
||||
mon = dict(r)
|
||||
try:
|
||||
prow = _compose_pending_row(
|
||||
mon, mode=mode, capital=capital, now_iso=now_iso,
|
||||
)
|
||||
if not dup:
|
||||
orders.append(prow)
|
||||
except Exception as exc:
|
||||
logger.warning("compose pending order row failed: %s", exc)
|
||||
if prow and prow.get("key") not in seen_keys:
|
||||
pk = f"{prow.get('symbol_code') or ''}:{prow.get('direction') or ''}"
|
||||
dup = any(
|
||||
(x.get("symbol_code") or "") + ":" + (x.get("direction") or "") == pk
|
||||
and x.get("order_state") == "pending"
|
||||
for x in orders
|
||||
)
|
||||
if not dup:
|
||||
orders.append(prow)
|
||||
except Exception as exc:
|
||||
logger.warning("compose pending order row failed: %s", exc)
|
||||
return orders
|
||||
|
||||
def _compose_ctp_order_row_any(
|
||||
|
||||
Reference in New Issue
Block a user