From c37518f0b1024f3e1f3ff46cf0f98d07059b04ad Mon Sep 17 00:00:00 2001 From: olli Date: Wed, 3 Jan 2024 15:57:38 +0100 Subject: [PATCH] put coingecko to separate function --- dabo/functions/get_coingecko_data.sh | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 dabo/functions/get_coingecko_data.sh diff --git a/dabo/functions/get_coingecko_data.sh b/dabo/functions/get_coingecko_data.sh new file mode 100644 index 0000000..b65ca55 --- /dev/null +++ b/dabo/functions/get_coingecko_data.sh @@ -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 + + +}