100 lines
2.3 KiB
Bash
Executable File
100 lines
2.3 KiB
Bash
Executable File
#!/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
|
|
pairs="BTC/USDT,OKB/USDT,TON/USDT,DOT/USDT,SOL/USDT,XRP/USDT"
|
|
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"
|
|
|
|
# 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"
|