硬性策略质量门禁 validate_strategy()

新增 STRATEGY_QUALITY_GATES 检查清单(9条红线):
CRITICAL: 止损/止盈存在+>0, 买入区下沿<上沿
HIGH: 止损≤买入区, 买入推荐含RR≥1.5, 港股标currency=HKD
MEDIUM: signal短词, tech_snapshot含技术位

enforce_strategy_quality() 插在写入链的两处:
1. reassess_with_context() return前 → 单只重评必过
2. regenerate_all() for d in decisions: 写DB前 → 批量重评必过

不过的:status=review_needed, signal降级→信号不充分
不会写进DB/JSON,除非修复了CRITICAL问题
This commit is contained in:
知微
2026-07-02 13:46:53 +08:00
parent 04b8a6d4bc
commit 7c0e85af28
32 changed files with 12496 additions and 75159 deletions
+3 -2
View File
@@ -27,9 +27,9 @@ DB_PATH = DATA_DIR / "mofin.db"
# ═══════════════════════════════════════════════════════════
def get_conn() -> sqlite3.Connection:
"""获取数据库连接(WAL 模式,外键约束,Row 工厂)"""
"""获取数据库连接(WAL 模式,外键约束,Row 工厂5秒超时防并发锁"""
DATA_DIR.mkdir(parents=True, exist_ok=True)
conn = sqlite3.connect(str(DB_PATH))
conn = sqlite3.connect(str(DB_PATH), timeout=5)
conn.row_factory = sqlite3.Row
conn.execute("PRAGMA journal_mode=WAL")
conn.execute("PRAGMA foreign_keys=ON")
@@ -677,6 +677,7 @@ def query_holdings(conn: sqlite3.Connection) -> list[dict]:
"""持仓列表(含最新策略)"""
rows = conn.execute("""
SELECT h.code, h.name, h.shares, h.cost, h.position_pct, h.is_active,
h.price, h.change_pct, h.currency,
hs.stop_loss, hs.take_profit, hs.entry_low, hs.entry_high,
hs.reason as action, hs.created_at as strategy_updated
FROM holdings h