Sync displayed entry price from CTP exchange position average.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-30 09:19:27 +08:00
parent c8fef65de7
commit f41276806e
3 changed files with 14 additions and 15 deletions
+8 -14
View File
@@ -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: