Compare commits

..

No commits in common. "dcf5336a752f1475033c82b066bca50cfb7a87c3" and "26cc07598420470fcb77623587e28caa781f67ce" have entirely different histories.

4 changed files with 42 additions and 47 deletions

View File

@ -29,7 +29,7 @@ function currency_converter {
unset f_currency_converter_result unset f_currency_converter_result
local f_line f_rate f_histfile f_date_array f_stablecoin f_reverse f_file f_link_file f_timeframe local f_line f_rate f_histfile f_date_array f_stablecoin f_reverse f_file f_link_file
if [[ $f_currency_target =~ ^20.*-.*: ]] if [[ $f_currency_target =~ ^20.*-.*: ]]
then then
@ -63,12 +63,13 @@ function currency_converter {
do do
# Link USD Stablecoin files to USD # Link USD Stablecoin files to USD
cd "$f_asset_histories" cd "$f_asset_histories"
find . -maxdepth 1 -mindepth 1 -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"
ln -sf "$f_file" "$f_link_file" ln -sf "$f_file" "$f_link_file"
done done
cd - >/dev/null cd -
# use USD # use USD
if [[ $f_currency_target = $f_stablecoin ]] if [[ $f_currency_target = $f_stablecoin ]]
then then
@ -87,35 +88,28 @@ function currency_converter {
return 0 return 0
fi fi
# define possiblefiles # try direct pair
[ "${f_currency}" = "USD" ] && get_marketdata_coinmarketcap "${f_currency_target}-${f_currency}" "${f_currency_target}${f_currency}"
[ "${f_currency_target}" = "USD" ] && get_marketdata_coinmarketcap "${f_currency}-${f_currency_target}" "${f_currency}${f_currency_target}"
local f_histfile_default="${f_asset_histories}${f_currency_target}${f_currency}.history" local f_histfile_default="${f_asset_histories}${f_currency_target}${f_currency}.history"
local f_histfile_coinmarketcap="${f_asset_histories}${f_currency_target}${f_currency}.history"
# reverse as backup
local f_histfile_default_reverse="${f_asset_histories}${f_currency}${f_currency_target}.history" local f_histfile_default_reverse="${f_asset_histories}${f_currency}${f_currency_target}.history"
local f_histfile_coinmarketcap_reverse="${f_asset_histories}${f_currency}${f_currency_target}.history"
# search for rate by date
for f_histfile in "$f_histfile_default" "$f_histfile_default_reverse" echo "$f_histfile_default" "$f_histfile_default_reverse" "$f_histfile_coinmarketcap" "$f_histfile_coinmarketcap_reverse"
echo "$f_currency_date_minute $f_currency_date_hour $f_currency_date_day $f_currency_date_month"
for f_histfile in "$f_histfile_default" "$f_histfile_default_reverse" "$f_histfile_coinmarketcap" "$f_histfile_coinmarketcap_reverse"
do do
# search for most precise date # search for most precise date
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 | 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"*h.csv 2>/dev/null | tail -n1)
[ -z "$f_line" ] && f_line=$(egrep "^$f_currency_date_day" "$f_histfile"*h.csv 2>/dev/null | sort | tail -n1) [ -z "$f_line" ] && f_line=$(egrep "^$f_currency_date_day" "$f_histfile"*d.csv 2>/dev/null | tail -n1)
done [ -z "$f_line" ] && f_line=$(egrep "^$f_currency_date_month" "$f_histfile"*.csv 2>/dev/null | tail -n1)
# download from coinmarketcap if nothing found
[ -z "$f_line" ] && for f_histfile in "$f_histfile_default" "$f_histfile_default_reverse"
do
# download data from coinmarketcap
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}"
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)
[ -z "$f_line" ] && f_line=$(egrep "^$f_currency_date_day" "$f_histfile"*h.csv 2>/dev/null | sort | tail -n1)
[ -z "$f_line" ] && f_line=$(egrep "^$f_currency_date_month" "$f_histfile"*.csv 2>/dev/null | sort | tail -n1)
[ -n "$f_line" ] && break
done
# extract rate/price
[ -n "$f_line" ] && f_rate=$(echo "$f_line" | cut -d, -f2) [ -n "$f_line" ] && f_rate=$(echo "$f_line" | cut -d, -f2)
f_reverse=false f_reverse=false
if [ -n "$f_rate" ] if [ -n "$f_rate" ]
@ -126,6 +120,7 @@ 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
done
# end if no rate found # end if no rate found
if [ -z "$f_rate" ] if [ -z "$f_rate" ]
@ -152,6 +147,3 @@ function currency_converter {
} }

