migrate: remove JSON, DB-only — mo_data, server, scripts, prompts (27 files)

This commit is contained in:
知微
2026-07-03 12:12:05 +08:00
parent b1a79d962c
commit b3bedc8024
43 changed files with 8272 additions and 7449 deletions
+57 -51
View File
@@ -1,51 +1,57 @@
#!/usr/bin/env python3
"""修复decisions.json中所有决策的trigger字段(由regenerate_all负责填充)"""
import json, sys, os
from mo_data import read_portfolio, read_decisions, read_watchlist
DECISIONS_PATH = "/home/hmo/web-dashboard/data/decisions.json"
DECISIONS_BAK = DECISIONS_PATH + ".bak"
try:
with open(DECISIONS_PATH) as f:
dec = json.load(f)
except Exception as e:
print(f"读decisions.json失败: {e}")
sys.exit(1)
count = 0
for d in dec.get("decisions", []):
trig = d.get("trigger", {})
if trig:
continue # 已有trigger,跳过
sl = d.get("stop_loss", 0) or 0
tp = d.get("take_profit", 0) or 0
el = d.get("entry_low", 0) or 0
eh = d.get("entry_high", 0) or 0
code = d.get("code", "")
name = d.get("name", "")
new_trig = {}
if sl and float(sl) > 0:
new_trig["stop_loss"] = float(sl)
if el and eh and float(el) > 0 and float(eh) > 0:
new_trig["entry_zone"] = f"{float(el)}~{float(eh)}"
if tp and float(tp) > 0:
new_trig["take_profit_zone"] = f"0~{float(tp)}"
d["trigger"] = new_trig
count += 1
if new_trig:
print(f" {code} {name}: trigger={new_trig}")
# 备份
os.makedirs(os.path.dirname(DECISIONS_BAK), exist_ok=True)
with open(DECISIONS_BAK, 'w') as f:
json.dump(mo_data.read_decisions(), f, indent=2, ensure_ascii=False)
with open(DECISIONS_PATH, 'w') as f:
json.dump(dec, f, indent=2, ensure_ascii=False)
print(f"\n{count}只,已更新trigger字段")
#!/usr/bin/env python3
"""修复decisions.json中所有决策的trigger字段(由regenerate_all负责填充)"""
import json, sys, os
from mo_data import read_portfolio, read_decisions, read_watchlist
from mofin_db import get_conn, write_holding_strategy
DECISIONS_PATH = "/home/hmo/web-dashboard/data/decisions.json"
DECISIONS_BAK = DECISIONS_PATH + ".bak"
try:
dec = read_decisions()
except Exception as e:
print(f"读decisions.json失败: {e}")
sys.exit(1)
count = 0
for d in dec.get("decisions", []):
trig = d.get("trigger", {})
if trig:
continue # 已有trigger,跳过
sl = d.get("stop_loss", 0) or 0
tp = d.get("take_profit", 0) or 0
el = d.get("entry_low", 0) or 0
eh = d.get("entry_high", 0) or 0
code = d.get("code", "")
name = d.get("name", "")
new_trig = {}
if sl and float(sl) > 0:
new_trig["stop_loss"] = float(sl)
if el and eh and float(el) > 0 and float(eh) > 0:
new_trig["entry_zone"] = f"{float(el)}~{float(eh)}"
if tp and float(tp) > 0:
new_trig["take_profit_zone"] = f"0~{float(tp)}"
d["trigger"] = new_trig
count += 1
if new_trig:
print(f" {code} {name}: trigger={new_trig}")
# 备份
os.makedirs(os.path.dirname(DECISIONS_BAK), exist_ok=True)
with open(DECISIONS_BAK, 'w') as f:
json.dump(mo_data.read_decisions(), f, indent=2, ensure_ascii=False)
# DB 写入(替代 json.dump
conn = get_conn()
for d in dec.get("decisions", []):
write_holding_strategy(conn, d.get("code", ""), d.get("name", ""), d)
conn.close()
# [migrated to DB] — cold backup removed
# with open(DECISIONS_PATH, 'w') as f:
# json.dump(dec, f, indent=2, ensure_ascii=False)
print(f"\n{count}只,已更新trigger字段")