Showing posts with label Application programming interface. Show all posts
Showing posts with label Application programming interface. Show all posts

Wednesday, August 9, 2017

Bash (Unix shell): Converting Bitcoin Cash Amount to Yen

Command:

$ cat ./cryptocurrency_price_bittrex.sh


Result:

#!/bin/bash
if [ "$#" -ne 2 ]; then
echo "Usage: $0 PAIR AMOUNT" >&2
exit 1
fi

pair=$1;
amount=$2;
yenrate=$(curl -s "https://coincheck.com/api/rate/BTC_JPY" | python -c "import sys, json; print json.load(sys.stdin)['rate']");
curl -s "https://bittrex.com/api/v1.1/public/getticker?market=$pair" | python -c "import sys, json; print float(json.load(sys.stdin)['result']['Last']) * float(sys.argv[1]) * float(sys.argv[2])" $amount $yenrate


Command (How many Yen for 0.19 Bitcoin Cash):

$ ./cryptocurrency_price_bittrex.sh BTC-BCC 0.19


Result:

7461.446566

Monday, March 21, 2016