修复复盘盈亏未按ETH指数折U;买一平仓取消确认,自动卖回USDT。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-20 22:08:28 +08:00
parent e1c2e5889f
commit 4bda3b7703
2 changed files with 43 additions and 26 deletions
+36 -14
View File
@@ -298,22 +298,44 @@ def sync_options_from_local_trades(
def _index_px(underly: str) -> float | None:
u = (underly or "ETH").strip().upper() or "ETH"
pub = ex
if pub is None:
try:
from lib.sim.hooks import _APP_MODULE
pub = getattr(_APP_MODULE, "exchange", None) if _APP_MODULE else None
except Exception:
pub = None
if pub is None:
return None
inst = f"{u}-USDT"
pubs: list[Any] = []
try:
t = pub.fetch_ticker(f"{u}/USDT") or {}
last = t.get("last") or t.get("close")
return float(last) if last is not None else None
from lib.sim.hooks import _APP_MODULE, _sim_public_exchange
pub = _sim_public_exchange(ex) if _APP_MODULE is not None else None
if pub is not None:
pubs.append(pub)
except Exception:
return None
pass
if ex is not None and ex not in pubs:
pubs.append(ex)
for pub in pubs:
try:
if hasattr(pub, "public_get_market_ticker"):
rows = (pub.public_get_market_ticker({"instId": inst}) or {}).get("data") or []
if rows:
last = rows[0].get("last") or rows[0].get("lastPx")
if last is not None and float(last) > 0:
return float(last)
except Exception:
pass
try:
from lib.exchange.okx_options_lib import fetch_index_price
px = fetch_index_price(pub, f"{u}-USD")
if px is not None and float(px) > 0:
return float(px)
except Exception:
pass
try:
t = pub.fetch_ticker(f"{u}/USDT") or {}
last = t.get("last") or t.get("close")
if last is not None and float(last) > 0:
return float(last)
except Exception:
continue
return None
def _to_usdt(amount: float | None, *, ccy: str, idx: float | None) -> float | None:
if amount is None: