From eb096d915d5e6608410e40d79764292a2f50b5e9 Mon Sep 17 00:00:00 2001 From: fish Date: Mon, 27 Jul 2026 10:09:35 +0800 Subject: [PATCH] =?UTF-8?q?=E9=94=81=E4=BB=93=E6=93=8D=E4=BD=9C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E9=94=81=E4=BB=93=E4=BB=B7=E4=BD=8D=E7=A1=AE=E8=AE=A4?= =?UTF-8?q?=E5=BC=B9=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.7 --- ft-app/app/routers/positions.py | 26 ++++++++++++++++--- ft-app/app/templates/positions.html | 39 ++++++++++++++++++++++++++--- 2 files changed, 58 insertions(+), 7 deletions(-) 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 @@
-
- -
+
@@ -181,8 +180,40 @@ function filterContracts() { }); } } + function showLockConfirm(pid, lockPrice) { + document.getElementById('lockPid').value = pid; + document.getElementById('lockPriceInput').value = lockPrice; + document.getElementById('lockModal').style.display = 'block'; + document.getElementById('lockModalOverlay').style.display = 'block'; + document.getElementById('lockPriceInput').focus(); + } + function hideLockModal() { + document.getElementById('lockModal').style.display = 'none'; + document.getElementById('lockModalOverlay').style.display = 'none'; + } + function doLock() { + var pid = document.getElementById('lockPid').value; + var fd = new FormData(); + fd.append('lock_price', document.getElementById('lockPriceInput').value); + fetch('/positions/' + pid + '/lock', {method:'POST', body:fd}) + .then(function() { location.reload(); }); + } + + +