From 8076cbbd51b5fd617be920d2e4818c2529400d21 Mon Sep 17 00:00:00 2001 From: fish Date: Sun, 26 Jul 2026 13:49:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=9F=E6=9D=83=E6=96=B0=E5=A2=9E=E4=B9=B0?= =?UTF-8?q?=E5=8D=96=E6=96=B9=E5=90=91=E5=92=8C=E7=9B=88=E4=BA=8F=E7=AE=97?= =?UTF-8?q?=E6=B3=95=E5=B1=95=E7=A4=BA?= 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/models.py | 6 ++- ft-app/app/routers/option_trades.py | 4 ++ ft-app/app/templates/options.html | 71 ++++++++++++++++++++++++++--- ft-app/app/templates/trades.html | 35 ++++++++++++++ 4 files changed, 108 insertions(+), 8 deletions(-) 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 @@ -
+
+
+ + +
@@ -84,16 +92,23 @@ {% if open_trades %}
- + {% for t in open_trades %} + @@ -148,16 +163,23 @@
已平仓 · {{ closed_trades|length }} 笔
品种合约类型行权价权利金开仓日期手续费操作
品种合约类型买卖行权价权利金开仓日期手续费操作
{{ t.product_code }} {{ t.contract_code.replace(t.product_code, '', 1) }} {% if t.option_type == 'C' %} - C 看涨 + C {% else %} - P 看跌 + P + {% endif %} + + {% if t.direction == 'sell' %} + + {% else %} + {% endif %} {{ t.strike_price }}
- + {% for t in closed_trades %} + @@ -173,6 +195,8 @@ {% if p > 0 %}+{% endif %}{{ p }} + {% endif %}
品种合约类型行权价开仓平仓权利金平仓价开仓费平仓费盈亏操作
品种合约类型买卖行权价开仓平仓权利金平仓价开仓费平仓费盈亏操作
{{ t.product_code }} {{ t.contract_code.replace(t.product_code, '', 1) }} {% if t.option_type == 'C' %} - C 看涨 + C {% else %} - P 看跌 + P + {% endif %} + + {% if t.direction == 'sell' %} + + {% else %} + {% endif %} {{ t.strike_price }} @@ -233,4 +257,37 @@ function hideCloseForm() { } {% endif %} + + + + + {% endblock %} diff --git a/ft-app/app/templates/trades.html b/ft-app/app/templates/trades.html index 31115df..c1bc0c2 100644 --- a/ft-app/app/templates/trades.html +++ b/ft-app/app/templates/trades.html @@ -167,6 +167,8 @@ {% if p > 0 %}+{% endif %}{{ p }} + {% endif %} @@ -227,4 +229,37 @@ function hideCloseForm() { } {% endif %} + + + + + {% endblock %}