Files
jyx_code4/如何运行.md
2026-02-21 14:46:34 +08:00

91 lines
2.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 如何运行代码
## 一、环境准备
1. **进入项目目录**
```powershell
cd c:\Users\27942\Desktop\codes\jyx_code4
```
2. **创建并激活 conda 环境(若尚未创建)**
```powershell
conda create -y -n jyx_code4 python=3.13
conda activate jyx_code4
```
3. **安装依赖**
```powershell
pip install -r requirements.txt
```
---
## 二、运行顺序(方案 B 实盘开单)
要运行主程序 **四分之一,五分钟,反手条件充足.py**(方案 B 开单),需先完成下面两步。
### 步骤 1抓取 K 线数据
保证 `models/database.db` 里有最新 1m / 5m / 15m / 1h 等 K 线:
```powershell
python 抓取多周期K线.py
```
脚本里默认会从 `2010-01-01` 起抓取所有周期;若需改日期或周期,可编辑该文件末尾 `collect_from_date` 的 `start_date` 和 `periods`。
### 步骤 2训练方案 B 并保存模型
```powershell
python run_scheme_b_train.py
```
可选参数:
- `--start 2024-01-01`:回测开始日期
- `--end 2024-12-31`:回测结束日期
- `--period 15`:主周期(默认 15 分钟)
训练完成后会在 `models/` 下生成:
- `scheme_b_last_model.joblib`
- `scheme_b_scaler.joblib`
- `scheme_b_features.json`
### 步骤 3运行实盘/模拟开单脚本
```powershell
python "四分之一,五分钟,反手条件充足.py"
```
该脚本会:
- 使用方案 B 的 15 分钟信号(含 1m/5m/1h 辅助特征)决定开多/开空/反手;
- 通过 BitMart 合约 API 与浏览器操作执行开单、平仓、止损止盈。
**注意**:脚本内含有 API Key、bit_id 等,请勿泄露;运行前确认已接受 conda 频道条款(若曾报 Terms of Service 错误,需先执行 `conda tos accept` 相关命令)。
---
## 三、其他脚本
| 脚本 | 说明 |
|------|------|
| `抓取多周期K线.py` | 抓取 1m/3m/5m/15m/30m/1h K 线到 `models/database.db` |
| `run_scheme_b_train.py` | 仅训练方案 B 并保存模型(供实盘用) |
| `四分之一,五分钟,反手条件充足.py` | 方案 B 实盘开单主程序 |
| `strategy/compare.py` | 方案 A vs 方案 B 回测对比(可选) |
---
## 四、常见问题
- **conda 报 Terms of Service**:在终端执行:
```powershell
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/msys2
```
- **方案 B 模型未找到**:先运行步骤 1 和步骤 2再运行主程序。
- **conda 命令找不到**:使用完整路径,例如:
```powershell
C:\Users\27942\Miniconda3\condabin\conda.bat activate jyx_code4
```