sh 根据coinmarketcap.com发现最佳和最差的加密货币执行者

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 根据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 .

以上是关于sh 根据coinmarketcap.com发现最佳和最差的加密货币执行者的主要内容,如果未能解决你的问题,请参考以下文章

coinmarketcap.com爬虫

Python从Coinmarketcap网站API获取数据

IONIC v3获取CoinMArketCap API数据

如何从 Coinmarketcap 解析历史 BTC 数据?

VBA - Excel 中显示的 API 调用

linux chattr用法