fix: price_monitor record_event 名称守卫(上次被deploy_guard回滚,重打)
This commit is contained in:
@@ -515,8 +515,26 @@ def record_event(code, name, event_type, price, trigger_value, event_label=""):
|
||||
_exch, _typ = ("SH", "A")
|
||||
else:
|
||||
_exch, _typ = ("SZ", "A")
|
||||
# 2026-08-22 名称治理:无名字先查 stocks 已有真名,再腾讯 quote 兜底,杜绝 name=code 垃圾行
|
||||
if not name:
|
||||
try:
|
||||
_r = _c.execute("SELECT name FROM stocks WHERE code=?", (str(code),)).fetchone()
|
||||
if _r and _r[0] and _r[0] != str(code):
|
||||
name = _r[0]
|
||||
except Exception:
|
||||
pass
|
||||
if not name:
|
||||
try:
|
||||
from mofin_db import fetch_stock_name_tencent
|
||||
name = fetch_stock_name_tencent(code) or ""
|
||||
except Exception:
|
||||
pass
|
||||
_c.execute("INSERT OR IGNORE INTO stocks (code, name, exchange, type, updated_at) VALUES (?,?,?,?,?)",
|
||||
(str(code), name or str(code), _exch, _typ, now))
|
||||
if name:
|
||||
# 治愈已有 name=code 的坏行(INSERT OR IGNORE 不会更新已存在行)
|
||||
_c.execute("UPDATE stocks SET name=?, updated_at=? WHERE code=? AND name=?",
|
||||
(name, now, str(code), str(code)))
|
||||
_c.commit()
|
||||
write_price_event(_c, code=code, name=name, event_type=event_type,
|
||||
price=round(price, 2), trigger_value=str(trigger_value),
|
||||
|
||||
Reference in New Issue
Block a user