// frontend/src/components/LedgerTable.tsx import React from 'react'; export interface LedgerItem { timestamp: string; action: 'BUY' | 'SELL'; ticker: string; shares: number; market_price: number; execution_price: number; commission: number; total_value: number; total_cost?: number; revenue?: number; realized_pnl?: number; cash_remaining: number; } interface LedgerTableProps { ledger: LedgerItem[]; onRowClick?: (item: LedgerItem) => void; } export const LedgerTable: React.FC = ({ ledger, onRowClick }) => { const formatTime = (timeStr: string) => { // 简化时间显示,只保留 "YYYY-MM-DD HH:MM" try { const parts = timeStr.split(' '); if (parts.length >= 2) { return `${parts[0]} ${parts[1].substring(0, 5)}`; } } catch (e) {} return timeStr; }; return (

交易流水账单 (Transaction Ledger)

{ledger.length === 0 ? (

回测期间系统保持空仓防守,未触发交易信号。

) : ( {[...ledger].reverse().map((item, index) => { const pnl = item.realized_pnl; const hasPnl = pnl !== undefined && item.action === 'SELL'; const pnlColor = hasPnl ? (pnl >= 0 ? 'var(--color-green)' : 'var(--color-red)') : 'inherit'; const pnlText = hasPnl ? `${pnl >= 0 ? '+' : ''}$${pnl.toFixed(2)}` : '--'; return ( onRowClick && onRowClick(item)} style={{ cursor: onRowClick ? 'pointer' : 'default' }} > ); })}
交易时间 操作 代码 股数 成交均价 ( 盘面价格 ) 交易手续费 净收益 PnL
{formatTime(item.timestamp)} {item.action === 'BUY' ? 'BUY / 买入' : 'SELL / 平仓'} {item.ticker} {item.shares} ${item.execution_price.toFixed(2)} ${item.market_price.toFixed(2)} ${item.commission.toFixed(2)} {pnlText}
)}
); };