fix: 买入区用live_prices+统一DB读取+报告前验价
This commit is contained in:
@@ -99,11 +99,18 @@ def main():
|
||||
import sqlite3
|
||||
_conn = sqlite3.connect(str(SCRIPTS_DIR.parent / "data" / "mofin.db"))
|
||||
_actionable = _conn.execute(
|
||||
"SELECT code FROM holding_strategies WHERE status='active' "
|
||||
"AND timing_signal IN ('买入','可买入','可加仓','卖出','止盈')"
|
||||
"SELECT hs.code, lp.price, hs.entry_low, hs.entry_high FROM holding_strategies hs "
|
||||
"LEFT JOIN live_prices lp ON hs.code = lp.code "
|
||||
"WHERE hs.status='active' "
|
||||
"AND hs.timing_signal IN ('买入','可买入','可加仓','卖出','止盈')"
|
||||
).fetchall()
|
||||
_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:
|
||||
subprocess.run(
|
||||
["python3", str(SCRIPTS_DIR / "per_stock_reassess.py"), _code],
|
||||
|
||||
@@ -741,14 +741,19 @@ def batch_fetch_prices(codes):
|
||||
# 主通道:从 DB 读取(price_monitor 唯一价格入口)
|
||||
try:
|
||||
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
|
||||
for raw_code in codes:
|
||||
raw_code = str(raw_code).split('_')[0]
|
||||
if not raw_code: continue
|
||||
# 优先级:live_prices > holdings > holding_strategies
|
||||
row = db.execute(
|
||||
"SELECT price, change_pct FROM holdings WHERE code=? AND is_active=1", (raw_code,)
|
||||
"SELECT price, change_pct FROM live_prices WHERE code=?", (raw_code,)
|
||||
).fetchone()
|
||||
if not row:
|
||||
row = db.execute(
|
||||
"SELECT price, change_pct FROM holdings WHERE code=? AND is_active=1", (raw_code,)
|
||||
).fetchone()
|
||||
if not row:
|
||||
row = db.execute(
|
||||
"SELECT price, change_pct FROM holding_strategies WHERE code=? AND status='active' ORDER BY updated_at DESC LIMIT 1", (raw_code,)
|
||||
|
||||
Reference in New Issue
Block a user