From 7e21738be266558674acce29b83871ea642a3ec9 Mon Sep 17 00:00:00 2001 From: olli Date: Fri, 4 Oct 2024 11:58:40 +0200 Subject: [PATCH] fixes error handling and coinmarketcap ids --- dabo/functions/currency_converter.sh | 38 ++++++++----------- .../functions/get_marketdata_coinmarketcap.sh | 18 ++++++--- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/dabo/functions/currency_converter.sh b/dabo/functions/currency_converter.sh index 2cd7fe9..ce34063 100644 --- a/dabo/functions/currency_converter.sh +++ b/dabo/functions/currency_converter.sh @@ -66,7 +66,7 @@ function currency_converter { find . -name "*${f_stablecoin}.history.*.csv" | while read f_file do f_link_file=${f_file/${f_stablecoin}/USD} - echo "Linkfile $f_link_file" + #echo "Linkfile $f_link_file" ln -sf "$f_file" "$f_link_file" done cd - @@ -105,27 +105,21 @@ function currency_converter { for f_histfile in "$f_histfile_default" "$f_histfile_default_reverse" "$f_histfile_coinmarketcap" "$f_histfile_coinmarketcap_reverse" do - # histfile has to exist - #if [ -s "${f_histfile}*.csv" ] - #then - # search for most precise date - set -x - f_line=$(egrep "^$f_currency_date_minute" "$f_histfile".*m.csv 2>/dev/null | tail -n1) - [ -z "$f_line" ] && f_line=$(egrep "^$f_currency_date_hour" "$f_histfile".*h.csv 2>/dev/null | tail -n1) - [ -z "$f_line" ] && f_line=$(egrep "^$f_currency_date_day" "$f_histfile".*d.csv 2>/dev/null | tail -n1) - [ -z "$f_line" ] && f_line=$(egrep "^$f_currency_date_month" "$f_histfile"*.csv 2>/dev/null | tail -n1) - [ -n "$f_line" ] && f_rate=$(echo "$f_line" | cut -d, -f2) - set +x - f_reverse=false - if [ -n "$f_rate" ] - then - [[ $f_histfile =~ ${f_currency}${f_currency_target} ]] && f_reverse=true - [ $f_currency_target = "USD" ] && f_reverse=true - [ $f_currency = "USD" ] && f_reverse=false - [ $f_currency_target = "EUR" ] && [ $f_currency = "USD" ] && f_reverse=true - [[ $f_line =~ ^$f_currency_date_hour ]] && break - fi - #fi + # search for most precise date + f_line=$(egrep "^$f_currency_date_minute" "$f_histfile"*m.csv 2>/dev/null | tail -n1) + [ -z "$f_line" ] && f_line=$(egrep "^$f_currency_date_hour" "$f_histfile"*h.csv 2>/dev/null | tail -n1) + [ -z "$f_line" ] && f_line=$(egrep "^$f_currency_date_day" "$f_histfile"*d.csv 2>/dev/null | tail -n1) + [ -z "$f_line" ] && f_line=$(egrep "^$f_currency_date_month" "$f_histfile"*.csv 2>/dev/null | tail -n1) + [ -n "$f_line" ] && f_rate=$(echo "$f_line" | cut -d, -f2) + f_reverse=false + if [ -n "$f_rate" ] + then + [[ $f_histfile =~ ${f_currency}${f_currency_target} ]] && f_reverse=true + [ $f_currency_target = "USD" ] && f_reverse=true + [ $f_currency = "USD" ] && f_reverse=false + [ $f_currency_target = "EUR" ] && [ $f_currency = "USD" ] && f_reverse=true + [[ $f_line =~ ^$f_currency_date_hour ]] && break + fi done # end if no rate found diff --git a/dabo/functions/get_marketdata_coinmarketcap.sh b/dabo/functions/get_marketdata_coinmarketcap.sh index a9d8fbc..add0d07 100644 --- a/dabo/functions/get_marketdata_coinmarketcap.sh +++ b/dabo/functions/get_marketdata_coinmarketcap.sh @@ -67,7 +67,7 @@ function get_marketdata_coinmarketcap { fi local f_id - f_id=$(egrep "^${f_item}," COINMARKETCAPIDS | head -n1 | cut -d, -f2) + f_id=$(egrep "^${f_item},[1-9]" COINMARKETCAPIDS | head -n1 | cut -d, -f2) [[ $f_item = EURC ]] && f_id=20641 if [ -z "$f_id" ] then @@ -86,11 +86,8 @@ function get_marketdata_coinmarketcap { fi # end if already exists and modified under given time - set -x if [ -s "${f_targetcsv}" ] && find "${f_targetcsv}" -mmin -2 | grep -q "${f_targetcsv}" then - echo XXX - set +x return 0 fi @@ -144,15 +141,24 @@ function get_marketdata_coinmarketcap_ids { for f_id in $(seq 1 50000) do + #echo "checking COINMARKETCAPID $f_id - Writing to $f_target_loop" 1>&2 + sleep 0.3 + # download curl -s --request GET --url "https://api.coinmarketcap.com/data-api/v3.1/cryptocurrency/historical?id=${f_id}&interval=1d" >"$g_tmp/get_marketdata_coinmarketcap_ids.json" + + # check latest date f_latest_date=$(jq -r '.data.quotes[] | .quote.timestamp[0:10]' "$g_tmp/get_marketdata_coinmarketcap_ids.json" | tail -n1) + [ -z "$f_latest_date" ] && continue + + # check for up-to-date data f_latest_date_seconds=$(date -d "$f_latest_date" +%s) if [ $f_latest_date_seconds_now -lt $f_latest_date_seconds ] then - jq -r '.[] | .symbol + "," + (.id|tostring)' "$g_tmp/get_marketdata_coinmarketcap_ids.json" | head -n 1 + jq -r '.[] | .symbol + "," + (.id|tostring) + "," + .name' "$g_tmp/get_marketdata_coinmarketcap_ids.json" | head -n 1 + # jq -r '.[] | .symbol + "," + (.id|tostring) + "," + .name' "$g_tmp/get_marketdata_coinmarketcap_ids.json" | head -n 1 1>&2 fi - done | egrep --line-buffered '^.+,[0-9]*$' >"$f_target_loop" + done | egrep --line-buffered '^.+,[0-9]*,' >"$f_target_loop" if [ -s "$f_target_tmp" ] then