From dce1494ec8ab1236105c6c62e584ff969bb6eaba Mon Sep 17 00:00:00 2001
From: Arne Baeumler <arne@br0tkasten.de>
Date: Tue, 27 Oct 2020 09:34:12 +0100
Subject: [PATCH] update script output

---
 scripts/cryptoAnalyze.sh | 50 +++++++++++++++++++++++++---------------
 1 file changed, 32 insertions(+), 18 deletions(-)

diff --git a/scripts/cryptoAnalyze.sh b/scripts/cryptoAnalyze.sh
index ebf163f..b285938 100755
--- a/scripts/cryptoAnalyze.sh
+++ b/scripts/cryptoAnalyze.sh
@@ -2,36 +2,50 @@
 
 HOUR=$(date +%H)
 IFS=";"
-while read DATE CURRENCY COIN PRICE FEE BUYRATE;
+while read DATE CURRENCY COIN PRICE FEE BUYRATE SELLTHRESH;
 do
 	weeklyMax=$(rrdtool fetch rrd/crypto-${CURRENCY}.rrd AVERAGE --start -7d | grep -v -- '-nan' | sort -n -k 2 | tail -1 | awk '{print $2}' | sed 's/e+/ * 10^/g; s/e-/ * 10^-/g;' | bc -l)
 	current=$(rrdtool fetch rrd/crypto-${CURRENCY}.rrd LAST --start -10m | grep -v -- '-nan' | tail -1 | awk '{print $2}' | sed 's/e+/ * 10^/g; s/e-/ * 10^-/g' | bc -l)
-	curValue=$(echo "$COIN * $current - $FEE" | bc)
+	curValue=$(echo "$COIN * $current - $FEE" | bc -l)
 	curProfit=$(printf "%0.2f" $(echo "$curValue - $PRICE" | bc))
-	maxDiff=$(echo "(($weeklyMax) - ($current)) / ($weeklyMax) * 100" | bc)
+	profitPerc=$(printf "%0.2f" $(echo "$curProfit / $PRICE * 100" | bc -l))
+	maxDiff=$(printf "%0.2f" $(echo "(($weeklyMax) - ($current)) / ($weeklyMax) * 100" | bc -l))
 
-	if [ "$CURRENCY" == "BTC" ] && [ "${current%%.*}" -lt "5000" ];
+	if [ "$CURRENCY" == "BTC" ] && [ "${current%%.*}" -lt "7000" ];
 	then
-		echo "[$CURRENCY] low exchange rate: $current EUR/${CURRENCY}\n  => Buy more?"
-		continue;	
-	fi
-
-	if [ "${maxDiff%%.*}" -gt "10" ];
-	then
-		echo "[$CURRENCY] exchange rate dropps by more than 10% (max: $weeklyMax EUR/${CURRENCY}, cur: $current EUR/${CURRENCY})\n  => Buy more?"
+		echo "[$CURRENCY] low exchange rate: $current EUR/${CURRENCY} => Buy more?"
 		continue;
 	fi
 
-	if [ "0${maxDiff%%.*}" -gt "3" ];
+	if [ "${profitPerc%%.*}" -ge "$SELLTHRESH" ];
 	then
-		echo "[$CURRENCY] prices dropping by more than 3% (max: $weeklyMax, cur: $current)"
-		if [ "0$curProfit" -gt "0" ];
-		then
-			echo "[$CURRENCY] profit: $curProfit EUR\n  => sell?"
-		fi
+		echo "[$CURRENCY] profit: ${profitPerc}% >= ${SELLTHRESH}% !!!!"
+		echo "[$CURRENCY] profit: $curProfit EUR (${profitPerc}%)"
+		echo "[$CURRENCY] maxDiff: ${maxDiff}%"
+		echo
+		continue
 	fi
+
+#	if [ "0${maxDiff%%.*}" -ge "10" ];
+#	then
+#		echo "[$CURRENCY] exchange rate dropped ${maxDiff}% (max: $weeklyMax EUR/${CURRENCY}, cur: $current EUR/${CURRENCY}) => Buy more?"
+#		continue;
+#	fi
+#
+#	if [ "0${maxDiff%%.*}" -gt "3" ];
+#	then
+#		echo "[$CURRENCY] prices dropped ${maxDiff}% (max: $weeklyMax EUR/${CURRENCY}, cur: $current EUR/${CURRENCY})"
+#		if [ "0${profitPerc%%.*}" -ge "10" ];
+#		then
+#			echo "[$CURRENCY] profit: $curProfit EUR (${profitPerc}%) => sell?"
+#			continue;
+#		fi
+#	fi
+
 	if [ "0$HOUR" -eq "6" ];
 	then
-		echo "[$CURRENCY] profit: $curProfit EUR"
+		echo "[$CURRENCY] profit: $curProfit EUR (${profitPerc}%)"
+		echo "[$CURRENCY] maxDiff: ${maxDiff}%"
+		echo
 	fi
 done < $1