Sync displayed entry price from CTP exchange position average.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+4
-10
@@ -1093,12 +1093,12 @@ def install_trading(app, *, login_required, require_nav, get_db, get_setting, se
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
if ctp:
|
if ctp:
|
||||||
if not mon:
|
|
||||||
ctp_lots = int(ctp.get("lots") or 0)
|
ctp_lots = int(ctp.get("lots") or 0)
|
||||||
if ctp_lots > 0:
|
if ctp_lots > 0:
|
||||||
lots = ctp_lots
|
lots = ctp_lots
|
||||||
if float(ctp.get("avg_price") or 0) > 0:
|
ctp_avg = float(ctp.get("avg_price") or 0)
|
||||||
entry = float(ctp.get("avg_price") or 0)
|
if ctp_avg > 0:
|
||||||
|
entry = ctp_avg
|
||||||
ctp_margin = float(ctp.get("margin") or 0)
|
ctp_margin = float(ctp.get("margin") or 0)
|
||||||
if (margin is None or float(margin or 0) <= 0) and ctp_margin > 0:
|
if (margin is None or float(margin or 0) <= 0) and ctp_margin > 0:
|
||||||
margin = ctp_margin
|
margin = ctp_margin
|
||||||
@@ -1674,8 +1674,6 @@ def install_trading(app, *, login_required, require_nav, get_db, get_setting, se
|
|||||||
if not positions:
|
if not positions:
|
||||||
positions = _ctp_positions(mode, refresh_if_empty=False)
|
positions = _ctp_positions(mode, refresh_if_empty=False)
|
||||||
quotes: list[dict] = []
|
quotes: list[dict] = []
|
||||||
conn = get_db()
|
|
||||||
try:
|
|
||||||
for p in positions:
|
for p in positions:
|
||||||
lots = int(p.get("lots") or 0)
|
lots = int(p.get("lots") or 0)
|
||||||
if lots <= 0:
|
if lots <= 0:
|
||||||
@@ -1685,9 +1683,6 @@ def install_trading(app, *, login_required, require_nav, get_db, get_setting, se
|
|||||||
continue
|
continue
|
||||||
direction = (p.get("direction") or "long").strip().lower()
|
direction = (p.get("direction") or "long").strip().lower()
|
||||||
entry = float(p.get("avg_price") or 0)
|
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:
|
if entry <= 0:
|
||||||
continue
|
continue
|
||||||
mark = ctp_get_tick_price(mode, ths)
|
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,
|
"position_key": row_key,
|
||||||
"mark_price": mark,
|
"mark_price": mark,
|
||||||
"current_price": mark,
|
"current_price": mark,
|
||||||
|
"entry_price": entry,
|
||||||
"float_pnl": float_pnl,
|
"float_pnl": float_pnl,
|
||||||
})
|
})
|
||||||
finally:
|
|
||||||
conn.close()
|
|
||||||
return {"ok": True, "quotes": quotes}
|
return {"ok": True, "quotes": quotes}
|
||||||
|
|
||||||
def _push_position_quotes_async() -> None:
|
def _push_position_quotes_async() -> None:
|
||||||
|
|||||||
@@ -832,12 +832,15 @@
|
|||||||
if (isPhoneLayout() && posMobileCache[key]) {
|
if (isPhoneLayout() && posMobileCache[key]) {
|
||||||
var cached = posMobileCache[key];
|
var cached = posMobileCache[key];
|
||||||
if (q.mark_price != null) cached.current_price = q.mark_price;
|
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;
|
if (q.float_pnl != null) cached.float_pnl = q.float_pnl;
|
||||||
}
|
}
|
||||||
var row = findPosRow(key);
|
var row = findPosRow(key);
|
||||||
if (!row) return;
|
if (!row) return;
|
||||||
|
var entryEl = row.querySelector('.dash-p-entry');
|
||||||
var markEl = row.querySelector('.dash-p-mark');
|
var markEl = row.querySelector('.dash-p-mark');
|
||||||
var pnlEl = row.querySelector('.dash-p-pnl');
|
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 (markEl && q.mark_price != null) markEl.textContent = fmtNum(q.mark_price);
|
||||||
if (pnlEl && q.float_pnl != null) {
|
if (pnlEl && q.float_pnl != null) {
|
||||||
pnlEl.textContent = fmtPnl(q.float_pnl);
|
pnlEl.textContent = fmtPnl(q.float_pnl);
|
||||||
|
|||||||
+3
-1
@@ -216,9 +216,11 @@
|
|||||||
data.quotes.forEach(function (q) {
|
data.quotes.forEach(function (q) {
|
||||||
var card = findPosCardByKey(q.key || q.position_key);
|
var card = findPosCardByKey(q.key || q.position_key);
|
||||||
if (!card) return;
|
if (!card) return;
|
||||||
|
var entryEl = card.querySelector('.pos-q-entry');
|
||||||
var markEl = card.querySelector('.pos-q-mark');
|
var markEl = card.querySelector('.pos-q-mark');
|
||||||
var pnlEl = card.querySelector('.pos-q-pnl');
|
var pnlEl = card.querySelector('.pos-q-pnl');
|
||||||
var pnlWrap = card.querySelector('.pos-q-pnl-wrap');
|
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 (markEl && q.mark_price != null) markEl.textContent = fmtNum(q.mark_price);
|
||||||
if (pnlEl && q.float_pnl != null) {
|
if (pnlEl && q.float_pnl != null) {
|
||||||
var pnl = q.float_pnl;
|
var pnl = q.float_pnl;
|
||||||
@@ -1204,7 +1206,7 @@
|
|||||||
'<div class="pos-card-meta pos-card-meta-line">' + metaLine + '</div>' +
|
'<div class="pos-card-meta pos-card-meta-line">' + metaLine + '</div>' +
|
||||||
'<div class="pos-metrics">' +
|
'<div class="pos-metrics">' +
|
||||||
'<div class="cell"><label>手数</label><div><strong>' + row.lots + ' 手</strong></div></div>' +
|
'<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>当前价格</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>' + 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>' +
|
'<div class="cell"><label>仓位占比</label><div>' + (row.position_pct != null ? fmtNum(row.position_pct) + '%' : '--') + '</div></div>' +
|
||||||
|
|||||||
Reference in New Issue
Block a user