Skip to content

Instantly share code, notes, and snippets.

@donpdonp
Last active August 11, 2020 17:43
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 donpdonp/8514501eb0a7acbd0752c619f2583ebf to your computer and use it in GitHub Desktop.
Save donpdonp/8514501eb0a7acbd0752c619f2583ebf to your computer and use it in GitHub Desktop.
coincap.io coin price lookup
#!/bin/bash
if [ -z "$1" ];
then
COINS=`cat ~/.coins`
PARAM="ids=$COINS"
else
echo $1
PARAM="search=$1"
fi
DATA=`curl --silent "https://api.coincap.io/v2/assets?$PARAM"`
echo "$DATA" | jq -r 'def leftpad(str; len): str + (" " * (len - (str|length)));
def numpad(str; dec; frac): (str|index(".")) as $dot | " " * (dec-$dot) + str[0:$dot+frac+1];
def longest(path): map(path|length) | max;
def biggest(path): map(path | index(".")) | max;
.data | longest(.symbol) as $sym_max |
longest(.id) as $id_max |
biggest(.priceUsd) as $price_max |
.[] |
[leftpad(.symbol; $sym_max),
leftpad(.id; $id_max),
"$" + numpad(.priceUsd; $price_max; 5)
]
| join (" ")'
$ cat ~/.coins
bitcoin,ethereum
$ coin
bitcoin,ethereum
BTC bitcoin $11540.53330
ETH ethereum $ 386.07154
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment