feat(hub): enrich AI coach with fund history, closed trades, and chat uploads

- Add 15-day fund snapshot store and /api/hub/account on all instances

- Summary includes yesterday/today trades, fund columns, and section 5 操作建议

- Chat context distinguishes empty positions from local monitors

- Support image/document attachments in AI chat

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-07 08:54:20 +08:00
parent 51c59b073b
commit 62e48dab92
19 changed files with 947 additions and 106 deletions
+17
View File
@@ -205,6 +205,7 @@ def install_on_app(
meta_fn,
views: dict,
ohlcv_fn=None,
account_fn=None,
):
app.config["HUB_CTX"] = {
"exchange": exchange,
@@ -213,6 +214,7 @@ def install_on_app(
"get_db": get_db,
"row_to_dict": row_to_dict,
"meta_fn": meta_fn,
"account_fn": account_fn,
"views": views,
"ohlcv_fn": ohlcv_fn,
}
@@ -338,6 +340,21 @@ def register_hub_routes(app):
meta = meta_fn() if callable(meta_fn) else {}
return jsonify({"ok": True, "meta": meta})
@app.route("/api/hub/account")
@_hub_auth_required
def api_hub_account():
"""中控 AI:资金账户 / 交易账户余额(无需浏览器登录)。"""
fn = _ctx().get("account_fn")
if not callable(fn):
return jsonify({"ok": False, "msg": "未配置 account_fn"}), 501
try:
data = fn()
if not isinstance(data, dict):
data = {}
return jsonify({"ok": True, **data})
except Exception as e:
return jsonify({"ok": False, "msg": str(e)}), 500
@app.route("/api/hub/monitor")
@_hub_auth_required
def api_hub_monitor():