diff --git a/frontend/src/api/live.ts b/frontend/src/api/live.ts index feb1f11..50aca53 100644 --- a/frontend/src/api/live.ts +++ b/frontend/src/api/live.ts @@ -124,3 +124,21 @@ export async function getLiveStatus(aid: number): Promise { const { data } = await apiClient.get(`/live/${aid}/status`) return data } + +export async function deleteLive(aid: number): Promise<{ account_id: number; deleted: boolean }> { + const { data } = await apiClient.delete(`/live/${aid}`) + return data +} + +export interface LiveUpdateReq { + name?: string + account?: string + vt_symbol?: string + strategy_name?: string + interval?: string +} + +export async function updateLive(aid: number, req: LiveUpdateReq): Promise<{ updated: boolean }> { + const { data } = await apiClient.put(`/live/${aid}`, req) + return data +} diff --git a/frontend/src/api/paper.ts b/frontend/src/api/paper.ts index b3ecc15..e67a12b 100644 --- a/frontend/src/api/paper.ts +++ b/frontend/src/api/paper.ts @@ -124,3 +124,29 @@ export async function getPending(aid: number): Promise { const { data } = await apiClient.get(`/paper/${aid}/pending`) return data } + +export async function stopPaper(aid: number): Promise<{ account_id: number; status: string }> { + const { data } = await apiClient.post(`/paper/${aid}/stop`) + return data +} + +export async function resumePaper(aid: number): Promise<{ account_id: number; status: string }> { + const { data } = await apiClient.post(`/paper/${aid}/resume`) + return data +} + +export async function deletePaper(aid: number): Promise<{ account_id: number; deleted: boolean }> { + const { data } = await apiClient.delete(`/paper/${aid}`) + return data +} + +export interface PaperUpdateReq { + name?: string + symbols?: string[] + initial_capital?: number +} + +export async function updatePaper(aid: number, req: PaperUpdateReq): Promise<{ updated: boolean }> { + const { data } = await apiClient.put(`/paper/${aid}`, req) + return data +} diff --git a/frontend/src/views/live/List.vue b/frontend/src/views/live/List.vue index 401c2b2..a05fa31 100644 --- a/frontend/src/views/live/List.vue +++ b/frontend/src/views/live/List.vue @@ -2,8 +2,11 @@ import { ref, computed, onMounted, onUnmounted } from 'vue' import { useRouter } from 'vue-router' import { ElMessage, ElMessageBox } from 'element-plus' +import { ref, reactive, computed, onMounted, onUnmounted } from 'vue' +import { useRouter } from 'vue-router' +import { ElMessage, ElMessageBox } from 'element-plus' import { - listLives, startLive, stopLive, + listLives, startLive, stopLive, deleteLive, updateLive, type LiveAccount, } from '@/api/live' @@ -73,6 +76,51 @@ function goNew(): void { router.push('/live/new') } +async function onDelete(a: LiveAccount): Promise { + try { + await ElMessageBox.confirm( + `删除实盘实例 #${a.id}(${a.name})?成交/持仓/余额数据将一并删除,不可恢复。`, + '删除确认', + { type: 'warning' }, + ) + } catch { + return + } + actionLoading.value = a.id + try { + await deleteLive(a.id) + ElMessage.success(`#${a.id} 已删除`) + await refreshSilent() + } catch (e: unknown) { + ElMessage.error(e instanceof Error ? e.message : '删除失败') + } finally { + actionLoading.value = null + } +} + +// 编辑(仅 stopped 可改;后端运行中会 400) +const editVisible = ref(false) +const editForm = reactive({ id: 0, name: '', account: '', vt_symbol: '', strategy_name: '', interval: '' }) +function openEdit(a: LiveAccount): void { + editForm.id = a.id + editForm.name = a.name + editForm.account = a.account + editForm.vt_symbol = a.vt_symbol + editForm.strategy_name = a.strategy_name + editForm.interval = a.interval + editVisible.value = true +} +async function saveEdit(): Promise { + try { + await updateLive(editForm.id, { ...editForm }) + ElMessage.success(`#${editForm.id} 已更新`) + editVisible.value = false + await refreshSilent() + } catch (e: unknown) { + ElMessage.error(e instanceof Error ? e.message : '更新失败') + } +} + async function onStart(a: LiveAccount): Promise { actionLoading.value = a.id try { @@ -178,7 +226,7 @@ async function onStop(a: LiveAccount): Promise { - + + + + + + + + + + + + diff --git a/frontend/src/views/paper/List.vue b/frontend/src/views/paper/List.vue index c227961..db3830e 100644 --- a/frontend/src/views/paper/List.vue +++ b/frontend/src/views/paper/List.vue @@ -1,8 +1,11 @@ diff --git a/frontend/src/views/paper/Result.vue b/frontend/src/views/paper/Result.vue index e021bf4..a9f2619 100644 --- a/frontend/src/views/paper/Result.vue +++ b/frontend/src/views/paper/Result.vue @@ -1,8 +1,9 @@