diff --git a/run_position_closer.sh b/run_position_closer.sh new file mode 100755 index 0000000..0cf7326 --- /dev/null +++ b/run_position_closer.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# 运行 position_closer.py,可选每 1 小时循环一次。 +# 用法: +# ./run_position_closer.sh # 运行一次 +# ./run_position_closer.sh loop # 每 1 小时运行一次(前台循环) +# 配合 crontab 每小时运行一次: 0 * * * * /path/to/bn-pc/run_position_closer.sh + +set -e +cd "$(dirname "$0")" + +if [[ -x .venv/bin/python ]]; then + PYTHON=".venv/bin/python" +else + PYTHON="python3" +fi + +run_once() { + set +e + "$PYTHON" -m position_closer + set -e +} + +if [[ "${1:-}" == "loop" ]]; then + echo "每 1 小时运行一次 position_closer,按 Ctrl+C 停止" + while true; do + run_once + echo "下一轮于 1 小时后执行..." + sleep 30 + done +else + run_once +fi