Files
stock/stock-html/auto_sync_kline_5min.sh
T
freedakgmail 9c7d7abdd4 Initial commit
2026-07-17 18:49:35 +08:00

38 lines
1.2 KiB
Bash
Executable File
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.
#!/bin/bash
# 5分钟K线数据每日采集脚本
# 交易日收盘后执行,采集当天全市场的5分钟K线数据
# 建议在 17:30 后运行(收盘后数据完整)
#
# 使用新浪APIstock_zh_a_minute),稳定不限流
# 3线程并发(东财API),全市场约5800只,预计耗时约60-90分钟
DAY_OF_WEEK=$(date +%u)
# 周六(6)、周日(7)跳过
if [ "$DAY_OF_WEEK" -ge 6 ]; then
echo "$(date '+%Y-%m-%d %H:%M:%S') 今天是周末,跳过5分钟K线采集"
exit 0
fi
echo "$(date '+%Y-%m-%d %H:%M:%S') 开始5分钟K线采集..."
cd /opt/stock-app
export DB_PASSWORD=stock_password_2025
# 清理可能残留的锁文件(防止权限问题导致无法启动)
LOCK_FILE="/tmp/sync_kline_5min.lock"
if [ -f "$LOCK_FILE" ]; then
# 检查锁文件中记录的PID是否仍在运行
OLD_PID=$(cat "$LOCK_FILE" 2>/dev/null)
if [ -n "$OLD_PID" ] && ! kill -0 "$OLD_PID" 2>/dev/null; then
echo "$(date '+%Y-%m-%d %H:%M:%S') 清理残留锁文件 (旧PID: $OLD_PID 已不存在)"
rm -f "$LOCK_FILE"
fi
fi
/opt/stock-app/venv/bin/python sync_kline_5min.py --delay 0.8 --workers 3
EXIT_CODE=$?
echo "$(date '+%Y-%m-%d %H:%M:%S') 5分钟K线采集完成,退出码: $EXIT_CODE"
exit $EXIT_CODE