btc-returns (647B)
1 #!/usr/bin/env bash 2 3 spend=$1 4 low=$2 5 high=$3 6 7 if [ -z "$spend" ] || [ -z "$low" ] || [ -z "$high" ] 8 then 9 printf 'usage: btc-returns <spend> <low> <high>\n' 10 exit 1 11 fi 12 13 cad=$(curl -sL 'https://api.quadrigacx.com/v2/ticker' | jq -r .last &) 14 printf 'current price %s CAD\n' "$cad" 15 16 # buy 17 btc=$(bcalc --price "$low" "$spend" fiat to btc) 18 printf 'spend %s @ %s CAD of btc -> %s\n' "$spend" "$low" "$btc" 19 20 fiat_profit=$(echo "$(bcalc -n --price "$high" "$btc" to fiat) - $low" | bc -l) 21 22 btc_profit=$(bcalc --price "$high" "$fiat_profit" fiat to btc) 23 24 printf '\nfiat profit %s, btc profit %s @ %s CAD/BTC\n' "$fiat_profit" \ 25 "$btc_profit" "$high" 26