diff --git a/frontend/admin.html b/frontend/admin.html index 1682f03..0bf1e22 100644 --- a/frontend/admin.html +++ b/frontend/admin.html @@ -5,46 +5,16 @@ 后台管理 - Tradus + + + +
-
+
-
-
- 模拟交易 - PAPER + - @@ -591,13 +441,36 @@ return { currentTab: 'positions', loading: false, - account: { - current_balance: 0, - available: 0, - used_margin: 0, - total_position_value: 0, + sendingReport: false, + stats: { + total_trades: 0, + winning_trades: 0, + losing_trades: 0, + win_rate: 0, total_pnl: 0, - total_trades: 0 + average_win: 0, + average_loss: 0, + profit_factor: 0, + max_drawdown: 0, + best_trade: 0, + worst_trade: 0, + return_percent: 0 + }, + account: { + initial_balance: 10000, + current_balance: 10000, + used_margin: 0, + available_margin: 10000, + leverage: 10, + margin_per_order: 1000, + active_orders: 0, + max_orders: 10, + available_orders: 10, + total_position_value: 0, + margin_ratio: 0, + realized_pnl: 0, + current_total_leverage: 0, + max_total_leverage: 10 }, orders: [] }; @@ -623,8 +496,11 @@ try { await Promise.all([ this.fetchAccountStatus(), + this.fetchStatistics(), this.fetchOrders() ]); + } catch (e) { + console.error('刷新数据失败:', e); } finally { this.loading = false; } @@ -641,6 +517,17 @@ } }, + async fetchStatistics() { + try { + const response = await axios.get('/api/trading/statistics'); + if (response.data.success) { + this.stats = response.data.statistics; + } + } catch (error) { + console.error('获取统计数据失败:', error); + } + }, + async fetchOrders() { try { const response = await axios.get('/api/trading/orders'); @@ -652,11 +539,11 @@ } }, - async closeOrder(orderId) { + async closeOrder(order) { if (!confirm('确定要平仓吗?')) return; try { - const response = await axios.post(`/api/trading/orders/${orderId}/close`); + const response = await axios.post(`/api/trading/orders/${order.order_id}/close`); if (response.data.success) { await this.refreshData(); alert('平仓成功'); @@ -669,11 +556,11 @@ } }, - async cancelOrder(orderId) { + async cancelOrder(order) { if (!confirm('确定要撤单吗?')) return; try { - const response = await axios.post(`/api/trading/orders/${orderId}/cancel`); + const response = await axios.post(`/api/trading/orders/${order.order_id}/cancel`); if (response.data.success) { await this.refreshData(); alert('撤单成功'); @@ -703,6 +590,23 @@ } }, + async sendReport() { + this.sendingReport = true; + try { + const response = await axios.post('/api/trading/report?hours=4&send_telegram=true'); + if (response.data.success) { + alert('报告已发送'); + } else { + alert('发送失败: ' + (response.data.message || '未知错误')); + } + } catch (error) { + console.error('发送报告失败:', error); + alert('发送失败: ' + (error.response?.data?.detail || error.message)); + } finally { + this.sendingReport = false; + } + }, + formatTime(timeStr) { if (!timeStr) return '-'; const date = new Date(timeStr);