Show option contract ID and expiry date in trade detail.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -32,6 +32,9 @@ type Group = {
|
|||||||
bias: string | null;
|
bias: string | null;
|
||||||
option_side: string | null;
|
option_side: string | null;
|
||||||
perp_side: string | null;
|
perp_side: string | null;
|
||||||
|
option_inst_id?: string | null;
|
||||||
|
perp_inst_id?: string | null;
|
||||||
|
expiry_ymd?: string | null;
|
||||||
initial_premium: number;
|
initial_premium: number;
|
||||||
realized_pnl: number;
|
realized_pnl: number;
|
||||||
net_pnl?: number | null;
|
net_pnl?: number | null;
|
||||||
@@ -58,6 +61,7 @@ type Fill = {
|
|||||||
leg: string;
|
leg: string;
|
||||||
action: string;
|
action: string;
|
||||||
side: string;
|
side: string;
|
||||||
|
inst_id?: string | null;
|
||||||
fill_px: number;
|
fill_px: number;
|
||||||
fee: number;
|
fee: number;
|
||||||
qty_eth: number;
|
qty_eth: number;
|
||||||
@@ -113,6 +117,34 @@ function fmtMovePoints(n: number | null | undefined) {
|
|||||||
return s;
|
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() {
|
export default function TradesPage() {
|
||||||
const titleId = useId();
|
const titleId = useId();
|
||||||
const [groups, setGroups] = useState<Group[]>([]);
|
const [groups, setGroups] = useState<Group[]>([]);
|
||||||
@@ -385,6 +417,35 @@ export default function TradesPage() {
|
|||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</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">
|
<div className="kv">
|
||||||
<span>开仓时间</span>
|
<span>开仓时间</span>
|
||||||
<span className="mono">
|
<span className="mono">
|
||||||
@@ -473,6 +534,9 @@ export default function TradesPage() {
|
|||||||
f.side,
|
f.side,
|
||||||
selectedGroup.close_reason,
|
selectedGroup.close_reason,
|
||||||
)}
|
)}
|
||||||
|
{f.inst_id ? (
|
||||||
|
<span className="meta"> · {f.inst_id}</span>
|
||||||
|
) : null}
|
||||||
</span>
|
</span>
|
||||||
<span className="mono">
|
<span className="mono">
|
||||||
价 {f.fill_px.toFixed(4)} · 数量 {f.qty_eth} · 手续费{" "}
|
价 {f.fill_px.toFixed(4)} · 数量 {f.qty_eth} · 手续费{" "}
|
||||||
|
|||||||
Reference in New Issue
Block a user