diff --git a/plugins/coinmarketcap/README.md b/plugins/coinmarketcap/README.md new file mode 100644 index 000000000..5d98daedd --- /dev/null +++ b/plugins/coinmarketcap/README.md @@ -0,0 +1,19 @@ +# Unofficial Cryptocurrency Market Capitalizations coinmarketcap.com + +[coinmarketcap](https://coinmarketcap.com) plugin — Market Capitalization is one way to rank the relative size of a cryptocurrency. It's calculated by multiplying the Price by the Circulating Supply. + +## Usage + +For Bitcoin Gold +``` +coin BTG +``` + +For all currencies +``` +coin ALL +``` + +## Dependencies +commands like awk, grep and curl need to be in the $PATH +Tested in Linux and MacOs diff --git a/plugins/coinmarketcap/coinmarketcap.plugin.zsh b/plugins/coinmarketcap/coinmarketcap.plugin.zsh new file mode 100644 index 000000000..ea4581ed7 --- /dev/null +++ b/plugins/coinmarketcap/coinmarketcap.plugin.zsh @@ -0,0 +1,36 @@ + +# Displays the current USD value of crypto coins from the api.coinmarketcap.com +# +# See README.md for details + +function coinmarketcap() { + curl -s https://api.coinmarketcap.com/v1/ticker/ > $HOME/.coinmarketcap.json + curl -s https://api.coinmarketcap.com/v1/ticker/bitcoin-gold/ > $HOME/.coinmarketcap-btg.json + if [[ -n "$1" ]]; then + coin=$1 + symbols=(`cat $HOME/.coinmarketcap.json | grep -Po '(?<="symbol": ")[^"]*' | awk -F "\n" '{print $1}'`) + price=(`cat $HOME/.coinmarketcap.json | grep -Po '(?<="price_usd": ")[^"]*' | awk -F "\n" '{print $1}'`) + if [[ "${coin}" == "ALL" ]]; then + for ((i=0; i<${#symbols[*]}; i++)); + do + echo -e ${symbols[i]}"\t : \t"${price[i]} + done + elif [[ "${coin}" == "BTG" ]]; then + btg_symbols=(`cat $HOME/.coinmarketcap-btg.json | grep -Po '(?<="symbol": ")[^"]*'`) + btg_price=(`cat $HOME/.coinmarketcap-btg.json | grep -Po '(?<="price_usd": ")[^"]*'`) + echo -e ${btg_price} + else + for ((i=0; i<${#symbols[*]}; i++)); + do + if [[ "${symbols[i]}" == "${coin}" ]]; then + echo -e ${price[i]} + fi + done + fi + else + echo "Usage example for Bitcoin Gold: \"coin BTG\"" + echo "Usage example all crypto currencies: \"coin ALL\"" + fi +} + +alias coin=coinmarketcap