feat: mo_data.py unified read layer (DB-first, JSON fallback) + cash_log table + batch JSON→DB migration (16 files)
This commit is contained in:
+5
-4
@@ -17,6 +17,7 @@ strategy_tree.py — 情景化多分支策略决策引擎
|
||||
|
||||
import json, os, sys, re
|
||||
from datetime import datetime, date, timedelta
|
||||
from mo_data import read_portfolio, read_decisions, read_watchlist
|
||||
|
||||
DECISIONS_PATH = "/home/hmo/web-dashboard/data/decisions.json"
|
||||
PORTFOLIO_PATH = "/home/hmo/web-dashboard/data/portfolio.json"
|
||||
@@ -141,7 +142,7 @@ def evaluate_branches(code, scenario_id, price, shares, cost):
|
||||
返回: [{branch_id, action_type, action_detail, priority, applicable}]
|
||||
"""
|
||||
try:
|
||||
dec = json.load(open(DECISIONS_PATH))
|
||||
dec = mo_data.read_decisions()
|
||||
except Exception:
|
||||
return []
|
||||
|
||||
@@ -237,7 +238,7 @@ def _check_branch_condition(branch, scenario_id, price, shares, cost):
|
||||
def record_branch_trigger(code, branch_id):
|
||||
"""记录分支被触发了一次,用于自成长统计"""
|
||||
try:
|
||||
dec = json.load(open(DECISIONS_PATH))
|
||||
dec = mo_data.read_decisions()
|
||||
for e in dec.get("decisions", []):
|
||||
if e.get("code") == code:
|
||||
st = e.setdefault("strategy_tree", {})
|
||||
@@ -261,7 +262,7 @@ def prune_low_performance_branches(min_triggers=5, min_success_rate=0.3):
|
||||
被剪的分支移入 history 字段,不打删除(可追溯)
|
||||
"""
|
||||
try:
|
||||
dec = json.load(open(DECISIONS_PATH))
|
||||
dec = mo_data.read_decisions()
|
||||
except Exception:
|
||||
return []
|
||||
|
||||
@@ -382,7 +383,7 @@ def init_default_branches(code, name, entry_low, entry_high, stop_loss, take_pro
|
||||
def check_portfolio_constraint(action_type, amount, cash_remain=None):
|
||||
"""组合约束检查:现金够不够?仓位上限?"""
|
||||
try:
|
||||
pf = json.load(open(PORTFOLIO_PATH))
|
||||
pf = mo_data.read_portfolio()
|
||||
except Exception:
|
||||
return True, "无法读取组合"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user