feat: strategy_lifecycle regenerate_all now writes to DB (holdings+strategies+watchlist)
This commit is contained in:
@@ -1914,6 +1914,21 @@ def regenerate_all(stdout=True):
|
|||||||
if added_to_wl and stdout:
|
if added_to_wl and stdout:
|
||||||
print(f" 清仓→自选自动加入: {', '.join(added_to_wl)}")
|
print(f" 清仓→自选自动加入: {', '.join(added_to_wl)}")
|
||||||
|
|
||||||
|
# DB 写入(替代 JSON dump — 强制币种约束)
|
||||||
|
try:
|
||||||
|
from mofin_db import get_conn, write_holdings_batch, write_portfolio_summary, write_watchlist_stock, write_holding_strategy
|
||||||
|
conn = get_conn()
|
||||||
|
write_holdings_batch(conn, existing_pf.get('holdings', []))
|
||||||
|
write_portfolio_summary(conn, existing_pf)
|
||||||
|
for s in wl.get('stocks', []):
|
||||||
|
s.setdefault('currency', 'CNY')
|
||||||
|
write_watchlist_stock(conn, s)
|
||||||
|
for d in decisions:
|
||||||
|
write_holding_strategy(conn, d.get('code', ''), d.get('name', ''), d)
|
||||||
|
conn.close()
|
||||||
|
except Exception as e:
|
||||||
|
print(f" [DB写入失败] {e}", flush=True)
|
||||||
|
# JSON 冷备
|
||||||
json.dump(existing_pf, open(PORTFOLIO_PATH, "w"), ensure_ascii=False, indent=2)
|
json.dump(existing_pf, open(PORTFOLIO_PATH, "w"), ensure_ascii=False, indent=2)
|
||||||
json.dump(wl, open(WATCHLIST_PATH, "w"), ensure_ascii=False, indent=2)
|
json.dump(wl, open(WATCHLIST_PATH, "w"), ensure_ascii=False, indent=2)
|
||||||
|
|
||||||
@@ -1925,6 +1940,7 @@ def regenerate_all(stdout=True):
|
|||||||
"regenerated_at": datetime.now().strftime('%Y-%m-%d %H:%M'),
|
"regenerated_at": datetime.now().strftime('%Y-%m-%d %H:%M'),
|
||||||
}
|
}
|
||||||
json.dump(decisions_data, open(decisions_path, "w"), ensure_ascii=False, indent=2)
|
json.dump(decisions_data, open(decisions_path, "w"), ensure_ascii=False, indent=2)
|
||||||
|
# DB 已在上方写入(和 portfolio/watchlist 一起)
|
||||||
|
|
||||||
# 记录策略→提示词版本关联
|
# 记录策略→提示词版本关联
|
||||||
if HAS_PROMPT_TRACKING:
|
if HAS_PROMPT_TRACKING:
|
||||||
|
|||||||
Reference in New Issue
Block a user