修复 OKX 期权翻倍出场与币本位浮盈:中控/看板按指数折 U,避免 BTC 币数量当美金。

翻倍出场按全仓买一判定且对冲表异常不再整段跳过;面板按当前倍数展示需回收公式。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-09-30 22:17:02 +08:00
parent bd4adc9eca
commit 32746b0a34
9 changed files with 212 additions and 71 deletions
+40
View File
@@ -79,12 +79,52 @@ class HubOptionsFundsLibTests(TestCase):
"premium_ccy": "ETH",
"upl": 0.0016,
"idx_px": 2280.0,
"close_preview": {"bid_invalid": True},
}
],
}
out = options_float_pnl_usdt(snap)
self.assertAlmostEqual(out, round(0.0016 * 2280.0, 4), places=4)
def test_options_float_pnl_usdt_btc_coin_times_btc_index(self):
from lib.hub.hub_options_funds_lib import options_float_pnl_usdt
snap = {
"ok": True,
"enabled": True,
"options_margin_mode": "coin",
# 默认指数若误用 ETH 也不应覆盖逐仓 BTC idx
"options_index_px": 3000.0,
"upl_total_usdc": -100.0,
"positions": [
{
"inst_id": "BTC-USD-260327-100000-P",
"margin_mode": "coin",
"premium_ccy": "BTC",
"upl": -0.001,
"idx_px": 100000.0,
"close_preview": {"bid_invalid": True},
}
],
}
out = options_float_pnl_usdt(snap)
self.assertAlmostEqual(out, -100.0, places=4)
def test_options_float_pnl_usdt_fallback_already_usdt_no_double_fx(self):
"""实例 hub 合计已折 U 时,回退不可再 × 指数."""
from lib.hub.hub_options_funds_lib import options_float_pnl_usdt
snap = {
"ok": True,
"enabled": True,
"options_margin_mode": "coin",
"options_index_px": 100000.0,
"upl_total_usdc": -100.0,
"positions": [],
}
out = options_float_pnl_usdt(snap)
self.assertAlmostEqual(out, -100.0, places=4)
def test_repair_double_counted_fund_entry(self):
raw = {
"funding_usdt": 586.82,