You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

231 lines
5.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# 智能期货期权分析系统 - 部署指南
## 系统架构
```
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Nginx │──────▶ 前端 (React) │ │ 后端 (NestJS) │
│ (反向代理) │ │ Port: 80 │ │ Port: 3000 │
└─────────────────┘ └─────────────────┘ └────────┬────────┘
┌─────────────────┐ │
│ PostgreSQL │◀───────┤
│ Port: 5432 │ │
└─────────────────┘ │
┌─────────────────┐ │
│ Redis │◀───────┘
│ Port: 6379 │
└─────────────────┘
```
## 快速开始
### 方式一Docker Compose (推荐)
```bash
# 1. 克隆代码
git clone <repository-url>
cd AlphaFuturesProMax
# 2. 设置环境变量
cp app/server/.env.example app/server/.env
# 编辑 .env 文件,设置必要的配置
# 3. 启动服务
docker-compose up -d
# 4. 查看日志
docker-compose logs -f backend
# 5. 停止服务
docker-compose down
```
### 方式二:手动部署
#### 1. 环境要求
- Node.js 20+
- PostgreSQL 15+
- Redis 7+
#### 2. 后端部署
```bash
# 进入后端目录
cd app/server
# 安装依赖
npm install
# 设置环境变量
cp .env.example .env
# 编辑 .env 配置数据库连接等信息
# 执行数据库迁移
npx prisma migrate deploy
# 生成Prisma客户端
npx prisma generate
# 导入种子数据
npx prisma db seed
# 启动服务
npm run start:prod
```
#### 3. 前端部署
```bash
# 进入前端目录
cd app
# 安装依赖
npm install
# 设置API地址
# 编辑 .env.production 文件
VITE_API_BASE_URL=http://your-api-server:3000/api/v1
VITE_WS_URL=http://your-api-server:3000/market
# 构建
npm run build
# 部署到Nginx
# 将 dist 目录复制到Nginx的web目录
```
## 环境变量配置
### 后端环境变量 (.env)
```bash
# 应用配置
NODE_ENV=production
PORT=3000
# 数据库
DATABASE_URL=postgresql://user:password@localhost:5432/futures_analysis
# Redis
REDIS_URL=redis://localhost:6379
# JWT密钥 (生产环境必须修改!)
JWT_SECRET=your-super-secret-key-change-this
# OpenAI (可选用于AI分析)
OPENAI_API_KEY=your-openai-key
```
### 前端环境变量 (.env.production)
```bash
VITE_API_BASE_URL=http://api.yourdomain.com/api/v1
VITE_WS_URL=http://api.yourdomain.com/market
```
## API文档
启动后端服务后访问以下地址查看API文档
```
http://localhost:3000/docs
```
## 功能清单
### ✅ 已实现功能
#### 后端功能
- [x] 用户认证系统 (JWT)
- [x] 行情数据服务 (REST + WebSocket)
- [x] 技术指标计算 (MACD, RSI, KDJ, BOLL, SAR, OBV, DMI, CCI, WR)
- [x] 期权分析模块 (Black-Scholes定价、希腊值、波动率曲面)
- [x] AI智能分析 (支持OpenAI API)
- [x] 热点事件管理
- [x] 自选股功能
- [x] 价格预警系统
#### 前端功能
- [x] 市场概览仪表盘
- [x] 品种筛选和搜索
- [x] K线图展示 (含MACD、成交量)
- [x] 热点事件分析
- [x] 风险提醒
### 🚧 待实现功能
- [ ] 交易信号系统
- [ ] 量化策略回测
- [ ] 移动端APP
- [ ] 管理后台
## 监控和维护
### 查看服务状态
```bash
# Docker方式
docker-compose ps
# 查看日志
docker-compose logs -f [service-name]
```
### 数据库备份
```bash
# Docker方式
docker-compose exec postgres pg_dump -U futures_user futures_analysis > backup.sql
# 恢复
docker-compose exec -T postgres psql -U futures_user futures_analysis < backup.sql
```
## 常见问题
### 1. 端口冲突
编辑 `docker-compose.yml` 修改端口映射:
```yaml
services:
backend:
ports:
- "3001:3000" # 修改为3001
```
### 2. 数据库连接失败
检查 `DATABASE_URL` 是否正确确保PostgreSQL服务已启动。
### 3. 前端无法访问API
检查前端环境变量 `VITE_API_BASE_URL` 是否正确配置。
## 生产环境建议
1. **安全**
- 修改默认的JWT密钥
- 启用HTTPS
- 配置防火墙规则
2. **性能**
- 启用Redis缓存
- 配置CDN加速静态资源
- 数据库索引优化
3. **监控**
- 配置日志收集 (ELK/Loki)
- 设置告警规则
- 监控API响应时间
## 技术栈
- **前端**: React 18 + TypeScript + Vite + Tailwind CSS + shadcn/ui
- **后端**: NestJS + TypeScript
- **数据库**: PostgreSQL 15
- **缓存**: Redis 7
- **部署**: Docker + Docker Compose