View File

@ -58,7 +58,7 @@ function get_bitpanda_api_transactions {
select(.effective_leverage!= null) | select(.effective_leverage!= null) |
.time.date_iso8601 + ",leverage-" + .type + "," + .cryptocoin_symbol + "," + .amount_cryptocoin + ",EUR," + .amount_fiat + ",Bitpanda" .time.date_iso8601 + ",leverage-" + .type + "," + .cryptocoin_symbol + "," + .amount_cryptocoin + ",EUR," + .amount_fiat + ",Bitpanda"
' BITPANDA_trades.json >>BITPANDA.csv.tmp ' BITPANDA_trades.json >>BITPANDA.csv.tmp
# Workaround for staking-rewards (not availabpe per API yet (https://help.blockpit.io/hc/de-at/articles/360011790820-Wie-importiere-ich-Daten-mittels-Bitpanda-API-Key) # Workaround fpr staking-rewards (not availabpe per API yet (https://help.blockpit.io/hc/de-at/articles/360011790820-Wie-importiere-ich-Daten-mittels-Bitpanda-API-Key)
[ -s bitpanda-export.csv ] && cat bitpanda-export.csv | grep reward,incoming | awk -F, '{print $2",reward-staking,"$8","$7",EUR,"$5",Bitpanda"}' >>BITPANDA.csv.tmp [ -s bitpanda-export.csv ] && cat bitpanda-export.csv | grep reward,incoming | awk -F, '{print $2",reward-staking,"$8","$7",EUR,"$5",Bitpanda"}' >>BITPANDA.csv.tmp
cat BITPANDA.csv.tmp | grep -v ",reward.best," | sort >TRANSACTIONS-BITPANDA.csv cat BITPANDA.csv.tmp | grep -v ",reward.best," | sort >TRANSACTIONS-BITPANDA.csv

View File

@ -60,11 +60,14 @@ function get_marketdata_coinmarketcap {
then then
# remove /* # remove /*
f_item=${f_item///*/} f_item=${f_item///*/}
## remove :* (for example :USDT in contract markets)
#f_item=${f_item//:*}
# remove spaces
#f_item=${f_item/ /}
fi fi
local f_id local f_id
# get id -> If multiple take the one with the largest marketcap f_id=$(egrep "^${f_item},[1-9]" COINMARKETCAPIDS | head -n1 | cut -d, -f2)
f_id=$(egrep "^${f_item},[1-9]" COINMARKETCAPIDS | sort -n -t, -k4 | tail -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
@ -152,7 +155,8 @@ function get_marketdata_coinmarketcap_ids {
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 '.data | .symbol + "," + (.id|tostring) + "," + .name + "," + (.quotes[].quote|.marketCap|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"

View File

@ -154,7 +154,6 @@ function transactions_overview {
[[ $f_type =~ stake ]] && continue [[ $f_type =~ stake ]] && continue
# what did I spent on asset in currency # what did I spent on asset in currency
#if [[ $f_type =~ buy|leverage-buy ]]
if [[ $f_type =~ buy|leverage-buy|reward-staking|instant_trade_bonus|giveaway ]] if [[ $f_type =~ buy|leverage-buy|reward-staking|instant_trade_bonus|giveaway ]]
then then
g_calc "$f_currency_spent+$f_currency_amount" g_calc "$f_currency_spent+$f_currency_amount"