From ec8871e2bedd27cd4f24dc48ebe4748b8378f686 Mon Sep 17 00:00:00 2001 From: "zhangkun9038@dingtalk.com" Date: Thu, 11 Dec 2025 11:34:15 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E4=BA=86=20live.sh=20?= =?UTF-8?q?=E4=B8=AD=E6=89=80=E6=9C=89=E4=B8=8E=20remote=5Fpairs=20?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/live.sh | 95 ++++++++++++++------------------------------------- 1 file changed, 25 insertions(+), 70 deletions(-) diff --git a/tools/live.sh b/tools/live.sh index bc65c69b..ccce9724 100755 --- a/tools/live.sh +++ b/tools/live.sh @@ -60,56 +60,7 @@ get_open_trades_pairs() { echo "${pairs[@]}" } -# 2. 从远程接口获取币对列表 -get_remote_pairs() { - local remote_url="$1" - local pairs=() - - if [ -z "$remote_url" ]; then - echo "⚠️ 未提供远程币对列表URL,远程币对列表为空" >&2 - echo "" - return - fi - - echo "正在从远程URL获取币对列表: $remote_url" >&2 - local pairs_json=$(curl -s "$remote_url") - - if [ $? -ne 0 ] || [ -z "$pairs_json" ]; then - echo "⚠️ 远程币对列表获取失败,使用空列表" >&2 - echo "" - return - fi - - local parsed_pairs=$(echo "$pairs_json" | python3 -c " -import sys, json -data = json.load(sys.stdin) -pairs = [pair.replace('-', '/') for pair in data.get('pairlist', [])] -print(' '.join(pairs) if pairs else '') -") - - if [ -n "$parsed_pairs" ]; then - pairs=($parsed_pairs) - echo "从远程获取到币对: ${pairs[*]}" >&2 - else - echo "⚠️ 远程币对列表解析为空" >&2 - fi - - echo "${pairs[@]}" -} - -# 3. 合并并去重两个币对列表 -merge_and_deduplicate_pairs() { - local -a db_pairs=($1) - local -a remote_pairs=($2) - local -a merged=() - - merged=($(printf "%s\n" "${db_pairs[@]}" "${remote_pairs[@]}" | sort -u | tr '\n' ' ')) - - echo "合并去重后的币对列表: ${merged[*]}" >&2 - echo "${merged[@]}" -} - -# 4. 验证JSON文件格式是否有效 +# 2. 验证JSON文件格式是否有效 validate_json_file() { local json_path="$1" @@ -129,7 +80,7 @@ validate_json_file() { fi } -# 5. 更新live.json中的pair_whitelist +# 3. 更新live.json中的pair_whitelist update_live_json_pair_whitelist() { local json_path="$1" local -a pairlist=($2) @@ -185,23 +136,20 @@ if [[ "$current_branch" == *"dryrun"* ]]; then echo "✅ Git工作区已清理" >&2 fi -# 设置默认远程币对列表URL,支持命令行参数覆盖 -DEFAULT_PAIR_REMOTE_URL="http://pairlist.xl.home/api/pairlist?mute=true&count=30" -PAIR_REMOTE_LIST_URL="$DEFAULT_PAIR_REMOTE_URL" - -# 解析命令行参数:如果提供则覆盖默认值 +# 解析命令行参数:获取手动指定的币对列表 +MANUAL_PAIRS="" while [[ $# -gt 0 ]]; do case "$1" in - --pairRemoteList=*) - PAIR_REMOTE_LIST_URL="${1#*=}" + --pairs=*) + MANUAL_PAIRS="${1#*=}" shift ;; - --pairRemoteList) + --pairs) if [[ -n "$2" && "$2" != -* ]]; then - PAIR_REMOTE_LIST_URL="$2" + MANUAL_PAIRS="$2" shift 2 else - echo "错误:--pairRemoteList需要指定值" >&2 + echo "错误:--pairs需要指定值" >&2 exit 1 fi ;; @@ -219,22 +167,29 @@ PARAMS_NAME=$(echo "$STRATEGY_NAME" | tr '[:upper:]' '[:lower:]') echo "使用策略: $STRATEGY_NAME" >&2 echo "使用配置: $CONFIG_FILE" >&2 echo "测试分支: $TEST_BRANCH" >&2 -echo "远程币对列表URL: $PAIR_REMOTE_LIST_URL" >&2 # 显示当前使用的URL ### 核心:处理币对列表 ### +# 定义写死的币对白名单 +DEFAULT_PAIRS="WCT/USDT TRUMP/USDT SUI/USDT PEPE/USDT TRB/USDT MASK/USDT UNI/USDT KAITO/USDT" + # 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") +# 2. 处理手动指定的币对 +if [ -n "$MANUAL_PAIRS" ]; then + # 将逗号分隔的币对转换为空格分隔 + final_pairs=$(echo "$MANUAL_PAIRS" | tr ',' ' ') + echo "使用手动指定的币对: $final_pairs" >&2 +else + # 如果没有手动指定的币对,则使用写死的币对白名单 + final_pairs=$DEFAULT_PAIRS + echo "使用写死的币对白名单作为最终列表: $final_pairs" >&2 +fi -# 3. 合并去重 -merged_pairs=$(merge_and_deduplicate_pairs "$db_pairs" "$remote_pairs") - -# 4. 更新配置文件 -update_live_json_pair_whitelist "../config_examples/live.json" "$merged_pairs" +# 3. 更新配置文件 +update_live_json_pair_whitelist "../config_examples/live.json" "$final_pairs" # 编辑 ../freqtrade/templates/${PARAMS_NAME}.json 文件,删除包含 "protection": {}, 的行 echo "正在编辑 ../freqtrade/templates/${PARAMS_NAME}.json 文件,删除 'protection': {} 行..." >&2 @@ -287,4 +242,4 @@ if [ $? -eq 0 ]; then else echo "❌ 容器启动失败" >&2 exit 1 -fi +fi \ No newline at end of file