feat: 买入信号写入时自动推XMPP通知(通过5805桥)
This commit is contained in:
@@ -247,6 +247,28 @@ def save_result(code, full_text, parsed):
|
||||
sql = f"UPDATE holding_strategies SET {', '.join(updates)} WHERE code=? AND status='active'"
|
||||
conn.execute(sql, params)
|
||||
conn.commit()
|
||||
|
||||
# 买入信号→推XMPP通知(在conn close前执行)
|
||||
if parsed.get("signal") == "买入":
|
||||
try:
|
||||
_nr = conn.execute("SELECT name, price FROM holding_strategies WHERE code=? AND status='active'", (code,)).fetchone()
|
||||
_name = _nr[0] if _nr else code
|
||||
_p = _nr[1] if _nr else 0
|
||||
_el = parsed.get("entry_low", 0)
|
||||
_eh = parsed.get("entry_high", 0)
|
||||
_sl = parsed.get("stop_loss", 0)
|
||||
_tp = parsed.get("take_profit", 0)
|
||||
_pos = parsed.get("position", "")
|
||||
_msg = f"📈 {_name}({code}) 价{_p}→12维分析生成买入信号!区间{_el}~{_eh} 损{_sl} 盈{_tp} 仓位{_pos}"
|
||||
import urllib.request, json as _jj
|
||||
_req = urllib.request.Request("http://127.0.0.1:5805/",
|
||||
data=_jj.dumps({"body": _msg, "to": "hmo@yoin.fun", "type": "chat"}).encode(),
|
||||
headers={"Content-Type": "application/json"})
|
||||
urllib.request.urlopen(_req, timeout=5)
|
||||
print(f" 📨 XMPP推送成功: {_msg[:60]}")
|
||||
except Exception as _e:
|
||||
print(f" ⚠️ XMPP推送失败: {_e}")
|
||||
|
||||
conn.close()
|
||||
|
||||
def process_stock(code):
|
||||
|
||||
@@ -477,6 +477,19 @@ def main():
|
||||
__import__('sqlite3').connect('/home/hmo/MoFin/data/mofin.db').execute(
|
||||
"UPDATE holding_strategies SET timing_signal=? WHERE code=? AND status='active'", (_sig, code)).connection.commit()
|
||||
print(f" ✅ LLM信号={_sig} 已写入")
|
||||
# 买入信号→推XMPP
|
||||
if _sig == "买入":
|
||||
try:
|
||||
_nr2 = __import__('sqlite3').connect('/home/hmo/MoFin/data/mofin.db').execute(
|
||||
"SELECT name, price, entry_low, entry_high, stop_loss, take_profit, position_advice FROM holding_strategies WHERE code=? AND status='active'", (code,)).fetchone()
|
||||
if _nr2:
|
||||
_xm = f"📈 {_nr2[0] or code}({code}) 价{_nr2[1]}→12维买入信号!区间{_nr2[2]}~{_nr2[3]} 损{_nr2[4]} 盈{_nr2[5]} 仓位{_nr2[6] or '-'}"
|
||||
_xr = __import__('urllib.request').Request("http://127.0.0.1:5805/",
|
||||
data=__import__('json').dumps({"body": _xm, "to": "hmo@yoin.fun", "type": "chat"}).encode(),
|
||||
headers={"Content-Type": "application/json"})
|
||||
__import__('urllib.request').urlopen(_xr, timeout=5)
|
||||
print(f" 📨 XMPP推送买入信号")
|
||||
except: pass
|
||||
except: pass
|
||||
# 冷却期已更新(reassessed_at写入)
|
||||
except Exception as _dbe:
|
||||
|
||||
Reference in New Issue
Block a user