模拟盘买币改用公开行情,避免无效 OKX Key 导致 50111。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-20 16:05:10 +08:00
parent f63b3d9f2a
commit 1bb7f9b0ba
2 changed files with 26 additions and 14 deletions
+13
View File
@@ -15,6 +15,19 @@ def _now() -> str:
def _ticker_bid_ask(exchange: Any, symbol: str) -> tuple[float, float]:
"""取买卖一.优先 public ticker,避免私钥无效时 ccxt 带坏 Key 导致 50111."""
inst = symbol.replace("/", "-") if symbol and "/" in symbol else (symbol or "")
if inst and exchange is not None and hasattr(exchange, "public_get_market_ticker"):
try:
rows = (exchange.public_get_market_ticker({"instId": inst}) or {}).get("data") or []
if rows:
t = rows[0]
bid = t.get("bidPx") or t.get("last") or t.get("lastPx")
ask = t.get("askPx") or t.get("last") or t.get("lastPx")
if bid is not None and ask is not None and float(bid) > 0 and float(ask) > 0:
return float(bid), float(ask)
except Exception:
pass
t = exchange.fetch_ticker(symbol)
last = t.get("last")
bid = t.get("bid")