Show hedge targets in options monitoring

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-17 07:15:00 +08:00
parent 6e6cb7caac
commit 8f71dbe874
8 changed files with 150 additions and 10 deletions
+39
View File
@@ -4,6 +4,7 @@ import unittest
from lib.hedge_plan.hedge_plan_db import (
_metrics_from_pnls,
active_options_targets_by_inst,
delete_plan,
init_hedge_plan_tables,
insert_leg,
@@ -116,6 +117,44 @@ class TestHedgeHistoryStats(unittest.TestCase):
self.assertIn("永续 ETH/USDT:USDT", s)
self.assertIn("ETH-USD_UM-260715-1790-P", s)
def test_active_options_targets_are_read_only_plan_targets(self):
conn = _mem()
pid = insert_plan(
conn,
{
"plan_type": "options_options",
"status": "active",
"underlying": "ETH",
"target_price_up": 1950,
"target_price_down": 1800,
},
)
insert_leg(
conn,
{
"plan_id": pid,
"leg_role": "option_a",
"inst_id": "ETH-USD_UM-260719-1890-C",
"opt_type": "C",
"status": "open",
},
)
insert_leg(
conn,
{
"plan_id": pid,
"leg_role": "option_b",
"inst_id": "ETH-USD_UM-260719-1850-P",
"opt_type": "P",
"status": "open",
},
)
targets = active_options_targets_by_inst(conn)
self.assertEqual(targets["ETH-USD_UM-260719-1890-C"]["target_index"], 1950)
self.assertEqual(targets["ETH-USD_UM-260719-1850-P"]["target_index"], 1800)
self.assertEqual(targets["ETH-USD_UM-260719-1890-C"]["managed_by"], "hedge_plan")
if __name__ == "__main__":
unittest.main()