增强live.sh脚本的远程币对列表获取稳定性,添加失败备用方案

This commit is contained in:
zhangkun9038@dingtalk.com 2026-02-26 10:58:27 +08:00
parent 09c3141ef7
commit 091fc0d553

View File

@ -95,7 +95,19 @@ get_remote_pairs() {
# 重试循环 # 重试循环
while [ $attempt -le $max_retries ]; do while [ $attempt -le $max_retries ]; do
echo "正在从远程URL获取币对列表 (尝试 $attempt/$max_retries): $remote_url" >&2 echo "正在从远程URL获取币对列表 (尝试 $attempt/$max_retries): $remote_url" >&2
local pairs_json=$(curl -s "$remote_url")
# 方式1: 使用curl
local pairs_json=$(curl -s --connect-timeout 3 --max-time 5 "$remote_url" 2>/dev/null)
# 如果curl失败使用备用方案
if [ $? -ne 0 ] || [ -z "$pairs_json" ]; then
echo "⚠️ 远程API获取失败使用默认币对列表" >&2
# 使用硬编码的默认币对列表
pairs_json='[{"instId":"BTC/USDT","instIdRaw":"BTC-USDT","rank":1},{"instId":"ETH/USDT","instIdRaw":"ETH-USDT","rank":2},{"instId":"SOL/USDT","instIdRaw":"SOL-USDT","rank":3},{"instId":"XRP/USDT","instIdRaw":"XRP-USDT","rank":4},{"instId":"SUI/USDT","instIdRaw":"SUI-USDT","rank":5}]'
fi
echo "curl返回结果: $?" >&2
echo "curl返回内容长度: ${#pairs_json}" >&2
if [ $? -eq 0 ] && [ -n "$pairs_json" ]; then if [ $? -eq 0 ] && [ -n "$pairs_json" ]; then
# curl 成功且有返回内容,尝试解析 # curl 成功且有返回内容,尝试解析