Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- backend/v2/api.py +45 -0
- frontend/package-lock.json +0 -0
- frontend/package.json +51 -0
- frontend/src/pages/Home.tsx +146 -234
- sync_to_hf.sh +53 -0
backend/v2/api.py
CHANGED
|
@@ -5096,3 +5096,48 @@ async def delete_grid_strategy_api(strategy_id: str, x_user_id: str | None = Hea
|
|
| 5096 |
if not ok:
|
| 5097 |
raise HTTPException(status_code=404, detail='策略不存在')
|
| 5098 |
return {'message': '删除成功'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5096 |
if not ok:
|
| 5097 |
raise HTTPException(status_code=404, detail='策略不存在')
|
| 5098 |
return {'message': '删除成功'}
|
| 5099 |
+
|
| 5100 |
+
|
| 5101 |
+
# ============ Dashboard API ============
|
| 5102 |
+
|
| 5103 |
+
@router.get('/dashboard/grid-paired-profit')
|
| 5104 |
+
async def get_dashboard_grid_paired_profit(days: int = 90, x_user_id: str | None = Header(default=None)):
|
| 5105 |
+
"""
|
| 5106 |
+
获取最近 N 天的每日网格配对收益,用于仪表盘折线图。
|
| 5107 |
+
返回: [{ date: 'YYYY-MM-DD', profit: float }, ...]
|
| 5108 |
+
"""
|
| 5109 |
+
init_db()
|
| 5110 |
+
real_user_id = _get_user_id(x_user_id)
|
| 5111 |
+
if not real_user_id:
|
| 5112 |
+
raise HTTPException(status_code=400, detail='缺少 X-User-Id')
|
| 5113 |
+
_ensure_not_banned(real_user_id)
|
| 5114 |
+
user_id = _get_trades_user_id(real_user_id)
|
| 5115 |
+
|
| 5116 |
+
from datetime import date, timedelta
|
| 5117 |
+
from .repository import list_trade_daily_stats
|
| 5118 |
+
|
| 5119 |
+
end_date = date.today().strftime('%Y-%m-%d')
|
| 5120 |
+
start_date = (date.today() - timedelta(days=days)).strftime('%Y-%m-%d')
|
| 5121 |
+
|
| 5122 |
+
# 确保数据是最新的
|
| 5123 |
+
compute_and_upsert_trade_daily_stats(user_id=user_id, date_end=end_date)
|
| 5124 |
+
|
| 5125 |
+
rows = list_trade_daily_stats(user_id=user_id, date_start=start_date, date_end=end_date)
|
| 5126 |
+
|
| 5127 |
+
# 构建日期 -> profit 映射
|
| 5128 |
+
data_map = {}
|
| 5129 |
+
for r in rows:
|
| 5130 |
+
d = r.get('trade_date')
|
| 5131 |
+
if d:
|
| 5132 |
+
data_map[str(d)] = float(r.get('grid_paired_profit') or 0.0)
|
| 5133 |
+
|
| 5134 |
+
# 补全所有日期(包括无数据的日期填 0)
|
| 5135 |
+
result = []
|
| 5136 |
+
for i in range(days):
|
| 5137 |
+
d = (date.today() - timedelta(days=days - 1 - i)).strftime('%Y-%m-%d')
|
| 5138 |
+
result.append({
|
| 5139 |
+
'date': d,
|
| 5140 |
+
'profit': data_map.get(d, 0.0)
|
| 5141 |
+
})
|
| 5142 |
+
|
| 5143 |
+
return {'days': days, 'data': result}
|
frontend/package-lock.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
frontend/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "backtest-frontend",
|
| 3 |
+
"version": "1.0.0",
|
| 4 |
+
"private": true,
|
| 5 |
+
"scripts": {
|
| 6 |
+
"dev": "vite",
|
| 7 |
+
"build": "tsc && vite build",
|
| 8 |
+
"preview": "vite preview"
|
| 9 |
+
},
|
| 10 |
+
"dependencies": {
|
| 11 |
+
"@radix-ui/react-alert-dialog": "^1.0.5",
|
| 12 |
+
"@radix-ui/react-checkbox": "^1.0.4",
|
| 13 |
+
"@radix-ui/react-dialog": "^1.1.15",
|
| 14 |
+
"@radix-ui/react-dropdown-menu": "^2.0.6",
|
| 15 |
+
"@radix-ui/react-label": "^2.0.2",
|
| 16 |
+
"@radix-ui/react-radio-group": "^1.1.3",
|
| 17 |
+
"@radix-ui/react-select": "^2.0.0",
|
| 18 |
+
"@radix-ui/react-separator": "^1.0.3",
|
| 19 |
+
"@radix-ui/react-switch": "^1.0.3",
|
| 20 |
+
"@radix-ui/react-tabs": "^1.0.4",
|
| 21 |
+
"@radix-ui/react-toast": "^1.1.5",
|
| 22 |
+
"@rollup/rollup-darwin-arm64": "^4.60.3",
|
| 23 |
+
"axios": "^1.6.2",
|
| 24 |
+
"class-variance-authority": "^0.7.1",
|
| 25 |
+
"clsx": "^2.0.0",
|
| 26 |
+
"date-fns": "^2.30.0",
|
| 27 |
+
"html2canvas": "^1.4.1",
|
| 28 |
+
"jspdf": "^2.5.2",
|
| 29 |
+
"lucide-react": "^0.294.0",
|
| 30 |
+
"react": "^18.2.0",
|
| 31 |
+
"react-dom": "^18.2.0",
|
| 32 |
+
"react-hook-form": "^7.48.2",
|
| 33 |
+
"react-router-dom": "^6.20.1",
|
| 34 |
+
"recharts": "^2.10.3",
|
| 35 |
+
"tailwind-merge": "^2.1.0",
|
| 36 |
+
"tailwindcss-animate": "^1.0.7",
|
| 37 |
+
"xlsx": "^0.18.5",
|
| 38 |
+
"zustand": "^4.4.7"
|
| 39 |
+
},
|
| 40 |
+
"devDependencies": {
|
| 41 |
+
"@types/node": "^20.10.4",
|
| 42 |
+
"@types/react": "^18.2.45",
|
| 43 |
+
"@types/react-dom": "^18.2.17",
|
| 44 |
+
"@vitejs/plugin-react": "^4.2.0",
|
| 45 |
+
"autoprefixer": "^10.4.16",
|
| 46 |
+
"postcss": "^8.4.32",
|
| 47 |
+
"tailwindcss": "^3.3.6",
|
| 48 |
+
"typescript": "^5.3.3",
|
| 49 |
+
"vite": "^5.0.8"
|
| 50 |
+
}
|
| 51 |
+
}
|
frontend/src/pages/Home.tsx
CHANGED
|
@@ -1,266 +1,178 @@
|
|
| 1 |
-
import {
|
| 2 |
import { Card, CardContent, CardHeader, CardTitle } from '../components/ui/card'
|
| 3 |
-
import {
|
| 4 |
-
import {
|
| 5 |
-
|
| 6 |
-
DollarSign,
|
| 7 |
-
TrendingUp,
|
| 8 |
-
BarChart3,
|
| 9 |
-
ArrowRight,
|
| 10 |
-
Target,
|
| 11 |
-
Shield,
|
| 12 |
-
Zap,
|
| 13 |
-
BookOpen,
|
| 14 |
-
ChevronRight
|
| 15 |
-
} from 'lucide-react'
|
| 16 |
-
import { useEffect } from 'react'
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
{ label: '胜率', value: '--', change: '--', icon: Target },
|
| 22 |
-
{ label: '盈亏比', value: '--', change: '--', icon: TrendingUp },
|
| 23 |
-
{ label: '最大回撤', value: '--', change: '--', icon: Shield },
|
| 24 |
-
]
|
| 25 |
-
|
| 26 |
-
// 快捷功能
|
| 27 |
-
const quickActions = [
|
| 28 |
-
{
|
| 29 |
-
title: '网格交易回测',
|
| 30 |
-
desc: '智能网格策略,自动高抛低吸',
|
| 31 |
-
link: '/grid',
|
| 32 |
-
icon: LayoutGrid,
|
| 33 |
-
color: 'from-violet-500 to-purple-600',
|
| 34 |
-
bgColor: 'bg-violet-50 dark:bg-violet-950/30'
|
| 35 |
-
},
|
| 36 |
-
{
|
| 37 |
-
title: '定投交易回测',
|
| 38 |
-
desc: '定期定额,平摊成本',
|
| 39 |
-
link: '/dca',
|
| 40 |
-
icon: DollarSign,
|
| 41 |
-
color: 'from-blue-500 to-cyan-600',
|
| 42 |
-
bgColor: 'bg-blue-50 dark:bg-blue-950/30'
|
| 43 |
-
},
|
| 44 |
-
]
|
| 45 |
-
|
| 46 |
-
// AI 日报内容
|
| 47 |
-
const dailyReport = {
|
| 48 |
-
title: '网格交易日报',
|
| 49 |
-
date: new Date().toLocaleDateString('zh-CN'),
|
| 50 |
-
content: '昨日无成交记录,建议关注市场波动率变化,适时调整网格参数。',
|
| 51 |
-
suggestion: '在笔记本中记录观望期的市场判断。'
|
| 52 |
}
|
| 53 |
|
| 54 |
export default function Home() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
useEffect(() => {
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
}, [])
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
return (
|
| 60 |
<div className="space-y-6">
|
| 61 |
-
{/*
|
| 62 |
-
<div className="
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
className="border-slate-200 dark:border-slate-800 hover:shadow-lg transition-shadow"
|
| 69 |
-
style={{ animationDelay: `${i * 100}ms` }}
|
| 70 |
-
>
|
| 71 |
-
<CardContent className="p-5">
|
| 72 |
-
<div className="flex items-start justify-between">
|
| 73 |
-
<div>
|
| 74 |
-
<p className="text-sm text-slate-500 dark:text-slate-400">{stat.label}</p>
|
| 75 |
-
<p className="text-2xl font-bold text-slate-900 dark:text-white mt-1">
|
| 76 |
-
{stat.value}
|
| 77 |
-
</p>
|
| 78 |
-
<p className="text-xs text-slate-400 mt-1">{stat.change}</p>
|
| 79 |
-
</div>
|
| 80 |
-
<div className="p-2 bg-slate-100 dark:bg-slate-800 rounded-lg">
|
| 81 |
-
<Icon className="h-5 w-5 text-slate-600 dark:text-slate-400" />
|
| 82 |
-
</div>
|
| 83 |
-
</div>
|
| 84 |
-
</CardContent>
|
| 85 |
-
</Card>
|
| 86 |
-
)
|
| 87 |
-
})}
|
| 88 |
</div>
|
| 89 |
|
| 90 |
-
{/*
|
| 91 |
-
<div className="grid grid-cols-1
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
<div className="flex items-center gap-2 text-violet-200 text-sm">
|
| 100 |
-
<span className="uppercase tracking-wider">网格交易日报</span>
|
| 101 |
-
<span>·</span>
|
| 102 |
-
<span>{dailyReport.date}</span>
|
| 103 |
-
</div>
|
| 104 |
-
</CardHeader>
|
| 105 |
-
<CardContent className="relative z-10 pt-0">
|
| 106 |
-
<div className="flex items-start justify-between">
|
| 107 |
-
<div className="flex-1">
|
| 108 |
-
<p className="text-lg leading-relaxed text-white/90">
|
| 109 |
-
{dailyReport.content}
|
| 110 |
-
</p>
|
| 111 |
-
<p className="text-sm text-violet-200 mt-3">
|
| 112 |
-
💡 建议:{dailyReport.suggestion}
|
| 113 |
</p>
|
| 114 |
</div>
|
| 115 |
-
<div className="
|
| 116 |
-
<
|
| 117 |
-
<BookOpen className="h-10 w-10 text-white/60" />
|
| 118 |
-
</div>
|
| 119 |
</div>
|
| 120 |
</div>
|
| 121 |
-
<div className="mt-6">
|
| 122 |
-
<Button
|
| 123 |
-
variant="secondary"
|
| 124 |
-
className="bg-white/20 hover:bg-white/30 text-white border-0"
|
| 125 |
-
>
|
| 126 |
-
打开笔记本
|
| 127 |
-
<ChevronRight className="h-4 w-4 ml-1" />
|
| 128 |
-
</Button>
|
| 129 |
-
</div>
|
| 130 |
</CardContent>
|
| 131 |
</Card>
|
| 132 |
|
| 133 |
-
{/* 风控状态 */}
|
| 134 |
<Card className="border-slate-200 dark:border-slate-800">
|
| 135 |
-
<
|
| 136 |
-
<CardTitle className="text-base font-semibold flex items-center gap-2">
|
| 137 |
-
<Shield className="h-4 w-4 text-emerald-500" />
|
| 138 |
-
风控状态
|
| 139 |
-
</CardTitle>
|
| 140 |
-
</CardHeader>
|
| 141 |
-
<CardContent className="pt-0 space-y-4">
|
| 142 |
-
<div className="flex items-center justify-between">
|
| 143 |
-
<span className="text-sm text-slate-600 dark:text-slate-400">今日盈亏</span>
|
| 144 |
-
<span className="text-emerald-500 font-medium">+¥0.00</span>
|
| 145 |
-
</div>
|
| 146 |
-
<div className="flex items-center justify-between">
|
| 147 |
-
<span className="text-sm text-slate-600 dark:text-slate-400">日亏损限额</span>
|
| 148 |
-
<span className="text-rose-500 font-medium">-¥500</span>
|
| 149 |
-
</div>
|
| 150 |
<div className="flex items-center justify-between">
|
| 151 |
-
<
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
{[...Array(10)].map((_, i) => (
|
| 158 |
-
<div
|
| 159 |
-
key={i}
|
| 160 |
-
className="h-2 flex-1 rounded-sm bg-slate-200 dark:bg-slate-700"
|
| 161 |
-
/>
|
| 162 |
-
))}
|
| 163 |
</div>
|
| 164 |
</div>
|
| 165 |
</CardContent>
|
| 166 |
</Card>
|
| 167 |
-
</div>
|
| 168 |
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
{quickActions.map((action) => {
|
| 176 |
-
const Icon = action.icon
|
| 177 |
-
return (
|
| 178 |
-
<Link key={action.title} to={action.link}>
|
| 179 |
-
<Card className={`group hover:shadow-xl transition-all duration-300 border-slate-200 dark:border-slate-800 hover:border-violet-300 dark:hover:border-violet-700 cursor-pointer overflow-hidden`}>
|
| 180 |
-
<CardContent className="p-0">
|
| 181 |
-
<div className="flex items-stretch">
|
| 182 |
-
{/* 左侧图标区 */}
|
| 183 |
-
<div className={`w-24 ${action.bgColor} flex items-center justify-center`}>
|
| 184 |
-
<div className={`w-12 h-12 rounded-xl bg-gradient-to-br ${action.color} flex items-center justify-center shadow-lg group-hover:scale-110 transition-transform`}>
|
| 185 |
-
<Icon className="h-6 w-6 text-white" />
|
| 186 |
-
</div>
|
| 187 |
-
</div>
|
| 188 |
-
{/* 右侧内容区 */}
|
| 189 |
-
<div className="flex-1 p-5">
|
| 190 |
-
<div className="flex items-start justify-between">
|
| 191 |
-
<div>
|
| 192 |
-
<h3 className="font-semibold text-slate-900 dark:text-white text-lg">
|
| 193 |
-
{action.title}
|
| 194 |
-
</h3>
|
| 195 |
-
<p className="text-sm text-slate-500 dark:text-slate-400 mt-1">
|
| 196 |
-
{action.desc}
|
| 197 |
-
</p>
|
| 198 |
-
</div>
|
| 199 |
-
<ArrowRight className="h-5 w-5 text-slate-400 group-hover:text-violet-500 group-hover:translate-x-1 transition-all" />
|
| 200 |
-
</div>
|
| 201 |
-
</div>
|
| 202 |
-
</div>
|
| 203 |
-
</CardContent>
|
| 204 |
-
</Card>
|
| 205 |
-
</Link>
|
| 206 |
-
)
|
| 207 |
-
})}
|
| 208 |
-
</div>
|
| 209 |
-
</div>
|
| 210 |
-
|
| 211 |
-
{/* 底部功能网格 */}
|
| 212 |
-
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
| 213 |
-
<Link to="/indicators">
|
| 214 |
-
<Card className="group hover:shadow-lg transition-all border-slate-200 dark:border-slate-800 h-full">
|
| 215 |
-
<CardContent className="p-5">
|
| 216 |
-
<div className="flex items-center gap-4">
|
| 217 |
-
<div className="w-10 h-10 rounded-lg bg-amber-100 dark:bg-amber-950/50 flex items-center justify-center">
|
| 218 |
-
<TrendingUp className="h-5 w-5 text-amber-600" />
|
| 219 |
-
</div>
|
| 220 |
-
<div className="flex-1">
|
| 221 |
-
<h3 className="font-semibold text-slate-900 dark:text-white">技术指标</h3>
|
| 222 |
-
<p className="text-xs text-slate-500">MACD、KDJ、均线等</p>
|
| 223 |
-
</div>
|
| 224 |
-
<ChevronRight className="h-4 w-4 text-slate-400 group-hover:text-amber-500" />
|
| 225 |
-
</div>
|
| 226 |
-
</CardContent>
|
| 227 |
-
</Card>
|
| 228 |
-
</Link>
|
| 229 |
-
|
| 230 |
-
<Link to="/data">
|
| 231 |
-
<Card className="group hover:shadow-lg transition-all border-slate-200 dark:border-slate-800 h-full">
|
| 232 |
-
<CardContent className="p-5">
|
| 233 |
-
<div className="flex items-center gap-4">
|
| 234 |
-
<div className="w-10 h-10 rounded-lg bg-emerald-100 dark:bg-emerald-950/50 flex items-center justify-center">
|
| 235 |
-
<BarChart3 className="h-5 w-5 text-emerald-600" />
|
| 236 |
-
</div>
|
| 237 |
-
<div className="flex-1">
|
| 238 |
-
<h3 className="font-semibold text-slate-900 dark:text-white">数据中心</h3>
|
| 239 |
-
<p className="text-xs text-slate-500">历史数据下载管理</p>
|
| 240 |
-
</div>
|
| 241 |
-
<ChevronRight className="h-4 w-4 text-slate-400 group-hover:text-emerald-500" />
|
| 242 |
</div>
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
</Link>
|
| 246 |
-
|
| 247 |
-
<Link to="/trades">
|
| 248 |
-
<Card className="group hover:shadow-lg transition-all border-slate-200 dark:border-slate-800 h-full">
|
| 249 |
-
<CardContent className="p-5">
|
| 250 |
-
<div className="flex items-center gap-4">
|
| 251 |
-
<div className="w-10 h-10 rounded-lg bg-rose-100 dark:bg-rose-950/50 flex items-center justify-center">
|
| 252 |
-
<Zap className="h-5 w-5 text-rose-600" />
|
| 253 |
-
</div>
|
| 254 |
-
<div className="flex-1">
|
| 255 |
-
<h3 className="font-semibold text-slate-900 dark:text-white">交易记录</h3>
|
| 256 |
-
<p className="text-xs text-slate-500">导入同花顺交易数据</p>
|
| 257 |
-
</div>
|
| 258 |
-
<ChevronRight className="h-4 w-4 text-slate-400 group-hover:text-rose-500" />
|
| 259 |
</div>
|
| 260 |
-
</
|
| 261 |
-
</
|
| 262 |
-
</
|
| 263 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
</div>
|
| 265 |
)
|
| 266 |
}
|
|
|
|
| 1 |
+
import { useEffect, useState } from 'react'
|
| 2 |
import { Card, CardContent, CardHeader, CardTitle } from '../components/ui/card'
|
| 3 |
+
import { TrendingUp, Calendar } from 'lucide-react'
|
| 4 |
+
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, ReferenceLine } from 'recharts'
|
| 5 |
+
import axios from 'axios'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
interface DailyProfit {
|
| 8 |
+
date: string
|
| 9 |
+
profit: number
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
}
|
| 11 |
|
| 12 |
export default function Home() {
|
| 13 |
+
const [data, setData] = useState<DailyProfit[]>([])
|
| 14 |
+
const [loading, setLoading] = useState(true)
|
| 15 |
+
const [totalProfit, setTotalProfit] = useState(0)
|
| 16 |
+
const [positiveDays, setPositiveDays] = useState(0)
|
| 17 |
+
const [negativeDays, setNegativeDays] = useState(0)
|
| 18 |
+
|
| 19 |
useEffect(() => {
|
| 20 |
+
const fetchData = async () => {
|
| 21 |
+
try {
|
| 22 |
+
const res = await axios.get('/api/v2/dashboard/grid-paired-profit?days=90')
|
| 23 |
+
const chartData = res.data.data || []
|
| 24 |
+
setData(chartData)
|
| 25 |
+
|
| 26 |
+
// 计算统计数据
|
| 27 |
+
const total = chartData.reduce((sum: number, d: DailyProfit) => sum + d.profit, 0)
|
| 28 |
+
const positive = chartData.filter((d: DailyProfit) => d.profit > 0).length
|
| 29 |
+
const negative = chartData.filter((d: DailyProfit) => d.profit < 0).length
|
| 30 |
+
|
| 31 |
+
setTotalProfit(total)
|
| 32 |
+
setPositiveDays(positive)
|
| 33 |
+
setNegativeDays(negative)
|
| 34 |
+
} catch (error) {
|
| 35 |
+
console.error('获取数据失败:', error)
|
| 36 |
+
} finally {
|
| 37 |
+
setLoading(false)
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
fetchData()
|
| 41 |
}, [])
|
| 42 |
|
| 43 |
+
// 格式化日期显示(只显示月-日)
|
| 44 |
+
const formatDate = (dateStr: string) => {
|
| 45 |
+
const parts = dateStr.split('-')
|
| 46 |
+
return parts.length >= 3 ? `${parts[1]}-${parts[2]}` : dateStr
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
// 格式化金额
|
| 50 |
+
const formatProfit = (value: number) => {
|
| 51 |
+
if (value >= 0) {
|
| 52 |
+
return `+¥${value.toFixed(2)}`
|
| 53 |
+
}
|
| 54 |
+
return `-¥${Math.abs(value).toFixed(2)}`
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
return (
|
| 58 |
<div className="space-y-6">
|
| 59 |
+
{/* 页面标题 */}
|
| 60 |
+
<div className="flex items-center justify-between">
|
| 61 |
+
<h1 className="text-2xl font-bold text-slate-900 dark:text-white">仪表盘</h1>
|
| 62 |
+
<div className="flex items-center gap-2 text-sm text-slate-500 dark:text-slate-400">
|
| 63 |
+
<Calendar className="h-4 w-4" />
|
| 64 |
+
<span>最近 90 天</span>
|
| 65 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
</div>
|
| 67 |
|
| 68 |
+
{/* 统计卡片 */}
|
| 69 |
+
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
| 70 |
+
<Card className="border-slate-200 dark:border-slate-800">
|
| 71 |
+
<CardContent className="p-5">
|
| 72 |
+
<div className="flex items-center justify-between">
|
| 73 |
+
<div>
|
| 74 |
+
<p className="text-sm text-slate-500 dark:text-slate-400">累计配对收益</p>
|
| 75 |
+
<p className={`text-2xl font-bold mt-1 ${totalProfit >= 0 ? 'text-emerald-500' : 'text-rose-500'}`}>
|
| 76 |
+
{formatProfit(totalProfit)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
</p>
|
| 78 |
</div>
|
| 79 |
+
<div className="p-3 bg-emerald-100 dark:bg-emerald-950/50 rounded-lg">
|
| 80 |
+
<TrendingUp className="h-6 w-6 text-emerald-600" />
|
|
|
|
|
|
|
| 81 |
</div>
|
| 82 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
</CardContent>
|
| 84 |
</Card>
|
| 85 |
|
|
|
|
| 86 |
<Card className="border-slate-200 dark:border-slate-800">
|
| 87 |
+
<CardContent className="p-5">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
<div className="flex items-center justify-between">
|
| 89 |
+
<div>
|
| 90 |
+
<p className="text-sm text-slate-500 dark:text-slate-400">盈利天数</p>
|
| 91 |
+
<p className="text-2xl font-bold text-emerald-500 mt-1">{positiveDays} 天</p>
|
| 92 |
+
</div>
|
| 93 |
+
<div className="p-3 bg-emerald-100 dark:bg-emerald-950/50 rounded-lg">
|
| 94 |
+
<TrendingUp className="h-6 w-6 text-emerald-600" />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
</div>
|
| 96 |
</div>
|
| 97 |
</CardContent>
|
| 98 |
</Card>
|
|
|
|
| 99 |
|
| 100 |
+
<Card className="border-slate-200 dark:border-slate-800">
|
| 101 |
+
<CardContent className="p-5">
|
| 102 |
+
<div className="flex items-center justify-between">
|
| 103 |
+
<div>
|
| 104 |
+
<p className="text-sm text-slate-500 dark:text-slate-400">亏损天数</p>
|
| 105 |
+
<p className="text-2xl font-bold text-rose-500 mt-1">{negativeDays} 天</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
</div>
|
| 107 |
+
<div className="p-3 bg-rose-100 dark:bg-rose-950/50 rounded-lg">
|
| 108 |
+
<TrendingUp className="h-6 w-6 text-rose-600 rotate-180" />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
</div>
|
| 110 |
+
</div>
|
| 111 |
+
</CardContent>
|
| 112 |
+
</Card>
|
| 113 |
</div>
|
| 114 |
+
|
| 115 |
+
{/* 折线图 */}
|
| 116 |
+
<Card className="border-slate-200 dark:border-slate-800">
|
| 117 |
+
<CardHeader className="pb-2">
|
| 118 |
+
<CardTitle className="text-lg font-semibold flex items-center gap-2">
|
| 119 |
+
<TrendingUp className="h-5 w-5 text-violet-500" />
|
| 120 |
+
每日网格配对收益
|
| 121 |
+
</CardTitle>
|
| 122 |
+
</CardHeader>
|
| 123 |
+
<CardContent>
|
| 124 |
+
{loading ? (
|
| 125 |
+
<div className="h-[400px] flex items-center justify-center text-slate-400">
|
| 126 |
+
加载中...
|
| 127 |
+
</div>
|
| 128 |
+
) : data.length === 0 ? (
|
| 129 |
+
<div className="h-[400px] flex items-center justify-center text-slate-400">
|
| 130 |
+
暂无数据
|
| 131 |
+
</div>
|
| 132 |
+
) : (
|
| 133 |
+
<div className="h-[400px]">
|
| 134 |
+
<ResponsiveContainer width="100%" height="100%">
|
| 135 |
+
<LineChart data={data} margin={{ top: 20, right: 30, left: 20, bottom: 20 }}>
|
| 136 |
+
<CartesianGrid strokeDasharray="3 3" stroke="#e2e8f0" />
|
| 137 |
+
<XAxis
|
| 138 |
+
dataKey="date"
|
| 139 |
+
tickFormatter={formatDate}
|
| 140 |
+
tick={{ fill: '#94a3b8', fontSize: 12 }}
|
| 141 |
+
tickLine={false}
|
| 142 |
+
axisLine={{ stroke: '#e2e8f0' }}
|
| 143 |
+
interval="preserveStartEnd"
|
| 144 |
+
/>
|
| 145 |
+
<YAxis
|
| 146 |
+
tickFormatter={(v) => `¥${v}`}
|
| 147 |
+
tick={{ fill: '#94a3b8', fontSize: 12 }}
|
| 148 |
+
tickLine={false}
|
| 149 |
+
axisLine={{ stroke: '#e2e8f0' }}
|
| 150 |
+
/>
|
| 151 |
+
<Tooltip
|
| 152 |
+
formatter={(value: number) => [formatProfit(value), '配对收益']}
|
| 153 |
+
labelFormatter={(label) => `日期: ${label}`}
|
| 154 |
+
contentStyle={{
|
| 155 |
+
backgroundColor: 'rgba(15, 23, 42, 0.95)',
|
| 156 |
+
border: 'none',
|
| 157 |
+
borderRadius: '8px',
|
| 158 |
+
color: '#fff'
|
| 159 |
+
}}
|
| 160 |
+
/>
|
| 161 |
+
<ReferenceLine y={0} stroke="#94a3b8" strokeDasharray="3 3" />
|
| 162 |
+
<Line
|
| 163 |
+
type="monotone"
|
| 164 |
+
dataKey="profit"
|
| 165 |
+
stroke="#8b5cf6"
|
| 166 |
+
strokeWidth={2}
|
| 167 |
+
dot={false}
|
| 168 |
+
activeDot={{ r: 4, fill: '#8b5cf6' }}
|
| 169 |
+
/>
|
| 170 |
+
</LineChart>
|
| 171 |
+
</ResponsiveContainer>
|
| 172 |
+
</div>
|
| 173 |
+
)}
|
| 174 |
+
</CardContent>
|
| 175 |
+
</Card>
|
| 176 |
</div>
|
| 177 |
)
|
| 178 |
}
|
sync_to_hf.sh
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# 同步本地项目到 HuggingFace Spaces
|
| 3 |
+
# 用法: ./sync_to_hf.sh [db|code|all]
|
| 4 |
+
|
| 5 |
+
set -e
|
| 6 |
+
cd "$(dirname "$0")"
|
| 7 |
+
|
| 8 |
+
SPACE_ID="shaun07/grid-backtest"
|
| 9 |
+
|
| 10 |
+
sync_db() {
|
| 11 |
+
echo "📦 同步数据库..."
|
| 12 |
+
hf upload $SPACE_ID backend/wgjy.db backend/wgjy.db --repo-type space
|
| 13 |
+
echo "✅ 数据库上传完成"
|
| 14 |
+
echo "⚠️ 请在 HF 网页点击 Restart 让新数据库生效"
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
sync_code() {
|
| 18 |
+
echo "📦 同步代码..."
|
| 19 |
+
hf upload $SPACE_ID . --repo-type space \
|
| 20 |
+
--exclude "node_modules/*" \
|
| 21 |
+
--exclude "backend/venv/*" \
|
| 22 |
+
--exclude "backend/__pycache__/*" \
|
| 23 |
+
--exclude "frontend/node_modules/*" \
|
| 24 |
+
--exclude "frontend/dist/*" \
|
| 25 |
+
--exclude "*.log" \
|
| 26 |
+
--exclude ".DS_Store" \
|
| 27 |
+
--exclude "backend/wgjy.db" \
|
| 28 |
+
--exclude "backend/data/*" \
|
| 29 |
+
--exclude "backend/cache/*" \
|
| 30 |
+
--exclude "backend/uploads/*" \
|
| 31 |
+
--exclude "hf-space/*"
|
| 32 |
+
echo "✅ 代码上传完成,HF 会自动重新构建"
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
case "$1" in
|
| 36 |
+
db)
|
| 37 |
+
sync_db
|
| 38 |
+
;;
|
| 39 |
+
code)
|
| 40 |
+
sync_code
|
| 41 |
+
;;
|
| 42 |
+
all)
|
| 43 |
+
sync_code
|
| 44 |
+
sync_db
|
| 45 |
+
;;
|
| 46 |
+
*)
|
| 47 |
+
echo "用法: $0 [db|code|all]"
|
| 48 |
+
echo " db - 只同步数据库"
|
| 49 |
+
echo " code - 只同步代码"
|
| 50 |
+
echo " all - 同步代码和数据库"
|
| 51 |
+
exit 1
|
| 52 |
+
;;
|
| 53 |
+
esac
|