中控期权浮盈只显示U;总浮盈亏按指数把币本位浮盈计入USDT

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-20 18:13:39 +08:00
parent 467f4f092f
commit 1ddfe3f72e
4 changed files with 136 additions and 14 deletions
+28 -1
View File
@@ -66,6 +66,33 @@ class TestHubMonitorTotals(unittest.TestCase):
self.assertEqual(out["options_float_pnl_u"], 1.5)
self.assertEqual(out["float_pnl_u"], 1.5)
def test_aggregate_monitor_board_totals_coin_options_to_usdt(self):
rows = [
{
"capabilities": ["options"],
"options": {
"ok": True,
"enabled": True,
"options_margin_mode": "coin",
"options_index_px": 2000.0,
"positions": [
{
"inst_id": "ETH-USD-260822-2250-C",
"margin_mode": "coin",
"premium_ccy": "ETH",
"upl": 0.002,
"idx_px": 2000.0,
}
],
"upl_total_usdc": 0.002,
},
"agent": {"positions": [], "total_unrealized_pnl": 10.0},
}
]
out = aggregate_monitor_board_totals(rows, trading_day="2026-08-20", reset_hour=8)
self.assertEqual(out["options_float_pnl_u"], 4.0)
self.assertEqual(out["float_pnl_u"], 14.0)
def test_aggregate_excludes_option_like_agent_positions(self):
"""子代理误把期权当永续上报时:不算进持仓数,浮盈只用期权 snap."""
rows = [
@@ -74,7 +101,7 @@ class TestHubMonitorTotals(unittest.TestCase):
"options": {
"ok": True,
"enabled": True,
"positions": [{"inst_id": "ETH-USD-260806-1875-C"}],
"positions": [{"inst_id": "ETH-USD_UM-260806-1875-C"}],
"upl_total_usdc": -0.4,
},
"agent": {
+22
View File
@@ -63,6 +63,28 @@ class HubOptionsFundsLibTests(TestCase):
self.assertEqual(out["options_open_position_count"], 1)
self.assertEqual(out["options_float_pnl_u"], 0.5)
def test_options_float_pnl_usdt_coin_converts_by_index(self):
from lib.hub.hub_options_funds_lib import options_float_pnl_usdt
snap = {
"ok": True,
"enabled": True,
"options_margin_mode": "coin",
"options_index_px": 2280.0,
"upl_total_usdc": 0.0016,
"positions": [
{
"inst_id": "ETH-USD-260822-2250-C",
"margin_mode": "coin",
"premium_ccy": "ETH",
"upl": 0.0016,
"idx_px": 2280.0,
}
],
}
out = options_float_pnl_usdt(snap)
self.assertAlmostEqual(out, round(0.0016 * 2280.0, 4), places=4)
def test_repair_double_counted_fund_entry(self):
raw = {
"funding_usdt": 586.82,