refactor: 截图识别重构为LLM执行协议(trade_capture模块+server.py集成)
This commit is contained in:
@@ -1886,6 +1886,33 @@ def upload_confirm():
|
||||
except:
|
||||
pass # 行情获取失败不影响主流程
|
||||
|
||||
# 使用 trade_capture 协议写入
|
||||
from trade_capture import execute_trade, validate_trade
|
||||
import sqlite3 as _sq
|
||||
_db = _sq.connect('/home/hmo/web-dashboard/data/mofin.db', timeout=30)
|
||||
_cur = {}
|
||||
for _r in _db.execute("SELECT code, shares, cost FROM holdings WHERE is_active=1"):
|
||||
_cur[_r[0]] = {"shares": _r[1], "cost": _r[2]}
|
||||
_db.close()
|
||||
_results = []
|
||||
for s in stocks:
|
||||
_t = {"action": "买入" if int(s.get("shares", 0)) > 0 else "卖出",
|
||||
"code": s.get("code", ""), "name": s.get("name", ""),
|
||||
"shares": abs(int(s.get("shares", 0))), "price": float(s.get("price", 0))}
|
||||
_e = validate_trade(_t, _cur)
|
||||
if _e:
|
||||
_results.append({"code": _t["code"], "ok": False, "errors": _e})
|
||||
else:
|
||||
_r = execute_trade(_t)
|
||||
_results.append({"code": _t["code"], "ok": _r.get("ok"), "new_shares": _r.get("new_shares")})
|
||||
try:
|
||||
from clean_watchlist import main as _cwl
|
||||
_cwl()
|
||||
except Exception:
|
||||
pass
|
||||
return jsonify({"results": _results, "type": doc_type})
|
||||
|
||||
# 以下为旧逻辑(保留fallback)
|
||||
# 更新对应数据文件
|
||||
if doc_type == "portfolio":
|
||||
existing = read_portfolio()
|
||||
|
||||
Reference in New Issue
Block a user