关键位与今日计划列表实时现价及距区间距离(1s轮询)

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-15 14:30:01 +08:00
parent 58020b6e9c
commit 38ff40111a
6 changed files with 177 additions and 7 deletions
+69 -1
View File
@@ -481,7 +481,75 @@ def api_symbol_search():
q = request.args.get("q", "")
return jsonify(search_symbols(q))
# —————————————— 页面路由 ——————————————
@app.route("/api/key_prices")
@login_required
def api_key_prices():
"""关键位监控列表:批量现价与距上/下沿距离。"""
conn = get_db()
rows = conn.execute(
"SELECT id, symbol, market_code, sina_code, upper, lower "
"FROM key_monitors WHERE status='active' OR status IS NULL"
).fetchall()
conn.close()
out = []
for r in rows:
sym = r["symbol"]
market = r["market_code"] or ""
sina = r["sina_code"] or ""
upper = float(r["upper"])
lower = float(r["lower"])
price = fetch_price(sym, market, sina)
dist_upper = None
dist_lower = None
if price is not None:
dist_upper = round(upper - price, 2)
dist_lower = round(price - lower, 2)
out.append({
"id": r["id"],
"price": price,
"dist_upper": dist_upper,
"dist_lower": dist_lower,
})
return jsonify(out)
@app.route("/api/plan_prices")
@login_required
def api_plan_prices():
"""今日计划:批量现价与距决策区间上/下沿距离。"""
today = today_str()
conn = get_db()
rows = conn.execute(
"SELECT id, symbol, market_code, sina_code, zone_upper, zone_lower "
"FROM order_plans WHERE plan_date=? AND status IN ('planned', 'active')",
(today,),
).fetchall()
conn.close()
out = []
for r in rows:
sym = r["symbol"]
market = r["market_code"] or ""
sina = r["sina_code"] or ""
upper = float(r["zone_upper"])
lower = float(r["zone_lower"])
price = fetch_price(sym, market, sina)
dist_upper = None
dist_lower = None
in_zone = False
if price is not None:
dist_upper = round(upper - price, 2)
dist_lower = round(price - lower, 2)
in_zone = lower <= price <= upper
out.append({
"id": r["id"],
"price": price,
"dist_upper": dist_upper,
"dist_lower": dist_lower,
"in_zone": in_zone,
})
return jsonify(out)
@app.route("/")
@login_required