diff --git a/ft-app/app/routers/contracts.py b/ft-app/app/routers/contracts.py index 9f1a5b0..43f5a5f 100644 --- a/ft-app/app/routers/contracts.py +++ b/ft-app/app/routers/contracts.py @@ -1,4 +1,4 @@ -from datetime import date +from datetime import date, timedelta from fastapi import APIRouter, Depends, Request from fastapi.responses import HTMLResponse from sqlalchemy.orm import Session @@ -80,10 +80,15 @@ def contract_detail(request: Request, contract: str, db: Session = Depends(get_d latest = bars[0] if bars else None # Predict next trading day amplitude: mean of latest 5 diffs + # Compute next trading date + next_date = latest.date + timedelta(days=1) if latest else None + if next_date and next_date.weekday() >= 5: + next_date += timedelta(days=7 - next_date.weekday()) + + # Predict next trading day amplitude next_amp = None if len(bars) >= 5: next_amp = round(sum(b.diff for b in bars[:5]) / 5) - template = request.app.state.templates.get_template("contract.html") return HTMLResponse( template.render( @@ -94,6 +99,8 @@ def contract_detail(request: Request, contract: str, db: Session = Depends(get_d rows=rows, latest=latest, next_amp=next_amp, + next_date=next_date.strftime("%Y/%-m/%-d") if next_date else None, + next_weekday=WEEKDAY_ZH.get(next_date.weekday(), "") if next_date else "", row_count=len(rows), ) ) diff --git a/ft-app/app/templates/contract.html b/ft-app/app/templates/contract.html index a256ae9..fefe097 100644 --- a/ft-app/app/templates/contract.html +++ b/ft-app/app/templates/contract.html @@ -52,9 +52,19 @@ {% else %} {% endif %} - - {% endfor %} + {% if next_date %} + + {{ next_date }} + {{ next_weekday }} + — + — + — + — + — + {{ next_amp }} + + {% endif %}