币种标记标准化 + data-pipeline诊断文档

stale_detector: HK股价格输出加(HKD)标记,防止LLM混读CNY/HKD
per_stock_reassess: 写回decisions.json的HK股加上currency: HKD
docs/data-pipeline-diagnosis.md: 完整数据管道重构需求文档

避免建滔积层板CNY/HKD错配类问题复发
This commit is contained in:
知微
2026-06-30 11:13:45 +08:00
parent 28afb14769
commit 28c001684e
4 changed files with 162 additions and 62 deletions
+14 -17
View File
@@ -43,29 +43,23 @@ def main():
try:
import urllib.request
code_raw = entry.get("code", "")
sym_map = {"6":"sh","5":"sh","0":"sz","3":"sz"}
prefix = ""
for k, v in sym_map.items():
if code_raw.startswith(k):
prefix = v
break
# 港股5位代码(含0开头)→ 前缀hk
if len(code_raw) == 5 and code_raw[0] in '01':
prefix = "hk"
else:
sym_map = {"6":"sh","5":"sh","0":"sz","3":"sz"}
for k, v in sym_map.items():
if code_raw.startswith(k):
prefix = v
break
if not prefix:
prefix = "hk" if len(code_raw) == 5 else "sz"
prefix = "sz"
url = f"http://qt.gtimg.cn/q={prefix}{code_raw}"
resp = urllib.request.urlopen(url, timeout=5)
text = resp.read().decode("gbk")
fields = text.split('"')[1].split("~")
price = float(fields[3]) if fields[3] else 0
# 港股:腾讯API返回HKD,统一转CNY
if len(code_raw) == 5 and code_raw[0] in '01':
try:
sys.path.insert(0, '/home/hmo/MoFin')
from hk_rate import hkd_to_cny
_hkd_rate = hkd_to_cny()
except Exception:
_hkd_rate = 0.87
price = round(price * _hkd_rate, 2)
print(f" 实时价: {price} {'(CNY)' if len(code_raw) == 5 and code_raw[0] in '01' else ''}")
print(f" 实时价: {price} {'(港股HKD)' if len(code_raw) == 5 and code_raw[0] in '01' else ''}")
except Exception as e:
print(f" 实时价获取失败: {e}", file=sys.stderr)
# Try portfolio.json as fallback (price_monitor keeps live prices)
@@ -117,6 +111,8 @@ def main():
# 更新 decisions_map 中对应的条目
updated = entry.copy()
# 币种标记:HK股保留HKD原始值,A股为CNY
is_hk = len(str(code)) == 5 and str(code)[0] in '01'
updated.update({
"action": result["action"],
"stop_loss": result.get("stop_loss", entry.get("stop_loss")),
@@ -128,6 +124,7 @@ def main():
"rr_ratio": result.get("rr_ratio", entry.get("rr_ratio", 0)),
"status": result.get("status", "updated"),
"price": price,
"currency": "HKD" if is_hk else "CNY",
})
# Save last reassessed price for debounce tracking
updated["last_reassessed_price"] = price