Last active
December 7, 2017 16:12
-
-
Save lu1s/a89f134bb2c8c89acb404956d379ba91 to your computer and use it in GitHub Desktop.
Run this script to get updated BTC price in MXN pesos. If it raises it prints green, if lowers, red, and if stays the same it won't print until it gets a new one. It requires python to parse the json response. It checks every 3 seconds.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function get_json_val () { | |
python -c "import json,sys;sys.stdout.write(json.dumps(json.load(sys.stdin)$1))"; | |
} | |
function print_red () { | |
printf "\033[0;31m$1\033[0m" | |
echo "" | |
} | |
function print_green () { | |
printf "\033[0;32m$1\033[0m" | |
echo "" | |
} | |
function ticker () { | |
curl -s "https://api.bitso.com/v3/ticker/?book=btc_mxn" > bitcoin_response.json | |
LAST_LAST=$(cat bitcoin_response.json | get_json_val "['payload']['last']") | |
LAST_LAST=$(sed -e 's/^"//' -e 's/"$//' <<<"$LAST_LAST") | |
print_green $LAST_LAST | |
sleep 3000 | |
while true; do | |
curl -s "https://api.bitso.com/v3/ticker/?book=btc_mxn" > bitcoin_response.json | |
TIMESTAMP=$(cat bitcoin_response.json | get_json_val "['payload']['created_at']") | |
LAST=$(cat bitcoin_response.json | get_json_val "['payload']['last']") | |
LAST=$(sed -e 's/^"//' -e 's/"$//' <<<"$LAST") | |
if (( $(echo "$LAST > $LAST_LAST" |bc -l) )); then | |
print_green $LAST | |
fi | |
if (( $(echo "$LAST < $LAST_LAST" |bc -l) )); then | |
print_red $LAST | |
fi | |
LAST_LAST=$LAST | |
sleep 3000 | |
done | |
} | |
ticker |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment