more pure bash to speed up things

This commit is contained in:
olli 2023-11-15 16:50:59 +01:00
parent b0cd49db41
commit f119372daa
3 changed files with 13 additions and 149 deletions

View File

@ -63,13 +63,21 @@ function analyze {
f_market_performace_array[${f_market_perf_date}]=${f_market_perf} f_market_performace_array[${f_market_perf_date}]=${f_market_perf}
done done
# go through data of time
local f_lines local f_lines
mapfile -t f_lines <<<$(egrep "^${ANALYZE_TIME}" "$file" | grep -v ',,') mapfile -t f_lines <<<$(egrep "^${ANALYZE_TIME}" "$file" | grep -v ',,')
for line in "${f_lines[@]}" local f_line
# for line in "${f_lines[@]}"
for f_line in "${f_lines[@]}"
do do
f_sell_score="" f_sell_score=""
f_buy_score="" f_buy_score=""
# ad line to last lines array...
f_last_lines_array+=("${f_line}")
# ... and stop here until 4 elements are present
[ -z "${f_last_lines_array[3]}" ] && continue
echo "$line" >>${g_tmp}/${tmpfile} echo "$line" >>${g_tmp}/${tmpfile}
# get vars # get vars
get_vars_from_csv ${g_tmp}/${tmpfile} || continue get_vars_from_csv ${g_tmp}/${tmpfile} || continue
@ -85,8 +93,7 @@ function analyze {
f_market_performance_before=${f_market_performance} f_market_performance_before=${f_market_performance}
echo "MARKET_PERF=$f_market_performance" echo "MARKET_PERF=$f_market_performance"
#echo "$line" >>${g_tmp}/${tmpfile} #echo " ${f_line},${f_market_performance}" | perl -pe 's/([0-9].[0-9][0-9][0-9][0-9][0-9][0-9])[0-9]+/$1/g' | column -t -s, >>${g_tmp}/output-${tmpfile}
#echo " ${line},${f_market_performance}" | perl -pe 's/([0-9].[0-9][0-9][0-9][0-9][0-9][0-9])[0-9]+/$1/g' | column -t -s, >>${g_tmp}/output-${tmpfile}
if [ -f "${g_tmp}/open-${tmpfile}" ] if [ -f "${g_tmp}/open-${tmpfile}" ]
then then
if [ "${ANALYZE_VERBOSE}" -eq "0" ] if [ "${ANALYZE_VERBOSE}" -eq "0" ]
@ -122,7 +129,7 @@ function analyze {
f_interim=$(g_calc "${f_interim}-${FEE}") f_interim=$(g_calc "${f_interim}-${FEE}")
fi fi
fi fi
echo "$line,${f_market_performance},${f_score},${f_buy_score},${f_sell_score},${f_intrade},${f_interim}" >>analyze-${analyzedate}/chart-${tmpfile} 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 # Chart Part End
done done

View File

@ -28,7 +28,7 @@ function check_sell_conditions {
f_TRADE_HIST_FILE_INTERIM=$(echo ${f_TRADE_HIST_FILE} | sed 's/-open\.history\.csv$/-interim.history.csv/') f_TRADE_HIST_FILE_INTERIM=$(echo ${f_TRADE_HIST_FILE} | sed 's/-open\.history\.csv$/-interim.history.csv/')
f_BUY_PRICE=$(grep -i ',BUY,' $f_TRADE_HIST_FILE | tail -n1 | cut -d, -f5) f_BUY_PRICE=$(grep -i ',BUY,' $f_TRADE_HIST_FILE | tail -n1 | cut -d, -f5)
else else
# analyze # analyze
f_BUY_PRICE=${BUY_PRICE} f_BUY_PRICE=${BUY_PRICE}
f_TRADE_HIST_FILE="${g_tmp}/open-${tmpfile}" f_TRADE_HIST_FILE="${g_tmp}/open-${tmpfile}"
f_TRADE_HIST_FILE_INTERIM="${g_tmp}/interim-${tmpfile}" f_TRADE_HIST_FILE_INTERIM="${g_tmp}/interim-${tmpfile}"
@ -120,32 +120,6 @@ function check_sell_conditions_strategy {
local f_BUY_PRICE="$5" local f_BUY_PRICE="$5"
local f_BUY_PRICE_LAST_RATE_DIFF="$6" local f_BUY_PRICE_LAST_RATE_DIFF="$6"
########## Obsolete Code #############
#
# # never occur rsi defaults to suppress error messages if no values from strategy given
# local SELL_RSI5_SIGNAL_UNTIL="0"
# local SELL_RSI14_SIGNAL_UNTIL="0"
# local SELL_RSI21_SIGNAL_UNTIL="0"
# local SELL_RSI60_SIGNAL_UNTIL="0"
# local SELL_RSI120_SIGNAL_UNTIL="0"
# local SELL_RSI240_SIGNAL_UNTIL="0"
# local SELL_RSI420_SIGNAL_UNTIL="0"
# local SELL_RSI720_SIGNAL_UNTIL="0"
# local SELL_RSI5_SIGNAL_FROM="101"
# local SELL_RSI14_SIGNAL_FROM="101"
# local SELL_RSI21_SIGNAL_FROM="101"
# local SELL_RSI60_SIGNAL_FROM="101"
# local SELL_RSI120_SIGNAL_FROM="101"
# local SELL_RSI240_SIGNAL_FROM="101"
# local SELL_RSI420_SIGNAL_FROM="101"
# local SELL_RSI720_SIGNAL_FROM="101"
#
# # never occur rsi defaults to suppress error messages if no values from strategy given
# local SELL_MACD_RELATION_FROM="-101"
#
# # default
# local SELL_HOLD_IF_RESULT_NEGATIVE="0"
f_do_sell="" f_do_sell=""
# run strategy # run strategy
@ -170,121 +144,4 @@ function check_sell_conditions_strategy {
return 0 return 0
fi fi
########## Obsolete Code #############
#
# # check if the result (profit/loss until now) is lowering and sell if too low ()
# if [ -f ${f_TRADE_HIST_FILE_INTERIM} ]
# then
# if [ -n "$SELL_IF_LAST_RATE_LOWER_THEN" ]
# then
# local f_BUY_PRICE_2ND_LAST_RATE_DIFF=$(tail -n2 ${f_TRADE_HIST_FILE_INTERIM} | head -n1)
# local f_diff_result=$(echo "${f_BUY_PRICE_LAST_RATE_DIFF} - (${f_BUY_PRICE_2ND_LAST_RATE_DIFF})" | bc | sed 's/^\./0./; s/^-\./-0./')
# if [ $(echo "${f_diff_result} < ${SELL_IF_LAST_RATE_LOWER_THEN}" | bc -l) -ne 0 ] && [ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} > ${FEE}" | bc -l) -ne 0 ]
# then
# f_SELL="Loss between last (${f_BUY_PRICE_LAST_RATE_DIFF}%) and 2nd last (${f_BUY_PRICE_2ND_LAST_RATE_DIFF}%) rate/result more then ${SELL_IF_LAST_RATE_LOWER_THEN}% (${f_diff_result}%)"
# fi
# fi
#
# if [ -n "$SELL_IF_LOWER_THEN_FEE_AFTER_PERIOD" ]
# then
# # Sell if the last X time units is lower then FEE
# if [ $(cat ${f_TRADE_HIST_FILE_INTERIM} | wc -l) -ge ${SELL_IF_LOWER_THEN_FEE_AFTER_PERIOD} ]
# then
# if [ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} < ${FEE}" | bc -l) -ne 0 ]
# then
# f_SELL="Result (${f_BUY_PRICE_LAST_RATE_DIFF}%) in more then ${SELL_IF_LOWER_THEN_FEE_AFTER_PERIOD} is under ${FEE}"
# fi
# fi
# fi
# fi
#
# # Sell on MACD Condition
# if [ -n "$SELL_MACD_RELATION_FROM" ]
# then
# if [ $(echo "${f_macd_histogram_relation} < ${SELL_MACD_RELATION_FROM}" | bc -l) -ne 0 ]
# then
# f_SELL="MACD condition met"
# fi
# fi
#
# # Sell on RSI conditions
# if \
# [ ${f_rsi5} -le ${SELL_RSI5_SIGNAL_UNTIL} ] && \
# [ ${f_rsi14} -le ${SELL_RSI14_SIGNAL_UNTIL} ] && \
# [ ${f_rsi21} -le ${SELL_RSI21_SIGNAL_UNTIL} ] && \
# [ ${f_rsi60} -le ${SELL_RSI60_SIGNAL_UNTIL} ] && \
# [ ${f_rsi120} -le ${SELL_RSI120_SIGNAL_UNTIL} ] && \
# [ ${f_rsi240} -le ${SELL_RSI240_SIGNAL_UNTIL} ] && \
# [ ${f_rsi420} -le ${SELL_RSI420_SIGNAL_UNTIL} ] && \
# [ ${f_rsi720} -le ${SELL_RSI720_SIGNAL_UNTIL} ]&& \
# [ ${f_rsi5} -ge ${SELL_RSI5_SIGNAL_FROM} ] && \
# [ ${f_rsi14} -ge ${SELL_RSI14_SIGNAL_FROM} ] && \
# [ ${f_rsi21} -ge ${SELL_RSI21_SIGNAL_FROM} ] && \
# [ ${f_rsi60} -ge ${SELL_RSI60_SIGNAL_FROM} ] && \
# [ ${f_rsi120} -ge ${SELL_RSI120_SIGNAL_FROM} ] && \
# [ ${f_rsi240} -ge ${SELL_RSI240_SIGNAL_FROM} ] && \
# [ ${f_rsi420} -ge ${SELL_RSI420_SIGNAL_FROM} ] && \
# [ ${f_rsi720} -ge ${SELL_RSI720_SIGNAL_FROM} ]
# then
# f_SELL="RSI conditions met"
# fi
#
#
# # Take profit after positive results
# if [ -n "${TAKE_PROFIT_CHECK_AFTER_POSTITIVE_RESULTS}" ] && [ -n "${TAKE_PROFIT_CHECK_AT_FEE_PLUS}" ] && [ -n "${TAKE_PROFIT_CHECK_AT_FACTOR}" ]
# then
# if [ $(grep -v "^-" ${f_TRADE_HIST_FILE_INTERIM} | wc -l) -ge ${TAKE_PROFIT_CHECK_AFTER_POSTITIVE_RESULTS} ]
# then
# # Only if result larger then fee
# if [ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} > (${FEE}+${TAKE_PROFIT_CHECK_AT_FEE_PLUS})" | bc -l) -ne 0 ]
# then
# # Take profit if interim result falls over 20% (/1.25) from the highest result
# local f_highest_profit=$(grep -v "^-" ${f_TRADE_HIST_FILE_INTERIM} | LANG=en_US.UTF-8 sort -n | tail -n1)
# local f_take_profit=$(echo "${f_highest_profit} / ${TAKE_PROFIT_CHECK_AT_FACTOR}" | bc -l)
# [ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} < ${f_take_profit}" | bc -l) -ne 0 ] && f_SELL="taking profit"
# fi
# fi
# fi
#
#
# # Take loss
# if [ -n "${TAKE_LOSS_CHECK_AFTER_NEGATIVE_RESULTS}" ] && [ -n "${TAKE_LOSS_CHECK_AT_FEE_PLUS}" ] && [ -n "${TAKE_LOSS_CHECK_AT_FACTOR}" ]
# then
# if [ $(tail -n${TAKE_LOSS_CHECK_AFTER_NEGATIVE_RESULTS} ${f_TRADE_HIST_FILE_INTERIM} | grep "^-" | wc -l) -ge ${TAKE_LOSS_CHECK_AFTER_NEGATIVE_RESULTS} ]
# then
# # if result larger then fee
# if [ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} > (${FEE}+${TAKE_LOSS_CHECK_AT_FEE_PLUS})" | bc -l) -ne 0 ]
# then
# f_SELL="taking profit by loss before"
# else
# # on loss
# local f_highest_loss=$(grep "^-" ${f_TRADE_HIST_FILE_INTERIM} | LANG=en_US.UTF-8 sort -n | head -n1)
# local f_take_loss=$(echo "${f_highest_loss} / ${TAKE_LOSS_CHECK_AT_FACTOR}" | bc -l)
# [ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} > ${f_take_loss}" | bc -l) -ne 0 ] && f_SELL="taking loss"
# fi
# fi
# fi
#
#
#
# # hold on negative result
# if [ "${SELL_HOLD_IF_RESULT_NEGATIVE}" -gt 0 ]
# then
# if [ $(echo "(${f_BUY_PRICE_LAST_RATE_DIFF} + -${FEE}) < 0" | bc -l) -ne 0 ]
# then
# echo " Result negative - holding (INTERIM RESULT ${f_BUY_PRICE_LAST_RATE_DIFF}% - FEE ${FEE}% < 0 --> Ignoring ${f_SELL}"
# f_SELL=""
# fi
# fi
#
#
# # check for SELL_PERCENTAGE_FROM_LAST_PURCHASE_NEGATIVE
# if [ -n "${SELL_PERCENTAGE_FROM_LAST_PURCHASE_NEGATIVE}" ]
# then
# if [ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} < ${SELL_PERCENTAGE_FROM_LAST_PURCHASE_NEGATIVE}" | bc -l) -ne 0 ]
# then
# f_SELL="SELL_PERCENTAGE_FROM_LAST_PURCHASE_NEGATIVE(${SELL_PERCENTAGE_FROM_LAST_PURCHASE_NEGATIVE}%) > Last rate (${f_BUY_PRICE_LAST_RATE_DIFF}%)"
# fi
# fi
} }

View File

@ -12,7 +12,7 @@ function get_vars_from_csv {
f_market_performance="-50" f_market_performance="-50"
fi fi
f_all_vars="f_market_performance=${f_market_performance}" f_all_vars="f_market_performance=${f_market_performance}"
# read last 4 lines in array if not given # read last 4 lines in array if not given
if [ -z "${f_last_lines_array}" ] if [ -z "${f_last_lines_array}" ]
then then