From ab854b2c3c11fdbc607bff727a8395a8b2844d93 Mon Sep 17 00:00:00 2001 From: dekun <253921841@qq.com> Date: Thu, 21 May 2026 16:51:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E6=A1=A3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 24 +++++------ .../scripts/patch_index_layout.py | 2 +- .../scripts/sync_gate_app.py | 2 +- crypto_monitor_binance/部署文档.md | 32 +++++++------- crypto_monitor_gate/部署文档.md | 26 ++++++------ crypto_monitor_gate_bot/部署文档.md | 26 ++++++------ crypto_monitor_okx/部署文档.md | 42 ++++++++++++------- deploy/README.md | 4 +- deploy/setup_env.ps1 | 4 +- deploy/setup_env.sh | 4 +- manual_trading_hub/scripts/后台运行-Ubuntu.md | 20 ++++----- manual_trading_hub/部署文档.md | 4 +- 一键部署.bat | 2 +- 备份与恢复.md | 26 ++++++------ 14 files changed, 116 insertions(+), 102 deletions(-) diff --git a/README.md b/README.md index 3cbea88..c79ea7e 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -# 复盘交易系统(crypto_monitor) +# 复盘交易系统(crypto_monitor_user) 本仓库为 **多交易所 USDT 永续** 的下单监控、关键位监控与交易复盘工具集:四个子项目分别对接 **Binance、Gate.io(主号)、Gate.io(机器人/趋势策略)、OKX**,共享相似的 Flask 架构与本地 SQLite 记账思路,可按账户独立部署、独立端口运行。 -**远程仓库(克隆地址)**:[https://git.bz121.com/dekun/crypto_monitor.git](https://git.bz121.com/dekun/crypto_monitor.git) +**远程仓库(克隆地址)**:[https://git.bz121.com/dekun/crypto_monitor_user.git](https://git.bz121.com/dekun/crypto_monitor_user.git) ```bash -git clone https://git.bz121.com/dekun/crypto_monitor.git -cd crypto_monitor +git clone https://git.bz121.com/dekun/crypto_monitor_user.git +cd crypto_monitor_user ``` ### 一键环境部署 @@ -73,19 +73,19 @@ cd crypto_monitor ## 五、Linux 推荐目录布局(可选) -为与仓库内《部署文档》示例一致,可将整个克隆结果置于 **`/opt/crypto_monitor/`** 下,例如: +为与仓库内《部署文档》示例一致,可将整个克隆结果置于 **`/opt/crypto_monitor_user/`** 下,例如: -- `/opt/crypto_monitor/crypto_monitor_binance` -- `/opt/crypto_monitor/crypto_monitor_gate` -- `/opt/crypto_monitor/crypto_monitor_gate_bot` -- `/opt/crypto_monitor/crypto_monitor_okx` -- `/opt/crypto_monitor/manual_trading_hub` +- `/opt/crypto_monitor_user/crypto_monitor_binance` +- `/opt/crypto_monitor_user/crypto_monitor_gate` +- `/opt/crypto_monitor_user/crypto_monitor_gate_bot` +- `/opt/crypto_monitor_user/crypto_monitor_okx` +- `/opt/crypto_monitor_user/manual_trading_hub` 具体 `mkdir`、`venv`、`pm2` 与 **SSH SOCKS** 步骤以各子目录 **《部署文档.md》** 为准。 ### 备份与恢复(服务器必读) -项目路径 **`/opt/crypto_monitor`**,数据备份 **`/root/backups`**: +项目路径 **`/opt/crypto_monitor_user`**,数据备份 **`/root/backups`**: | 类型 | 说明 | |------|------| @@ -135,7 +135,7 @@ cd crypto_monitor | 项 | 内容 | |----|------| -| 远程地址 | `https://git.bz121.com/dekun/crypto_monitor.git` | +| 远程地址 | `https://git.bz121.com/dekun/crypto_monitor_user.git` | | 说明 | 复盘交易系统(骆驼比特币私有代码仓库,Gitea) | | 本说明 | 仓库根目录 `README.md`,仅描述结构与文档索引,不包含业务代码变更说明 | diff --git a/crypto_monitor_binance/scripts/patch_index_layout.py b/crypto_monitor_binance/scripts/patch_index_layout.py index 8b68b31..8403b9e 100644 --- a/crypto_monitor_binance/scripts/patch_index_layout.py +++ b/crypto_monitor_binance/scripts/patch_index_layout.py @@ -7,7 +7,7 @@ TAG = "div" PATHS = [ Path(__file__).resolve().parent.parent / "templates" / "index.html", - Path(r"c:\Users\dekun\Desktop\crypto_monitor\crypto_monitor_gate\templates\index.html"), + Path(r"c:\Users\dekun\Desktop\crypto_monitor_user\crypto_monitor_gate\templates\index.html"), ] KEY_START = " {% if page == 'key_monitor' %}" diff --git a/crypto_monitor_binance/scripts/sync_gate_app.py b/crypto_monitor_binance/scripts/sync_gate_app.py index 81e467d..bbfa8d3 100644 --- a/crypto_monitor_binance/scripts/sync_gate_app.py +++ b/crypto_monitor_binance/scripts/sync_gate_app.py @@ -3,7 +3,7 @@ from pathlib import Path binance = Path(__file__).resolve().parent.parent / "app.py" -gate = Path(r"c:\Users\dekun\Desktop\crypto_monitor\crypto_monitor_gate\app.py") +gate = Path(r"c:\Users\dekun\Desktop\crypto_monitor_user\crypto_monitor_gate\app.py") b = binance.read_text(encoding="utf-8") g = gate.read_text(encoding="utf-8") diff --git a/crypto_monitor_binance/部署文档.md b/crypto_monitor_binance/部署文档.md index 9bff01e..520ba17 100644 --- a/crypto_monitor_binance/部署文档.md +++ b/crypto_monitor_binance/部署文档.md @@ -28,13 +28,13 @@ 将包含 `app.py` 的项目放到固定目录,例如: ```bash -mkdir -p /opt/crypto_monitor -cd /opt/crypto_monitor -git clone https://git.bz121.com/dekun/crypto_monitor.git -cd crypto_monitor/crypto_monitor_binance +mkdir -p /opt/crypto_monitor_user +cd /opt/crypto_monitor_user +git clone https://git.bz121.com/dekun/crypto_monitor_user.git +cd crypto_monitor_user/crypto_monitor_binance ``` -下文用 **`/opt/crypto_monitor/crypto_monitor_binance`** 仅为示例,请换成你的实际绝对路径。 +下文用 **`/opt/crypto_monitor_user/crypto_monitor_binance`** 仅为示例,请换成你的实际绝对路径。 拉取代码后,若目录下尚无 `.env`,先从模板生成(**勿**把填好密钥的 `.env` 提交 Git): @@ -100,7 +100,7 @@ curl -4 -sS --max-time 15 --proxy socks5h://127.0.0.1:1080 https://api.binance.c ## 4. Python 虚拟环境 ```bash -cd /opt/crypto_monitor/crypto_monitor_binance +cd /opt/crypto_monitor_user/crypto_monitor_binance python3 -m venv .venv source .venv/bin/activate @@ -128,7 +128,7 @@ export PYTHONDONTWRITEBYTECODE=1 ### 5.1 首次配置 ```bash -cd /opt/crypto_monitor/crypto_monitor_binance +cd /opt/crypto_monitor_user/crypto_monitor_binance cp -n .env.example .env # 已存在 .env 时不覆盖 nano .env # 填入 API、登录密码、端口、代理等 @@ -168,7 +168,7 @@ cp .env .env.backup.$(date +%Y%m%d) **一次性安装定时任务**(在对应项目目录执行,Binance / Gate 各执行一次): ```bash -cd /opt/crypto_monitor/crypto_monitor_binance +cd /opt/crypto_monitor_user/crypto_monitor_binance chmod +x scripts/backup_data.sh scripts/install_backup_cron.sh bash scripts/install_backup_cron.sh ``` @@ -176,14 +176,14 @@ bash scripts/install_backup_cron.sh Gate 实例: ```bash -cd /opt/crypto_monitor/crypto_monitor_gate +cd /opt/crypto_monitor_user/crypto_monitor_gate bash scripts/install_backup_cron.sh ``` Gate Bot 实例(趋势回调等): ```bash -cd /opt/crypto_monitor/crypto_monitor_gate_bot +cd /opt/crypto_monitor_user/crypto_monitor_gate_bot bash scripts/install_backup_cron.sh ``` @@ -247,7 +247,7 @@ BINANCE_SOCKS_PROXY=socks5h://127.0.0.1:1080 在已配置 `.env` 且网络可达的前提下: ```bash -cd /opt/crypto_monitor/crypto_monitor_binance +cd /opt/crypto_monitor_user/crypto_monitor_binance source .venv/bin/activate python scripts/verify_binance_funding.py ``` @@ -263,7 +263,7 @@ python scripts/verify_binance_funding.py 3. `.env` 已按需配置 `BINANCE_SOCKS_PROXY` 等 ```bash -cd /opt/crypto_monitor/crypto_monitor_binance +cd /opt/crypto_monitor_user/crypto_monitor_binance source .venv/bin/activate python app.py ``` @@ -286,7 +286,7 @@ pm2 -v 在项目根目录: ```bash -cd /opt/crypto_monitor/crypto_monitor_binance +cd /opt/crypto_monitor_user/crypto_monitor_binance pm2 start ecosystem.config.cjs pm2 status pm2 logs --lines 200 @@ -323,9 +323,9 @@ ssh -N -D 127.0.0.1:1080 bn-vps \ ### 10.2 Flask ```bash -cd /opt/crypto_monitor/crypto_monitor_binance -pm2 start /opt/crypto_monitor/crypto_monitor_binance/.venv/bin/python --name crypto-monitor-binance -- \ - /opt/crypto_monitor/crypto_monitor_binance/app.py +cd /opt/crypto_monitor_user/crypto_monitor_binance +pm2 start /opt/crypto_monitor_user/crypto_monitor_binance/.venv/bin/python --name crypto-monitor-binance -- \ + /opt/crypto_monitor_user/crypto_monitor_binance/app.py ``` --- diff --git a/crypto_monitor_gate/部署文档.md b/crypto_monitor_gate/部署文档.md index ae35ead..c09b9c9 100644 --- a/crypto_monitor_gate/部署文档.md +++ b/crypto_monitor_gate/部署文档.md @@ -25,13 +25,13 @@ 将包含 `app.py` 的项目放到固定目录,例如: ```bash -mkdir -p /opt/crypto_monitor -cd /opt/crypto_monitor -git clone https://git.bz121.com/dekun/crypto_monitor.git -cd crypto_monitor/crypto_monitor_gate +mkdir -p /opt/crypto_monitor_user +cd /opt/crypto_monitor_user +git clone https://git.bz121.com/dekun/crypto_monitor_user.git +cd crypto_monitor_user/crypto_monitor_gate ``` -下文用 **`/opt/crypto_monitor/crypto_monitor_gate`** 仅为示例,请换成你的实际绝对路径。 +下文用 **`/opt/crypto_monitor_user/crypto_monitor_gate`** 仅为示例,请换成你的实际绝对路径。 拉取代码后,若目录下尚无 `.env`: @@ -97,7 +97,7 @@ curl -4 -sS --max-time 15 --proxy socks5h://127.0.0.1:1080 https://api.gateio.ws ## 4. Python 虚拟环境 ```bash -cd /opt/crypto_monitor/crypto_monitor_gate +cd /opt/crypto_monitor_user/crypto_monitor_gate python3 -m venv .venv source .venv/bin/activate @@ -125,7 +125,7 @@ export PYTHONDONTWRITEBYTECODE=1 ### 5.1 首次配置 ```bash -cd /opt/crypto_monitor/crypto_monitor_gate +cd /opt/crypto_monitor_user/crypto_monitor_gate cp -n .env.example .env nano .env @@ -143,7 +143,7 @@ nano .env 与 Binance 实例相同:每天 **北京时间 0:00** → **`/root/backups`**,保留 **30 天**。 ```bash -cd /opt/crypto_monitor/crypto_monitor_gate +cd /opt/crypto_monitor_user/crypto_monitor_gate chmod +x scripts/backup_data.sh scripts/install_backup_cron.sh bash scripts/install_backup_cron.sh bash scripts/backup_data.sh # 试跑 @@ -185,7 +185,7 @@ GATE_SOCKS_PROXY=socks5h://127.0.0.1:1080 3. `.env` 已含 `GATE_SOCKS_PROXY` ```bash -cd /opt/crypto_monitor/crypto_monitor_gate +cd /opt/crypto_monitor_user/crypto_monitor_gate source .venv/bin/activate python app.py ``` @@ -208,7 +208,7 @@ pm2 -v 在项目根目录: ```bash -cd /opt/crypto_monitor/crypto_monitor_gate +cd /opt/crypto_monitor_user/crypto_monitor_gate pm2 start ecosystem.config.cjs pm2 status pm2 logs --lines 200 @@ -245,9 +245,9 @@ ssh -N -D 127.0.0.1:1080 gate-vps \ ### 9.2 Flask ```bash -cd /opt/crypto_monitor/crypto_monitor_gate -pm2 start /opt/crypto_monitor/crypto_monitor_gate/.venv/bin/python --name crypto-monitor-gate -- \ - /opt/crypto_monitor/crypto_monitor_gate/app.py +cd /opt/crypto_monitor_user/crypto_monitor_gate +pm2 start /opt/crypto_monitor_user/crypto_monitor_gate/.venv/bin/python --name crypto-monitor-gate -- \ + /opt/crypto_monitor_user/crypto_monitor_gate/app.py ``` --- diff --git a/crypto_monitor_gate_bot/部署文档.md b/crypto_monitor_gate_bot/部署文档.md index 162292d..9f1ae82 100644 --- a/crypto_monitor_gate_bot/部署文档.md +++ b/crypto_monitor_gate_bot/部署文档.md @@ -25,13 +25,13 @@ 将包含 `app.py` 的项目放到固定目录,例如: ```bash -mkdir -p /opt/crypto_monitor -cd /opt/crypto_monitor -git clone https://git.bz121.com/dekun/crypto_monitor.git -cd crypto_monitor/crypto_monitor_gate_bot +mkdir -p /opt/crypto_monitor_user +cd /opt/crypto_monitor_user +git clone https://git.bz121.com/dekun/crypto_monitor_user.git +cd crypto_monitor_user/crypto_monitor_gate_bot ``` -下文用 **`/opt/crypto_monitor/crypto_monitor_gate_bot`** 仅为示例,请换成你的实际绝对路径。 +下文用 **`/opt/crypto_monitor_user/crypto_monitor_gate_bot`** 仅为示例,请换成你的实际绝对路径。 拉取代码后,若目录下尚无 `.env`: @@ -97,7 +97,7 @@ curl -4 -sS --max-time 15 --proxy socks5h://127.0.0.1:1080 https://api.gateio.ws ## 4. Python 虚拟环境 ```bash -cd /opt/crypto_monitor/crypto_monitor_gate_bot +cd /opt/crypto_monitor_user/crypto_monitor_gate_bot python3 -m venv .venv source .venv/bin/activate @@ -125,7 +125,7 @@ export PYTHONDONTWRITEBYTECODE=1 ### 5.1 首次配置 ```bash -cd /opt/crypto_monitor/crypto_monitor_gate_bot +cd /opt/crypto_monitor_user/crypto_monitor_gate_bot cp -n .env.example .env nano .env @@ -143,7 +143,7 @@ nano .env 每天 **北京时间 0:00** 备份到 **`/root/backups`**,保留 **30 天**(`crypto.db` + `static/images`)。 ```bash -cd /opt/crypto_monitor/crypto_monitor_gate_bot +cd /opt/crypto_monitor_user/crypto_monitor_gate_bot chmod +x scripts/backup_data.sh scripts/install_backup_cron.sh bash scripts/install_backup_cron.sh bash scripts/backup_data.sh # 试跑 @@ -219,7 +219,7 @@ TREND_PREVIEW_MAX_BALANCE_DRIFT_PCT=5 3. `.env` 已含 `GATE_SOCKS_PROXY` ```bash -cd /opt/crypto_monitor/crypto_monitor_gate_bot +cd /opt/crypto_monitor_user/crypto_monitor_gate_bot source .venv/bin/activate python app.py ``` @@ -242,7 +242,7 @@ pm2 -v 在项目根目录: ```bash -cd /opt/crypto_monitor/crypto_monitor_gate_bot +cd /opt/crypto_monitor_user/crypto_monitor_gate_bot pm2 start ecosystem.config.cjs pm2 status pm2 logs --lines 200 @@ -279,9 +279,9 @@ ssh -N -D 127.0.0.1:1080 gate-vps \ ### 9.2 Flask ```bash -cd /opt/crypto_monitor/crypto_monitor_gate_bot -pm2 start /opt/crypto_monitor/crypto_monitor_gate_bot/.venv/bin/python --name crypto-monitor-gate -- \ - /opt/crypto_monitor/crypto_monitor_gate_bot/app.py +cd /opt/crypto_monitor_user/crypto_monitor_gate_bot +pm2 start /opt/crypto_monitor_user/crypto_monitor_gate_bot/.venv/bin/python --name crypto-monitor-gate -- \ + /opt/crypto_monitor_user/crypto_monitor_gate_bot/app.py ``` --- diff --git a/crypto_monitor_okx/部署文档.md b/crypto_monitor_okx/部署文档.md index b1a13b1..aa2aed1 100644 --- a/crypto_monitor_okx/部署文档.md +++ b/crypto_monitor_okx/部署文档.md @@ -1,4 +1,4 @@ -# `crypto_monitor` 本地部署 + SSH SOCKS 转发 + PM2 启动指南(Ubuntu) +# `crypto_monitor_okx` 部署指南:SSH SOCKS + OKX + PM2(Ubuntu) 本文面向:**本地 Ubuntu 机器运行项目**,但 **本机直连 OKX 会被 TLS/SNI reset** 的场景。解决思路是: @@ -23,26 +23,40 @@ --- -## 1. 从云服务器把项目同步到本地(推荐:打包下载) +## 1. 获取代码与目录 + +### 1.1 Git 克隆(推荐) + +```bash +mkdir -p /opt/crypto_monitor_user +cd /opt/crypto_monitor_user +git clone https://git.bz121.com/dekun/crypto_monitor_user.git +cd crypto_monitor_user/crypto_monitor_okx +cp -n .env.example .env # 若尚无 .env +``` + +下文用 **`/opt/crypto_monitor_user/crypto_monitor_okx`** 仅为示例,请换成你的实际绝对路径。 + +### 1.2 从云服务器打包同步到本地(可选) 在云服务器项目目录(包含 `app.py` 的目录)执行: ```bash -cd /opt/crypto_monitor/crypto_monitor_okx +cd /opt/crypto_monitor_user/crypto_monitor_okx # 可选:清理 Python 缓存,减少小文件传输 find . -type d -name __pycache__ -prune -exec rm -rf {} + find . -type f -name "*.pyc" -delete -tar -czf crypto_monitor.tgz . +tar -czf crypto_monitor_user.tgz . ``` -下载 `crypto_monitor.tgz` 到本机后解压: +下载 `crypto_monitor_user.tgz` 到本机后解压: ```bash -mkdir -p /opt/crypto_monitor/crypto_monitor_okx -cd /opt/crypto_monitor -tar -xzf crypto_monitor.tgz -C crypto_monitor_okx +mkdir -p /opt/crypto_monitor_user/crypto_monitor_okx +cd /opt/crypto_monitor_user +tar -xzf crypto_monitor_user.tgz -C crypto_monitor_okx cd crypto_monitor_okx cp -n .env.example .env # 若尚无 .env ``` @@ -109,7 +123,7 @@ curl -4 -Iv --max-time 15 --proxy socks5h://127.0.0.1:1080 https://www.okx.com/a 在本机项目目录: ```bash -cd /opt/crypto_monitor/crypto_monitor_okx +cd /opt/crypto_monitor_user/crypto_monitor_okx python3 -m venv .venv source .venv/bin/activate @@ -138,7 +152,7 @@ export PYTHONDONTWRITEBYTECODE=1 ### 5.1 首次配置 ```bash -cd /opt/crypto_monitor/crypto_monitor_okx +cd /opt/crypto_monitor_user/crypto_monitor_okx cp -n .env.example .env # 已存在 .env 时不覆盖 nano .env @@ -195,7 +209,7 @@ AI_MODEL=你的模型名 启动: ```bash -cd /opt/crypto_monitor/crypto_monitor_okx +cd /opt/crypto_monitor_user/crypto_monitor_okx source .venv/bin/activate python app.py ``` @@ -250,10 +264,10 @@ pm2 startup `pm2` 管理 Python 的常用方式是直接启动解释器: ```bash -cd /opt/crypto_monitor/crypto_monitor_okx +cd /opt/crypto_monitor_user/crypto_monitor_okx -pm2 start /opt/crypto_monitor/crypto_monitor_okx/.venv/bin/python --name crypto-monitor -- \ - /opt/crypto_monitor/crypto_monitor_okx/app.py +pm2 start /opt/crypto_monitor_user/crypto_monitor_okx/.venv/bin/python --name crypto-monitor -- \ + /opt/crypto_monitor_user/crypto_monitor_okx/app.py ``` > 若项目目录与上文不一致,请替换为实际绝对路径;或用 `readlink -f app.py` 得到绝对路径。 diff --git a/deploy/README.md b/deploy/README.md index 0fe9a4f..1cc695c 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -7,7 +7,7 @@ 双击仓库根目录 **`一键部署.bat`**,或在 PowerShell 中: ```powershell -cd C:\path\to\crypto_monitor +cd C:\path\to\crypto_monitor_user .\deploy\setup_env.ps1 ``` @@ -46,7 +46,7 @@ sudo bash deploy/setup_env.sh --install-system-deps ``` ```bash -cd /opt/crypto_monitor +cd /opt/crypto_monitor_user bash deploy/setup_env.sh bash deploy/setup_env.sh --only binance,gate bash deploy/setup_env.sh --recreate-venv diff --git a/deploy/setup_env.ps1 b/deploy/setup_env.ps1 index 6fd6c34..aab137e 100644 --- a/deploy/setup_env.ps1 +++ b/deploy/setup_env.ps1 @@ -1,7 +1,7 @@ #Requires -Version 5.1 <# .SYNOPSIS - crypto_monitor 一键环境部署(Windows PowerShell) + crypto_monitor_user 一键环境部署(Windows PowerShell) .DESCRIPTION - 为各子项目创建 Python venv 并安装依赖 @@ -176,7 +176,7 @@ function Install-Pm2IfNeeded() { } # --- main --- -Write-Host "crypto_monitor 环境部署" -ForegroundColor White +Write-Host "crypto_monitor_user 环境部署" -ForegroundColor White Write-Host "仓库根目录: $RepoRoot" -ForegroundColor DarkGray if (-not (Test-Path $ReqFile)) { diff --git a/deploy/setup_env.sh b/deploy/setup_env.sh index bf64c19..805ab6c 100644 --- a/deploy/setup_env.sh +++ b/deploy/setup_env.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# crypto_monitor 一键环境部署(Linux / macOS / Git Bash) +# crypto_monitor_user 一键环境部署(Linux / macOS / Git Bash) # # 用法: # bash deploy/setup_env.sh @@ -233,7 +233,7 @@ install_pm2() { echo " 各子目录: pm2 start ecosystem.config.cjs" } -echo "crypto_monitor 环境部署" +echo "crypto_monitor_user 环境部署" echo "仓库根目录: ${REPO_ROOT}" [[ -f "${REQ_FILE}" ]] || { echo "缺少 ${REQ_FILE}" >&2; exit 1; } diff --git a/manual_trading_hub/scripts/后台运行-Ubuntu.md b/manual_trading_hub/scripts/后台运行-Ubuntu.md index ffe5a73..a85639e 100644 --- a/manual_trading_hub/scripts/后台运行-Ubuntu.md +++ b/manual_trading_hub/scripts/后台运行-Ubuntu.md @@ -22,9 +22,9 @@ chmod +x manual_trading_hub/scripts/stop_hub_screen.sh ./manual_trading_hub/scripts/stop_agents_3screen.sh ``` -脚本默认认为:`manual_trading_hub` 的**上一级目录**里并列放着三个 `crypto_monitor_*`。若你把 hub 单独放在 `/opt/crypto_monitor/manual_trading_hub`,而策略项目在例如 `/opt/crypto_monitor/` 下的其他位置,请先执行 -`export MANUAL_TRADING_REPO_ROOT=/opt/crypto_monitor` 再运行 `start_agents_3screen.sh`。 -启动后若 `screen -ls` 里没有 `mt-agent-*`,看日志:`tail -80 /opt/crypto_monitor/manual_trading_hub/logs/mt-agent-bn.log`。 +脚本默认认为:`manual_trading_hub` 的**上一级目录**里并列放着三个 `crypto_monitor_*`。若你把 hub 单独放在 `/opt/crypto_monitor_user/manual_trading_hub`,而策略项目在例如 `/opt/crypto_monitor_user/` 下的其他位置,请先执行 +`export MANUAL_TRADING_REPO_ROOT=/opt/crypto_monitor_user` 再运行 `start_agents_3screen.sh`。 +启动后若 `screen -ls` 里没有 `mt-agent-*`,看日志:`tail -80 /opt/crypto_monitor_user/manual_trading_hub/logs/mt-agent-bn.log`。 ### 局域网内其他电脑访问中控 @@ -39,14 +39,14 @@ chmod +x manual_trading_hub/scripts/stop_hub_screen.sh ```bash # 新建会话,在里面照常启动 agent 或 hub,然后按键 Ctrl+B 再按 D 脱离 tmux new -s hub -cd /opt/crypto_monitor/manual_trading_hub && source .venv/bin/activate && python hub.py +cd /opt/crypto_monitor_user/manual_trading_hub && source .venv/bin/activate && python hub.py # Ctrl+B, D tmux new -s agent-bn -cd /opt/crypto_monitor/crypto_monitor_binance && set -a && source .env && set +a +cd /opt/crypto_monitor_user/crypto_monitor_binance && set -a && source .env && set +a export EXCHANGE=binance PORT=15200 HOST=127.0.0.1 -source /opt/crypto_monitor/manual_trading_hub/.venv/bin/activate -python /opt/crypto_monitor/manual_trading_hub/agent.py +source /opt/crypto_monitor_user/manual_trading_hub/.venv/bin/activate +python /opt/crypto_monitor_user/manual_trading_hub/agent.py # Ctrl+B, D ``` @@ -57,7 +57,7 @@ python /opt/crypto_monitor/manual_trading_hub/agent.py ## 二、nohup(快速、无守护重启) ```bash -cd /opt/crypto_monitor/manual_trading_hub +cd /opt/crypto_monitor_user/manual_trading_hub source .venv/bin/activate nohup python hub.py > /tmp/manual-hub.log 2>&1 & ``` @@ -70,7 +70,7 @@ nohup python hub.py > /tmp/manual-hub.log 2>&1 & ## 三、systemd(推荐:开机自启、崩溃自动拉起) -1. 把下面两个示例里的 **`YOUR_REPO`** 改成 **`/opt/crypto_monitor`**(或你本机实际仓库根目录),`YOUR_USER` 改成 Linux 用户名。 +1. 把下面两个示例里的 **`YOUR_REPO`** 改成 **`/opt/crypto_monitor_user`**(或你本机实际仓库根目录),`YOUR_USER` 改成 Linux 用户名。 2. 复制到 `/etc/systemd/system/`(需 sudo),文件名例如 `manual-hub.service`、`manual-agent-binance.service`。 3. 执行: @@ -150,7 +150,7 @@ ExecStart=/bin/bash -lc 'set -a; source YOUR_REPO/crypto_monitor_binance/.env; s ## 四、常见问题(子代理 / screen / 依赖) 1. **`curl http://127.0.0.1:15202/status`(或其它端口)返回 `ok:false`,错误里提到 pysocks / SOCKS** - 策略目录 `.env` 里配置了 `GATE_SOCKS_PROXY`(或 `BINANCE_SOCKS_PROXY`、`OKX_SOCKS_PROXY`)时,ccxt 需要 **PySocks**。在 **`/opt/crypto_monitor/manual_trading_hub/.venv`**(或你本机的 `manual_trading_hub/.venv`)中执行: + 策略目录 `.env` 里配置了 `GATE_SOCKS_PROXY`(或 `BINANCE_SOCKS_PROXY`、`OKX_SOCKS_PROXY`)时,ccxt 需要 **PySocks**。在 **`/opt/crypto_monitor_user/manual_trading_hub/.venv`**(或你本机的 `manual_trading_hub/.venv`)中执行: `pip install PySocks` 或 `pip install -r requirements.txt`。 2. **已经 `pip install PySocks`,错误文案完全不变** diff --git a/manual_trading_hub/部署文档.md b/manual_trading_hub/部署文档.md index 4253d93..21043c9 100644 --- a/manual_trading_hub/部署文档.md +++ b/manual_trading_hub/部署文档.md @@ -17,7 +17,7 @@ 1. 已安装 **Python 3.10+**,且 `pip` 可用。 2. 各策略目录下已配置好交易所 API:在对应 `crypto_monitor_*` 目录执行过 **`cp .env.example .env`** 并填好密钥(与平时运行 Flask 时同一份 **`.env`**,或等价环境变量)。各项目 `app.py` 会读取同目录 `.env` 中的 **`APP_HOST` / `APP_PORT`** 用于 **Flask**;子代理使用环境变量 **`PORT`**,二者不能占用同一端口。策略目录的 **`.env` 不在 Git 中**,`git pull` 不会覆盖;升级前建议在各策略目录 `cp .env .env.backup.$(date +%Y%m%d)`。 3. 本机端口 **`15200`~`15203`、5100**(及你各策略 `.env` 里的 `APP_PORT`)无冲突;若被占用,须改子代理 `PORT` 并同步修改 `HUB_AGENTS`。 -4. **Linux 路径约定(可选)**:若部署在 Ubuntu 等环境,建议将整个代码树放在 **`/opt/crypto_monitor/`** 下(与 `scripts/后台运行-Ubuntu.md` 示例一致),例如策略目录为 `/opt/crypto_monitor/crypto_monitor_binance`、中控为 `/opt/crypto_monitor/manual_trading_hub`。 +4. **Linux 路径约定(可选)**:若部署在 Ubuntu 等环境,建议将整个代码树放在 **`/opt/crypto_monitor_user/`** 下(与 `scripts/后台运行-Ubuntu.md` 示例一致),例如策略目录为 `/opt/crypto_monitor_user/crypto_monitor_binance`、中控为 `/opt/crypto_monitor_user/manual_trading_hub`。 --- @@ -192,7 +192,7 @@ Windows 可将 `hub.py` 与各 `agent.py` 写入「启动」文件夹,或使 | `/status` 里 `ok:false`,文案含 **pysocks** / **SOCKS** | 使用 SOCKS 代理但未装 **PySocks** | 在 **`manual_trading_hub/.venv`** 执行 `pip install PySocks` 或 `pip install -r requirements.txt` | | **已安装 PySocks**,`/status` 仍报同样 pysocks 文案 | 子代理进程未重启 | 子代理是常驻进程,**仅 pip 不会替换已运行进程**;退出对应 screen / systemd 单元后重新拉起(Ubuntu 见 `scripts/后台运行-Ubuntu.md` §四) | | 跑 `start_agents_3screen.sh` 无新会话 | screen 会话已存在被脚本跳过 | 先 `stop_agents_3screen.sh`,或 `screen -S mt-agent-xxx -X quit` 后再启动 | -| 子代理行为异常、依赖已装仍报错 | 实际用的不是 hub 的 venv | `ps aux` 查看命令行,应为 **`/opt/crypto_monitor/manual_trading_hub/.venv/bin/python`** `…/manual_trading_hub/agent.py`(路径按你机器实际根目录调整);否则在**当前使用的解释器**对应环境中装依赖,或改用官方脚本启动 | +| 子代理行为异常、依赖已装仍报错 | 实际用的不是 hub 的 venv | `ps aux` 查看命令行,应为 **`/opt/crypto_monitor_user/manual_trading_hub/.venv/bin/python`** `…/manual_trading_hub/agent.py`(路径按你机器实际根目录调整);否则在**当前使用的解释器**对应环境中装依赖,或改用官方脚本启动 | | 子代理端口与 Flask 抢端口 | `PORT` 与策略目录 `.env` 的 `APP_PORT` 相同 | 子代理用 **15200~15203**(或自改),Flask 继续用 `APP_PORT`,二者勿重复 | | 全平失败 | 持仓模式、精度、交易所维护 | 看返回 JSON 中 `errors` 字段;对照交易所 App | diff --git a/一键部署.bat b/一键部署.bat index 11671b0..04f2244 100644 --- a/一键部署.bat +++ b/一键部署.bat @@ -2,7 +2,7 @@ chcp 65001 >nul setlocal cd /d "%~dp0" -echo crypto_monitor 一键环境部署 ... +echo crypto_monitor_user 一键环境部署 ... powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0deploy\setup_env.ps1" %* set ERR=%ERRORLEVEL% if not "%ERR%"=="0" ( diff --git a/备份与恢复.md b/备份与恢复.md index f106e71..b3a438f 100644 --- a/备份与恢复.md +++ b/备份与恢复.md @@ -1,6 +1,6 @@ # 备份与恢复(Ubuntu 服务器) -本文档面向 **VPS / Ubuntu**,项目统一放在 **`/opt/crypto_monitor`**,数据备份统一放在 **`/root/backups`**。 +本文档面向 **VPS / Ubuntu**,项目统一放在 **`/opt/crypto_monitor_user`**,数据备份统一放在 **`/root/backups`**。 | 类型 | 内容 | 存放位置 | 频率 | |------|------|----------|------| @@ -20,7 +20,7 @@ apt install -y sqlite3 2>/dev/null || true for dir in crypto_monitor_binance crypto_monitor_gate crypto_monitor_gate_bot; do - cd "/opt/crypto_monitor/${dir}" || exit 1 + cd "/opt/crypto_monitor_user/${dir}" || exit 1 chmod +x scripts/backup_data.sh scripts/install_backup_cron.sh bash scripts/install_backup_cron.sh bash scripts/backup_data.sh @@ -51,7 +51,7 @@ ls -la /root/backups/*/ ```bash INSTANCE=crypto_monitor_binance -cd "/opt/crypto_monitor/${INSTANCE}" +cd "/opt/crypto_monitor_user/${INSTANCE}" chmod +x scripts/backup_data.sh scripts/install_backup_cron.sh bash scripts/install_backup_cron.sh bash scripts/backup_data.sh @@ -68,7 +68,7 @@ bash scripts/backup_data.sh ```bash for dir in crypto_monitor_binance crypto_monitor_gate crypto_monitor_gate_bot; do echo ">>> ${dir}" - bash "/opt/crypto_monitor/${dir}/scripts/backup_data.sh" + bash "/opt/crypto_monitor_user/${dir}/scripts/backup_data.sh" done ls -la /root/backups/*/*/ ``` @@ -95,8 +95,8 @@ tail -n 20 /var/log/crypto-monitor-backup-crypto_monitor_gate_bot.log ```bash DATE=$(TZ=Asia/Shanghai date +%Y%m%d) for dir in crypto_monitor_binance crypto_monitor_gate crypto_monitor_gate_bot; do - src="/opt/crypto_monitor/${dir}/.env" - dst="/opt/crypto_monitor/${dir}/.env.backup.${DATE}" + src="/opt/crypto_monitor_user/${dir}/.env" + dst="/opt/crypto_monitor_user/${dir}/.env.backup.${DATE}" if [ -f "$src" ]; then cp -a "$src" "$dst" echo "ok: $dst" @@ -112,7 +112,7 @@ done DATE=$(TZ=Asia/Shanghai date +%Y%m%d) mkdir -p /root/backups/env for dir in crypto_monitor_binance crypto_monitor_gate crypto_monitor_gate_bot; do - src="/opt/crypto_monitor/${dir}/.env" + src="/opt/crypto_monitor_user/${dir}/.env" if [ -f "$src" ]; then cp -a "$src" "/root/backups/env/${dir}.env.${DATE}" echo "ok: /root/backups/env/${dir}.env.${DATE}" @@ -134,7 +134,7 @@ ls -la /root/backups/env/ ```bash INSTANCE=crypto_monitor_binance DATE=20260517 -cd "/opt/crypto_monitor/${INSTANCE}" +cd "/opt/crypto_monitor_user/${INSTANCE}" cp -a ".env.backup.${DATE}" .env echo "restored .env from .env.backup.${DATE}" ``` @@ -144,7 +144,7 @@ echo "restored .env from .env.backup.${DATE}" ```bash INSTANCE=crypto_monitor_binance DATE=20260517 -cp -a "/root/backups/env/${INSTANCE}.env.${DATE}" "/opt/crypto_monitor/${INSTANCE}/.env" +cp -a "/root/backups/env/${INSTANCE}.env.${DATE}" "/opt/crypto_monitor_user/${INSTANCE}/.env" echo "restored from /root/backups/env/${INSTANCE}.env.${DATE}" ``` @@ -170,7 +170,7 @@ pm2 restart crypto-monitor-gate-bot INSTANCE=crypto_monitor_binance DATE=2026-05-17 BK="/root/backups/${INSTANCE}/${DATE}" -PROJ="/opt/crypto_monitor/${INSTANCE}" +PROJ="/opt/crypto_monitor_user/${INSTANCE}" test -f "${BK}/crypto.db" || { echo "backup not found: ${BK}"; exit 1; } @@ -198,12 +198,12 @@ DATE=$(TZ=Asia/Shanghai date +%Y%m%d) mkdir -p /root/backups/env for dir in crypto_monitor_binance crypto_monitor_gate crypto_monitor_gate_bot; do - PROJ="/opt/crypto_monitor/${dir}" + PROJ="/opt/crypto_monitor_user/${dir}" [ -f "${PROJ}/.env" ] && cp -a "${PROJ}/.env" "/root/backups/env/${dir}.env.${DATE}" bash "${PROJ}/scripts/backup_data.sh" 2>/dev/null || true done -cd /opt/crypto_monitor +cd /opt/crypto_monitor_user git pull for dir in crypto_monitor_binance crypto_monitor_gate crypto_monitor_gate_bot; do @@ -250,7 +250,7 @@ pm2 restart all ```bash for dir in crypto_monitor_binance crypto_monitor_gate crypto_monitor_gate_bot; do - SCRIPT="/opt/crypto_monitor/${dir}/scripts/backup_data.sh" + SCRIPT="/opt/crypto_monitor_user/${dir}/scripts/backup_data.sh" crontab -l 2>/dev/null | grep -vF "$SCRIPT" | crontab - done crontab -l