Compare commits

...
2 Commits
3 changed files with 46 additions and 5 deletions
+10 -3
View File
@@ -99,11 +99,18 @@ def main():
import sqlite3 import sqlite3
_conn = sqlite3.connect(str(SCRIPTS_DIR.parent / "data" / "mofin.db")) _conn = sqlite3.connect(str(SCRIPTS_DIR.parent / "data" / "mofin.db"))
_actionable = _conn.execute( _actionable = _conn.execute(
"SELECT code FROM holding_strategies WHERE status='active' " "SELECT hs.code, lp.price, hs.entry_low, hs.entry_high FROM holding_strategies hs "
"AND timing_signal IN ('买入','可买入','可加仓','卖出','止盈')" "LEFT JOIN live_prices lp ON hs.code = lp.code "
"WHERE hs.status='active' "
"AND hs.timing_signal IN ('买入','可买入','可加仓','卖出','止盈')"
).fetchall() ).fetchall()
_conn.close() _conn.close()
for (_code,) in _actionable: for _code, _price, _el, _eh in _actionable:
# 价格必须在买入区内或附近(不高于上沿20%),否则不触发重评
if _price and _el and _eh and _price > 0 and _el > 0 and _eh > 0:
if _price > _eh * 1.20:
print(f" ⏭️ {_code}: 价{_price}超买入区上沿+{((_price/_eh)-1)*100:.0f}%,跳过重评")
continue
try: try:
subprocess.run( subprocess.run(
["python3", str(SCRIPTS_DIR / "per_stock_reassess.py"), _code], ["python3", str(SCRIPTS_DIR / "per_stock_reassess.py"), _code],
+29
View File
@@ -452,6 +452,35 @@ def run_once(round_label=""):
# === 第三步:买入区偏离检测 + 自动重评 === # === 第三步:买入区偏离检测 + 自动重评 ===
reassesed_codes = [] reassesed_codes = []
# 先做急跌检测(所有持仓,不依赖买入区)
for d in active:
code = d["code"]
name = d.get("name", code)
price_info = prices.get(code)
if not price_info:
continue
price, _, change_pct = price_info
if price == 0:
continue
# 单日跌幅>7%告警(不依赖zone边界,盘中急跌即触发)
try:
cp = float(change_pct) if change_pct else 0
except:
cp = 0
if cp <= -7:
prev_alert = state.get(code, {}).get("__sharp_decline_triggered", False)
if not prev_alert:
stop_loss = d.get("stop_loss", 0)
sl_note = f" 止损{stop_loss}" if stop_loss else ""
msg = f"🔻 {name}({code}) {price} 暴跌{cp:.1f}%{sl_note}"
push_to_xmpp(msg)
outputs.append(msg)
state.setdefault(code, {})["__sharp_decline_triggered"] = True
state_updated = True
elif cp > -5:
# 反弹后清除告警标记,下次再跌还能报
state.setdefault(code, {}).pop("__sharp_decline_triggered", None)
for d in active: for d in active:
code = d["code"] code = d["code"]
name = d.get("name", code) name = d.get("name", code)
+6 -1
View File
@@ -741,11 +741,16 @@ def batch_fetch_prices(codes):
# 主通道:从 DB 读取(price_monitor 唯一价格入口) # 主通道:从 DB 读取(price_monitor 唯一价格入口)
try: try:
import sqlite3 import sqlite3
db = sqlite3.connect('/home/hmo/web-dashboard/data/mofin.db') db = sqlite3.connect('/home/hmo/MoFin/data/mofin.db')
db.row_factory = sqlite3.Row db.row_factory = sqlite3.Row
for raw_code in codes: for raw_code in codes:
raw_code = str(raw_code).split('_')[0] raw_code = str(raw_code).split('_')[0]
if not raw_code: continue if not raw_code: continue
# 优先级:live_prices > holdings > holding_strategies
row = db.execute(
"SELECT price, change_pct FROM live_prices WHERE code=?", (raw_code,)
).fetchone()
if not row:
row = db.execute( row = db.execute(
"SELECT price, change_pct FROM holdings WHERE code=? AND is_active=1", (raw_code,) "SELECT price, change_pct FROM holdings WHERE code=? AND is_active=1", (raw_code,)
).fetchone() ).fetchone()