diff --git a/ft-app/app/models.py b/ft-app/app/models.py
index 7052cfb..99dffb0 100644
--- a/ft-app/app/models.py
+++ b/ft-app/app/models.py
@@ -156,6 +156,7 @@ class OptionTrade(Base):
product_code: Mapped[str] = mapped_column(String(10))
contract_code: Mapped[str] = mapped_column(String(10), index=True)
option_type: Mapped[str] = mapped_column(String(4))
+ direction: Mapped[str] = mapped_column(String(4))
strike_price: Mapped[float] = mapped_column(Float)
open_date: Mapped[date] = mapped_column(Date)
open_price: Mapped[float] = mapped_column(Float)
@@ -170,5 +171,8 @@ class OptionTrade(Base):
if self.close_price is None:
return None
mul = 20 # glass futures point value
- result = (self.close_price - self.open_price) * mul - (self.open_fee or 0) - (self.close_fee or 0)
+ if self.direction == "sell":
+ result = (self.open_price - self.close_price) * mul - (self.open_fee or 0) - (self.close_fee or 0)
+ else:
+ result = (self.close_price - self.open_price) * mul - (self.open_fee or 0) - (self.close_fee or 0)
return round(result, 2)
\ No newline at end of file
diff --git a/ft-app/app/routers/option_trades.py b/ft-app/app/routers/option_trades.py
index 3bfc158..7b7b96d 100644
--- a/ft-app/app/routers/option_trades.py
+++ b/ft-app/app/routers/option_trades.py
@@ -8,6 +8,7 @@ from app.models import OptionTrade, Contract, Product
router = APIRouter(prefix="/options", tags=["options"])
OPTION_TYPES = [("C", "C 看涨"), ("P", "P 看跌")]
+OPTION_DIRECTIONS = [("buy", "买"), ("sell", "卖")]
def get_product_contracts(db: Session) -> dict:
@@ -43,6 +44,7 @@ def option_page(request: Request, db: Session = Depends(get_db)):
active_nav="options",
product_contracts=get_product_contracts(db),
option_types=OPTION_TYPES,
+ option_directions=OPTION_DIRECTIONS,
open_trades=open_trades,
closed_trades=closed_trades,
today=today_str(),
@@ -55,6 +57,7 @@ def open_trade(
request: Request,
contract_code: str = Form(...),
option_type: str = Form(...),
+ direction: str = Form(...),
strike_price: float = Form(...),
open_date: str = Form(...),
open_price: float = Form(...),
@@ -69,6 +72,7 @@ def open_trade(
product_code=product_code,
contract_code=code,
option_type=option_type,
+ direction=direction,
strike_price=strike_price,
open_date=date.fromisoformat(open_date),
open_price=open_price,
diff --git a/ft-app/app/templates/options.html b/ft-app/app/templates/options.html
index 2cd85eb..d3d7653 100644
--- a/ft-app/app/templates/options.html
+++ b/ft-app/app/templates/options.html
@@ -49,7 +49,7 @@
-