Skip to content

Instantly share code, notes, and snippets.

@markhu
Created January 23, 2018 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markhu/2ea97bb7023c7c702b670df0ee33e4f2 to your computer and use it in GitHub Desktop.
Save markhu/2ea97bb7023c7c702b670df0ee33e4f2 to your computer and use it in GitHub Desktop.
finds best and worst cryptocurrency performers according to coinmarketcap.com
#!/bin/bash
# coin-performers.sh
# finds best and worst cryptocurrency performers according to coinmarketcap.com
# quick hacky bash script could use refactoring into Python or something...
window=${1:-"[1-9]+[dh]"}
now=$(date +%s)
# cache the top 100
curl -s "https://api.coinmarketcap.com/v1/ticker/" | jq '.[]' > /tmp/coinz-$now.json
echo 'curl -s "https://api.coinmarketcap.com/v1/ticker/" | grep $1' " # ($window)"
# find best and worst
best=$(egrep "percent_change_${window}\": ?\"[0-9]{1,3}" /tmp/coinz-$now.json \
| egrep -o '[0-9]{1,5}\.[0-9]{1,2}' | sort -rn | head -n1)
worst=$(egrep "percent_change_${window}\": ?\"-?[0-9]{1}" /tmp/coinz-$now.json \
| egrep -o '\-?[0-9]{1,5}\.[0-9]{1,2}' | sort -n | head -n1)
echo "best: $best and worst: $worst (percent) as of $now" | egrep "$best|$worst" --color
# record details on best and worst
# jq . -c /tmp/coinz-$now.json | egrep "\"$best\"|\"$worst\"" | jq .
jq . -c /tmp/coinz-$now.json | egrep "\"$best\"" | jq . > /tmp/coinz-$now-best
jq . -c /tmp/coinz-$now.json | egrep "\"$worst\"" | jq . > /tmp/coinz-$now-worst
best_id=$(jq .id --raw-output /tmp/coinz-$now-best)
worst_id=$(jq .id --raw-output /tmp/coinz-$now-worst)
best_name=$(jq .name /tmp/coinz-$now-best)
worst_name=$(jq .name /tmp/coinz-$now-worst)
best_symbol=$(jq .symbol /tmp/coinz-$now-best)
worst_symbol=$(jq .symbol /tmp/coinz-$now-worst)
# compare details on best and worst
diff -y /tmp/coinz-$now-best /tmp/coinz-$now-worst --width=80 \
| egrep "$best|$worst|$best_name|$worst_name|$best_symbol|$worst_symbol" -C8 --color=always \
| egrep '^ ' | sort | uniq
# clickable links
echo "https://coinmarketcap.com/currencies/$best_id/"
echo "https://coinmarketcap.com/currencies/$worst_id/"
# $ topGrowth=$(curl -s "https://api.coinmarketcap.com/v1/ticker/" | egrep 'percent_change_[1-9]+[dh]": ?"[0-9]{3}' | egrep -o '[0-9]{3,5}\...' | sort -rn | head -n1) ; echo $topGrowth
# $ botGrowth=$(curl -s "https://api.coinmarketcap.com/v1/ticker/" | egrep 'percent_change_[1-9]+[dh]": ?"-?[0-9]{1}' | egrep -o '\-?[0-9]{1,5}\...' | sort -n | head -n1) ; echo $botGrowth
# $ curl -s "https://api.coinmarketcap.com/v1/ticker/" | jq '.[]' -c | egrep "$topGrowth|$botGrowth|RPX" | jq .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment