put coingecko to separate function
This commit is contained in:
parent
530230cbb5
commit
c37518f0b1
35
dabo/functions/get_coingecko_data.sh
Normal file
35
dabo/functions/get_coingecko_data.sh
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
function get_coingecko_data {
|
||||||
|
# get data from coingecko
|
||||||
|
echo "curl -s -X 'GET' \"https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=250&page=1&sparkline=false&price_change_percentage=1h,24h,7d,14d,30d,1y\" -H 'accept: application/json'" >COINGECKO_GET_ASSETS_CMD
|
||||||
|
g_runcmd g_retrycmd sh COINGECKO_GET_ASSETS_CMD >COINGECKO_GET_ASSETS_CMD_OUT || return 1
|
||||||
|
|
||||||
|
[ ${FULL_LOOP} == 0 ] && return 0
|
||||||
|
if [ -s COINGECKO_GET_ASSETS_CMD_OUT ] && grep -q "market_cap_rank" COINGECKO_GET_ASSETS_CMD_OUT
|
||||||
|
then
|
||||||
|
|
||||||
|
# get marketcap sort
|
||||||
|
jq -r '.[].symbol' COINGECKO_GET_ASSETS_CMD_OUT | tr [:lower:] [:upper:] | head -n $LARGEST_MARKETCAP >ASSET_MARKETCAP_OUT.tmp-sort
|
||||||
|
if [ -s ASSET_MARKETCAP_OUT.tmp-sort ] && egrep -q "^[A-Z0-9]+$" ASSET_MARKETCAP_OUT.tmp-sort
|
||||||
|
then
|
||||||
|
mv ASSET_MARKETCAP_OUT.tmp-sort SORTMARKETCAP
|
||||||
|
else
|
||||||
|
g_echo_warn "ASSET_MARKETCAP_OUT.tmp-sort has wrong Syntax. - Not updating ASSET_MARKETCAP_OUT.tmp-sort $(tail -n 10 ASSET_MARKETCAP_OUT.tmp-sort)"
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
# write down 24h pricechange
|
||||||
|
cat COINGECKO_GET_ASSETS_CMD_OUT | jq -r '.[] | .symbol + "," + (.price_change_percentage_24h|tostring)' | tr [:lower:] [:upper:] >ASSET_PRICE_CHANGE_PERCENTAGE_24H
|
||||||
|
|
||||||
|
# store coingecko symbolids for coingecko info URLs
|
||||||
|
jq -r '.[] | .symbol + "," + .id' COINGECKO_GET_ASSETS_CMD_OUT >COINGECKO_IDS.tmp
|
||||||
|
if [ -s COINGECKO_IDS.tmp ]
|
||||||
|
then
|
||||||
|
mv COINGECKO_IDS.tmp COINGECKO_IDS
|
||||||
|
else
|
||||||
|
g_echo_warn "COINGECKO_IDS.tmp has wrong Syntax. - Not updating COINGECKO_IDS $(tail -n 10 COINGECKO_IDS.tmp)"
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user