fix analyze.sh for multiple strategies

This commit is contained in:
olli 2023-05-10 09:29:53 +02:00
parent 12d1dc08bc
commit f59ce6054f
3 changed files with 63 additions and 24 deletions

View File

@ -186,6 +186,11 @@ Logs/Output:
docker compose logs -f docker compose logs -f
``` ```
Update:
```
git pull -f --all
```
dabo-bot.sh is the bot that trades and collects the quotes and analyze.sh is the tool with which you can try out strategies with the historical data. dabo-bot.sh is the bot that trades and collects the quotes and analyze.sh is the tool with which you can try out strategies with the historical data.
The configuration files are called dabo-bot.conf and analyze.conf. analyze.sh also uses bot.conf but its variables are overwritten by analyze.conf if duplicated. The configuration files are called dabo-bot.conf and analyze.conf. analyze.sh also uses bot.conf but its variables are overwritten by analyze.conf if duplicated.

View File

@ -1,6 +1,11 @@
# Default Config file for Dabo-Bot. Pleasse don't change! # Default Config file for Dabo-Bot. Pleasse don't change!
# Timeframe analyze should be run egrep Regex possible
ANALYZE_TIME="^2023-04-17" ANALYZE_TIME="^2023-04-17"
. bot.conf # Verbosity
ANALYZE_VERBOSE=0
# Run in batch mode and noch in parallel (usually only for debugging purposes)
ANALYZE_BATCH=0

View File

