Sync displayed entry price from CTP exchange position average.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+8
-14
@@ -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:
|
||||
|
||||
@@ -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);
|
||||
|
||||
+3
-1
@@ -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 @@
|
||||
'<div class="pos-card-meta pos-card-meta-line">' + metaLine + '</div>' +
|
||||
'<div class="pos-metrics">' +
|
||||
'<div class="cell"><label>手数</label><div><strong>' + row.lots + ' 手</strong></div></div>' +
|
||||
'<div class="cell"><label>均价</label><div>' + fmtNum(row.entry_price) + '</div></div>' +
|
||||
'<div class="cell"><label>均价</label><div class="pos-q-entry">' + fmtNum(row.entry_price) + '</div></div>' +
|
||||
'<div class="cell"><label>当前价格</label><div class="pos-q-mark">' + (row.current_price != null ? fmtNum(row.current_price) : '--') + '</div></div>' +
|
||||
'<div class="cell"><label>' + marginLabel + '</label><div>' + (row.margin != null ? fmtNum(row.margin) + ' 元' : '--') + '</div></div>' +
|
||||
'<div class="cell"><label>仓位占比</label><div>' + (row.position_pct != null ? fmtNum(row.position_pct) + '%' : '--') + '</div></div>' +
|
||||
|
||||
Reference in New Issue
Block a user