模拟盘买币改用公开行情,避免无效 OKX Key 导致 50111。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user