fix: OKX 持仓张数优先读 info.pos,滚仓后同步 order_amount

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-02 22:40:41 +08:00
parent 394793b9d2
commit be7896cc25
4 changed files with 51 additions and 22 deletions
+15 -12
View File
@@ -2817,18 +2817,20 @@ def exchange_private_api_configured():
def _position_row_effective_contracts(p):
info = p.get("info", {}) or {}
contracts = p.get("contracts")
if contracts is None:
raw_pos = info.get("pos")
try:
contracts = abs(float(raw_pos)) if raw_pos is not None else 0.0
except Exception:
contracts = 0.0
try:
return float(contracts)
except Exception:
"""张数:OKX 以 info.pos 为准,再兜底 ccxt contracts 等(与 Binance/Gate 多字段一致)。"""
if not p:
return 0.0
info = p.get("info", {}) or {}
for val in (info.get("pos"), p.get("contracts"), info.get("positionAmt"), info.get("size")):
if val is None or val == "":
continue
try:
x = abs(float(val))
if x > 0:
return x
except (TypeError, ValueError):
continue
return 0.0
def _position_matches_wanted_contract(exchange_symbol, position):
@@ -6685,7 +6687,7 @@ def api_price_snapshot():
"SELECT id,symbol,monitor_type,direction,upper,lower,fib_entry_price,fib_stop_loss,fib_take_profit,fib_limit_order_id,created_at FROM key_monitors"
).fetchall()
order_rows = conn.execute(
"SELECT id,symbol,exchange_symbol,direction,trigger_price,stop_loss,initial_stop_loss,take_profit,margin_capital,leverage,"
"SELECT id,symbol,exchange_symbol,direction,trigger_price,stop_loss,initial_stop_loss,take_profit,margin_capital,leverage,order_amount,"
"time_close_enabled,time_close_hours,time_close_at_ms,opened_at_ms FROM order_monitors WHERE status='active'"
).fetchall()
@@ -6878,6 +6880,7 @@ def api_price_snapshot():
"float_pnl": round(pnl, 2),
"float_pct": pnl_pct,
"plan_margin": round(margin, 2) if margin else None,
"order_amount": float(r["order_amount"]) if r["order_amount"] not in (None, "") else None,
"exchange_initial_margin": None,
"exchange_notional": None,
"exchange_mark_price": None,