Last active
August 11, 2020 17:43
-
-
Save donpdonp/8514501eb0a7acbd0752c619f2583ebf to your computer and use it in GitHub Desktop.
coincap.io coin price lookup
This file contains 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 | |
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 (" ")' |
This file contains 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
$ 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