Fix float P/L when using OpenCost entry and clear CTP hint on connect.

Recalculate position quotes from resolved entry instead of stale CTP PositionProfit, and hide the auto-connect disabled banner once CTP is connected.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-02 21:24:48 +08:00
parent dca773d6be
commit 075fae37ec
2 changed files with 10 additions and 7 deletions
+6 -5
View File
@@ -2337,19 +2337,20 @@ def install_trading(app, *, login_required, require_nav, get_db, get_setting, se
mark = ctp_get_tick_price(mode, ths)
if not mark or mark <= 0:
continue
entry, _ = _resolve_ctp_entry_price(
entry, entry_src = _resolve_ctp_entry_price(
mode, ths, direction, p,
)
if entry <= 0:
continue
mult = float(get_contract_spec(ths).get("mult") or 10)
ctp_pnl = float(p.get("pnl") or 0)
if ctp_pnl != 0:
float_pnl = round(ctp_pnl, 2)
elif direction == "long":
if direction == "long":
float_pnl = round((mark - entry) * mult * lots, 2)
else:
float_pnl = round((entry - mark) * mult * lots, 2)
if entry_src == "position_cost":
ctp_pnl = float(p.get("pnl") or 0)
if ctp_pnl != 0:
float_pnl = round(ctp_pnl, 2)
row_key = _canonical_position_key(
ths, direction, (p.get("exchange") or ""),
)
+4 -2
View File
@@ -299,14 +299,16 @@
syncBadge.textContent = '';
}
}
if (!connected && !connecting && data.ctp_status && data.ctp_status.last_error) {
if (connected) {
showCtpError('');
} else if (!connecting && data.ctp_status && data.ctp_status.last_error) {
showCtpError(data.ctp_status.last_error);
if (isCtpLoginBanError(data.ctp_status.last_error)) {
lastCtpLoginBanAt = Date.now();
} else if (isCtpUnreachableError(data.ctp_status.last_error)) {
lastCtpUnreachableAt = Date.now();
}
} else if (!connected && data.ctp_status && data.ctp_status.disabled_hint) {
} else if (!connecting && data.ctp_status && data.ctp_status.disabled_hint) {
showCtpError(data.ctp_status.disabled_hint);
}
var riskBadge = document.getElementById('risk-badge');