fix: HK stocks store HKD, calc_total_assets converts to CNY at aggregation

This commit is contained in:
知微
2026-07-03 23:29:37 +08:00
parent 8e487f400f
commit 9337130ca2
4 changed files with 95 additions and 19 deletions
+10 -10
View File
@@ -84,11 +84,11 @@ STRATEGY_QUALITY_GATES = [
"fix": "tech_snapshot 包含强撑/弱撑/弱压/强压至少3个数值"
},
{
"id": "GATE_CURRENCY",
"severity": "CRITICAL",
"desc": "港股决策金额应为港币标价(currency=HKD)A股为CNY",
"check": lambda d: d.get("currency") in ("HKD", "CNY") or not d.get("code"),
"fix": "设置 d['currency']='HKD' for HK stocks"
"id": "GATE_CURRENCY_SET",
"desc": "港股必须标 currency=HKD(个股存原币种,汇总时由calc_total_assets转CNY",
"check": lambda d: not is_hk_stock(d.get("code","")) or d.get("currency") == "HKD",
"severity": "HIGH",
"fix": "设置 d['currency']='HKD'"
},
# --- 第4条 CRITICAL 红线:9维交叉验证 (2026-07-02 Dad要求) ---
# 策略不能只有价格数字,必须有证据经过了多维分析:
@@ -2293,10 +2293,10 @@ def regenerate_all(stdout=True):
sector_ctx_str = f"大盘上涨比{market_breadth}%"
new_entry = {
"code": code, "name": name, "price": price,
"cost": old_entry.get("cost", cost) if old_entry else cost,
"shares": shares,
"avg_price": old_entry.get("avg_price", 0),
"currency": "HKD" if is_hk_stock(code) else "CNY",
"cost": old_entry.get("cost", cost) if old_entry else cost, # 优先保留旧成本(holding.xls权威)
"shares": shares, # 当前实际持仓股数(不继承旧决策的可能为0的值)
"avg_price": old_entry.get("avg_price", 0), # 保留持仓均价
"currency": "HKD" if is_hk_stock(str(code)) else "CNY",
"action": result["action"],
"stop_loss": result.get("stop_loss"),
"entry_low": result["entry_low"],
@@ -2526,7 +2526,7 @@ def regenerate_all(stdout=True):
write_holdings_batch(conn, existing_pf.get('holdings', []))
write_portfolio_summary(conn, existing_pf)
for s in wl.get('stocks', []):
s.setdefault('currency', 'HKD') if is_hk_stock(str(s.get('code',''))) else s.setdefault('currency', 'CNY')
s.setdefault('currency', 'CNY')
write_watchlist_stock(conn, s)
for d in decisions:
# ── 策略质量门禁 ──