Fix Gate mark/PnL/TP-SL snapshot and intraday order UI
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -181,6 +181,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,
|
||||
@@ -7261,9 +7262,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,
|
||||
@@ -7551,25 +7550,31 @@ 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), 2) 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), 2) if margin > 0 else 0
|
||||
payload = {
|
||||
"id": r["id"],
|
||||
"symbol": r["symbol"],
|
||||
"price": round(price, 6),
|
||||
"price_display": format_price_for_symbol(ex_sym, price),
|
||||
"float_pnl": round(pnl, FUNDS_DECIMALS),
|
||||
"float_pct": pnl_pct,
|
||||
"plan_margin": round(margin, FUNDS_DECIMALS) if margin else None,
|
||||
@@ -7579,6 +7584,12 @@ def api_price_snapshot():
|
||||
"exchange_mark_price_display": None,
|
||||
"pnl_source": "plan",
|
||||
}
|
||||
if price is not None:
|
||||
payload["price"] = round(price, 6)
|
||||
payload["price_display"] = format_price_for_symbol(ex_sym, price)
|
||||
else:
|
||||
payload["price"] = None
|
||||
payload["price_display"] = "-"
|
||||
if ex_metrics:
|
||||
if ex_metrics.get("initial_margin") is not None:
|
||||
payload["exchange_initial_margin"] = ex_metrics["initial_margin"]
|
||||
|
||||
Reference in New Issue
Block a user