diff --git a/ft-app/app/routers/positions.py b/ft-app/app/routers/positions.py index 722a6ab..c536032 100644 --- a/ft-app/app/routers/positions.py +++ b/ft-app/app/routers/positions.py @@ -20,11 +20,11 @@ def get_active_contracts(db: Session) -> list[str]: @router.get("/", response_class=HTMLResponse) def positions_page(request: Request, db: Session = Depends(get_db)): - active_round = ( + active_rounds = ( db.query(Round) .filter(Round.status == "active") .order_by(Round.started_at.desc()) - .first() + .all() ) template = request.app.state.templates.get_template("positions.html") @@ -33,7 +33,7 @@ def positions_page(request: Request, db: Session = Depends(get_db)): request=request, active_nav="positions", contracts=get_active_contracts(db), - active_round=active_round, + active_rounds=active_rounds, ) ) @@ -45,12 +45,15 @@ def create_round( daily_hands: int = Form(1), db: Session = Depends(get_db), ): - existing = db.query(Round).filter(Round.status == "active").first() + code = contract_code.upper() + existing = db.query(Round).filter( + Round.status == "active", Round.contract_code == code + ).first() if existing: - return RedirectResponse("/positions/?error=已有活跃轮次", status_code=303) + return RedirectResponse(f"/positions/?error={code} 已有活跃轮次", status_code=303) r = Round( - contract_code=contract_code.upper(), + contract_code=code, daily_hands=daily_hands, status="active", started_at=date.today(), @@ -60,21 +63,22 @@ def create_round( return RedirectResponse("/positions/", status_code=303) -@router.post("/add") +@router.post("/{round_id}/add") def add_position( request: Request, + round_id: int, open_price: int = Form(...), amp_threshold: int = Form(...), hands: int = Form(1), db: Session = Depends(get_db), ): - active_round = db.query(Round).filter(Round.status == "active").first() - if not active_round: - return RedirectResponse("/positions/?error=无活跃轮次", status_code=303) + r = db.query(Round).filter(Round.id == round_id).first() + if not r or r.status != "active": + return RedirectResponse("/positions/?error=轮次不存在或已结束", status_code=303) lock_price = open_price + amp_threshold p = Position( - round_id=active_round.id, + round_id=r.id, open_price=open_price, amp_threshold=amp_threshold, lock_price=lock_price, @@ -104,14 +108,15 @@ def unlock_position(position_id: int, db: Session = Depends(get_db)): return RedirectResponse("/positions/", status_code=303) -@router.post("/close") +@router.post("/{round_id}/close") def close_round( request: Request, + round_id: int, result: str = Form(...), db: Session = Depends(get_db), ): - active_round = db.query(Round).filter(Round.status == "active").first() - if active_round: - active_round.status = result + r = db.query(Round).filter(Round.id == round_id).first() + if r and r.status == "active": + r.status = result db.commit() return RedirectResponse("/positions/", status_code=303) diff --git a/ft-app/app/templates/base.html b/ft-app/app/templates/base.html index 16f213f..933556f 100644 --- a/ft-app/app/templates/base.html +++ b/ft-app/app/templates/base.html @@ -59,12 +59,6 @@ border-left-color: var(--accent); font-weight: 600; } .sidebar-nav .icon { font-size: 1.1rem; width: 22px; text-align: center; } - .nav-parent { position: relative; } - .nav-arrow { font-size: 0.65rem; margin-left: auto; transition: transform .2s; color: var(--sub); } - .nav-group.open .nav-arrow { transform: rotate(-180deg); } - .nav-children { display: none; } - .nav-group.open .nav-children { display: block; } - .nav-children a { padding-left: 48px !important; font-size: 0.84rem !important; } .sidebar-footer { padding: 16px 20px; border-top: 1px solid var(--border); } @@ -201,20 +195,12 @@