From 4d392cac273fbeae73a6e33005ab4a64132ccfe3 Mon Sep 17 00:00:00 2001 From: olli Date: Mon, 30 Oct 2023 16:33:53 +0100 Subject: [PATCH] range fix --- dabo/functions/get_asset.sh | 7 ++++++- dabo/functions/get_range.sh | 22 ++++++++++++++++------ dabo/functions/webpage.sh | 2 +- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/dabo/functions/get_asset.sh b/dabo/functions/get_asset.sh index 7286544..8856062 100644 --- a/dabo/functions/get_asset.sh +++ b/dabo/functions/get_asset.sh @@ -94,7 +94,12 @@ function get_asset { echo -n ,$(jq -r ".[] |select(.symbol==\"${f_asset}\")|\"\\(.market_cap_change_percentage_24h)\"" COINGECKO_GET_ASSETS_CMD_OUT) >>${f_ASSET_HIST_FILE} # range and fibonacci - get_range ${f_ASSET_HIST_FILE} + if ! get_range ${f_ASSET_HIST_FILE} + then + local f_oldrange=$(tail -n2 ${f_ASSET_HIST_FILE} | head -n1 | cut -d, -f24,25,26,27,28,29,30,31,32,33,34,35) + g_echo_note "Taking old range ${f_oldrange}" + echo -n ",${f_oldrange}" >>$f_ASSET_HIST_FILE + fi # Calculate EMA 50:36 100:37 200:38 800:39 local f_calcemanumcolumn diff --git a/dabo/functions/get_range.sh b/dabo/functions/get_range.sh index a0285af..b38536d 100644 --- a/dabo/functions/get_range.sh +++ b/dabo/functions/get_range.sh @@ -7,11 +7,19 @@ function get_range { # get histfile local f_hist_file="$1" - # Get range from a day 12h before (past day ist the usual range for calculationg Levels / Pivot Point) + # Get last days (past day is the usual range for calculationg Levels / Pivot Point) - Should be Tiomezone where most traders on exchange are in + # TODO:Add support for timezone local f_latest_date=$(tail -n1 ${f_hist_file} | cut -d, -f1) - local f_range_to_date=$(date "+%F %H:" --date="${f_latest_date} 12 hours ago") - local f_range_from_date=$(date "+%F %H:" --date="${f_latest_date} 36 hours ago") - local f_range_data=$(sed -n "/${f_range_from_date}/,/${f_range_to_date}/p" ${f_hist_file} | cut -d , -f2 | grep "^[0-9]") + local f_range_day=$(date "+%F " --date="${f_latest_date} yesterday") + local f_range_data=$(grep "^${f_range_day}" ${f_hist_file} | cut -d , -f2 | grep "^[0-9]") + + # Check for new range + local f_last_range_day=$(tail -n1 ${f_hist_file} | cut -d, -f24) + if echo "${f_latest_date}" | grep -q ${f_last_range_day} + then + g_echo_note "${FUNCNAME} $@: No new range" + return 1 + fi if [ -n "${f_range_data}" ] then @@ -36,11 +44,13 @@ function get_range { local f_support3=$(echo "scale=8; ${f_pivot_point}-((${f_highest_in_range}-${f_lowest_in_range})*1)" | bc | sed 's/^\./0./;' ) local f_resist3=$(echo "scale=8; ${f_pivot_point}+((${f_highest_in_range}-${f_lowest_in_range})*1)" | bc | sed 's/^\./0./;' ) else - g_echo_note "Not enough data for calculating range" + g_echo_note "${FUNCNAME} $@: Not enough data for calculating range" + return 1 fi # 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}" + echo -n ",${f_range_day},${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}" + return 0 } diff --git a/dabo/functions/webpage.sh b/dabo/functions/webpage.sh index b23af9f..354be93 100644 --- a/dabo/functions/webpage.sh +++ b/dabo/functions/webpage.sh @@ -266,7 +266,7 @@ function webpage { " >>../index.html.tmp echo "
${asset} Charts" >>../index.html.tmp echo "Price, EMA, Levels" >>../index.html.tmp - genchart asset-histories/${asset}.history.csv 50 2,25,26,27,28,29,30,31,32,33,34,35,4,36,37,38,39 green,DarkSlateGrey,DarkSlateGrey,Gold,DarkOrange,DarkOrange,GoldenRod,GoldenRod,GoldenRod,GoldenRod,DarkOrange,DarkOrange,MidnightBlue,Indigo,DarkSlateBlue,DodgerBlue,DeepSkyBlue >>../index.html.tmp + genchart asset-histories/${asset}.history.csv 50 2,25,26,27,28,29,30,31,32,33,34,35,5,36,37,38 green,DarkSlateGrey,DarkSlateGrey,Gold,DarkOrange,DarkOrange,GoldenRod,GoldenRod,GoldenRod,GoldenRod,DarkOrange,DarkOrange,MidnightBlue,Indigo,DarkSlateBlue,DodgerBlue,DeepSkyBlue >>../index.html.tmp echo "MACD" >>../index.html.tmp genchart asset-histories/${asset}.history.csv 50 8,6,7 >>../index.html.tmp echo "RSIs" >>../index.html.tmp