optimations and fixes

This commit is contained in:
olli 2024-10-18 23:00:11 +02:00
parent dcf5336a75
commit d71f344777

View File

@ -33,7 +33,7 @@ function currency_converter {
if [[ $f_currency_target =~ ^20.*-.*: ]] if [[ $f_currency_target =~ ^20.*-.*: ]]
then then
g_echo_warn "${FUNCNAME}: Invalid target $f_currency_target" g_echo_warn "${FUNCNAME} $@: Invalid target"
g_traceback g_traceback
return 1 return 1
fi fi
@ -80,6 +80,29 @@ function currency_converter {
fi fi
done done
# map EUR-Stablecoins to EUR
local f_stablecoins="EURC"
for f_stablecoin in $f_stablecoins
do
# Link EUR Stablecoin files to EUR
cd "$f_asset_histories"
find . -maxdepth 1 -mindepth 1 -name "*${f_stablecoin}.history.*.csv" | while read f_file
do
f_link_file=${f_file/${f_stablecoin}/EUR}
ln -sf "$f_file" "$f_link_file"
done
cd - >/dev/null
# use USD
if [[ $f_currency_target = $f_stablecoin ]]
then
f_currency_target=EUR
fi
if [[ $f_currency = $f_stablecoin ]]
then
f_currency=EUR
fi
done
# if there is no currency change (USD USD or USDT USD) # if there is no currency change (USD USD or USDT USD)
if [[ $f_currency == $f_currency_target ]] if [[ $f_currency == $f_currency_target ]]
then then
@ -106,7 +129,7 @@ function currency_converter {
for f_timeframe in 1d 1w for f_timeframe in 1d 1w
do do
[ "${f_currency}" = "USD" ] && get_marketdata_coinmarketcap "${f_currency_target}-${f_currency}" "${f_currency_target}${f_currency}" $f_timeframe [ "${f_currency}" = "USD" ] && get_marketdata_coinmarketcap "${f_currency_target}-${f_currency}" "${f_currency_target}${f_currency}" $f_timeframe
[ "${f_currency_target}" = "USD" ] && get_marketdata_coinmarketcap "${f_currency}-${f_currency_target}" "${f_currency}${f_currency_target}" [ "${f_currency_target}" = "USD" ] && get_marketdata_coinmarketcap "${f_currency}-${f_currency_target}" "${f_currency}${f_currency_target}" $f_timeframe
done done
f_line=$(egrep "^$f_currency_date_minute" "$f_histfile"*m.csv 2>/dev/null | sort | tail -n1) f_line=$(egrep "^$f_currency_date_minute" "$f_histfile"*m.csv 2>/dev/null | sort | tail -n1)
[ -z "$f_line" ] && f_line=$(egrep "^$f_currency_date_hour" "$f_histfile"*m.csv 2>/dev/null | sort | tail -n1) [ -z "$f_line" ] && f_line=$(egrep "^$f_currency_date_hour" "$f_histfile"*m.csv 2>/dev/null | sort | tail -n1)
@ -123,24 +146,32 @@ function currency_converter {
[[ $f_histfile =~ ${f_currency}${f_currency_target} ]] && f_reverse=true [[ $f_histfile =~ ${f_currency}${f_currency_target} ]] && f_reverse=true
[ $f_currency_target = "USD" ] && f_reverse=true [ $f_currency_target = "USD" ] && f_reverse=true
[ $f_currency = "USD" ] && f_reverse=false [ $f_currency = "USD" ] && f_reverse=false
[ $f_currency_target = "EUR" ] && [ $f_currency = "USD" ] && f_reverse=true [ $f_currency_target = "EUR" ] && [ $f_currency = "USD" ] && f_reverse=false
[[ $f_line =~ ^$f_currency_date_hour ]] && break [[ $f_line =~ ^$f_currency_date_hour ]] && break
fi fi
# end if no rate found # if no rate found
if [ -z "$f_rate" ] if [ -z "$f_rate" ]
then then
# try workaround over USD if EUR # if EUR spurce or traget try way over USD as workarount
if [[ ${f_currency_target} = EUR ]] && [[ $f_currency != USD ]] if [[ ${f_currency_target} = EUR ]] && [[ $f_currency != USD ]] && [[ $f_currency != EUR ]]
then then
#g_echo_note "trying way over USD (workaround)" g_echo_note "trying way over USD (workaround) Target EUR"
if currency_converter $f_currency_amount $f_currency USD $f_currency_date if currency_converter $f_currency_amount $f_currency USD "$f_currency_date"
then then
f_currency_amount=$f_currency_converter_result currency_converter $f_currency_converter_result USD EUR "$f_currency_date"
currency_converter $f_currency_amount USD EUR $f_currency_date return $?
fi
elif [[ ${f_currency_target} != USD ]] && [[ ${f_currency_target} != EUR ]] && [[ $f_currency = EUR ]]
then
g_echo_note "trying way over USD (workaround) Source EUR"
if currency_converter $f_currency_amount EUR USD "$f_currency_date"
then
currency_converter $f_currency_converter_result USD ${f_currency_target} "$f_currency_date"
return $? return $?
fi fi
fi fi
# end if no rate found
g_echo_error "didn't find rate for ${f_currency}-${f_currency_target} - '${FUNCNAME} $@'" g_echo_error "didn't find rate for ${f_currency}-${f_currency_target} - '${FUNCNAME} $@'"
return 1 return 1
fi fi
@ -151,7 +182,3 @@ function currency_converter {
f_currency_converter_result=$g_calc_result f_currency_converter_result=$g_calc_result
} }