From a1d4773189e928f8921c6476632b06782fc3a047 Mon Sep 17 00:00:00 2001 From: claude_dev Date: Fri, 14 Aug 2026 21:51:39 +0800 Subject: [PATCH] =?UTF-8?q?fix(api):=20PUT=20/live=20=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E6=BC=8F=E8=A1=A5vt=5Fsymbol=E5=90=8E=E7=BC=80(=E6=96=B0?= =?UTF-8?q?=E5=BB=BA=E6=9C=89normalize=E7=BC=96=E8=BE=91=E6=B2=A1=E6=9C=89?= =?UTF-8?q?);2026-08-14=E5=AE=9E=E5=86=B5=3D=E7=94=A8=E6=88=B7=E6=94=B9300?= =?UTF-8?q?024=E6=88=90=E8=A3=B8=E7=A0=81=E2=86=92=E5=BC=95=E6=93=8E'vt=5F?= =?UTF-8?q?symbol=E6=97=A0=E6=B3=95=E8=A7=A3=E6=9E=90,=E8=B7=B3=E8=BF=87'?= =?UTF-8?q?=E2=86=92=E5=81=87=E8=BF=90=E8=A1=8C=E6=94=B6=E4=B8=8D=E5=88=B0?= =?UTF-8?q?=E8=A1=8C=E6=83=85;=E7=BC=96=E8=BE=91=E4=B8=8E=E6=96=B0?= =?UTF-8?q?=E5=BB=BA=E5=90=8C=E8=A7=84normalize+=E5=9B=9E=E5=BD=92?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=20[vps]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sanguo_api/routes_live.py | 4 ++++ tests/api/test_portfolio_live.py | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/sanguo_api/routes_live.py b/sanguo_api/routes_live.py index 96fc4fb..3dd46a1 100644 --- a/sanguo_api/routes_live.py +++ b/sanguo_api/routes_live.py @@ -243,6 +243,10 @@ def update_live(aid: int, req: LiveUpdateRequest): } for col, v in field_map.items(): if v is not None: + # 编辑与新建同规:裸 6 位码补交易所后缀(2026-08-14 实况:编辑漏补 + # → 引擎 "vt_symbol 无法解析,跳过" → 假运行收不到行情) + if col == "vt_symbol": + v = _normalize_vt_symbol(v) sets.append(f"{col}=?"); args.append(v) if req.setting is not None: sets.append("setting=?"); args.append(json.dumps(req.setting)) diff --git a/tests/api/test_portfolio_live.py b/tests/api/test_portfolio_live.py index 972dbb5..83156ee 100644 --- a/tests/api/test_portfolio_live.py +++ b/tests/api/test_portfolio_live.py @@ -162,3 +162,29 @@ def test_normalize_vt_symbol_bare_code_gets_exchange_suffix(): assert _normalize_vt_symbol("600000.SSE") == "600000.SSE" assert _normalize_vt_symbol("hs300_subset") == "hs300_subset" assert _normalize_vt_symbol("") == "" + + +def test_update_live_normalizes_vt_symbol(tmp_path, monkeypatch): + """编辑实盘裸码补后缀(2026-08-14 实况:编辑漏补→引擎订阅跳过→假运行)。""" + import os + from fastapi.testclient import TestClient + from sanguo_api.app import create_app + from sanguo_api.auth import create_token, set_jwt_config + from sanguo_api.routes_live import set_db_path + + set_jwt_config(secret="t", expire_minutes=60) + db = os.path.join(str(tmp_path), "l.db") + app = create_app(db_path=db) + set_db_path(db) + c = TestClient(app) + h = {"Authorization": f"Bearer {create_token('admin')}"} + + aid = c.post("/api/v1/live/create", json={ + "name": "t", "account": "A1", "vt_symbol": "600000.SSE", + "strategy_class": "AShareDoubleMaStrategy", + "strategy_name": "AShareDoubleMa_600000", + }, headers=h).json()["account_id"] + r = c.put(f"/api/v1/live/{aid}", json={"vt_symbol": "300024"}, headers=h) + assert r.status_code == 200 + acc = c.get(f"/api/v1/live/{aid}", headers=h).json() + assert acc["vt_symbol"] == "300024.SZSE"