diff --git a/install_trading.py b/install_trading.py index 74e8aa4..c8f0833 100644 --- a/install_trading.py +++ b/install_trading.py @@ -1093,12 +1093,12 @@ def install_trading(app, *, login_required, require_nav, get_db, get_setting, se return None if ctp: - if not mon: - ctp_lots = int(ctp.get("lots") or 0) - if ctp_lots > 0: - lots = ctp_lots - if float(ctp.get("avg_price") or 0) > 0: - entry = float(ctp.get("avg_price") or 0) + ctp_lots = int(ctp.get("lots") or 0) + if ctp_lots > 0: + lots = ctp_lots + ctp_avg = float(ctp.get("avg_price") or 0) + if ctp_avg > 0: + entry = ctp_avg ctp_margin = float(ctp.get("margin") or 0) if (margin is None or float(margin or 0) <= 0) and ctp_margin > 0: margin = ctp_margin @@ -1674,9 +1674,7 @@ def install_trading(app, *, login_required, require_nav, get_db, get_setting, se if not positions: positions = _ctp_positions(mode, refresh_if_empty=False) quotes: list[dict] = [] - conn = get_db() - try: - for p in positions: + for p in positions: lots = int(p.get("lots") or 0) if lots <= 0: continue @@ -1685,9 +1683,6 @@ def install_trading(app, *, login_required, require_nav, get_db, get_setting, se continue direction = (p.get("direction") or "long").strip().lower() entry = float(p.get("avg_price") or 0) - mon = _find_active_monitor(conn, ths, direction) - if mon and float(mon.get("entry_price") or 0) > 0: - entry = float(mon["entry_price"]) if entry <= 0: continue mark = ctp_get_tick_price(mode, ths) @@ -1706,10 +1701,9 @@ def install_trading(app, *, login_required, require_nav, get_db, get_setting, se "position_key": row_key, "mark_price": mark, "current_price": mark, + "entry_price": entry, "float_pnl": float_pnl, }) - finally: - conn.close() return {"ok": True, "quotes": quotes} def _push_position_quotes_async() -> None: diff --git a/static/js/dashboard.js b/static/js/dashboard.js index d8ae924..202a851 100644 --- a/static/js/dashboard.js +++ b/static/js/dashboard.js @@ -832,12 +832,15 @@ if (isPhoneLayout() && posMobileCache[key]) { var cached = posMobileCache[key]; if (q.mark_price != null) cached.current_price = q.mark_price; + if (q.entry_price != null) cached.entry_price = q.entry_price; if (q.float_pnl != null) cached.float_pnl = q.float_pnl; } var row = findPosRow(key); if (!row) return; + var entryEl = row.querySelector('.dash-p-entry'); var markEl = row.querySelector('.dash-p-mark'); var pnlEl = row.querySelector('.dash-p-pnl'); + if (entryEl && q.entry_price != null) entryEl.textContent = fmtNum(q.entry_price); if (markEl && q.mark_price != null) markEl.textContent = fmtNum(q.mark_price); if (pnlEl && q.float_pnl != null) { pnlEl.textContent = fmtPnl(q.float_pnl); diff --git a/static/js/trade.js b/static/js/trade.js index 2078a78..60b6c12 100644 --- a/static/js/trade.js +++ b/static/js/trade.js @@ -216,9 +216,11 @@ data.quotes.forEach(function (q) { var card = findPosCardByKey(q.key || q.position_key); if (!card) return; + var entryEl = card.querySelector('.pos-q-entry'); var markEl = card.querySelector('.pos-q-mark'); var pnlEl = card.querySelector('.pos-q-pnl'); var pnlWrap = card.querySelector('.pos-q-pnl-wrap'); + if (entryEl && q.entry_price != null) entryEl.textContent = fmtNum(q.entry_price); if (markEl && q.mark_price != null) markEl.textContent = fmtNum(q.mark_price); if (pnlEl && q.float_pnl != null) { var pnl = q.float_pnl; @@ -1204,7 +1206,7 @@ '
' + metaLine + '
' + '
' + '
' + row.lots + ' 手
' + - '
' + fmtNum(row.entry_price) + '
' + + '
' + fmtNum(row.entry_price) + '
' + '
' + (row.current_price != null ? fmtNum(row.current_price) : '--') + '
' + '
' + (row.margin != null ? fmtNum(row.margin) + ' 元' : '--') + '
' + '
' + (row.position_pct != null ? fmtNum(row.position_pct) + '%' : '--') + '
' +