Fix hub funds overview double-counting OKX USDT with options.

Only add options USDC/USDG onto perpetual USDT totals, repair historical double-counted snapshots, and label the options line as USDC.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-07 10:30:34 +08:00
parent 4bc238b014
commit 0b8e5a0914
5 changed files with 134 additions and 19 deletions
+40 -3
View File
@@ -4,6 +4,7 @@ from lib.hub.hub_options_funds_lib import (
merge_board_row_balances,
merge_perp_options_balances,
options_balances_usdt_equiv,
repair_double_counted_fund_entry,
)
@@ -18,20 +19,30 @@ class HubOptionsFundsLibTests(TestCase):
self.assertTrue(out["ok"])
self.assertEqual(out["funding_usdt"], 10.0)
self.assertEqual(out["trading_usdt"], 7.0)
self.assertEqual(out["funding_usdc_equiv"], 10.0)
self.assertEqual(out["trading_usdc_equiv"], 2.0)
def test_merge_perp_options_balances(self):
def test_merge_perp_options_balances_adds_usdc_only(self):
"""永续已含同账户 USDT 时,只叠加期权 USDC,避免双计."""
out = merge_perp_options_balances(
100,
50,
{
"ok": True,
"enabled": True,
"balances": {"funding_usdc": 8, "trading_usdc": 4},
"balances": {
"funding_usdt": 100,
"funding_usdc": 8,
"trading_usdt": 50,
"trading_usdc": 4,
},
},
)
self.assertEqual(out["funding_usdt"], 108.0)
self.assertEqual(out["trading_usdt"], 54.0)
self.assertEqual(out["total_usdt"], 162.0)
self.assertEqual(out["options_funding_usdt"], 8.0)
self.assertEqual(out["options_trading_usdt"], 4.0)
def test_merge_board_row_balances(self):
row = {
@@ -42,7 +53,7 @@ class HubOptionsFundsLibTests(TestCase):
"options": {
"ok": True,
"enabled": True,
"balances": {"funding_usdc": 1, "trading_usdc": 2},
"balances": {"funding_usdt": 20, "funding_usdc": 1, "trading_usdc": 2},
"positions": [{"inst_id": "X"}],
"upl_total_usdc": 0.5,
},
@@ -51,3 +62,29 @@ class HubOptionsFundsLibTests(TestCase):
self.assertEqual(out["total_usdt"], 53.0)
self.assertEqual(out["options_open_position_count"], 1)
self.assertEqual(out["options_float_pnl_u"], 0.5)
def test_repair_double_counted_fund_entry(self):
raw = {
"funding_usdt": 586.82,
"trading_usdt": 69.46,
"total_usdt": 656.28,
"options_funding_usdt": 293.26,
"options_trading_usdt": 69.44,
}
fixed = repair_double_counted_fund_entry(raw)
self.assertTrue(fixed.get("repaired_double_count"))
self.assertEqual(fixed["funding_usdt"], 293.26)
self.assertEqual(fixed["trading_usdt"], 69.44)
self.assertEqual(fixed["total_usdt"], round(293.26 + 69.44, 4))
def test_repair_skips_new_usdc_only_options_line(self):
raw = {
"funding_usdt": 293.26,
"trading_usdt": 69.44,
"total_usdt": 362.7,
"options_funding_usdt": 0.5,
"options_trading_usdt": 69.42,
}
fixed = repair_double_counted_fund_entry(raw)
self.assertFalse(fixed.get("repaired_double_count"))
self.assertEqual(fixed["total_usdt"], 362.7)