修复审计P1:基数纠偏用开仓止损并清空币数量、Gate保证金/手动平仓成交价/全仓实盘空仓校验、OKX·Binance占位函数、快照超时。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -3106,13 +3106,16 @@ def parse_ccxt_position_metrics(position, order_leverage=None):
|
||||
return None
|
||||
p = position
|
||||
info = p.get("info", {}) or {}
|
||||
initial = _coerce_float(p.get("collateral"), p.get("initialMargin"), p.get("margin"))
|
||||
# 优先 initialMargin;collateral 常含未实现,仅作兜底
|
||||
initial = _coerce_float(p.get("initialMargin"), p.get("margin"))
|
||||
if initial is None or initial <= 0:
|
||||
initial = _coerce_float(
|
||||
info.get("margin"),
|
||||
info.get("imr"),
|
||||
info.get("initial_margin"),
|
||||
)
|
||||
if initial is None or initial <= 0:
|
||||
initial = _coerce_float(p.get("collateral"))
|
||||
notional = _coerce_float(p.get("notional"), p.get("notionalValue"))
|
||||
if notional is None or notional <= 0:
|
||||
notional = _coerce_float(info.get("notionalUsd"), info.get("notional"))
|
||||
@@ -3136,6 +3139,26 @@ def parse_ccxt_position_metrics(position, order_leverage=None):
|
||||
)
|
||||
mark = _coerce_float(p.get("markPrice"), p.get("mark_price"), info.get("markPx"))
|
||||
out = {}
|
||||
try:
|
||||
contracts = abs(float(p.get("contracts") or info.get("pos") or 0))
|
||||
except (TypeError, ValueError):
|
||||
contracts = 0.0
|
||||
coin_amt = None
|
||||
if contracts > 0:
|
||||
try:
|
||||
sym0 = (p.get("symbol") or "").strip()
|
||||
cs0 = float(get_contract_size(sym0)) if sym0 else 1.0
|
||||
coin_amt = contracts * cs0 if cs0 > 0 else None
|
||||
except Exception:
|
||||
coin_amt = None
|
||||
from lib.trade.trade_margin_record_lib import sanitize_exchange_initial_margin
|
||||
|
||||
initial = sanitize_exchange_initial_margin(
|
||||
initial,
|
||||
notional=notional,
|
||||
order_leverage=order_leverage,
|
||||
coin_amount=coin_amt,
|
||||
)
|
||||
if initial is not None and initial > 0:
|
||||
out["initial_margin"] = round(initial, FUNDS_DECIMALS)
|
||||
if notional is not None and notional > 0:
|
||||
@@ -3410,6 +3433,11 @@ def get_live_position_exchange_metrics(exchange_symbol, direction, order_leverag
|
||||
return parse_ccxt_position_metrics(prow, order_leverage=order_leverage)
|
||||
|
||||
|
||||
def try_persist_exchange_margin_for_order(conn, order_id, exchange_symbol, direction, order_leverage=None, max_attempts=6, sleep_s=0.45):
|
||||
"""OKX 暂无 order_monitors.exchange_margin_usdt 列;占位避免开仓后 NameError."""
|
||||
return False
|
||||
|
||||
|
||||
def opened_at_str_to_ms(opened_at_str):
|
||||
if not opened_at_str:
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user