fix: 自选统一到holding_strategies(read_watchlist)+清理watchlist_stocks
This commit is contained in:
+24
-12
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user