From 839680820efd1b77df7e6ecd036c063638add43c Mon Sep 17 00:00:00 2001 From: olli Date: Wed, 15 Nov 2023 17:08:03 +0100 Subject: [PATCH] more pure bash to speed up things --- dabo/analyze.sh | 74 ++++++++++++++------------ dabo/functions/check_buy_conditions.sh | 3 +- 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/dabo/analyze.sh b/dabo/analyze.sh index cd39ffe..94b48ed 100755 --- a/dabo/analyze.sh +++ b/dabo/analyze.sh @@ -46,7 +46,7 @@ function analyze { >${g_tmp}/${tmpfile} >${g_tmp}/result-${tmpfile} - rm -rf ${g_tmp}/open-${tmpfile} + #rm -rf ${g_tmp}/open-${tmpfile} rm -rf ${g_tmp}/interim-${tmpfile} rm -rf ${g_tmp}/output-${tmpfile} @@ -92,47 +92,50 @@ function analyze { f_market_performance_before=${f_market_performance} echo "MARKET_PERF=$f_market_performance" - if [ -f "${g_tmp}/open-${tmpfile}" ] + #if [ -f "${g_tmp}/open-${tmpfile}" ] + if [ -n "${f_open_trade}" ] then - if [ "${ANALYZE_VERBOSE}" -eq "0" ] - then - check_sell_conditions ${g_tmp}/${tmpfile} >>${g_tmp}/output-${tmpfile} - else +# if [ "${ANALYZE_VERBOSE}" -eq "0" ] +# then +# check_sell_conditions ${g_tmp}/${tmpfile} >>${g_tmp}/output-${tmpfile} +# else check_sell_conditions ${g_tmp}/${tmpfile} - fi - fi - if ! [ -f "${g_tmp}/open-${tmpfile}" ] - then - if [ "${ANALYZE_VERBOSE}" -eq "0" ] - then - check_buy_conditions ${g_tmp}/${tmpfile} >>${g_tmp}/output-${tmpfile} - else +# fi +# fi +# if ! [ -f "${g_tmp}/open-${tmpfile}" ] + else +# then +# if [ "${ANALYZE_VERBOSE}" -eq "0" ] +# then +# check_buy_conditions ${g_tmp}/${tmpfile} >>${g_tmp}/output-${tmpfile} +# else check_buy_conditions ${g_tmp}/${tmpfile} - fi +# fi fi ## Chart Part - #local f_intrade=0 - #local f_score=${f_buy_score} - #local f_interim="0" - #[ -z "${f_buy_score}" ] && f_buy_score=0 - #if [ -z "${f_sell_score}" ] - #then - # f_sell_score=0 - #else - # f_score=${f_sell_score} - # f_intrade=1 - # if [ -s ${g_tmp}/interim-${tmpfile} ] - # then - # f_interim=$(tail -n1 ${g_tmp}/interim-${tmpfile}) - # f_interim=$(g_calc "${f_interim}-${FEE}") - # fi - #fi - #echo "$f_line,${f_market_performance},${f_score},${f_buy_score},${f_sell_score},${f_intrade},${f_interim}" >>analyze-${analyzedate}/chart-${tmpfile} - # Chart Part End + local f_intrade=0 + local f_score=${f_buy_score} + local f_interim="0" + [ -z "${f_buy_score}" ] && f_buy_score=0 + if [ -z "${f_sell_score}" ] + then + f_sell_score=0 + else + f_score=${f_sell_score} + f_intrade=1 + if [ -s ${g_tmp}/interim-${tmpfile} ] + then + f_interim=$(tail -n1 ${g_tmp}/interim-${tmpfile}) + f_interim=$(g_calc "${f_interim}-${FEE}") + fi + fi + echo "$f_line,${f_market_performance},${f_score},${f_buy_score},${f_sell_score},${f_intrade},${f_interim}" >>analyze-${analyzedate}/chart-${tmpfile} + ## Chart Part End done # sell at the end to have a final result. - if [ -f ${g_tmp}/open-${tmpfile} ] + #if [ -f ${g_tmp}/open-${tmpfile} ] + if [ -n "${f_open_trade}" ] then f_SELL="SELL ${f_ASSET}: End of file/data" echo "SELL: $(tail -n1 ${g_tmp}/${tmpfile} | cut -d, -f1) === ${f_SELL}" >>${g_tmp}/output-${tmpfile} 2>&1 @@ -140,7 +143,8 @@ function analyze { result=$(g_calc "${result}-${FEE}") echo "$result" >>${g_tmp}/result-${tmpfile} echo "RESULT: ${result}% (${BUY_PRICE} -> ${f_price})" >>${g_tmp}/output-${tmpfile} - rm -f ${g_tmp}/open-${tmpfile} + #rm -f ${g_tmp}/open-${tmpfile} + unset f_open_trade rm -f ${g_tmp}/interim-${tmpfile} fi diff --git a/dabo/functions/check_buy_conditions.sh b/dabo/functions/check_buy_conditions.sh index 4a53da7..8f5fd22 100644 --- a/dabo/functions/check_buy_conditions.sh +++ b/dabo/functions/check_buy_conditions.sh @@ -97,7 +97,8 @@ function check_buy_conditions { echo "BUY: ${f_BUY}" #echo "${csv_headline},Marketperformance #${f_last_line}" | cut -d, -f 2-22 | perl -pe 's/([0-9].[0-9][0-9][0-9][0-9][0-9][0-9])[0-9]+/$1/g' | perl -pe 's/((?<=,)|(?<=^)),/ ,/g;' | column -t -s, - echo "${f_echo_prefix}${f_BUY}" >${g_tmp}/open-${tmpfile} + f_open_trade=1 + #echo "${f_echo_prefix}${f_BUY}" >${g_tmp}/open-${tmpfile} BUY_PRICE=$f_price f_BUY="" fi