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:
@@ -1981,6 +1981,8 @@ def _position_matches_wanted_contract(wanted_unified_sym, position_dict):
|
||||
|
||||
def _position_row_effective_contracts(p):
|
||||
"""持仓数量:优先 ccxt contracts,否则用交易所原始 positionAmt/size/pos(避免统一层为 0 时被误判空仓)。"""
|
||||
from lib.hub.hub_position_metrics import normalize_contracts_qty
|
||||
|
||||
if not p:
|
||||
return 0.0
|
||||
info = p.get("info") or {}
|
||||
@@ -1990,7 +1992,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
|
||||
@@ -7688,6 +7690,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"],
|
||||
@@ -7705,6 +7714,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)
|
||||
|
||||
Reference in New Issue
Block a user