feat(HEL-382): 搭建 datahub 底座和盘后正式数据链路

新增独立 xiaobai-datahub 服务(SQLite WAL、Tushare 盘后发布、/v1 契约和管理后台),不改现站页面与数据链路。

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
总工
2026-09-02 12:05:26 +08:00
co-authored by Cursor multica-agent
parent c2ebc0ab91
commit 3498dd7a4b
52 changed files with 4259 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
from __future__ import annotations
from datahub.db import HubDB
def resolve_code(db: HubDB, raw: str) -> str | None:
text = str(raw or "").strip().upper()
if not text:
return None
if "." in text:
row = db.fetchone("SELECT ts_code FROM stock_master WHERE ts_code = ?", (text,))
if row:
return row["ts_code"]
# indices are not always in stock_master
return text
matches = db.fetchall(
"SELECT ts_code FROM stock_master WHERE symbol = ? OR ts_code LIKE ?",
(text, f"{text}.%"),
)
if len(matches) == 1:
return matches[0]["ts_code"]
if len(matches) > 1:
return None
# unique exchange guess for 6-digit codes
suffix = "SH" if text.startswith("6") or text.startswith("9") else "SZ" if text.startswith(("0", "3")) else "BJ"
return f"{text}.{suffix}"