feat(web): Result 轮询(running每3s)+状态提示, New 默认 DoubleMaStrategy
This commit is contained in:
@@ -10,7 +10,7 @@ const form = ref<PaperCreate>({
|
||||
mode: 'replay',
|
||||
interval: 'd',
|
||||
symbols: ['600000'],
|
||||
strategies: [{ name: 'DoubleMa', params: {}, match_session: 'next_open', symbol: '600000' }],
|
||||
strategies: [{ name: 'DoubleMaStrategy', params: { fast_window: 5, slow_window: 10 }, match_session: 'next_open', symbol: '600000' }],
|
||||
initial_capital: 1_000_000,
|
||||
start: '2024-01-01',
|
||||
end: '2024-06-30',
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { ref, onMounted, onUnmounted } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import {
|
||||
getEquity, getTrades, getStrategies,
|
||||
getEquity, getTrades, getStrategies, getPaper,
|
||||
type BalancePoint, type PaperTrade, type StrategySummary,
|
||||
} from '@/api/paper'
|
||||
|
||||
@@ -11,11 +11,33 @@ const aid = Number(route.params.id)
|
||||
const equity = ref<BalancePoint[]>([])
|
||||
const trades = ref<PaperTrade[]>([])
|
||||
const strategies = ref<StrategySummary[]>([])
|
||||
const status = ref<string>('')
|
||||
let timer: ReturnType<typeof setInterval> | null = null
|
||||
|
||||
onMounted(async () => {
|
||||
async function load(): Promise<void> {
|
||||
try {
|
||||
const acc = await getPaper(aid)
|
||||
status.value = acc.status
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
equity.value = await getEquity(aid)
|
||||
trades.value = await getTrades(aid)
|
||||
strategies.value = await getStrategies(aid)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void load()
|
||||
timer = setInterval(async () => {
|
||||
if (status.value === 'done' || status.value === 'failed') {
|
||||
if (timer) clearInterval(timer)
|
||||
return
|
||||
}
|
||||
await load()
|
||||
}, 3000)
|
||||
})
|
||||
onUnmounted(() => {
|
||||
if (timer) clearInterval(timer)
|
||||
})
|
||||
|
||||
function rowClass({ row }: { row: PaperTrade }): string {
|
||||
@@ -25,6 +47,18 @@ function rowClass({ row }: { row: PaperTrade }): string {
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<el-alert
|
||||
v-if="status === 'running' || status === 'pending' || status === 'created'"
|
||||
type="info"
|
||||
:closable="false"
|
||||
style="margin-bottom: 16px"
|
||||
>
|
||||
回放进行中({{ status }})…每 3 秒刷新,完成自动停止
|
||||
</el-alert>
|
||||
<el-alert v-else-if="status === 'failed'" type="error" :closable="false" style="margin-bottom: 16px">
|
||||
回放失败
|
||||
</el-alert>
|
||||
|
||||
<el-card header="账户净值" style="margin-bottom: 16px">
|
||||
<el-table :data="equity" size="small" max-height="240">
|
||||
<el-table-column prop="date" label="日期" />
|
||||
|
||||
Reference in New Issue
Block a user