From 2e09814fe53fa346358f61aad9cf4f0ad136a629 Mon Sep 17 00:00:00 2001 From: dekun Date: Wed, 30 Sep 2026 23:33:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=A0=E5=AF=B9=E5=86=B2?= =?UTF-8?q?=E5=90=8E=E6=8C=81=E4=BB=93=E6=8E=A5=E5=8F=A3=20NameError?= =?UTF-8?q?=EF=BC=9A=E6=81=A2=E5=A4=8D=20tgt=5Fmap/profit=5Fexit=5Fmap=20?= =?UTF-8?q?=E8=B5=8B=E5=80=BC=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- lib/options/options_register.py | 3 +++ tests/test_remove_hedge_smoke.py | 11 +++++++++++ 2 files changed, 14 insertions(+) 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()