Fix btc_eth live card option premium USDT conversion.

Use option (BTC) index for coin-to-U; never fall back to ETH perp mark. Also add no-server-ops Cursor rule.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-14 20:48:10 +08:00
parent e1fd77cd06
commit e8f33c3c52
4 changed files with 153 additions and 19 deletions
+42
View File
@@ -172,6 +172,48 @@ class TestHedgePoMode(unittest.TestCase):
self.assertEqual(p["exit_mode"], "profit")
self.assertIn("子账户", p["instance_rule"])
def test_resolve_option_index_cross_no_perp_fallback(self):
# 跨币缺指数时不得用 ETH 永续价折 BTC 权利金(曾导致 0.014×2476≈34U)
from lib.hedge_plan.hedge_plan_live_positions_lib import resolve_option_index_px
with patch(
"lib.exchange.okx_public_http_lib.fetch_index_px",
side_effect=RuntimeError("no net"),
):
px = resolve_option_index_px(
{},
"BTC",
ex_opt=None,
cross_asset=True,
perp_fallback=2476.0,
)
self.assertIsNone(px)
with patch(
"lib.exchange.okx_public_http_lib.fetch_index_px",
return_value=91000.0,
):
px = resolve_option_index_px(
{},
"BTC",
cross_asset=True,
perp_fallback=2476.0,
)
self.assertAlmostEqual(px, 91000.0)
# 同币允许永续价兜底
with patch(
"lib.exchange.okx_public_http_lib.fetch_index_px",
side_effect=RuntimeError("no net"),
):
px = resolve_option_index_px(
{},
"ETH",
cross_asset=False,
perp_fallback=2476.0,
)
self.assertAlmostEqual(px, 2476.0)
if __name__ == "__main__":
unittest.main()