diff --git a/modules/trading/install.py b/modules/trading/install.py index 93c2db1..2427538 100644 --- a/modules/trading/install.py +++ b/modules/trading/install.py @@ -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 ""), ) diff --git a/modules/web/static/js/trade.js b/modules/web/static/js/trade.js index 3135afb..6519f5d 100644 --- a/modules/web/static/js/trade.js +++ b/modules/web/static/js/trade.js @@ -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');