summaryrefslogtreecommitdiff
path: root/bin/xchg.buy
diff options
context:
space:
mode:
authorepochqwert <epoch@hacking.allowed.org>2018-12-19 19:33:37 +0000
committerepochqwert <epoch@hacking.allowed.org>2018-12-19 19:33:37 +0000
commit36f7747780ea5f459e17f34c42d646abff6e6dbc (patch)
treea72a0c3f6fa918323b37bff7da047c08a8bdb9a4 /bin/xchg.buy
parentff822dd2295faa2e3fce3fe2bde391c5a1ad53e7 (diff)
downloadsegfault_home-36f7747780ea5f459e17f34c42d646abff6e6dbc.tar.gz
segfault_home-36f7747780ea5f459e17f34c42d646abff6e6dbc.zip
updated scripts, and xchg stuff added
Diffstat (limited to 'bin/xchg.buy')
-rwxr-xr-xbin/xchg.buy89
1 files changed, 89 insertions, 0 deletions
diff --git a/bin/xchg.buy b/bin/xchg.buy
new file mode 100755
index 0000000..a0a3a8a
--- /dev/null
+++ b/bin/xchg.buy
@@ -0,0 +1,89 @@
+#!/usr/bin/env bash
+nick=$1
+amount=$2
+target=$3
+source=$4
+if [ "$nick" = "" ];then
+ echo missing argument for nick
+ exit 1
+fi
+if [ ! -d /var/cache/segfault/xchg/$nick/ ];then
+ /home/segfault/bin/xchg.init $nick
+fi
+if [ "$amount" = "" ];then
+ echo missing argument for amount
+ exit 1
+fi
+if [ "$target" = "" ];then
+ echo missing argument for target currency
+ exit 1
+fi
+if [ "$source" = "" ];then
+ echo missing argument for source currency
+ exit 1
+fi
+
+rate=1
+
+#if [ $target != BTC ];then
+# rate2=$(/home/segfault/bin/xchg.getrate $target)
+# if [ "$rate2" = "null" ];then
+# echo "invalid currency type $target used"
+# exit 1
+# fi
+# rate=$(echo | awk "{print $rate / $rate2}")
+#fi
+
+#if [ $source != BTC ];then
+# rate2=$(/home/segfault/bin/xchg.getrate $source)
+# if [ "$rate2" = "null" ];then
+# echo "invalid currency type $source used"
+# exit 1
+# fi
+# rate=$(echo | awk "{print $rate * $rate2}")
+#fi
+
+rate=$(/home/segfault/bin/xchg.getdoublerate $source $target)
+
+walletsrc=$(cat /var/cache/segfault/xchg/$nick/$source 2>&-)
+walletdst=$(cat /var/cache/segfault/xchg/$nick/$target 2>&-)
+
+if [ "$walletsrc" = "" ];then
+ walletsrc=0
+fi
+if [ "$walletdst" = "" ];then
+ walletdst=0
+fi
+
+### if other types of ways of specifying how much are added, remember to set both srcamt and amount.
+if [ $amount = "all" ];then
+ amount="100%"
+fi
+if grep '%' <<< "$amount" 2>&1 > /dev/null;then
+ percentage="$(printf "%s\n" "$amount" | tr -cd '0-9.')"
+ srcamt="$(echo | awk "{print ($percentage / 100) * $walletsrc}")"
+ amount=$(echo | awk "{print $srcamt / $rate}")
+else
+ srcamt=$(echo | awk "{print $amount * $rate}")
+fi
+
+if [ "$srcamt" = "" ];then
+ srcamt=0
+fi
+
+echo trying to buy $amount of $target for $srcamt $source...
+
+
+postwalletsrc=$(echo | awk "{print $walletsrc - $srcamt}")
+
+if printf "%s\n" $postwalletsrc | grep ^- 2>&1 > /dev/null;then
+ echo you, $1, would need to have $srcamt $source to buy $amount $target. you only have $walletsrc $source.
+ exit 1
+fi
+
+### if we got here we have enough money... guess make the purchase
+#echo updating your source wallet...
+echo $(echo | awk "{print $walletsrc - $srcamt}") > /var/cache/segfault/xchg/$nick/$source
+#echo updating your target wallet...
+echo $(echo | awk "{print $walletdst + $amount}") > /var/cache/segfault/xchg/$nick/$target
+echo done