|
|
|
@ -33,7 +33,7 @@ function currency_converter {
|
|
|
|
|
|
|
|
|
|
if [[ $f_currency_target =~ ^20.*-.*: ]]
|
|
|
|
|
then
|
|
|
|
|
g_echo_warn "${FUNCNAME}: Invalid target $f_currency_target"
|
|
|
|
|
g_echo_warn "${FUNCNAME} $@: Invalid target"
|
|
|
|
|
g_traceback
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
@ -80,6 +80,29 @@ function currency_converter {
|
|
|
|
|
fi
|
|
|
|
|
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 [[ $f_currency == $f_currency_target ]]
|
|
|
|
|
then
|
|
|
|
@ -106,7 +129,7 @@ function currency_converter {
|
|
|
|
|
for f_timeframe in 1d 1w
|
|
|
|
|
do
|
|
|
|
|
[ "${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
|
|
|
|
|
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)
|
|
|
|
@ -123,24 +146,32 @@ function currency_converter {
|
|
|
|
|
[[ $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_currency_target = "EUR" ] && [ $f_currency = "USD" ] && f_reverse=false
|
|
|
|
|
[[ $f_line =~ ^$f_currency_date_hour ]] && break
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# end if no rate found
|
|
|
|
|
# if no rate found
|
|
|
|
|
if [ -z "$f_rate" ]
|
|
|
|
|
then
|
|
|
|
|
# try workaround over USD if EUR
|
|
|
|
|
if [[ ${f_currency_target} = EUR ]] && [[ $f_currency != USD ]]
|
|
|
|
|
# if EUR spurce or traget try way over USD as workarount
|
|
|
|
|
if [[ ${f_currency_target} = EUR ]] && [[ $f_currency != USD ]] && [[ $f_currency != EUR ]]
|
|
|
|
|
then
|
|
|
|
|
#g_echo_note "trying way over USD (workaround)"
|
|
|
|
|
if currency_converter $f_currency_amount $f_currency USD $f_currency_date
|
|
|
|
|
g_echo_note "trying way over USD (workaround) Target EUR"
|
|
|
|
|
if currency_converter $f_currency_amount $f_currency USD "$f_currency_date"
|
|
|
|
|
then
|
|
|
|
|
f_currency_amount=$f_currency_converter_result
|
|
|
|
|
currency_converter $f_currency_amount USD EUR $f_currency_date
|
|
|
|
|
currency_converter $f_currency_converter_result 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 $?
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
# end if no rate found
|
|
|
|
|
g_echo_error "didn't find rate for ${f_currency}-${f_currency_target} - '${FUNCNAME} $@'"
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
@ -151,7 +182,3 @@ function currency_converter {
|
|
|
|
|
f_currency_converter_result=$g_calc_result
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|