dabo/functions/get_vars_from_csv.sh

48 lines
1.2 KiB
Bash
Raw Normal View History

2023-04-28 17:09:15 +02:00
function get_vars_from_csv {
local f_ASSET_HIST_FILE="$1"
if ! [ -s "${f_ASSET_HIST_FILE}" ]
then
g_echo_warn "${f_ASSET_HIST_FILE} does not exist or is empty"
return 1
fi
f_last_line="$(tail -n1 "${f_ASSET_HIST_FILE}")"
readarray -d "," -t f_last_line_array < <(echo "0,${f_last_line}")
get_var_from_line date 1
get_var_from_line price 2
get_var_from_line price_change 3
get_var_from_line macd_histogram 8
get_var_from_line macd_signal_relation 9
f_macd_histogram_relation=$(echo "${f_macd_signal_relation}" | cut -d\| -f1)
f_macd_histogram_signal=$(echo "${f_macd_signal_relation}" | cut -d\| -f2)
get_var_from_line rsi5 10
get_var_from_line rsi14 11
get_var_from_line rsi21 12
get_var_from_line rsi720 13
get_var_from_line rsi60 14
get_var_from_line rsi120 15
get_var_from_line rsi240 16
get_var_from_line rsi420 17
get_var_from_line price_change_1_day 18
get_var_from_line price_change_7_day 19
get_var_from_line price_change_14_day 20
get_var_from_line price_change_30_day 21
}
function get_var_from_line {
if [ -z "${f_last_line_array[$2]}" ]
then
g_echo_note "Didn't get $1 in position $2"
return 1
fi
declare -g f_$1="$(echo ${f_last_line_array[$2]})"
}