diff --git a/ft-app/app/routers/contracts.py b/ft-app/app/routers/contracts.py index 05d6e02..e927ac0 100644 --- a/ft-app/app/routers/contracts.py +++ b/ft-app/app/routers/contracts.py @@ -59,6 +59,20 @@ def contract_index(request: Request, db: Session = Depends(get_db)): if bar.contract not in contract_bars: contract_bars[bar.contract] = bar + # Next-day amplitude: mean of latest 5 diffs per contract + contract_next_amp = {} + for code in all_codes: + diffs = [ + r[0] for r in + db.query(DailyBar.high - DailyBar.low) + .filter(DailyBar.contract == code) + .order_by(DailyBar.date.desc()) + .limit(5) + .all() + ] + if len(diffs) >= 5: + contract_next_amp[code] = round(sum(diffs) / 5) + template = request.app.state.templates.get_template("index.html") return HTMLResponse( template.render( @@ -66,6 +80,7 @@ def contract_index(request: Request, db: Session = Depends(get_db)): active_nav="contracts", product_groups=product_groups, contract_bars=contract_bars, + contract_next_amp=contract_next_amp, ) ) diff --git a/ft-app/app/templates/index.html b/ft-app/app/templates/index.html index f491b92..42ec499 100644 --- a/ft-app/app/templates/index.html +++ b/ft-app/app/templates/index.html @@ -17,7 +17,7 @@
- + {% for c in pg.contracts %} @@ -34,8 +34,15 @@ {% endif %} + {% else %} - + {% endif %}
合约日期开盘收盘最高最低振幅操作
合约日期开盘收盘最高最低振幅次日振幅操作
{{ c }} + {% if c in contract_next_amp %} + {{ contract_next_amp[c] }} + {% else %} + + {% endif %} + 暂无数据暂无数据详情 →