From 8b5fa347cbf6ced8068e7b62079862841828c11d Mon Sep 17 00:00:00 2001 From: fish Date: Sun, 26 Jul 2026 13:56:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=A4=E6=98=93=E8=AE=B0=E5=BD=95=E5=92=8C?= =?UTF-8?q?=E6=9C=9F=E6=9D=83=E6=96=B0=E5=A2=9E=E7=BC=96=E8=BE=91=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= 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/option_trades.py | 36 ++++++++++++ ft-app/app/routers/trades.py | 32 ++++++++++ ft-app/app/templates/options.html | 91 ++++++++++++++++++++++++++++- ft-app/app/templates/trades.html | 77 +++++++++++++++++++++++- 4 files changed, 234 insertions(+), 2 deletions(-) diff --git a/ft-app/app/routers/option_trades.py b/ft-app/app/routers/option_trades.py index 7b7b96d..54cf942 100644 --- a/ft-app/app/routers/option_trades.py +++ b/ft-app/app/routers/option_trades.py @@ -103,6 +103,42 @@ def close_trade( return RedirectResponse("/options/", status_code=303) +@router.post("/{trade_id}/edit") +def edit_trade( + request: Request, + trade_id: int, + contract_code: str = Form(...), + option_type: str = Form(...), + direction: str = Form(...), + strike_price: float = Form(...), + open_date: str = Form(...), + open_price: float = Form(...), + open_fee: float = Form(0.0), + close_date: str = Form(""), + close_price: float = Form(None), + close_fee: float = Form(None), + db: Session = Depends(get_db), +): + t = db.query(OptionTrade).filter(OptionTrade.id == trade_id).first() + if t: + code = contract_code.upper() + contract = db.query(Contract).filter(Contract.code == code).first() + t.product_code = contract.product.code if contract else code[:2] + t.contract_code = code + t.option_type = option_type + t.direction = direction + t.strike_price = strike_price + t.open_date = date.fromisoformat(open_date) + t.open_price = open_price + t.open_fee = open_fee + if close_date and close_price is not None: + t.close_date = date.fromisoformat(close_date) + t.close_price = close_price + t.close_fee = close_fee or 0 + db.commit() + return RedirectResponse("/options/", status_code=303) + + @router.post("/{trade_id}/delete") def delete_trade(trade_id: int, db: Session = Depends(get_db)): t = db.query(OptionTrade).filter(OptionTrade.id == trade_id).first() diff --git a/ft-app/app/routers/trades.py b/ft-app/app/routers/trades.py index 862a03b..fe8990a 100644 --- a/ft-app/app/routers/trades.py +++ b/ft-app/app/routers/trades.py @@ -108,6 +108,38 @@ def close_trade( return RedirectResponse("/trades/", status_code=303) +@router.post("/{trade_id}/edit") +def edit_trade( + request: Request, + trade_id: int, + contract_code: str = Form(...), + direction: str = Form(...), + open_date: str = Form(...), + open_price: float = Form(...), + open_fee: float = Form(0.0), + close_date: str = Form(""), + close_price: float = Form(None), + close_fee: float = Form(None), + db: Session = Depends(get_db), +): + t = db.query(Trade).filter(Trade.id == trade_id).first() + if t: + code = contract_code.upper() + contract = db.query(Contract).filter(Contract.code == code).first() + t.product_code = contract.product.code if contract else code[:2] + t.contract_code = code + t.direction = direction + t.open_date = date.fromisoformat(open_date) + t.open_price = open_price + t.open_fee = open_fee + if close_date and close_price is not None: + t.close_date = date.fromisoformat(close_date) + t.close_price = close_price + t.close_fee = close_fee or 0 + db.commit() + return RedirectResponse("/trades/", status_code=303) + + @router.post("/{trade_id}/delete") def delete_trade(trade_id: int, db: Session = Depends(get_db)): t = db.query(Trade).filter(Trade.id == trade_id).first() diff --git a/ft-app/app/templates/options.html b/ft-app/app/templates/options.html index d3d7653..d36db8e 100644 --- a/ft-app/app/templates/options.html +++ b/ft-app/app/templates/options.html @@ -118,7 +118,9 @@ -
+ +
@@ -200,6 +202,8 @@ {% endif %} +
@@ -258,6 +262,67 @@ function hideCloseForm() { {% endif %} + + +