Fix hedge market quotes via public HTTP and default cloud-server deploy settings.

Avoid load_markets hangs on weak networks; enable login-required sim defaults and document Baota Nginx reverse proxy.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-14 10:13:39 +08:00
parent b4d62ea0a6
commit 135cdc13ba
11 changed files with 392 additions and 118 deletions
+46 -4
View File
@@ -723,11 +723,34 @@ def options_header_balance_pack(
def fetch_index_price(ex: ccxt.okx, uly: str) -> float | None:
inst = f"{uly}" if "-" in uly else f"{uly}-USD"
"""指数价:优先公共 HTTP/curl,再回退 ccxt."""
try:
rows = ex.public_get_market_index_tickers({"instId": inst}).get("data") or []
from lib.exchange.okx_public_http_lib import fetch_index_px
px = fetch_index_px(uly)
if px and px > 0:
return float(px)
except Exception:
pass
u = (uly or "ETH").strip().upper() or "ETH"
candidates = [u] if "-" in u else [f"{u}-USD", f"{u}-USDT"]
for inst in candidates:
try:
rows = ex.public_get_market_index_tickers({"instId": inst}).get("data") or []
if rows:
px = _safe_float(rows[0].get("idxPx"))
if px and px > 0:
return px
except Exception:
continue
try:
rows = (ex.public_get_market_ticker({"instId": f"{u.split('-')[0]}-USDT-SWAP"}) or {}).get(
"data"
) or []
if rows:
return _safe_float(rows[0].get("idxPx"))
px = _safe_float(rows[0].get("markPx")) or _safe_float(rows[0].get("last"))
if px and px > 0:
return px
except Exception:
pass
return None
@@ -755,6 +778,16 @@ def fetch_option_instruments(
):
return list(entry["rows"])
last_err: Exception | None = None
try:
from lib.exchange.okx_public_http_lib import fetch_option_instruments_public
live = fetch_option_instruments_public(family)
with _OPTION_INSTRUMENTS_CACHE_LOCK:
_OPTION_INSTRUMENTS_CACHE[family] = {"updated_at": now, "rows": live}
return list(live)
except Exception as e:
last_err = e
try:
rows = ex.public_get_public_instruments(
{"instType": "OPTION", "instFamily": family}
@@ -764,6 +797,7 @@ def fetch_option_instruments(
_OPTION_INSTRUMENTS_CACHE[family] = {"updated_at": now, "rows": live}
return list(live)
except Exception as e:
last_err = e
if allow_stale:
with _OPTION_INSTRUMENTS_CACHE_LOCK:
entry = _OPTION_INSTRUMENTS_CACHE.get(family)
@@ -771,11 +805,19 @@ def fetch_option_instruments(
age = now - float(entry.get("updated_at") or 0)
if age <= _OPTION_INSTRUMENTS_STALE_MAX:
return list(entry["rows"])
raise
raise last_err
def fetch_option_tickers(ex: ccxt.okx, inst_family: str) -> dict[str, dict[str, Any]]:
out: dict[str, dict[str, Any]] = {}
try:
from lib.exchange.okx_public_http_lib import fetch_option_tickers_public
got = fetch_option_tickers_public(inst_family)
if got:
return got
except Exception:
pass
try:
rows = ex.public_get_market_tickers(
{"instType": "OPTION", "instFamily": inst_family}