diff --git a/ft-app/app/routers/positions.py b/ft-app/app/routers/positions.py index 3893d2f..a16e63a 100644 --- a/ft-app/app/routers/positions.py +++ b/ft-app/app/routers/positions.py @@ -80,6 +80,7 @@ def add_position( round_id: int, open_price: int = Form(...), amp_threshold: int = Form(...), + lock_price: str = Form(""), hands: int = Form(1), db: Session = Depends(get_db), ): @@ -87,12 +88,12 @@ def add_position( if not r or r.status != "active": return RedirectResponse("/positions/?error=轮次不存在或已结束", status_code=303) - lock_price = open_price + amp_threshold + final_lock = int(lock_price) if lock_price else open_price + amp_threshold p = Position( round_id=r.id, open_price=open_price, amp_threshold=amp_threshold, - lock_price=lock_price, + lock_price=final_lock, hands=hands, opened_at=date.today(), ) @@ -102,9 +103,15 @@ def add_position( @router.post("/{position_id}/lock") -def lock_position(position_id: int, db: Session = Depends(get_db)): +def lock_position( + position_id: int, + lock_price: str = Form(""), + db: Session = Depends(get_db), +): p = db.query(Position).filter(Position.id == position_id).first() if p and p.locked_count < p.hands: + if lock_price: + p.lock_price = int(lock_price) p.locked_count += 1 db.commit() return RedirectResponse("/positions/", status_code=303) @@ -119,6 +126,19 @@ def unlock_position(position_id: int, db: Session = Depends(get_db)): return RedirectResponse("/positions/", status_code=303) +@router.post("/{position_id}/update-lock-price") +def update_lock_price( + position_id: int, + lock_price: int = Form(...), + db: Session = Depends(get_db), +): + p = db.query(Position).filter(Position.id == position_id).first() + if p and p.locked_count == 0: + p.lock_price = lock_price + db.commit() + return RedirectResponse("/positions/", status_code=303) + + @router.post("/{round_id}/close") def close_round( request: Request, diff --git a/ft-app/app/templates/positions.html b/ft-app/app/templates/positions.html index 4cf2b31..7f94803 100644 --- a/ft-app/app/templates/positions.html +++ b/ft-app/app/templates/positions.html @@ -145,10 +145,9 @@