Files
crypto_monitor/manual_trading_hub/scripts/run_agent.sh
T

35 lines
1.0 KiB
Bash
Raw 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.
#!/usr/bin/env bash
# PM2 子代理入口:在策略目录(cwd)加载 .env 后启动 agent.py
set -e
set -o pipefail
HUB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
VENV_PY="${HUB_DIR}/.venv/bin/python"
AGENT_PY="${HUB_DIR}/agent.py"
# PM2 ecosystem 注入,须在 source .env 之后再次强制(避免 .env 覆盖 PORT/EXCHANGE
_PM2_EXCHANGE="${EXCHANGE:-}"
_PM2_PORT="${PORT:-}"
_PM2_HOST="${HOST:-}"
if [[ ! -x "${VENV_PY}" ]]; then
echo "未找到 ${VENV_PY},请先在 manual_trading_hub: python3 -m venv .venv && pip install -r requirements.txt" >&2
exit 1
fi
if [[ -f .env ]]; then
set -a
# shellcheck disable=SC1091
. ./.env
set +a
else
echo "警告: $(pwd) 下无 .envagent 可能缺少 API 密钥" >&2
fi
[[ -n "${_PM2_EXCHANGE}" ]] && export EXCHANGE="${_PM2_EXCHANGE}"
[[ -n "${_PM2_PORT}" ]] && export PORT="${_PM2_PORT}"
[[ -n "${_PM2_HOST}" ]] && export HOST="${_PM2_HOST}"
echo "agent start: exchange=${EXCHANGE:-?} port=${PORT:-?} cwd=$(pwd)" >&2
exec "${VENV_PY}" "${AGENT_PY}"