From 0227713b2d5b82fa7c46c155f92939ffaeffa1a7 Mon Sep 17 00:00:00 2001 From: olli Date: Tue, 24 Oct 2023 20:27:57 +0200 Subject: [PATCH] optimations --- dabo/dabo-bot.sh | 4 +-- dabo/functions/get_asset.sh | 13 +++++--- dabo/functions/get_range.sh | 61 +++++++++++++++++++++++-------------- 3 files changed, 49 insertions(+), 29 deletions(-) diff --git a/dabo/dabo-bot.sh b/dabo/dabo-bot.sh index 0df7907..7614f98 100755 --- a/dabo/dabo-bot.sh +++ b/dabo/dabo-bot.sh @@ -7,8 +7,8 @@ export LANGUAGE="en_US" ### CONFIG ### BASEPATH=/dabo/htdocs -g_tries=5 -g_tries_delay=10 +g_tries=7 +g_tries_delay=15 ### FUNCTIONS ### for bashfunc in $(find ${BASEPATH}/../functions -type f -name "*.sh") diff --git a/dabo/functions/get_asset.sh b/dabo/functions/get_asset.sh index 7d19b57..7286544 100644 --- a/dabo/functions/get_asset.sh +++ b/dabo/functions/get_asset.sh @@ -26,12 +26,12 @@ function get_asset { for f_price in $(tail -n 50 "${f_ASSET_HIST_FILE}" | grep "^[0-9]" | cut -d, -f2) do - if [ "$f_last_price" == "$f_price" ] + if [ "${f_last_price}" == "${f_price}" ] then continue fi let "f_linecount+=1" - f_last_price=$f_price + f_last_price=${f_price} done if [ ${f_linecount} -le 3 ] && [ ${f_lines} -ge 50 ] @@ -102,10 +102,15 @@ function get_asset { do local f_calcema=$(echo ${f_calcemanumcolumn} | cut -d: -f1) local f_caclemacolumn=$(echo ${f_calcemanumcolumn} | cut -d: -f2) - get_ema "${f_ASSET_HIST_FILE}" 2 ${f_calcema} "$(tail -n2 "${f_ASSET_HIST_FILE}" | head -n1 | grep ^2 | cut -d, -f${f_caclemacolumn})" "${f_price}" + local f_last_ema="$(tail -n2 "${f_ASSET_HIST_FILE}" | head -n1 | grep "^[0-9]" | cut -d, -f${f_caclemacolumn})" + if [ -z "${f_last_ema}" ] || [ -z "${f_price}" ] + then + get_ema "${f_ASSET_HIST_FILE}" 2 ${f_calcema} + else + get_ema "${f_ASSET_HIST_FILE}" 2 ${f_calcema} "${f_last_ema}" "${f_price}" + fi if [ -z "${f_ema}" ] then - g_echo_note "${FUNCNAME} $@: Not enough data for calculating EMA - waiting for more values" echo -n "," >>"${f_ASSET_HIST_FILE}" else echo -n ",${f_ema}" >>"${f_ASSET_HIST_FILE}" diff --git a/dabo/functions/get_range.sh b/dabo/functions/get_range.sh index a33737d..16aa83e 100644 --- a/dabo/functions/get_range.sh +++ b/dabo/functions/get_range.sh @@ -1,36 +1,55 @@ #!/bin/bash -#. /etc/bash/gaboshlib.include - function get_range { g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" # get histfile local f_hist_file="$1" # find constant range in defined periods - local f_test_periods=1000 + local f_test_periods=300 + + # check for range change + local f_current_price=$(tail -n1 "${f_hist_file}" | cut -d, -f2 | grep "^[0-9]" | head -n1) + local f_last_lowest_in_range=$(tail -n2 "${f_hist_file}" | head -n1 | cut -d, -f25) + local f_last_highest_in_range=$(tail -n2 "${f_hist_file}" | head -n1 | cut -d, -f26) + if [ -n "${f_last_lowest_in_range}" ] + then + if [ -n "${f_last_highest_in_range}" ] + then + if [ $(echo "${f_current_price} > ${f_last_lowest_in_range}" | bc -l) -ne 0 ] + then + if [ $(echo "${f_current_price} < ${f_last_highest_in_range}" | bc -l) -ne 0 ] + then + local f_range_periods=$(tail -n2 "${f_hist_file}" | head -n1 | cut -d, -f24) + f_range_periods=$((f_range_periods+1)) + fi + fi + fi + fi # go reverse through periods and look for range - for f_test_period in $(seq 1 ${f_test_periods}) - do - # get average from period to now - local f_rangeaverage=$(tail -n${f_test_period} "${f_hist_file}" | cut -d, -f2 | grep "^[0-9]" | awk '{ sum += $1; n++ } END { OFMT = "%2.8f"; if (n > 0) print sum / n; }') - # get old price from period - local f_period_price=$(tail -n${f_test_period} "${f_hist_file}" | cut -d, -f2 | grep "^[0-9]" | head -n1) - # get percentage diff from old price and last average - local f_period_price_diff=$(g_percentage-diff ${f_period_price} ${f_rangeaverage} | sed 's/^-//; s/\..*$//') - # if percentage change is larger then 2% to the average we have an new price range - local f_range_periods=${f_test_period} - if [ ${f_period_price_diff} -gt 2 ] - then - break - fi - done + if [ -z "${f_range_periods}" ] + then + for f_test_period in $(seq 1 ${f_test_periods}) + do + # get average from period to now + local f_rangeaverage=$(tail -n${f_test_period} "${f_hist_file}" | cut -d, -f2 | grep "^[0-9]" | awk '{ sum += $1; n++ } END { OFMT = "%2.8f"; if (n > 0) print sum / n; }') + # get old price from period + local f_period_price=$(tail -n${f_test_period} "${f_hist_file}" | cut -d, -f2 | grep "^[0-9]" | head -n1) + # get percentage diff from old price and last average + local f_period_price_diff=$(g_percentage-diff ${f_period_price} ${f_rangeaverage} | sed 's/^-//; s/\..*$//') + # if percentage change is larger then 2% to the average we have an new price range + local f_range_periods=${f_test_period} + if [ ${f_period_price_diff} -gt 2 ] + then + break + fi + done + fi # get highest, lowest and current price in period local f_highest_in_range=$(tail -n${f_range_periods} "${f_hist_file}" | cut -d, -f2 | grep "^[0-9]" | sort -n | tail -n1) local f_lowest_in_range=$(tail -n${f_range_periods} "${f_hist_file}" | cut -d, -f2 | grep "^[0-9]" | sort -n | head -n1) - local f_current_price=$(tail -n1 "${f_hist_file}" | cut -d, -f2 | grep "^[0-9]" | head -n1) # calculate Pivot Point (PP) local f_pivot_point=$(echo "scale=8; (${f_highest_in_range}+${f_lowest_in_range}+${f_current_price})/3" | bc | sed 's/^\./0./;') @@ -47,9 +66,5 @@ function get_range { # write down in history echo -n ",${f_range_periods},${f_lowest_in_range},${f_highest_in_range},${f_pivot_point},${f_support1},${f_resist1},${f_golden_pocket_support},${f_golden_pocket_resist},${f_golden_pocket65_support},${f_golden_pocket65_resist},${f_support3},${f_resist3}" >>"${f_hist_file}" - } -#get_range /home/docker/dabo-bitpanda.ds9.dedyn.io/data/botdata/asset-histories/SHIBEUR.history.csv - -