From 63225f64de98561c65ccffe578ae3ee0bbf0ec88 Mon Sep 17 00:00:00 2001 From: dekun Date: Sun, 2 Aug 2026 09:54:07 +0800 Subject: [PATCH] Show option contract ID and expiry date in trade detail. Co-authored-by: Cursor --- frontend/src/pages/Trades.tsx | 64 +++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/frontend/src/pages/Trades.tsx b/frontend/src/pages/Trades.tsx index ba97621..b4d6514 100644 --- a/frontend/src/pages/Trades.tsx +++ b/frontend/src/pages/Trades.tsx @@ -32,6 +32,9 @@ type Group = { bias: string | null; option_side: string | null; perp_side: string | null; + option_inst_id?: string | null; + perp_inst_id?: string | null; + expiry_ymd?: string | null; initial_premium: number; realized_pnl: number; net_pnl?: number | null; @@ -58,6 +61,7 @@ type Fill = { leg: string; action: string; side: string; + inst_id?: string | null; fill_px: number; fee: number; qty_eth: number; @@ -113,6 +117,34 @@ function fmtMovePoints(n: number | null | undefined) { return s; } +/** 期权到期日 YYMMDD / YYYYMMDD → 可读日期 */ +function fmtExpiryYmd(ymd: string | null | undefined) { + if (!ymd) return "—"; + const s = String(ymd).trim(); + if (/^\d{6}$/.test(s)) { + return `20${s.slice(0, 2)}-${s.slice(2, 4)}-${s.slice(4, 6)}`; + } + if (/^\d{8}$/.test(s)) { + return `${s.slice(0, 4)}-${s.slice(4, 6)}-${s.slice(6, 8)}`; + } + return s; +} + +/** 从成交明细回退取期权合约 ID */ +function optionInstFromFills(fills: Fill[]) { + for (const f of fills) { + if (f.leg === "option" && f.inst_id) return String(f.inst_id); + } + return null; +} + +/** 从合约 ID 解析 YYMMDD(ETH-260801-1875-C / ETH-260801-1875-C) */ +function expiryYmdFromInstId(instId: string | null | undefined) { + if (!instId) return null; + const m = String(instId).match(/(?:^|-)(\d{6})(?:-|$)/); + return m ? m[1] : null; +} + export default function TradesPage() { const titleId = useId(); const [groups, setGroups] = useState([]); @@ -385,6 +417,35 @@ export default function TradesPage() { )} +
+ 期权合约 + + {selectedGroup.option_inst_id || + optionInstFromFills(fills) || + "—"} + +
+
+ 期权到期日 + + {fmtExpiryYmd( + selectedGroup.expiry_ymd || + expiryYmdFromInstId( + selectedGroup.option_inst_id || + optionInstFromFills(fills), + ), + )} + +
+ {selectedGroup.strike != null && + !selectedGroup.expiry_settle ? ( +
+ 行权价 + + {fmt(selectedGroup.strike, 0)} + +
+ ) : null}
开仓时间 @@ -473,6 +534,9 @@ export default function TradesPage() { f.side, selectedGroup.close_reason, )} + {f.inst_id ? ( + · {f.inst_id} + ) : null} 价 {f.fill_px.toFixed(4)} · 数量 {f.qty_eth} · 手续费{" "}