Polish dashboard tables: hub-style orders, options source/expiry, hedge status.

Show 进行中 in green for active hedges; options columns include source/target/expiry; merge live mark/contracts/pnl from price snapshot.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-17 12:23:25 +08:00
parent cd2dfac2ba
commit 35117ba84e
7 changed files with 365 additions and 85 deletions
+61
View File
@@ -103,9 +103,70 @@ class TestInstanceDashboardLib(unittest.TestCase):
self.assertEqual(payload["strategy"]["count"], 2)
self.assertTrue(payload["options"]["visible"])
self.assertEqual(payload["options"]["count"], 1)
self.assertEqual(payload["options"]["items"][0]["source_label"], "纯期权")
self.assertFalse(payload["hedge_plan"]["visible"])
conn.close()
def test_hedge_status_label_active(self):
conn = _mem_conn()
conn.executescript(
"""
CREATE TABLE hedge_plans (
id INTEGER PRIMARY KEY,
underlying TEXT,
plan_type TEXT,
status TEXT
);
CREATE TABLE hedge_plan_legs (
id INTEGER PRIMARY KEY,
plan_id INTEGER,
leg_role TEXT,
symbol TEXT,
inst_id TEXT,
opt_type TEXT,
status TEXT
);
"""
)
conn.execute(
"INSERT INTO hedge_plans (id, underlying, plan_type, status) "
"VALUES (2, 'ETH', 'options_options', 'active')"
)
conn.execute(
"INSERT INTO hedge_plan_legs (plan_id, leg_role, inst_id, opt_type, status) "
"VALUES (2, 'option', 'ETH-USD-260719-1850-P', 'P', 'open')"
)
conn.commit()
def fetch_opts():
return [
{
"inst_id": "ETH-USD-260719-1850-P",
"opt_type": "P",
"pos": 40,
"upl": 1.2,
"exp_time_ms": 1784505600000,
"hedge_plan_target": {
"plan_id": 2,
"opt_type": "P",
"target_index": 1800,
},
}
]
payload = build_instance_dashboard_payload(
conn,
fetch_options_positions=fetch_opts,
hedge_enabled=True,
)
self.assertTrue(payload["hedge_plan"]["visible"])
self.assertEqual(payload["hedge_plan"]["items"][0]["status_label"], "进行中")
self.assertTrue(payload["hedge_plan"]["items"][0]["status_active"])
opt = payload["options"]["items"][0]
self.assertEqual(opt["source_label"], "期期对冲")
self.assertIn("对冲#2", opt["target_monitor"])
conn.close()
if __name__ == "__main__":
unittest.main()