From 39c5e22ed6e6d2a39171c3c45e21aed8c1a30ebf Mon Sep 17 00:00:00 2001 From: fish Date: Tue, 28 Jul 2026 14:37:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=8C=E4=B9=B0=E4=BA=A4=E6=98=93=E8=A1=8C?= =?UTF-8?q?=E6=9D=83=E4=BB=B7=E6=8B=86=E5=88=86=E4=B8=BA=E7=9C=8B=E6=B6=A8?= =?UTF-8?q?=E8=A1=8C=E6=9D=83=E4=BB=B7=E5=92=8C=E7=9C=8B=E8=B7=8C=E8=A1=8C?= =?UTF-8?q?=E6=9D=83=E4=BB=B7=EF=BC=8C=E6=94=AF=E6=8C=81=E4=B8=8D=E5=90=8C?= =?UTF-8?q?=E4=BB=B7=E4=BD=8D?= 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 | 7 ++-- ft-app/app/routers/dual_options.py | 12 ++++-- ft-app/app/seed.py | 9 +++++ ft-app/app/templates/dual_options.html | 53 ++++++++++++++++---------- 4 files changed, 53 insertions(+), 28 deletions(-) diff --git a/ft-app/app/models.py b/ft-app/app/models.py index 3808733..dc5c854 100644 --- a/ft-app/app/models.py +++ b/ft-app/app/models.py @@ -188,7 +188,8 @@ class DualOptionTrade(Base): id: Mapped[int] = mapped_column(primary_key=True) product_code: Mapped[str] = mapped_column(String(10)) contract_code: Mapped[str] = mapped_column(String(10), index=True) - strike_price: Mapped[float] = mapped_column(Float) + call_strike_price: Mapped[float] = mapped_column(Float) + put_strike_price: Mapped[float] = mapped_column(Float) call_open_price: Mapped[float] = mapped_column(Float) put_open_price: Mapped[float] = mapped_column(Float) call_open_fee: Mapped[float | None] = mapped_column(Float, nullable=True, default=0) @@ -225,8 +226,8 @@ class DualOptionTrade(Base): @property def breakeven_upper(self) -> float: - return self.strike_price + self.total_premium + return self.call_strike_price + self.total_premium @property def breakeven_lower(self) -> float: - return self.strike_price - self.total_premium \ No newline at end of file + return self.put_strike_price - self.total_premium \ No newline at end of file diff --git a/ft-app/app/routers/dual_options.py b/ft-app/app/routers/dual_options.py index 073b4ee..1bcc149 100644 --- a/ft-app/app/routers/dual_options.py +++ b/ft-app/app/routers/dual_options.py @@ -52,7 +52,8 @@ def dual_option_page(request: Request, db: Session = Depends(get_db)): def open_trade( request: Request, contract_code: str = Form(...), - strike_price: float = Form(...), + call_strike_price: float = Form(...), + put_strike_price: float = Form(...), call_open_price: float = Form(...), put_open_price: float = Form(...), call_open_fee: float = Form(0.0), @@ -72,7 +73,8 @@ def open_trade( t = DualOptionTrade( product_code=product_code, contract_code=code, - strike_price=strike_price, + call_strike_price=call_strike_price, + put_strike_price=put_strike_price, call_open_price=call_open_price, put_open_price=put_open_price, call_open_fee=call_open_fee, @@ -114,7 +116,8 @@ def edit_trade( request: Request, trade_id: int, contract_code: str = Form(...), - strike_price: float = Form(...), + call_strike_price: float = Form(...), + put_strike_price: float = Form(...), call_open_price: float = Form(...), put_open_price: float = Form(...), call_open_fee: float = Form(0.0), @@ -138,7 +141,8 @@ def edit_trade( t.product_code = product.code if product else code[:2] t.point_value = product.point_value if product else 20 t.contract_code = code - t.strike_price = strike_price + t.call_strike_price = call_strike_price + t.put_strike_price = put_strike_price t.call_open_price = call_open_price t.put_open_price = put_open_price t.call_open_fee = call_open_fee diff --git a/ft-app/app/seed.py b/ft-app/app/seed.py index 642f039..917aac6 100644 --- a/ft-app/app/seed.py +++ b/ft-app/app/seed.py @@ -53,6 +53,15 @@ def _migrate(engine): if "point_value" not in cols: cur.execute("ALTER TABLE option_trades ADD COLUMN point_value INTEGER DEFAULT 20") + cur.execute("PRAGMA table_info(dual_option_trades)") + cols = {row[1] for row in cur.fetchall()} + if "call_strike_price" not in cols: + cur.execute("ALTER TABLE dual_option_trades ADD COLUMN call_strike_price FLOAT DEFAULT 0") + if "put_strike_price" not in cols: + cur.execute("ALTER TABLE dual_option_trades ADD COLUMN put_strike_price FLOAT DEFAULT 0") + if "strike_price" in cols: + cur.execute("ALTER TABLE dual_option_trades DROP COLUMN strike_price") + conn.commit() finally: conn.close() diff --git a/ft-app/app/templates/dual_options.html b/ft-app/app/templates/dual_options.html index f6c8404..dd43100 100644 --- a/ft-app/app/templates/dual_options.html +++ b/ft-app/app/templates/dual_options.html @@ -48,9 +48,13 @@ -
- - +
+ + +
+
+ +
@@ -83,12 +87,13 @@ {% if open_trades %}
- + {% for t in open_trades %} - + + @@ -99,7 +104,7 @@ + onclick="showEditForm({{ t.id }}, '{{ t.product_code }}', '{{ t.contract_code }}', {{ t.call_strike_price }}, {{ t.put_strike_price }}, {{ t.call_open_price }}, {{ t.put_open_price }}, {{ t.call_open_fee or 0 }}, {{ t.put_open_fee or 0 }}, '{{ t.open_date }}', null, null, null, null, null, 'open')">编辑 @@ -153,12 +158,13 @@
已平仓 · {{ closed_trades|length }} 笔
品种合约行权价开仓日期看涨开仓价看跌开仓价C手续费P手续费总成本操作
品种合约C行权价P行权价开仓日期看涨开仓价看跌开仓价C手续费P手续费总成本操作
{{ t.product_code }} {{ t.contract_code.replace(t.product_code, '', 1) }}{{ t.strike_price }}{{ t.call_strike_price }}{{ t.put_strike_price }} {{ t.open_date }} {{ weekdays[t.open_date.weekday()] }} {{ t.call_open_price }} {{ t.put_open_price }}
- + {% for t in closed_trades %} - + + @@ -172,12 +178,12 @@ {% if p > 0 %}+{% endif %}{{ p }} + onclick="showDualPnlDrawer('{{ t.product_code }} {{ t.contract_code.replace(t.product_code, '', 1) }}', {{ t.call_strike_price }}, {{ t.put_strike_price }}, {{ t.call_open_price }}, {{ t.put_open_price }}, {{ t.call_close_price }}, {{ t.put_close_price }}, {{ t.call_open_fee or 0 }}, {{ t.put_open_fee or 0 }}, {{ t.call_close_fee or 0 }}, {{ t.put_close_fee or 0 }}, {{ p }}, {{ t.point_value }})" title="盈亏分析">ⓘ {% endif %}
品种合约行权价开仓日平仓日持仓看涨(开/平)看跌(开/平)总成本盈亏操作
品种合约C行权价P行权价开仓日平仓日持仓看涨(开/平)看跌(开/平)总成本盈亏操作
{{ t.product_code }} {{ t.contract_code.replace(t.product_code, '', 1) }}{{ t.strike_price }}{{ t.call_strike_price }}{{ t.put_strike_price }} {{ t.open_date }} {{ weekdays[t.open_date.weekday()] }} {{ t.close_date }} {{ weekdays[t.close_date.weekday()] }} {{ (t.close_date - t.open_date).days }}天 + onclick="showEditForm({{ t.id }}, '{{ t.product_code }}', '{{ t.contract_code }}', {{ t.call_strike_price }}, {{ t.put_strike_price }}, {{ t.call_open_price }}, {{ t.put_open_price }}, {{ t.call_open_fee or 0 }}, {{ t.put_open_fee or 0 }}, '{{ t.open_date }}', {{ t.call_close_price }}, {{ t.put_close_price }}, {{ t.call_close_fee or 0 }}, {{ t.put_close_fee or 0 }}, '{{ t.close_date }}', 'closed')">编辑
@@ -256,8 +262,12 @@ function hideCloseForm() {
- - + + +
+
+ +
@@ -319,9 +329,9 @@ function hideCloseForm() {