feat(hub): add symbol archive with permanent 5m klines
Add /archive page, hub_symbol_archive.db, trade overlay, 4h background sync, and instance /api/hub/trades/archive. Document in hub-symbol-archive-kline.md with cross-links. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -418,6 +418,52 @@ def register_hub_routes(app):
|
||||
)
|
||||
)
|
||||
|
||||
@app.route("/api/hub/trades/archive")
|
||||
@_hub_auth_required
|
||||
def api_hub_trades_archive():
|
||||
"""中控币种档案:近 N 天已平仓记录。"""
|
||||
from hub_trades_lib import fetch_trades_for_archive, summarize_trades
|
||||
|
||||
c = _ctx()
|
||||
get_db = c.get("get_db")
|
||||
if not get_db:
|
||||
return jsonify({"ok": False, "msg": "HUB_CTX 缺少 get_db"}), 500
|
||||
try:
|
||||
days = int(request.args.get("days") or "365")
|
||||
except ValueError:
|
||||
days = 365
|
||||
try:
|
||||
limit = int(request.args.get("limit") or "2000")
|
||||
except ValueError:
|
||||
limit = 2000
|
||||
try:
|
||||
import os
|
||||
|
||||
reset_hour = int(os.getenv("TRADING_DAY_RESET_HOUR", "8") or "8")
|
||||
except ValueError:
|
||||
reset_hour = 8
|
||||
conn = get_db()
|
||||
try:
|
||||
trades = fetch_trades_for_archive(
|
||||
conn,
|
||||
days=days,
|
||||
row_to_dict_fn=c.get("row_to_dict"),
|
||||
reset_hour=reset_hour,
|
||||
limit=limit,
|
||||
)
|
||||
finally:
|
||||
conn.close()
|
||||
stats = summarize_trades(trades)
|
||||
return jsonify(
|
||||
{
|
||||
"ok": True,
|
||||
"days": max(1, min(days, 3650)),
|
||||
"trading_day_reset_hour": reset_hour,
|
||||
"trades": trades,
|
||||
"stats": stats,
|
||||
}
|
||||
)
|
||||
|
||||
@app.route("/api/hub/trades/today")
|
||||
@_hub_auth_required
|
||||
def api_hub_trades_today():
|
||||
|
||||
Reference in New Issue
Block a user