myTestFreqAI/tools/download.sh
zhangkun9038@dingtalk.com c7aceb3101 update download.sh
2025-11-07 09:26:31 +08:00

135 lines
3.8 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
# Function to extract the value of a parameter
get_param_value() {
local param="$1"
shift
while [[ $# -gt 0 ]]; do
case "$1" in
$param=*)
echo "${1#*=}"
return
;;
$param)
# Check if the next argument exists and does not start with a dash
if [[ -n "$2" && "$2" != -* ]]; then
echo "$2"
return
else
echo "Error: Missing value for parameter $param" >&2
exit 1
fi
;;
esac
shift
done
echo "Error: Parameter $param not found" >&2
exit 1
}
# Function to extract comma-separated values
get_csv_param_value() {
local param="$1"
shift
while [[ $# -gt 0 ]]; do
case "$1" in
$param=*)
echo "${1#*=}"
return
;;
$param)
# Check if the next argument exists and does not start with a dash
if [[ -n "$2" && "$2" != -* ]]; then
echo "$2"
return
else
echo "Error: Missing value for parameter $param" >&2
exit 1
fi
;;
esac
shift
done
echo ""
return
}
if [[ "$@" == *"--timerange"* ]] && [[ "$@" == *"--days"* ]]; then
echo "Error: Both --timerange and --days cannot be provided."
exit 1
fi
# Get timerange or days from parameters
timerange=""
days=""
if [[ "$@" == *"--timerange"* ]]; then
timerange=$(get_param_value "--timerange" "$@")
elif [[ "$@" == *"--days"* ]]; then
days=$(get_param_value "--days" "$@")
fi
# Get pairs and timeframe from parameters or use defaults
pairs=$(get_csv_param_value "--pairs" "$@")
timeframe=$(get_csv_param_value "--timeframe" "$@")
# Use default values if parameters are not provided
if [[ -z "$pairs" ]]; then
# 从API获取交易对列表
echo "Fetching pairs from API..."
pairs_json=$(curl -s "http://pairlist.xl.home/api/pairlist?mute=true&count=100")
# 检查API响应是否成功
if [[ $? -ne 0 || -z "$pairs_json" ]]; then
echo "Error: Failed to fetch pairs from API, using fallback list"
pairs="BTC/USDT TON/USDT DOT/USDT XRP/USDT OKB/USDT SOL/USDT DOGE/USDT WCT/USDT TRUMP/USDT SUI/USDT PEPE/USDT TRB/USDT MASK/USDT UNI/USDT KAITO/USDT"
else
# 解析JSON并提取交易对将连字符替换为斜杠
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 '')
")
# 定义静态币对列表
static_pairs="BTC/USDT TON/USDT DOT/USDT XRP/USDT OKB/USDT SOL/USDT DOGE/USDT WCT/USDT TRUMP/USDT SUI/USDT PEPE/USDT TRB/USDT MASK/USDT UNI/USDT KAITO/USTS"
# 如果解析失败,使用静态列表
if [[ -z "$pairs" ]]; then
echo "Error: Failed to parse API response, using static list"
pairs="$static_pairs"
else
# 合并API返回的币对和静态币对并去重
echo "Successfully fetched $(echo "$pairs" | wc -w) pairs from API"
echo "Merging with static pairs..."
# 合并两个列表并去重
merged_pairs="$pairs $static_pairs"
pairs=$(echo "$merged_pairs" | tr ' ' '\n' | sort -u | tr '\n' ' ' | sed 's/ $//')
echo "Total pairs after merging: $(echo "$pairs" | wc -w)"
echo "Pairs: $pairs"
fi
fi
fi
if [[ -z "$timeframe" ]]; then
timeframe="3m,5m,15m,30m,1h,4h,6h,12h,1d"
fi
# Convert timeframe string to array
IFS=',' read -r -a timeframe_array <<<"$timeframe"
timeframe_array_str=$(printf " '%s'" "${timeframe_array[@]}")
# Initialize the base command
cmd="docker-compose run --rm freqtrade download-data --config /freqtrade/config_examples/basic.json --pairs $pairs --timeframe$timeframe_array_str --days 50"
# Add timerange or days if provided
if [[ -n "$timerange" ]]; then
cmd+=" --timerange='$timerange'"
elif [[ -n "$days" ]]; then
cmd+=" --days=$days"
fi
# Execute the command
eval "$cmd"