Audit fixes: LIVE symbols/fills/expiry/pending, security harden, add 更新说明.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -126,9 +126,7 @@ class OkxTradeClient:
|
||||
if v and v > 0:
|
||||
self._ct_val_cache[inst_id] = float(v)
|
||||
return float(v)
|
||||
default = 0.01
|
||||
self._ct_val_cache[inst_id] = default
|
||||
return default
|
||||
raise RuntimeError(f"OKX 无法取得合约面值 ctVal: {inst_id} instType={inst_type}")
|
||||
|
||||
def place_market(
|
||||
self,
|
||||
@@ -159,7 +157,7 @@ class OkxTradeClient:
|
||||
fill = self._wait_fill(inst_id, ord_id)
|
||||
return fill
|
||||
|
||||
def _wait_fill(self, inst_id: str, ord_id: str, *, tries: int = 8) -> LiveFill:
|
||||
def _wait_fill(self, inst_id: str, ord_id: str, *, tries: int = 20) -> LiveFill:
|
||||
path = f"/api/v5/trade/order?instId={inst_id}&ordId={ord_id}"
|
||||
last: dict[str, Any] = {}
|
||||
for _ in range(tries):
|
||||
@@ -168,11 +166,11 @@ class OkxTradeClient:
|
||||
last = rows[0]
|
||||
state = str(last.get("state") or "")
|
||||
avg = safe_float(last.get("avgPx"))
|
||||
if state in ("filled", "partially_filled") and avg and avg > 0:
|
||||
# 仅完全成交;部分成交继续等,避免账本张数与交易所不一致
|
||||
if state == "filled" and avg and avg > 0:
|
||||
sz = safe_float(last.get("accFillSz")) or safe_float(last.get("sz")) or 0.0
|
||||
fee = abs(safe_float(last.get("fee")) or 0.0)
|
||||
fee_ccy = str(last.get("feeCcy") or "USDT")
|
||||
# 订单上 fee 常为空,再查成交明细
|
||||
if fee <= 0 and ord_id:
|
||||
fee, fee_ccy = self.sum_fill_fees(inst_id, ord_id)
|
||||
from .money import abs_fee_usdt
|
||||
@@ -188,8 +186,8 @@ class OkxTradeClient:
|
||||
)
|
||||
if state in ("canceled", "failed"):
|
||||
raise RuntimeError(f"OKX 订单失败 state={state} {last}")
|
||||
time.sleep(0.25)
|
||||
raise RuntimeError(f"OKX 订单未成交 ordId={ord_id} last={last}")
|
||||
time.sleep(0.3)
|
||||
raise RuntimeError(f"OKX 订单未完全成交 ordId={ord_id} last={last}")
|
||||
|
||||
def sum_fill_fees(self, inst_id: str, ord_id: str) -> tuple[float, str]:
|
||||
"""成交明细手续费合计(原币种金额, 币种)。"""
|
||||
|
||||
Reference in New Issue
Block a user