diff --git a/docs/WINDOWS_INSTALL.md b/docs/WINDOWS_INSTALL.md new file mode 100644 index 0000000..cafc944 --- /dev/null +++ b/docs/WINDOWS_INSTALL.md @@ -0,0 +1,289 @@ +# Windows 环境安装指南 + +本指南帮助您在 Windows 系统上部署加密货币预测系统。 + +--- + +## 一、前置要求 + +- Windows 10/11 (64位) +- 至少 8GB 内存 +- 至少 10GB 可用磁盘空间 +- 网络连接(需访问 GitHub、PyPI、Binance API) + +--- + +## 二、安装 Miniconda + +### 1. 下载 Miniconda + +访问 [Miniconda 官网](https://docs.conda.io/en/latest/miniconda.html) 下载 Windows 64-bit 安装包,或直接下载: + +``` +https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe +``` + +### 2. 安装 + +1. 双击运行安装程序 +2. 选择 "Just Me" (仅为当前用户安装) +3. 安装路径建议使用默认值或 `C:\Miniconda3` +4. **重要**:勾选 "Add Miniconda3 to my PATH environment variable" +5. 完成安装 + +### 3. 验证安装 + +打开 **命令提示符 (CMD)** 或 **PowerShell**: + +```powershell +conda --version +# 应显示类似: conda 24.x.x +``` + +--- + +## 三、创建 Conda 环境 + +### 1. 创建 Python 3.12 环境 + +```powershell +conda create -n crypto_pred_312 python=3.12 -y +``` + +### 2. 激活环境 + +```powershell +conda activate crypto_pred_312 +``` + +激活后,命令行前缀应显示 `(crypto_pred_312)` + +--- + +## 四、克隆项目 + +### 1. 安装 Git (如未安装) + +下载并安装 [Git for Windows](https://git-scm.com/download/win) + +### 2. 克隆仓库 + +```powershell +cd C:\Projects # 或您喜欢的目录 +git clone http://192.168.50.24:3000/subuhui/crpto_predictor.git +cd crpto_predictor +``` + +--- + +## 五、安装依赖 + +### 1. 安装 PyTorch (CPU 版本) + +```powershell +# CPU 版本 PyTorch(Windows 不使用 GPU) +pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu +``` + +### 2. 安装项目依赖 + +```powershell +pip install -r requirements.txt +``` + +### 3. 安装 IBM 时序模型 (TTM-R2) + +```powershell +pip install tsfm_public +``` + +--- + +## 六、配置环境变量 + +### 1. 复制环境变量模板 + +```powershell +copy .env.example .env +``` + +### 2. 编辑 .env 文件 + +使用记事本或 VSCode 编辑 `.env` 文件: + +```ini +# MySQL 数据库配置 +MYSQL_HOST=your_mysql_host +MYSQL_PORT=3306 +MYSQL_USER=your_username +MYSQL_PASSWORD=your_password +MYSQL_DB=crypto_predictor + +# Binance API (可选,用于实时数据) +BINANCE_API_KEY=your_api_key +BINANCE_API_SECRET=your_api_secret + +# Polymarket 配置 (可选,用于自动交易) +POLYMARKET_PRIVATE_KEY=your_private_key +DRY_RUN=true # 设为 true 进行模拟交易 + +# 代理配置 (可选) +USE_PROXY=false +SOCKS5_PROXY=socks5://127.0.0.1:1080 +``` + +--- + +## 七、数据库配置 + +### 1. 安装 MySQL + +下载并安装 [MySQL Community Server](https://dev.mysql.com/downloads/mysql/) + +或使用 Docker: +```powershell +docker run -d --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=yourpassword mysql:8.0 +``` + +### 2. 创建数据库 + +```sql +CREATE DATABASE crypto_predictor CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; +``` + +### 3. 初始化表结构 + +首次运行时会自动创建表,或手动执行: +```powershell +python -c "from api.models import init_model_predictions_table; from data.trading_db import TradingDatabase; TradingDatabase()" +``` + +--- + +## 八、验证安装 + +### 1. 测试 PyTorch + +```powershell +python -c "import torch; print(f'PyTorch: {torch.__version__}'); print(f'Device: cpu')" +``` + +### 2. 测试模型加载 + +```powershell +python -c "from training.config import TrainingConfig; c = TrainingConfig(); print(f'Device: {c.get_device()}')" +# 应输出: Device: cpu +``` + +### 3. 测试数据库连接 + +```powershell +python -c "from api.models import get_db_connection; conn = get_db_connection(); print('数据库连接成功!')" +``` + +--- + +## 九、运行系统 + +### 方式一:双击批处理脚本 (推荐) + +双击项目根目录的 `start_system.bat` + +### 方式二:PowerShell 脚本 + +```powershell +.\start_system.ps1 +``` + +### 方式三:Python 脚本 + +```powershell +python start_system.py +``` + +### 方式四:分别启动 + +```powershell +# 终端 1: API 服务 +python -m uvicorn api.main:app --host 0.0.0.0 --port 8000 + +# 终端 2: 自动交易 +python auto_trade_polymarket.py +``` + +--- + +## 十、访问系统 + +- **前端看板**: http://localhost:8000 +- **API 文档**: http://localhost:8000/docs + +--- + +## 常见问题 + +### Q1: `conda activate` 不生效 + +在 PowerShell 中需要先初始化 conda: +```powershell +conda init powershell +# 重启 PowerShell +``` + +### Q2: pip 安装超时 + +使用国内镜像: +```powershell +pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple +``` + +### Q3: PyTorch 安装失败 + +确保使用 CPU 版本的安装命令,不要安装 CUDA 版本。 + +### Q4: 数据库连接失败 + +1. 检查 MySQL 服务是否运行 +2. 检查 `.env` 中的数据库配置 +3. 检查防火墙是否允许 3306 端口 + +### Q5: 模型文件缺失 + +确保 `models/checkpoints/` 目录包含预训练模型文件。如缺失,联系管理员获取。 + +--- + +## 目录结构 + +``` +crpto_predictor/ +├── api/ # API 服务 +│ ├── main.py # FastAPI 入口 +│ ├── models.py # 数据库模型 +│ ├── prediction_service.py # 预测服务 +│ └── static/ # 前端静态文件 +├── models/ # 模型定义和权重 +│ ├── checkpoints/ # 模型权重文件 +│ └── dlinear/ # DLinear 模型 +├── data/ # 数据层 +├── training/ # 训练配置 +├── start_system.py # 跨平台启动脚本 +├── start_system.bat # Windows CMD 脚本 +├── start_system.ps1 # Windows PowerShell 脚本 +├── auto_trade_polymarket.py # 自动交易程序 +├── requirements.txt # 依赖列表 +└── .env # 环境变量 (需自行创建) +``` + +--- + +## 更新项目 + +```powershell +git pull origin main +pip install -r requirements.txt +``` + +--- + +*如有问题,请联系管理员。*