@ -16,14 +16,16 @@ function analyze {
tmpfile=$(basename "${file}") tmpfile=$(basename "${file}")
. /etc/bash/gaboshlib/g_percentage-diff.bashfunc . /etc/bash/gaboshlib/g_percentage-diff.bashfunc
. functions/check_buy_conditions.sh . dabo/functions/check_buy_conditions.sh
. functions/check_sell_conditions.sh . dabo/functions/check_sell_conditions.sh
. functions/get_vars_from_csv.sh . dabo/functions/get_vars_from_csv.sh
. dabo/dabo-bot.conf
. dabo-bot.conf . dabo-bot.conf
. dabo-bot.override.conf
. analyze.conf . analyze.conf
touch ${g_tmp}/output-${tmpfile}
tail -f ${g_tmp}/output-${tmpfile} &
#g_echo "Analyzing file: $file" #g_echo "Analyzing file: $file"
# cleanup # cleanup
@ -38,27 +40,38 @@ function analyze {
ORIGIFS="$IFS" ORIGIFS="$IFS"
IFS=$'\n' IFS=$'\n'
local f_strategy
for line in $(egrep "^${ANALYZE_TIME}" "$file") for line in $(egrep "^${ANALYZE_TIME}" "$file")
do do
IFS="$ORIGIFS" IFS="$ORIGIFS"
current=$(echo $line | cut -d, -f2) current=$(echo $line | cut -d, -f2)
time=$(echo $line | cut -d, -f1 | cut -d: -f1,2) time=$(echo $line | cut -d, -f1 | cut -d: -f1,2)
echo "$line" >>${g_tmp}/${tmpfile} echo "$line" >>${g_tmp}/${tmpfile}
if [ -f "${g_tmp}/open-${tmpfile}" ] if [ -f "${g_tmp}/open-${tmpfile}" ]
then then
check_sell_conditions ${g_tmp}/${tmpfile} >>${g_tmp}/output-${tmpfile} 2>&1 for f_strategy in $(find strategies -name "sell.*.conf" -type f)
do
if [ "${ANALYZE_VERBOSE}" -eq "0" ]
then
check_sell_conditions ${g_tmp}/${tmpfile} "${f_strategy}" >>${g_tmp}/output-${tmpfile} 2>&1
else
check_sell_conditions ${g_tmp}/${tmpfile} "${f_strategy}" 2>&1 | tee -a ${g_tmp}/output-${tmpfile}
fi
done
fi fi
if ! [ -f "${g_tmp}/open-${tmpfile}" ] if ! [ -f "${g_tmp}/open-${tmpfile}" ]
then then
f_market_performance=$(grep "^$time" htdocs/botdata/MARKET_PERFORMANCE | tail -n1 | cut -d: -f4 | cut -d"%" -f1 | sed 's/ *//') f_market_performance=$(grep "^$time" data/botdata/MARKET_PERFORMANCE | tail -n1 | cut -d: -f4 | cut -d"%" -f1 | sed 's/ *//')
[ -z "${f_market_performance}" ] && continue [ -z "${f_market_performance}" ] && continue
if [ $(echo "${f_market_performance} < ${GOOD_MARKET_PERFORMANCE_INDEX}" | bc -l) -eq 0 ] for f_strategy in $(find strategies -name "buy.*.conf" -type f)
then do
check_buy_conditions ${g_tmp}/${tmpfile} >>${g_tmp}/output-${tmpfile} 2>&1 || break if [ "${ANALYZE_VERBOSE}" -eq "0" ]
else then
g_echo_note "bad market (${f_market_performance} < ${GOOD_MARKET_PERFORMANCE_INDEX}) - Price: $current" >>${g_tmp}/output-${tmpfile} 2>&1 check_buy_conditions ${g_tmp}/${tmpfile} "${f_strategy}" >>${g_tmp}/output-${tmpfile} 2>&1 || break
fi else
( check_buy_conditions ${g_tmp}/${tmpfile} "${f_strategy}" 2>&1 || break ) | tee -a ${g_tmp}/output-${tmpfile}
fi
done
fi fi
done done
@ -88,26 +101,42 @@ function analyze {
} }
. bot.conf . dabo/dabo-bot.conf
. dabo-bot.conf
. analyze.conf . analyze.conf
set | grep ^[A-Z].*=[-0-9] set | grep ^[A-Z].*=[-0-9]
cores=$(cat /proc/cpuinfo | grep "^processor.*:" | tail -n1 | perl -pe 's/processor.*: //') if [ "${ANALYZE_BATCH}" -eq "0" ]
echo -n "parallel -j${cores} bash -c --" >/tmp/parallel-$$ then
cores=$(cat /proc/cpuinfo | grep "^processor.*:" | tail -n1 | perl -pe 's/processor.*: //')
echo -n "parallel -j${cores} bash -c --" >/tmp/parallel-$$
fi
analyzedate="$(date +%Y-%m-%d--%H-%M-%S)" analyzedate="$(date +%Y-%m-%d--%H-%M-%S)"
mkdir "analyze-${analyzedate}" mkdir "analyze-${analyzedate}"
cp bot.conf analyze.conf analyze-${analyzedate}/ cp dabo-bot.conf analyze.conf analyze-${analyzedate}/
cp -r strategies analyze-${analyzedate}/
for file in $@ for file in $@
do do
echo "${file}" | grep -q "BALANCE" && continue echo "${file}" | grep -q "BALANCE" && continue
echo -n " \"analyze ${file}\"" >>/tmp/parallel-$$ if [ "${ANALYZE_BATCH}" -eq "0" ]
then
echo -n " \"analyze ${file}\"" >>/tmp/parallel-$$
else
analyze ${file}
fi
done done
export -f g_echo_note
export g_tmp if [ "${ANALYZE_BATCH}" -eq "0" ]
export analyzedate then
. /tmp/parallel-$$ export -f g_echo_note
export g_tmp
export analyzedate
. /tmp/parallel-$$
fi
echo "OVERALL RESULT: $(cat ${g_tmp}/overall-result-* | awk '{ SUM += $1 } END { printf("%2.2f", SUM) }')%" | tee analyze-${analyzedate}/overall-result.log 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 cat analyze-${analyzedate}/*.history.csv.log >analyze-${analyzedate}/analyze-overall.log