refactor: 移除 gate_bot,统一为三所架构并更新文档

删除 crypto_monitor_gate_bot 目录,中控与子代理改为 binance/okx/gate 三账户;
文档与 UI 文案「四所」改为「三所」;新增清库前一次性配置备份脚本。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-04 22:00:08 +08:00
parent be51eee73f
commit 9f67de3677
138 changed files with 26395 additions and 40057 deletions
+18 -20
View File
@@ -16,11 +16,11 @@
| 组件 | 作用 | 默认监听 |
|------|------|----------|
| **hub.py** | 中控 Web + API | `0.0.0.0:5100` |
| **agent.py × N** | 各账户持仓 / 紧急全平 | `127.0.0.1:15200``15203` |
| **agent.py × N** | 各账户持仓 / 紧急全平 | `127.0.0.1:15200``15202` |
| **crypto_monitor_*.app** | 策略、关键位、下单逻辑 | 各目录 `.env``APP_PORT` |
- 账户列表与 URL 由 **`hub_settings.json`**(网页「系统设置」保存)或内置默认维护;**不再使用** `HUB_AGENTS`
- 实例 Flask **无需为中控改业务代码**(已注册 `hub_bridge`);与中控并行运行。
- 实例 Flask **无需为中控改业务代码**(已注册 `hub_bridge`);与中控并行运行。
---
@@ -29,7 +29,7 @@
1. **Python 3.10+**`python3-venv``pip`
2. **Node.js + npm**(用于安装 PM2):`sudo npm i -g pm2`
3.`crypto_monitor_*` 目录已 **`cp .env.example .env`** 并填好 API 密钥。
4. 端口无冲突:`5100``15200``15203`、各实例 `APP_PORT`5000/5001/5002/5004)。
4. 端口无冲突:`5100``15200``15202`、各实例 `APP_PORT`5000/5001/5004)。
5. 建议代码路径:`/opt/crypto_monitor/`(下文用此示例,请按实际路径替换)。
---
@@ -64,10 +64,10 @@ deactivate # 可选;交给 PM2 时不必保持激活
```
1. 各实例 FlaskAPP_PORT ← 各 crypto_monitor_* 目录 ecosystem.config.cjs
2. 中控 + 子代理(5100 + 1520015203) ← 本目录一条 PM2 命令同时启动
2. 中控 + 子代理(5100 + 1520015202) ← 本目录一条 PM2 命令同时启动
```
**`ecosystem.config.cjs` 会一次拉起 4 个 agent + 1 个 hub**,无需再单独 `pm2 start` 子代理。
**`ecosystem.config.cjs` 会一次拉起 3 个 agent + 1 个 hub**,无需再单独 `pm2 start` 子代理。
仅反代中控到公网时:Flask / agent 仍只监听 **127.0.0.1**;系统设置里 URL 填 `http://127.0.0.1:端口`
@@ -79,7 +79,7 @@ deactivate # 可选;交给 PM2 时不必保持激活
| 文件 | 包含进程 |
|------|----------|
| `ecosystem.config.cjs` | `manual-agent-binance` / `okx` / `gate` / `gate-bot` + **`manual-trading-hub`** |
| `ecosystem.config.cjs` | `manual-agent-binance` / `okx` / `gate` + **`manual-trading-hub`** |
`run_hub.sh` 加载 **`manual_trading_hub/.env`** 后执行 `hub.py`;各 agent 经 **`run_agent.sh`** 在对应策略目录加载 **`.env`**(含 API 密钥),再执行 `agent.py`
@@ -89,7 +89,7 @@ source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env
pm2 start ecosystem.config.cjs # 5 个进程一起起
pm2 start ecosystem.config.cjs # 4 个进程一起起
pm2 save
# 或
@@ -103,17 +103,16 @@ bash scripts/pm2_hub.sh start
| manual-agent-binance | crypto_monitor_binance | agent `15200` |
| manual-agent-okx | crypto_monitor_okx | agent `15201` |
| manual-agent-gate | crypto_monitor_gate | agent `15202` |
| manual-agent-gate-bot | crypto_monitor_gate_bot | agent `15203` |
| manual-trading-hub | manual_trading_hub | hub `5100` |
OKX 子代理会启动,但中控默认 `HUB_DISABLED_IDS=1` 不参与监控;不用 OKX 可 `pm2 stop manual-agent-okx`
OKX 子代理会启动;不用 OKX 可 `pm2 stop manual-agent-okx`
### 5.3 常用运维命令
```bash
pm2 status
pm2 logs manual-trading-hub --lines 200
pm2 restart ecosystem.config.cjs # 重启 hub + 全部 agent
pm2 restart ecosystem.config.cjs # 重启 hub + 全部 agent
bash scripts/pm2_hub.sh restart # 同上
bash scripts/pm2_hub.sh stop
@@ -129,7 +128,7 @@ pm2 restart manual-trading-hub
仅重启子代理:
```bash
pm2 restart manual-agent-binance manual-agent-gate manual-agent-gate-bot
pm2 restart manual-agent-binance manual-agent-gate manual-agent-okx
# 或
bash scripts/pm2_agents.sh restart
```
@@ -153,25 +152,24 @@ pm2 status
### 5.6 Gate 子代理「一会能连、一会子代理不可用」(Windows `.env` 换行)
**现象**Gate 训练 / Gate 趋势卡片红字「子代理不可用」;`pm2 logs manual-agent-gate` 反复出现:
**现象**Gate 卡片红字「子代理不可用」;`pm2 logs manual-agent-gate` 反复出现:
```text
./.env: line 22: $'\r': command not found
agent start: exchange=gate port=15202 ...
```
**原因**:在 Windows 编辑的 `crypto_monitor_gate/.env``crypto_monitor_gate_bot/.env`**CRLF**Linux 上 `source` 失败;PM2 反复重启,中控轮询时偶发连不上(**不是外网问题**)。
**原因**:在 Windows 编辑的 `crypto_monitor_gate/.env`**CRLF**Linux 上 `source` 失败;PM2 反复重启,中控轮询时偶发连不上(**不是外网问题**)。
**处理**(在服务器仓库根执行):
```bash
cd /opt/crypto_monitor
sed -i 's/\r$//' crypto_monitor_gate/.env crypto_monitor_gate_bot/.env
sed -i 's/\r$//' crypto_monitor_gate/.env
bash manual_trading_hub/scripts/fix_env_crlf.sh
cd manual_trading_hub
pm2 delete manual-agent-gate manual-agent-gate-bot 2>/dev/null || true
pm2 delete manual-agent-gate 2>/dev/null || true
pm2 start ecosystem.config.cjs --only manual-agent-gate
pm2 start ecosystem.config.cjs --only manual-agent-gate-bot
pm2 save
curl -s http://127.0.0.1:15202/status | head -c 200 # 应 ok:true
```
@@ -200,7 +198,7 @@ bash scripts/run_hub.sh
1. **http://127.0.0.1:5100/login** — 若 `.env` 已设 `HUB_PASSWORD`,用 `HUB_USERNAME` / `HUB_PASSWORD` 登录。
2. **http://127.0.0.1:5100/monitor** — 已启用账户显示持仓;Flask 已起时有关键位/趋势信息。
3. **http://127.0.0.1:5100/market** — 行情区可选交易所与周期拉 K 线;升级后强刷浏览器,详见 [行情区说明.md](./行情区说明.md)。
4. **http://127.0.0.1:5100/ai** — AI 教练(户今日总结 + 聊天);`manual_trading_hub/.env` 配与实例相同的 `AI_*` 变量,见 [AI教练说明.md](./AI教练说明.md)。
4. **http://127.0.0.1:5100/ai** — AI 教练(户今日总结 + 聊天);`manual_trading_hub/.env` 配与实例相同的 `AI_*` 变量,见 [AI教练说明.md](./AI教练说明.md)。
5. **http://127.0.0.1:5100/settings** — 保存后生成 `hub_settings.json`(增加第五户、Gate 子账户等见 [使用说明.md §4.5](./使用说明.md#45-增加账户例如再挂一个-gate))。
5. 监控卡片 **「实例」** — 在各 `crypto_monitor_*` 网页做下单、关键位、趋势;中控**不提供**下单表单。
@@ -237,8 +235,8 @@ curl -s http://127.0.0.1:15200/status | head -c 200
HUB_COOKIE_SECURE=true
```
4. `hub_settings.json` 中 Flask/Agent 保持 **`http://127.0.0.1:...`**(中控本机调 API)。
5. 实例 **`APP_AUTH_DISABLED=false`** + 与中控相同 **`HUB_BRIDGE_TOKEN`**。
6. 子代理 **`HOST=127.0.0.1`**;防火墙勿对公网开放 `15200``15203`、各 `APP_PORT`。
5. 实例 **`APP_AUTH_DISABLED=false`** + 与中控相同 **`HUB_BRIDGE_TOKEN`**。
6. 子代理 **`HOST=127.0.0.1`**;防火墙勿对公网开放 `15200``15202`、各 `APP_PORT`。
7. **复盘/实例外链**`HUB_PUBLIC_ORIGIN=https://你的域名` 或内网 IP;否则其它设备点「复盘」会跳到 `127.0.0.1`。
**说明**HTTPS 域名与 HTTP `内网IP:5100` Cookie **不共用**;内网访问 IP 需在 IP 地址再登录一次(见 [常见问题.md](./常见问题.md) §2.1)。
@@ -254,7 +252,7 @@ curl -s http://127.0.0.1:15200/status | head -c 200
| `HUB_DISABLED_IDS` | `1` | 强制关闭的账户 id(OKX) |
| `HUB_TRUST_LAN` | `true` | 私网可访问;仅本机可 `false` |
| `HUB_PUBLIC_ORIGIN` | 空 | 浏览器用复盘链接;如 `http://192.168.1.100`(**内网其它电脑访问中控时建议设置**) |
| `HUB_BRIDGE_TOKEN` | 空 | 与实例一致;公网建议配置 |
| `HUB_BRIDGE_TOKEN` | 空 | 与实例一致;公网建议配置 |
| `HUB_USERNAME` | `admin` | Web 登录用户名 |
| `HUB_PASSWORD` | 空 | 非空即启用登录 |
| `HUB_SESSION_SECRET` | — | 会话签名 |