Fix Gate mark/PnL/TP-SL snapshot and intraday order UI

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-06 22:04:19 +08:00
parent 5e4f885f80
commit d4a76f05d2
10 changed files with 315 additions and 50 deletions
+31 -15
View File
@@ -180,6 +180,7 @@ from lib.trade.entry_model_lib import (
hub_meta_entry_context,
migrate_entry_model_columns,
order_entry_template_context,
open_position_button_label,
parse_manual_order_style_fields,
resolve_trade_record_entry_reason,
trend_manual_entry_reason_count,
@@ -7042,9 +7043,7 @@ def render_main_page(page="trade", embed_mode=None):
position_sizing_mode_label=mode_label_zh(POSITION_SIZING_MODE),
trade_policy=trade_policy_template_context(TRADE_POLICY),
**order_entry_template_context(TRADE_POLICY),
open_position_button_label=(
"开仓(全仓杠杆)" if is_full_margin_mode(POSITION_SIZING_MODE) else "开仓(以损定仓)"
),
open_position_button_label=open_position_button_label(TRADE_POLICY, POSITION_SIZING_MODE),
breakeven_rr_trigger=BREAKEVEN_RR_TRIGGER,
breakeven_offset_pct=BREAKEVEN_OFFSET_PCT,
price_fmt=format_price_for_symbol,
@@ -7365,20 +7364,28 @@ def api_price_snapshot():
})
order_prices = []
from lib.hub.price_snapshot_lib import resolve_order_snapshot_price
for r in order_rows:
price = prices.get(r["symbol"])
if price is None:
continue
margin = float(r["margin_capital"] or 0)
leverage = float(r["leverage"] or 0)
entry = float(r["trigger_price"] or 0)
pnl = calc_pnl(r["direction"], entry, price, margin, leverage) if entry > 0 else 0
pnl_pct = round((pnl / margin * 100), 4) if margin > 0 else 0
exchange_tpsl = {"sl": None, "tp": None}
ex_sym = resolve_monitor_exchange_symbol(r)
prow = _select_live_position_row(all_swap_positions, ex_sym, r["direction"])
lev_row = r["leverage"] if "leverage" in r.keys() else None
ex_metrics = parse_ccxt_position_metrics(prow, order_leverage=lev_row) if prow else None
price = resolve_order_snapshot_price(
r["symbol"],
prices,
position_row=prow,
order_leverage=lev_row,
parse_position_metrics_fn=parse_ccxt_position_metrics,
get_mark_price_fn=get_symbol_mark_price,
fallback_entry=entry if entry > 0 else None,
)
pnl = calc_pnl(r["direction"], entry, price, margin, leverage) if entry > 0 and price else 0
pnl_pct = round((pnl / margin * 100), 4) if margin > 0 else 0
payload = {
"id": r["id"],
"symbol": r["symbol"],
@@ -7404,18 +7411,27 @@ def api_price_snapshot():
payload["float_pct"] = (
round((payload["float_pnl"] / float(denom)) * 100, 4) if denom and float(denom) > 0 else pnl_pct
)
px_for_fmt = float(price)
px_for_fmt = None
if price is not None:
try:
px_for_fmt = float(price)
except (TypeError, ValueError):
px_for_fmt = None
if ex_metrics and ex_metrics.get("mark_price") is not None:
try:
px_for_fmt = float(ex_metrics["mark_price"])
except (TypeError, ValueError):
pass
px_disp = format_price_for_symbol(r["symbol"], px_for_fmt)
try:
payload["price"] = float(px_disp) if px_disp != "-" else px_for_fmt
except Exception:
payload["price"] = px_for_fmt
payload["price_display"] = px_disp
if px_for_fmt is not None:
px_disp = format_price_for_symbol(r["symbol"], px_for_fmt)
try:
payload["price"] = float(px_disp) if px_disp != "-" else px_for_fmt
except Exception:
payload["price"] = px_for_fmt
payload["price_display"] = px_disp
else:
payload["price"] = None
payload["price_display"] = "-"
if exchange_private_api_configured():
try:
exchange_tpsl = fetch_exchange_tpsl_slots(