中控增加下单,关键位,系统设置
This commit is contained in:
@@ -19,16 +19,15 @@ const path = require("path");
|
||||
|
||||
const HUB_DIR = __dirname;
|
||||
const REPO_ROOT = path.join(HUB_DIR, "..");
|
||||
const PY = path.join(HUB_DIR, ".venv", "bin", "python");
|
||||
const AGENT = path.join(HUB_DIR, "agent.py");
|
||||
const RUN_SH = path.join(HUB_DIR, "scripts", "run_hub.sh");
|
||||
const RUN_HUB = path.join(HUB_DIR, "scripts", "run_hub.sh");
|
||||
const RUN_AGENT = path.join(HUB_DIR, "scripts", "run_agent.sh");
|
||||
|
||||
function agentApp(name, exchangeDir, exchange, port) {
|
||||
return {
|
||||
name,
|
||||
cwd: path.join(REPO_ROOT, exchangeDir),
|
||||
script: AGENT,
|
||||
interpreter: PY,
|
||||
script: RUN_AGENT,
|
||||
interpreter: "bash",
|
||||
instances: 1,
|
||||
autorestart: true,
|
||||
watch: false,
|
||||
@@ -50,7 +49,7 @@ module.exports = {
|
||||
{
|
||||
name: "manual-trading-hub",
|
||||
cwd: HUB_DIR,
|
||||
script: RUN_SH,
|
||||
script: RUN_HUB,
|
||||
interpreter: "bash",
|
||||
instances: 1,
|
||||
autorestart: true,
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env bash
|
||||
# PM2 子代理入口:在策略目录(cwd)加载 .env 后启动 agent.py
|
||||
# EXCHANGE / PORT / HOST 由 ecosystem.config.cjs 注入,.env 里一般无 PORT,不会覆盖
|
||||
set -euo pipefail
|
||||
|
||||
HUB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
VENV_PY="${HUB_DIR}/.venv/bin/python"
|
||||
AGENT_PY="${HUB_DIR}/agent.py"
|
||||
|
||||
if [[ ! -x "${VENV_PY}" ]]; then
|
||||
echo "未找到 ${VENV_PY},请先在 manual_trading_hub 下创建 venv" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -f .env ]]; then
|
||||
set -a
|
||||
# shellcheck disable=SC1091
|
||||
. ./.env
|
||||
set +a
|
||||
else
|
||||
echo "警告: $(pwd) 下无 .env,agent 可能缺少 API 密钥" >&2
|
||||
fi
|
||||
|
||||
exec "${VENV_PY}" "${AGENT_PY}"
|
||||
@@ -105,8 +105,13 @@
|
||||
kmap[k.id] = k;
|
||||
});
|
||||
let inner = "";
|
||||
const agOk = ag.ok !== false;
|
||||
const agErr = ag.error || row.error || "";
|
||||
if (!row.http_ok) {
|
||||
inner = `<div class="err">${esc(row.error || "子代理不可用")}</div>`;
|
||||
} else if (!agOk) {
|
||||
inner = `<div class="err">${esc(agErr || "子代理返回失败")}</div>`;
|
||||
inner += `<div class="rule-tip">请检查:PM2 子代理是否在对应 crypto_monitor_* 目录加载了 .env;<code>curl ${esc(row.agent_url || "")}/status</code></div>`;
|
||||
} else {
|
||||
const posRows = pos
|
||||
.map(
|
||||
|
||||
@@ -36,7 +36,7 @@ source .venv/bin/activate # 激活 venv(当前终端后续 pip/python
|
||||
pip install -r requirements.txt
|
||||
cp .env.example .env
|
||||
# 编辑 .env:HUB_PORT、HUB_DISABLED_IDS、公网时 HUB_BRIDGE_TOKEN 等
|
||||
chmod +x scripts/run_hub.sh scripts/pm2_hub.sh scripts/pm2_agents.sh
|
||||
chmod +x scripts/run_hub.sh scripts/run_agent.sh scripts/pm2_hub.sh scripts/pm2_agents.sh
|
||||
deactivate # 可选;交给 PM2 时不必保持激活
|
||||
```
|
||||
|
||||
@@ -70,7 +70,7 @@ deactivate # 可选;交给 PM2 时不必保持激活
|
||||
|------|----------|
|
||||
| `ecosystem.config.cjs` | `manual-agent-binance` / `okx` / `gate` / `gate-bot` + **`manual-trading-hub`** |
|
||||
|
||||
`run_hub.sh` 加载 **`manual_trading_hub/.env`** 后执行 `hub.py`;各 agent 在对应策略目录启动以读取该目录 **`.env`** 中的 API 密钥。
|
||||
`run_hub.sh` 加载 **`manual_trading_hub/.env`** 后执行 `hub.py`;各 agent 经 **`run_agent.sh`** 在对应策略目录加载 **`.env`**(含 API 密钥),再执行 `agent.py`。
|
||||
|
||||
```bash
|
||||
cd /opt/crypto_monitor/manual_trading_hub
|
||||
@@ -215,7 +215,8 @@ pm2 restart ecosystem.config.cjs
|
||||
| 现象 | 处理 |
|
||||
|------|------|
|
||||
| PM2 启动后立刻退出 | `pm2 logs manual-trading-hub`;检查 `.venv`、`.env`、`run_hub.sh` 可执行 |
|
||||
| 监控无持仓 | 子代理未起或 Agent URL 错;`curl http://127.0.0.1:15200/status` |
|
||||
| 余额显示 —、无报错 | 子代理未加载策略目录 `.env`(旧版 PM2 直接跑 agent.py) | 更新代码后 `pm2 restart ecosystem.config.cjs`;`curl http://127.0.0.1:15200/status` 应 `ok:true` 且有 `balance_usdt` |
|
||||
| 监控无持仓 | 子代理未起或 Agent URL 错;或交易所确实无仓 | `curl http://127.0.0.1:15200/status` |
|
||||
| 无关键位/下单 401 | Flask 未起或 `HUB_BRIDGE_TOKEN` 不一致;或设 `APP_AUTH_DISABLED=true` |
|
||||
| 子代理 SOCKS 报错 | 在 **manual_trading_hub/.venv** 安装 `PySocks` 后 **pm2 restart** 子代理 |
|
||||
| 公网访问中控 403 | 反代未指向本机、或客户端非私网且 `HUB_TRUST_LAN=true`;反代改 `127.0.0.1:5100` 或在反代层鉴权 |
|
||||
|
||||
Reference in New Issue
Block a user