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:
@@ -2876,6 +2876,8 @@ def exchange_private_api_configured():
|
||||
|
||||
def _position_row_effective_contracts(p):
|
||||
"""张数:OKX 以 info.pos 为准,再兜底 ccxt contracts 等(与 Binance/Gate 多字段一致)。"""
|
||||
from lib.hub.hub_position_metrics import normalize_contracts_qty
|
||||
|
||||
if not p:
|
||||
return 0.0
|
||||
info = p.get("info", {}) or {}
|
||||
@@ -2885,7 +2887,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
|
||||
@@ -7248,6 +7250,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"],
|
||||
@@ -7265,6 +7274,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