Fix hub total floating PnL by excluding OKX options from swap agent.

Option legs were scored with linear swap math and then added again from the options snapshot, inflating 总浮盈亏 and 持有仓位.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-05 22:13:22 +08:00
parent 3f6e67661b
commit 7352d10254
5 changed files with 209 additions and 69 deletions
+15
View File
@@ -14,6 +14,7 @@ sys.path.insert(0, str(ROOT))
from lib.hub.hub_position_metrics import ( # noqa: E402
enrich_ccxt_position_metrics_out,
estimate_linear_swap_upnl_usdt,
is_option_like_position,
parse_position_unrealized_pnl,
resolve_position_display_upnl,
)
@@ -89,6 +90,20 @@ class TestHubAgentMarkPrice(unittest.TestCase):
)
self.assertAlmostEqual(shown, 7.86, places=2)
def test_is_option_like_position(self):
self.assertTrue(
is_option_like_position({"symbol": "ETH/USD:USD-260806-1875-C", "contracts": 1})
)
self.assertTrue(
is_option_like_position(
{"symbol": "x", "info": {"instType": "OPTION", "instId": "ETH-USD-260806-1875-P"}}
)
)
self.assertFalse(
is_option_like_position({"symbol": "BTC/USDT:USDT", "contracts": 10})
)
self.assertFalse(is_option_like_position({"symbol": "ETH/USDT:USDT"}))
if __name__ == "__main__":
unittest.main()