#!/bin/bash . /etc/bash/gaboshlib.include g_nice function g_echo_note { [ -z "$1" ] && return 0 echo -en "\033[97m$(tail -n1 ${g_tmp}/$tmpfile | cut -d, -f1) \033[36mNOTE:" cat <<< "$@" echo -en "\033[0m" } function analyze { local file=$1 tmpfile=$(basename "${file}") . /etc/bash/gaboshlib/g_percentage-diff.bashfunc . functions/check_buy_conditions.sh . functions/check_sell_conditions.sh . functions/get_vars_from_csv.sh . bot.conf . analyze.conf #g_echo "Analyzing file: $file" # cleanup f_SELL=1 f_BUY="" >${g_tmp}/${tmpfile} >${g_tmp}/result-${tmpfile} rm -f ${g_tmp}/open-${tmpfile} rm -f ${g_tmp}/interim-${tmpfile} rm -f ${g_tmp}/output-${tmpfile} ORIGIFS="$IFS" IFS=$'\n' for line in $(egrep "^${ANALYZE_TIME}" "$file") do IFS="$ORIGIFS" current=$(echo $line | cut -d, -f2) time=$(echo $line | cut -d, -f1 | cut -d: -f1,2) echo "$line" >>${g_tmp}/${tmpfile} if [ -f "${g_tmp}/open-${tmpfile}" ] then check_sell_conditions ${g_tmp}/${tmpfile} >>${g_tmp}/output-${tmpfile} 2>&1 fi if ! [ -f "${g_tmp}/open-${tmpfile}" ] then f_market_performance=$(grep "^$time" htdocs/botdata/MARKET_PERFORMANCE | tail -n1 | cut -d: -f4 | cut -d"%" -f1 | sed 's/ *//') [ -z "${f_market_performance}" ] && continue if [ $(echo "${f_market_performance} < ${GOOD_MARKET_PERFORMANCE_INDEX}" | bc -l) -eq 0 ] then check_buy_conditions ${g_tmp}/${tmpfile} >>${g_tmp}/output-${tmpfile} 2>&1 || break else g_echo_note "bad market (${f_market_performance} < ${GOOD_MARKET_PERFORMANCE_INDEX}) - Price: $current" >>${g_tmp}/output-${tmpfile} 2>&1 fi fi done # sell at the end to have a final result. if [ -f ${g_tmp}/open-${tmpfile} ] 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 result=$(g_percentage-diff ${BUY_PRICE} ${current}) result=$(echo "${result}-${FEE}" | bc | sed 's/^\./0./; s/^-\./-0./') echo "$result" >>${g_tmp}/result-${tmpfile} echo "RESULT: ${result}% (${BUY_PRICE} -> ${current})" >>${g_tmp}/output-${tmpfile} rm -f ${g_tmp}/open-${tmpfile} rm -f ${g_tmp}/interim-${tmpfile} fi complete_result=0 for result in $(cat ${g_tmp}/result-${tmpfile}) do complete_result=$(echo "$complete_result+$result" | bc -l | sed 's/^\./0./; s/^-\./-0./' | xargs printf "%.2f") done echo "COMPLETE RESULT $file analyze-${analyzedate}/${tmpfile}.log: ${complete_result}%" | tee -a ${g_tmp}/output-${tmpfile} echo "=====================================" >>${g_tmp}/output-${tmpfile} echo "${complete_result}" >>${g_tmp}/overall-result-${tmpfile} cat ${g_tmp}/output-${tmpfile} >"analyze-${analyzedate}/${tmpfile}.log" } . bot.conf . analyze.conf set | grep ^[A-Z].*=[-0-9] cores=$(cat /proc/cpuinfo | grep "^processor.*:" | tail -n1 | perl -pe 's/processor.*: //') echo -n "parallel -j${cores} bash -c --" >/tmp/parallel-$$ analyzedate="$(date +%Y-%m-%d--%H-%M-%S)" mkdir "analyze-${analyzedate}" cp bot.conf analyze.conf analyze-${analyzedate}/ for file in $@ do echo "${file}" | grep -q "BALANCE" && continue echo -n " \"analyze ${file}\"" >>/tmp/parallel-$$ done export -f g_echo_note export g_tmp export analyzedate . /tmp/parallel-$$ echo "OVERALL RESULT: $(cat ${g_tmp}/overall-result-* | awk '{ SUM += $1 } END { printf("%2.2f", SUM) }')%" | tee analyze-${analyzedate}/overall-result.log cat analyze-${analyzedate}/*.history.csv.log >analyze-${analyzedate}/analyze-overall.log echo Trades: "$(grep "BUY: " analyze-${analyzedate}/analyze-overall.log | wc -l)" | tee -a analyze-${analyzedate}/overall-result.log echo Interim Results: "$(grep "INTERIM RESULT: " analyze-${analyzedate}/analyze-overall.log | wc -l)" | tee -a analyze-${analyzedate}/overall-result.log echo Interim Results Positive: "$(grep "INTERIM RESULT: [0-9]" analyze-${analyzedate}/analyze-overall.log | wc -l)" | tee -a analyze-${analyzedate}/overall-result.log echo Interim Results Negative: "$(grep "INTERIM RESULT: -" analyze-${analyzedate}/analyze-overall.log | wc -l)" | tee -a analyze-${analyzedate}/overall-result.log echo " Complete Results" >>analyze-${analyzedate}/overall-result.log grep "COMPLETE RESULT " analyze-${analyzedate}/analyze-overall.log | grep -v ": 0%" >>analyze-${analyzedate}/overall-result.log echo " Trades" >>analyze-${analyzedate}/overall-result.log egrep "BUY: |SELL: " analyze-${analyzedate}/analyze-overall.log >>analyze-${analyzedate}/overall-result.log