Skip to content

Instantly share code, notes, and snippets.

@schmichael
Created January 17, 2018 00:10
Show Gist options
  • Save schmichael/682b2016116f76097cf8bf7690c63225 to your computer and use it in GitHub Desktop.
Save schmichael/682b2016116f76097cf8bf7690c63225 to your computer and use it in GitHub Desktop.
#!/bin/bash
GREEN="\u001b[32m"
RED="\u001b[31m"
NC="\u001b[0m"
URL=https://api.coinmarketcap.com/v1/ticker/?limit=50
FAV="\"ETH\", \"BTC\", \"BCH\""
JQ=' def pad(s; n): (n - (s|length)) * " ";
def lpad(s; n): pad(s; n) + s;
def rpad(s; n): s + pad(s;n);
def color(s): if (s|tonumber < 0) then "'$RED'" else "'$GREEN'" end;
map(select([.symbol] | inside(['"$FAV"'])))
| .[]
| [ ((2 - (.rank | length)) * "0") + .rank,
lpad(.symbol; 4),
rpad(.name;25),
color(.percent_change_24h) + "$" + rpad(.price_usd; 10) + "'$NC'",
color(.percent_change_1h) + lpad(.percent_change_1h; 6) + "%'$NC'",
color(.percent_change_24h) + lpad(.percent_change_24h; 6) + "%'$NC'",
color(.percent_change_7d) + lpad(.percent_change_7d; 6) + "%'$NC'"]
| join (" ")'
curl --silent $URL | jq -r "$JQ"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment