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 @@ -
| 品种 | 合约 | 行权价 | 开仓日期 | 看涨开仓价 | 看跌开仓价 | 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 }} | @@ -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 @@
| 品种 | 合约 | 行权价 | 开仓日 | 平仓日 | 持仓 | 看涨(开/平) | 看跌(开/平) | 总成本 | 盈亏 | 操作 | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 品种 | 合约 | 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 }}天 | @@ -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 %}
+ 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() {
|