Fix roll position display: live contracts, TP profit, and 2-decimal qty precision.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-08 17:06:33 +08:00
parent 5ef6affabf
commit e3e53ff7f5
15 changed files with 217 additions and 33 deletions
+11 -1
View File
@@ -1941,6 +1941,8 @@ def _position_matches_wanted_contract(wanted_unified_sym, position_dict):
def _position_row_effective_contracts(p):
"""张数:优先 ccxt contracts,否则用 Gate 原始 size/pos(避免统一层为 0 时被误判空仓)。"""
from lib.hub.hub_position_metrics import normalize_contracts_qty
if not p:
return 0.0
info = p.get("info") or {}
@@ -1950,7 +1952,7 @@ def _position_row_effective_contracts(p):
try:
x = abs(float(val))
if x > 0:
return x
return normalize_contracts_qty(x)
except (TypeError, ValueError):
continue
return 0.0
@@ -7551,6 +7553,13 @@ def api_price_snapshot():
except Exception:
exchange_tpsl = {"sl": None, "tp": None}
payload["exchange_tpsl"] = exchange_tpsl
avg_entry = None
if ex_metrics and ex_metrics.get("entry_price") is not None:
avg_entry = ex_metrics["entry_price"]
elif prow:
from lib.hub.hub_position_metrics import parse_position_entry_price
avg_entry = parse_position_entry_price(prow)
apply_order_price_display_fields(
payload,
direction=r["direction"],
@@ -7568,6 +7577,7 @@ def api_price_snapshot():
contracts=abs(_position_row_effective_contracts(prow)) if prow else None,
contract_size=float(get_contract_size(r["symbol"])) if r["symbol"] else 1.0,
mark_price=ex_metrics.get("mark_price") if ex_metrics else price,
avg_entry_price=avg_entry,
funds_decimals=FUNDS_DECIMALS,
)
apply_time_close_to_payload(payload, r)