fix(backtest): 结果页4个显示bug—成交枚举/时间/浮点精度/日志空
1. 交易详情方向/开平显原始枚举: Direction.LONG/Offset.OPEN → 买/卖、开仓/平仓/平今/平昨
(TradesTable 加 fmtDir/fmtOff, 方向带涨跌色)
2. 交易详情时间 2024-06-25T00:00:00+08:00 → 2024-06-25 (日内带时分则保留)
3. 每日收益浮点精度 0.6533000000054017 → 0.65 (toFixed2, 涨跌色), 日期去 00:00:00
4. 日志tab硬编码"暂无日志数据": 前端接 getLog(/task/:id/log) + 后端 cta_engine 加
stdout tee 把引擎 load/run/stats 输出落盘到 {task_id}.log (worker 进程内隔离)
→ 新回测日志 tab 显示真实引擎输出(2117字)
验证: 交易 买/开仓/2024-06-25, 收益 0.15, 日志 2117字真实内容
This commit is contained in:
@@ -2,15 +2,62 @@
|
||||
import type { Trade } from '@/api/backtest'
|
||||
|
||||
defineProps<{ trades: Trade[] }>()
|
||||
|
||||
// vnpy 枚举 repr → 中文(兼容已是中文的情况)
|
||||
function fmtDir(d: string): string {
|
||||
if (!d) return ''
|
||||
const s = String(d)
|
||||
if (s.includes('LONG') || s === '多') return '买'
|
||||
if (s.includes('SHORT') || s === '空') return '卖'
|
||||
if (s.includes('NET')) return '净'
|
||||
return s
|
||||
}
|
||||
function fmtOff(o: string): string {
|
||||
if (!o) return ''
|
||||
const s = String(o)
|
||||
if (s.includes('CLOSETODAY')) return '平今'
|
||||
if (s.includes('CLOSEFIRST')) return '平昨'
|
||||
if (s.includes('CLOSE')) return '平仓'
|
||||
if (s.includes('OPEN')) return '开仓'
|
||||
return s
|
||||
}
|
||||
// 2024-06-25T00:00:00+08:00 → 2024-06-25(日内带时分则保留)
|
||||
function fmtDate(dt: string): string {
|
||||
if (!dt) return ''
|
||||
const s = String(dt).slice(0, 19).replace('T', ' ')
|
||||
return s.endsWith(' 00:00:00') ? s.slice(0, 10) : s
|
||||
}
|
||||
function dirClass(d: string): string {
|
||||
const v = fmtDir(d)
|
||||
return v === '买' ? 'up' : v === '卖' ? 'down' : ''
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-table :data="trades" stripe size="small" empty-text="无成交">
|
||||
<el-table-column prop="datetime" label="时间" width="220" />
|
||||
<el-table-column prop="direction" label="方向" width="80" />
|
||||
<el-table-column prop="offset" label="开平" width="80" />
|
||||
<el-table-column prop="price" label="价格" width="100" />
|
||||
<el-table-column prop="volume" label="数量" width="100" />
|
||||
<el-table-column prop="vt_symbol" label="标的" />
|
||||
<el-table-column label="时间" width="150">
|
||||
<template #default="{ row }"><span class="mono">{{ fmtDate(row.datetime) }}</span></template>
|
||||
</el-table-column>
|
||||
<el-table-column label="方向" width="70">
|
||||
<template #default="{ row }"><span :class="dirClass(row.direction)">{{ fmtDir(row.direction) }}</span></template>
|
||||
</el-table-column>
|
||||
<el-table-column label="开平" width="70">
|
||||
<template #default="{ row }">{{ fmtOff(row.offset) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="价格" width="100" align="right">
|
||||
<template #default="{ row }"><span class="mono">{{ row.price }}</span></template>
|
||||
</el-table-column>
|
||||
<el-table-column label="数量" width="90" align="right">
|
||||
<template #default="{ row }"><span class="mono">{{ row.volume }}</span></template>
|
||||
</el-table-column>
|
||||
<el-table-column label="标的" min-width="100">
|
||||
<template #default="{ row }"><span class="mono">{{ row.vt_symbol }}</span></template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
:deep(.mono) { font-family: var(--mono); font-size: 12px; color: var(--text); }
|
||||
.up { color: var(--up); }
|
||||
.down { color: var(--down); }
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user