./live.sh --strategy StaticGrid --pairs ETH/USDT

This commit is contained in:
zhangkun9038@dingtalk.com 2025-11-26 23:17:18 +08:00
parent acff2926e9
commit ddd127e0b3

View File

@ -192,6 +192,7 @@ PAIR_REMOTE_LIST_URL="$DEFAULT_PAIR_REMOTE_URL"
# 初始化策略配置(从 .env 加载)
STRATEGY_NAME=${STRATEGY_NAME:-TheForceV7}
CONFIG_FILE=${CONFIG_FILE:-basic.json}
PAIRS_ARG=""
# 解析命令行参数:支持策略名、配置文件、币对列表
while [[ $# -gt 0 ]]; do
@ -222,6 +223,19 @@ while [[ $# -gt 0 ]]; do
exit 1
fi
;;
--pairs=*)
PAIRS_ARG="${1#*=}"
shift
;;
--pairs)
if [[ -n "$2" && "$2" != -* ]]; then
PAIRS_ARG="$2"
shift 2
else
echo "错误:--pairs需要指定值" >&2
exit 1
fi
;;
--pairRemoteList=*)
PAIR_REMOTE_LIST_URL="${1#*=}"
shift
@ -264,28 +278,56 @@ echo "✅ 远程币对列表URL: $PAIR_REMOTE_LIST_URL" >&2
### 核心:处理币对列表 ###
# 1. 获取数据库币对(使用绝对路径)
db_path="/home/ubuntu/freqtrade/user_data/tradesv3.sqlite"
db_pairs=$(get_open_trades_pairs "$db_path")
# 2. 获取远程币对
remote_pairs=$(get_remote_pairs "$PAIR_REMOTE_LIST_URL")
# 3. 合并去重
merged_pairs=$(merge_and_deduplicate_pairs "$db_pairs" "$remote_pairs")
# 4. 更新配置文件
update_live_json_pair_whitelist "../config_examples/live.json" "$merged_pairs"
# 编辑 ../freqtrade/templates/${PARAMS_NAME}.json 文件,删除包含 "protection": {}, 的行
echo "正在编辑 ../freqtrade/templates/${PARAMS_NAME}.json 文件,删除 'protection': {} 行..." >&2
sed -i '/"protection": {},/d' "../freqtrade/templates/${PARAMS_NAME}.json"
if [ $? -eq 0 ]; then
echo "✅ 成功编辑 ../freqtrade/templates/${PARAMS_NAME}.json 文件" >&2
# 0. 判断是否使用 --pairs 传入的币对列表
if [ -n "$PAIRS_ARG" ]; then
echo "✅ 使用命令行 --pairs 参数:$PAIRS_ARG" >&2
# 更新配置文件中的 pair_whitelist
if [ -f "../config_examples/live.json" ]; then
update_live_json_pair_whitelist "../config_examples/live.json" "$PAIRS_ARG"
else
echo "⚠️ 找不到 ../config_examples/live.json跳过配置更新" >&2
fi
else
echo "❌ 编辑 ../freqtrade/templates/${PARAMS_NAME}.json 文件失败" >&2
exit 1
# 使用旧的逻辑:数据库 + 遥程 API
echo "✅ 使用旧逻辑(数据库 + 遥程 API" >&2
# 1. 获取数据库币对(使用绝对路径)
db_path="/home/ubuntu/freqtrade/user_data/tradesv3.sqlite"
db_pairs=$(get_open_trades_pairs "$db_path")
# 2. 获取遥程币对
remote_pairs=$(get_remote_pairs "$PAIR_REMOTE_LIST_URL")
# 3. 合并去重
merged_pairs=$(merge_and_deduplicate_pairs "$db_pairs" "$remote_pairs")
# 4. 更新配置文件
if [ -f "../config_examples/live.json" ]; then
update_live_json_pair_whitelist "../config_examples/live.json" "$merged_pairs"
else
echo "⚠️ 找不到 ../config_examples/live.json跳过配置更新" >&2
fi
fi
# 编辑参数文件,删除包含 "protection": {}, 的行(如果文件存在)
PARAMS_FILE="../freqtrade/templates/${PARAMS_NAME}.json"
if [ -f "$PARAMS_FILE" ]; then
echo "正在编辑 $PARAMS_FILE 文件,删除 'protection': {} 行..." >&2
# macOS 兼容的 sed 命令
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' '/'"protection"': {},/d' "$PARAMS_FILE"
else
sed -i '/'"protection"': {},/d' "$PARAMS_FILE"
fi
if [ $? -eq 0 ]; then
echo "✅ 成功编辑 $PARAMS_FILE 文件" >&2
else
echo "❌ 编辑 $PARAMS_FILE 文件失败" >&2
exit 1
fi
else
echo "⚠️ 参数文件 $PARAMS_FILE 不存在,跳过编辑" >&2
fi
### 启动容器 ###