fixes error handling and coinmarketcap ids

This commit is contained in:
olli 2024-10-04 11:58:40 +02:00
parent d6cefa56d1
commit 7e21738be2
2 changed files with 28 additions and 28 deletions

View File

@ -66,7 +66,7 @@ function currency_converter {
find . -name "*${f_stablecoin}.history.*.csv" | while read f_file find . -name "*${f_stablecoin}.history.*.csv" | while read f_file
do do
f_link_file=${f_file/${f_stablecoin}/USD} 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" ln -sf "$f_file" "$f_link_file"
done done
cd - cd -
@ -105,17 +105,12 @@ function currency_converter {
for f_histfile in "$f_histfile_default" "$f_histfile_default_reverse" "$f_histfile_coinmarketcap" "$f_histfile_coinmarketcap_reverse" for f_histfile in "$f_histfile_default" "$f_histfile_default_reverse" "$f_histfile_coinmarketcap" "$f_histfile_coinmarketcap_reverse"
do do
# histfile has to exist
#if [ -s "${f_histfile}*.csv" ]
#then
# search for most precise date # search for most precise date
set -x f_line=$(egrep "^$f_currency_date_minute" "$f_histfile"*m.csv 2>/dev/null | tail -n1)
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_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_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) [ -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) [ -n "$f_line" ] && f_rate=$(echo "$f_line" | cut -d, -f2)
set +x
f_reverse=false f_reverse=false
if [ -n "$f_rate" ] if [ -n "$f_rate" ]
then then
@ -125,7 +120,6 @@ function currency_converter {
[ $f_currency_target = "EUR" ] && [ $f_currency = "USD" ] && f_reverse=true [ $f_currency_target = "EUR" ] && [ $f_currency = "USD" ] && f_reverse=true
[[ $f_line =~ ^$f_currency_date_hour ]] && break [[ $f_line =~ ^$f_currency_date_hour ]] && break
fi fi
#fi
done done
# end if no rate found # end if no rate found

View File

@ -67,7 +67,7 @@ function get_marketdata_coinmarketcap {
fi fi
local f_id 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 [[ $f_item = EURC ]] && f_id=20641
if [ -z "$f_id" ] if [ -z "$f_id" ]
then then
@ -86,11 +86,8 @@ function get_marketdata_coinmarketcap {
fi fi
# end if already exists and modified under given time # end if already exists and modified under given time
set -x
if [ -s "${f_targetcsv}" ] && find "${f_targetcsv}" -mmin -2 | grep -q "${f_targetcsv}" if [ -s "${f_targetcsv}" ] && find "${f_targetcsv}" -mmin -2 | grep -q "${f_targetcsv}"
then then
echo XXX
set +x
return 0 return 0
fi fi
@ -144,15 +141,24 @@ function get_marketdata_coinmarketcap_ids {
for f_id in $(seq 1 50000) for f_id in $(seq 1 50000)
do do
#echo "checking COINMARKETCAPID $f_id - Writing to $f_target_loop" 1>&2
sleep 0.3 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" 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) 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) f_latest_date_seconds=$(date -d "$f_latest_date" +%s)
if [ $f_latest_date_seconds_now -lt $f_latest_date_seconds ] if [ $f_latest_date_seconds_now -lt $f_latest_date_seconds ]
then 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 fi
done | egrep --line-buffered '^.+,[0-9]*$' >"$f_target_loop" done | egrep --line-buffered '^.+,[0-9]*,' >"$f_target_loop"
if [ -s "$f_target_tmp" ] if [ -s "$f_target_tmp" ]
then then