修复交易记录基数误把折算标的币数量当保证金:写入清洗+列表展示自动纠偏。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+45
-10
@@ -3803,6 +3803,24 @@ def parse_ccxt_position_metrics(position, order_leverage=None):
|
||||
)
|
||||
mark = _coerce_float(p.get("markPrice"), p.get("mark_price"), info.get("mark_price"), info.get("markPrice"))
|
||||
out = {}
|
||||
try:
|
||||
contracts = abs(float(p.get("contracts") or info.get("size") or 0))
|
||||
except (TypeError, ValueError):
|
||||
contracts = 0.0
|
||||
try:
|
||||
sym0 = (p.get("symbol") or "").strip()
|
||||
cs0 = float(get_contract_size(sym0)) if sym0 else 1.0
|
||||
except Exception:
|
||||
cs0 = 1.0
|
||||
coin_amt = contracts * cs0 if contracts > 0 and cs0 > 0 else 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, 2)
|
||||
if notional is not None and notional > 0:
|
||||
@@ -3859,21 +3877,38 @@ def _order_row_exchange_margin_usdt(row):
|
||||
|
||||
def margin_capital_for_trade_record(order_row):
|
||||
"""trade_records.基数:优先交易所持仓保证金快照,旧数据无快照时回退计划保证金."""
|
||||
ex = _order_row_exchange_margin_usdt(order_row)
|
||||
if ex is not None:
|
||||
return round(ex, 2)
|
||||
from lib.trade.trade_margin_record_lib import resolve_trade_record_margin_usdt
|
||||
|
||||
if not order_row:
|
||||
return None
|
||||
try:
|
||||
v = order_row["margin_capital"]
|
||||
plan = order_row["margin_capital"]
|
||||
except (TypeError, KeyError, IndexError):
|
||||
return None
|
||||
if v is None:
|
||||
return None
|
||||
plan = None
|
||||
base = None
|
||||
notional = None
|
||||
lev = None
|
||||
trigger = None
|
||||
try:
|
||||
return float(v)
|
||||
except (TypeError, ValueError):
|
||||
return None
|
||||
keys = order_row.keys()
|
||||
except Exception:
|
||||
keys = []
|
||||
if "base_amount" in keys:
|
||||
base = order_row["base_amount"]
|
||||
if "notional_value" in keys:
|
||||
notional = order_row["notional_value"]
|
||||
if "leverage" in keys:
|
||||
lev = order_row["leverage"]
|
||||
if "trigger_price" in keys:
|
||||
trigger = order_row["trigger_price"]
|
||||
return resolve_trade_record_margin_usdt(
|
||||
exchange_margin_usdt=_order_row_exchange_margin_usdt(order_row),
|
||||
plan_margin_capital=plan,
|
||||
base_amount=base,
|
||||
notional_value=notional,
|
||||
leverage=lev,
|
||||
trigger_price=trigger,
|
||||
)
|
||||
|
||||
|
||||
def try_persist_exchange_margin_for_order(conn, order_id, exchange_symbol, direction, order_leverage=None, max_attempts=6, sleep_s=0.45):
|
||||
|
||||
Reference in New Issue
Block a user