From 5279a61164436de1ff4a2837198a31144a344ac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=A5=E5=BE=AE?= Date: Thu, 9 Jul 2026 16:35:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=87=AA=E9=80=89=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E5=88=B0holding=5Fstrategies(read=5Fwatchlist)+=E6=B8=85?= =?UTF-8?q?=E7=90=86watchlist=5Fstocks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/mo_data.py | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/scripts/mo_data.py b/scripts/mo_data.py index 9627df74..db6c7e01 100644 --- a/scripts/mo_data.py +++ b/scripts/mo_data.py @@ -110,24 +110,36 @@ def read_decisions(): # ── watchlist ───────────────────────────────────────────────────── def read_watchlist(): - """返回 watchlist.json 等价 dict。纯 DB。""" + """返回 watchlist 等价 dict。纯 DB。 + 从 holding_strategies(自选策略)读取,watchlist_stocks 已废弃。""" db = _get_db() + # 主数据源:holding_strategies 自选策略 rows = db.execute( "SELECT code, name, price, entry_low, entry_high, " - "stop_loss, currency, source, source_detail, notes, " - "added_by, added_at, analysis_json " - "FROM watchlist_stocks WHERE is_active=1" + "stop_loss, currency, updated_at " + "FROM holding_strategies WHERE status='active' AND decision_type='自选策略'" ).fetchall() - + stocks = [] + seen = set() for r in rows: - s = dict(r) - s['source_detail'] = _parse_json(r['source_detail'], None) - if r['analysis_json']: - s['analysis'] = _parse_json(r['analysis_json'], {}) - else: - s['analysis'] = {} - stocks.append(s) + code = str(r["code"]) + if code in seen: + continue + seen.add(code) + stocks.append({ + "code": code, + "name": r["name"] or "", + "price": r["price"] or 0, + "entry_low": r["entry_low"] or 0, + "entry_high": r["entry_high"] or 0, + "stop_loss": r["stop_loss"] or 0, + "currency": r["currency"] or "CNY", + "added_at": r["updated_at"] or "", + "analysis": {}, + }) + + return {"stocks": stocks, "total": len(stocks)} db.close()