diff --git a/lib/options/options_register.py b/lib/options/options_register.py index b3db227..6d43215 100644 --- a/lib/options/options_register.py +++ b/lib/options/options_register.py @@ -1340,6 +1340,9 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None: try: from lib.options.options_target_lib import targets_by_inst from lib.options.options_profit_exit_lib import profit_exit_by_inst + + tgt_map = targets_by_inst(conn) + profit_exit_map = profit_exit_by_inst(conn) rows = [] for p in raw: inst = str(p.get("instId") or "").strip() diff --git a/tests/test_remove_hedge_smoke.py b/tests/test_remove_hedge_smoke.py index e7f2f55..ad1812c 100644 --- a/tests/test_remove_hedge_smoke.py +++ b/tests/test_remove_hedge_smoke.py @@ -56,6 +56,17 @@ class RemoveHedgeSmokeTests(unittest.TestCase): self.assertFalse(tab_allowed("hedge_plan")) self.assertNotIn("hedge_plan", EMBED_TABS) + def test_positions_api_still_builds_target_maps(self): + """删对冲时勿再漏掉 tgt_map / profit_exit_map 赋值,否则有仓时接口 500、前端暂无持仓.""" + import inspect + from lib.options import options_register + + src = inspect.getsource(options_register.register_options_routes) + self.assertIn("tgt_map = targets_by_inst(conn)", src) + self.assertIn("profit_exit_map = profit_exit_by_inst(conn)", src) + self.assertNotIn("hedge_target_map", src) + self.assertNotIn("hedge_plan_target", src) + if __name__ == "__main__": unittest.main()