Show option contract ID and expiry date in trade detail.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-02 09:54:07 +08:00
parent 079dc83132
commit 63225f64de
+64
View File
@@ -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 解析 YYMMDDETH-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<Group[]>([]);
@@ -385,6 +417,35 @@ export default function TradesPage() {
)}
</span>
</div>
<div className="kv">
<span></span>
<span className="mono">
{selectedGroup.option_inst_id ||
optionInstFromFills(fills) ||
"—"}
</span>
</div>
<div className="kv">
<span></span>
<span className="mono">
{fmtExpiryYmd(
selectedGroup.expiry_ymd ||
expiryYmdFromInstId(
selectedGroup.option_inst_id ||
optionInstFromFills(fills),
),
)}
</span>
</div>
{selectedGroup.strike != null &&
!selectedGroup.expiry_settle ? (
<div className="kv">
<span></span>
<span className="mono">
{fmt(selectedGroup.strike, 0)}
</span>
</div>
) : null}
<div className="kv">
<span></span>
<span className="mono">
@@ -473,6 +534,9 @@ export default function TradesPage() {
f.side,
selectedGroup.close_reason,
)}
{f.inst_id ? (
<span className="meta"> · {f.inst_id}</span>
) : null}
</span>
<span className="mono">
{f.fill_px.toFixed(4)} · {f.qty_eth} · {" "}