diff --git a/tools/live.sh b/tools/live.sh index b35c495a..842a72a2 100755 --- a/tools/live.sh +++ b/tools/live.sh @@ -95,7 +95,19 @@ get_remote_pairs() { # 重试循环 while [ $attempt -le $max_retries ]; do 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 # curl 成功且有返回内容,尝试解析