diff --git a/dabo/functions/g_num_is_approx.sh b/dabo/functions/g_num_is_approx.sh deleted file mode 100644 index 3b5ebf7..0000000 --- a/dabo/functions/g_num_is_approx.sh +++ /dev/null @@ -1,17 +0,0 @@ -function g_num_is_approx { - - # check if $1 is in percentage range ($3 and $4) to $2 - local f_num=$1 - local f_base=$2 - local f_percentage_up=$3 - local f_percentage_down=$4 - - # Check for valid decimal number - - g_num_valid_number "${f_num}" "${f_base}" "${f_percentage_up}" "${f_percentage_down}" || return 1 - - local f_from=$(echo "${f_base} - (${f_base} / 100 * ${f_percentage_down})" | bc -l) - local f_to=$(echo "${f_base} + (${f_base} / 100 * ${f_percentage_up})" | bc -l) - - g_num_is_between ${f_num} ${f_from} ${f_to} -} diff --git a/dabo/functions/g_num_is_between.sh b/dabo/functions/g_num_is_between.sh deleted file mode 100644 index 3c0cc2d..0000000 --- a/dabo/functions/g_num_is_between.sh +++ /dev/null @@ -1,47 +0,0 @@ -function g_num_is_between { - - local f_num=$1 - local f_between1=$2 - local f_between2=$3 - - # Check for integer (can be done with bash itself) - if [[ ${f_num} =~ ^[0-9]+$ ]] && [[ ${f_between1} =~ ^[0-9]+$ ]] && [[ ${f_between2} =~ ^[0-9]+$ ]] - then - # Check which is the low (from) and the high (to) number - if [ "${f_between1}" -lt "${f_between2}" ] - then - local f_from=${f_between1} - local f_to=${f_between2} - else - local f_from=${f_between2} - local f_to=${f_between1} - fi - # Check if given number is in or out range - if [ ${f_num} -lt ${f_from} ] || [ ${f_num} -gt ${f_to} ] - then - return 1 - else - return 0 - fi - fi - - # Check for valid number - g_num_valid_number "$f_num" "$f_between1" "$f_between2" || return 1 - - # Check which is the low (from) and the high (to) number - if [ $(echo "${f_between1} < ${f_between2}" | bc -l) -ne 0 ] - then - local f_from=${f_between1} - local f_to=${f_between2} - else - local f_from=${f_between2} - local f_to=${f_between1} - fi - # Check if given number is in or out range - if [ $(echo "${f_num} < ${f_from}" | bc -l) -ne 0 ] || [ $(echo "${f_num} > ${f_to}" | bc -l) -ne 0 ] - then - return 1 - else - return 0 - fi -} diff --git a/dabo/functions/g_num_is_higher.sh b/dabo/functions/g_num_is_higher.sh deleted file mode 100644 index 4a54535..0000000 --- a/dabo/functions/g_num_is_higher.sh +++ /dev/null @@ -1,30 +0,0 @@ -function g_num_is_higher { - - local f_num=$1 - local f_checkhigher=$2 - - # Check for integer (can be done with bash itself) - if [[ ${f_num} =~ ^[0-9]+$ ]] && [[ ${f_checkhigher} =~ ^[0-9]+$ ]] - then - # Check which is the low (from) and the high (to) number - if [ "${f_num}" -gt "${f_checkhigher}" ] - then - return 0 - else - return 1 - fi - fi - - # Check for valid number - g_num_valid_number "$f_num" "$f_checkhigher" || return 1 - - # Check which is the low (from) and the high (to) number - # Check if given number is in or out range - if [ $(echo "${f_num} > ${f_checkhigher}" | bc) -ne 0 ] - then - return 0 - else - return 1 - fi -} - diff --git a/dabo/functions/g_num_valid_number.sh b/dabo/functions/g_num_valid_number.sh deleted file mode 100644 index ad1b5b0..0000000 --- a/dabo/functions/g_num_valid_number.sh +++ /dev/null @@ -1,12 +0,0 @@ -function g_num_valid_number { - local f_num - for f_num in $@ - do - if ! [[ ${f_num} =~ ^(-)?(\.)?[0-9]+(\.[0-9]+)?$ ]] - then - g_echo "\"${f_num}\": Not a valid number" - return 1 - fi - done -} - diff --git a/dabo/functions/get_vars_from_csv.sh b/dabo/functions/get_vars_from_csv.sh index db03864..9effc31 100644 --- a/dabo/functions/get_vars_from_csv.sh +++ b/dabo/functions/get_vars_from_csv.sh @@ -12,18 +12,42 @@ function get_vars_from_csv { f_market_performance="-50" fi f_all_vars="f_market_performance=${f_market_performance}" - + f_last_line="$(tail -n1 "${f_ASSET_HIST_FILE}"),${f_market_performance}" - readarray -d "," -t f_last_line_array < <(echo "0,${f_last_line}") f_asset=$(basename ${f_ASSET_HIST_FILE} | cut -d\. -f1) - + # basics get_var_from_line date 1 get_var_from_line price 2 get_var_from_line price_change 3 + # Check for price trend last 4 iterations + f_last_4_prices=$(tail -n4 "${f_ASSET_HIST_FILE}" | cut -d, -f2) + f_last_4_price=$(echo ${f_last_4_prices} | head -n1) + f_last_4_prices_change=$(g_percentage-diff ${f_last_4_price} ${f_price}) + + local f_orig_ifs=${IFS} + IFS=\n + if echo ${f_last_4_prices} | sort -n -C + then + f_price_trend="constantly growing,${f_last_4_prices_change}" + elif echo ${f_last_4_prices} | sort -n -r -C + then + f_price_trend="constantly falling,${f_last_4_prices_change}" + elif g_num_is_higher ${f_last_4_prices_change} 0 + then + f_price_trend="growing,${f_last_4_prices_change}" + elif g_num_is_lower ${f_last_4_prices_change} 0 + then + f_price_trend="falling,${f_last_4_prices_change}" + else + f_price_trend="constant,${f_last_4_prices_change}" + fi + + + # MACD EMA get_var_from_line ema12 4 get_var_from_line ema26 5