fix(api): PUT /live 编辑漏补vt_symbol后缀(新建有normalize编辑没有);2026-08-14实况=用户改300024成裸码→引擎'vt_symbol无法解析,跳过'→假运行收不到行情;编辑与新建同规normalize+回归测试 [vps]
CI/CD / test (push) Successful in 17s
CI/CD / nas-deploy (push) Successful in 47s
CI/CD / nas-verify (push) Successful in 14s

This commit is contained in:
2026-08-14 21:51:39 +08:00
parent b27c3b479c
commit a1d4773189
2 changed files with 30 additions and 0 deletions
+4
View File
@@ -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))
+26
View File
@@ -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"