Compare commits
3 Commits
c9da86b94c
...
db4bbcadf8
Author | SHA1 | Date | |
---|---|---|---|
db4bbcadf8 | |||
7e49ae8927 | |||
9b6c5a1408 |
46
dabo/functions/get_bitpanda_api_transactions.sh
Normal file
46
dabo/functions/get_bitpanda_api_transactions.sh
Normal file
@ -0,0 +1,46 @@
|
||||
function get_bitpanda_api_transactions {
|
||||
|
||||
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
|
||||
|
||||
# Check for Bitpanda API Key - If there get data from Bitpanda API
|
||||
if [ -s /dabo/.bitpanda-secrets ]
|
||||
then
|
||||
source /dabo/.bitpanda-secrets
|
||||
g_echo "Bitpanda API-Key found. Getting data from Biotpanda API"
|
||||
curl -s -X GET "https://api.bitpanda.com/v1/wallets/transactions?page_size=999999" -H "X-Api-Key: ${BITPANDA_API_KEY}" >BITPANDA_wallets_transactions.csv.tmp \
|
||||
&& mv BITPANDA_wallets_transactions.csv.tmp BITPANDA_wallets_transactions.json
|
||||
curl -s -X GET "https://api.bitpanda.com/v1/fiatwallets/transactions?page_size=999999" -H "X-Api-Key: ${BITPANDA_API_KEY}" >BITPANDA_fiatwallets_transactions.csv.tmp \
|
||||
&& mv BITPANDA_fiatwallets_transactions.csv.tmp BITPANDA_fiatwallets_transactions.json
|
||||
curl -s -X GET "https://api.bitpanda.com/v1/trades?page_size=999999" -H "X-Api-Key: ${BITPANDA_API_KEY}" >BITPANDA_trades.csv.tmp \
|
||||
&& mv BITPANDA_trades.csv.tmp BITPANDA_trades.json
|
||||
unset BITPANDA_API_KEY
|
||||
jq -r '
|
||||
.data[].attributes |
|
||||
select(.status=="finished") |
|
||||
select(.type=="sell" or .type=="buy") |
|
||||
select(.cryptocoin_symbol!= null) |
|
||||
.time.date_iso8601 + "," + .type + "," + .cryptocoin_symbol + "," + .amount + ",EUR," + .amount_eur + ",Bitpanda"
|
||||
' BITPANDA_wallets_transactions.json >BITPANDA.csv.tmp
|
||||
jq -r '
|
||||
.data[].attributes |
|
||||
select(.status=="finished") |
|
||||
select(.type=="transfer") |
|
||||
select(.cryptocoin_symbol!= null) |
|
||||
.time.date_iso8601 + "," + .tags[].attributes.short_name + "," + .cryptocoin_symbol + "," + .amount + ",EUR," + .amount_eur + ",Bitpanda"
|
||||
' BITPANDA_wallets_transactions.json | sed 's/,reward,/,giveaway,/' >>BITPANDA.csv.tmp
|
||||
jq -r '
|
||||
.data[].attributes |
|
||||
select(.status=="finished") |
|
||||
select(.type=="sell" or .type=="buy") |
|
||||
select(.effective_leverage!= null) |
|
||||
.time.date_iso8601 + ",leverage-" + .type + "," + .cryptocoin_symbol + "," + .amount_cryptocoin + ",EUR," + .amount_fiat + ",Bitpanda"
|
||||
' BITPANDA_trades.json >>BITPANDA.csv.tmp
|
||||
# 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","$9",EUR,"$5",Bitpanda"}' >>BITPANDA.csv.tmp
|
||||
|
||||
cat BITPANDA.csv.tmp | grep -v ",reward.best," | sort >TRANSACTIONS-BITPANDA.csv
|
||||
rm -f BITPANDA.csv.tmp
|
||||
fi
|
||||
|
||||
}
|
||||
|
15
dabo/functions/get_justtrade_csv_transactions.sh
Normal file
15
dabo/functions/get_justtrade_csv_transactions.sh
Normal file
@ -0,0 +1,15 @@
|
||||
function get_justtrade_csv_transactions {
|
||||
|
||||
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
|
||||
|
||||
# Check for JustTrade API Key - If there is data from JustTrade csv
|
||||
if [ -s justtrade-export.csv ]
|
||||
then
|
||||
cat justtrade-export.csv | sed 's/\"//g' | egrep '^[0-9]' | egrep ',otc,justtrade,.+Z,EUR,' | awk -F, '{print $4",sell,"$7","$8","$5","$6",JustTrade"}' >JUSTTRADE-sell.csv.tmp
|
||||
cat justtrade-export.csv | sed 's/\"//g' | egrep '^[0-9]' | egrep -v ',otc,justtrade,.+Z,EUR,' | awk -F, '{print $4",buy,"$5","$6","$7","$8",JustTrade"}' >JUSTTRADE-buy.csv.tmp
|
||||
cat JUSTTRADE-buy.csv.tmp JUSTTRADE-sell.csv.tmp | sort >TRANSACTIONS-JUSTTRADE.csv
|
||||
rm -f JUSTTRADE-buy.csv.tmp JUSTTRADE-sell.csv.tmp
|
||||
fi
|
||||
|
||||
}
|
||||
|
264
dabo/functions/transactions_overview.sh
Normal file
264
dabo/functions/transactions_overview.sh
Normal file
@ -0,0 +1,264 @@
|
||||
function transactions_overview {
|
||||
|
||||
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
|
||||
|
||||
get_bitpanda_api_transactions
|
||||
get_justtrade_csv_transactions
|
||||
|
||||
>ALL_TRANSACTIONS_OVERVIEW.csv.tmp
|
||||
|
||||
local f_exchange f_transactions_array f_transaction
|
||||
|
||||
#f_seconds_one_year_ago=$(date -d "1 year ago" +%s)
|
||||
|
||||
f_tax_rate="32"
|
||||
|
||||
f_assets_per_exchange=$(egrep -h -v '^DATE,TYPE,ASSET,ASSET_AMOUNT,CURRENCY,CURRENCY_AMOUNT,EXCHANGE|^#|^$|^ +$|^$' TRANSACTIONS-*.csv | cut -d, -f3,7 | sort -u)
|
||||
|
||||
f_trade_result=0
|
||||
|
||||
for f_asset_per_exchange in ${f_assets_per_exchange}
|
||||
do
|
||||
f_asset_quantity=0
|
||||
f_currency_spent=0
|
||||
f_result=0
|
||||
f_asset_amount_tax_free=0
|
||||
f_asset_amount_tax_able=0
|
||||
f_trade_result_asset=0
|
||||
mapfile -d, -t f_asset_per_exchange_array < <(echo $f_asset_per_exchange)
|
||||
f_asset=${f_asset_per_exchange_array[0]}
|
||||
f_exchange=${f_asset_per_exchange_array[1]%$'\n'}
|
||||
echo "=== Asset $f_asset on Exchange $f_exchange"
|
||||
mapfile -t f_transactions_array < <(egrep -h -v '^DATE,TYPE,ASSET,ASSET_AMOUNT,CURRENCY,CURRENCY_AMOUNT,EXCHANGE|^#|^$|^ +$' TRANSACTIONS-*.csv | egrep ",${f_asset},.+,${f_exchange}" | sort)
|
||||
for f_transaction in ${f_transactions_array[@]}
|
||||
do
|
||||
mapfile -d, -t f_transaction_array < <(echo $f_transaction)
|
||||
f_date=${f_transaction_array[0]}
|
||||
f_type=${f_transaction_array[1]}
|
||||
f_asset_amount=${f_transaction_array[3]}
|
||||
f_currency=${f_transaction_array[4]}
|
||||
f_currency_amount=${f_transaction_array[5]}
|
||||
f_sell_result=0
|
||||
f_taxable=0
|
||||
f_tax_type=""
|
||||
f_one_year_ago=""
|
||||
f_staking_rewards_asset=0
|
||||
f_giveaway_asset=0
|
||||
f_instant_trade_bonus_asset=0
|
||||
f_leverage_result_asset=0
|
||||
f_asset_amount_tax_able=0
|
||||
f_asset_amount_tax_free=0
|
||||
|
||||
# Ignore USDT
|
||||
[[ $f_asset =~ USDT ]] && continue
|
||||
|
||||
# If moveng to stake -> irrelevant/ignore
|
||||
[[ $f_type =~ stake ]] && continue
|
||||
|
||||
# what did I spent on asset in currency
|
||||
if [[ $f_type =~ buy|leverage-buy ]]
|
||||
then
|
||||
g_calc "$f_currency_spent+$f_currency_amount"
|
||||
f_currency_spent=$g_calc_result
|
||||
fi
|
||||
|
||||
# what did I spent on asset
|
||||
if [[ $f_type =~ buy|leverage-buy|reward-staking|instant_trade_bonus|giveaway ]]
|
||||
then
|
||||
g_calc "$f_asset_quantity+$f_asset_amount"
|
||||
f_asset_quantity=$g_calc_result
|
||||
fi
|
||||
|
||||
|
||||
# rise result if reward-staking|instant_trade_bonus|giveaway
|
||||
if [[ $f_type =~ reward-staking|instant_trade_bonus|giveaway ]]
|
||||
then
|
||||
g_calc "$f_result+$f_currency_amount"
|
||||
f_result=$g_calc_result
|
||||
|
||||
if [[ $f_type =~ reward-staking ]]
|
||||
then
|
||||
f_staking_rewards_asset=$f_currency_amount
|
||||
f_taxable=$f_currency_amount
|
||||
f_tax_type="Staking Reward (Einkommenssteuersatz)"
|
||||
fi
|
||||
if [[ $f_type =~ instant_trade_bonus ]]
|
||||
then
|
||||
f_instant_trade_bonus_asset=$f_currency_amount
|
||||
f_taxable=$f_currency_amount
|
||||
f_tax_type="Instand Trade Bonus (Einkommenssteuersatz)"
|
||||
fi
|
||||
if [[ $f_type =~ giveaway ]]
|
||||
then
|
||||
f_giveaway_asset=$f_currency_amount
|
||||
f_taxable=$f_currency_amount
|
||||
f_tax_type="Giveaway (Einkommenssteuersatz)"
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
# calculate result and tax (if taxable) on sale
|
||||
if [[ $f_type =~ sell|leverage-sell ]]
|
||||
then
|
||||
|
||||
# how much in percentage is sold?
|
||||
g_calc "100/$f_asset_quantity*$f_asset_amount"
|
||||
printf -v f_sold_percentage %.2f $g_calc_result
|
||||
#echo "Sold percentage: $f_sold_percentage"
|
||||
|
||||
# what is the currency amount with result (profit/loss)?
|
||||
g_calc "$f_currency_amount/$f_sold_percentage*100"
|
||||
f_curency_amount_with_result=$g_calc_result
|
||||
#echo "f_curency_amount_with_result: $f_curency_amount_with_result"
|
||||
|
||||
# what is the result of this sell in currency (profit/loss)?
|
||||
g_calc "$f_curency_amount_with_result-$f_currency_spent"
|
||||
f_sell_result=$g_calc_result
|
||||
#echo "Result: $f_sell_result"
|
||||
|
||||
# at leverage always full taxable
|
||||
if [[ $f_type == leverage-sell ]]
|
||||
then
|
||||
f_taxable=$f_sell_result
|
||||
f_tax_type="Verkauf gehebelter Position (Kapitalertragssteuer)"
|
||||
# at no leverage-sell
|
||||
else
|
||||
## taxable - one year?
|
||||
f_seconds_sell_ago=$(date -d "$f_date 1 year ago" +%s)
|
||||
|
||||
oldIFS=$IFS
|
||||
IFS=$'\n'
|
||||
# add all but sell to f_asset_amount_tax_able or f_asset_amount_tax_free
|
||||
mapfile -t f_assetlines_array < <(egrep ",$f_exchange,[a-z]+,$f_asset," ALL_TRANSACTIONS_OVERVIEW.csv.tmp | grep -v ',sell,')
|
||||
for f_assetline in ${f_assetlines_array[@]}
|
||||
do
|
||||
mapfile -d, -t f_assetline_array < <(echo $f_assetline)
|
||||
f_assetline_date=${f_assetline_array[0]}
|
||||
f_assetline_type=${f_assetline_array[2]}
|
||||
f_assetline_amount=${f_assetline_array[4]}
|
||||
f_seconds_transfer_ago=$(date -d "$f_assetline_date" +%s)
|
||||
if [ $f_seconds_sell_ago -gt $f_seconds_transfer_ago ]
|
||||
then
|
||||
# buy from sell one year ago
|
||||
g_calc "$f_asset_amount_tax_free+$f_assetline_amount"
|
||||
f_asset_amount_tax_free=$g_calc_result
|
||||
else
|
||||
# buy from sell in one year
|
||||
g_calc "$f_asset_amount_tax_able+$f_assetline_amount"
|
||||
f_asset_amount_tax_able=$g_calc_result
|
||||
fi
|
||||
done
|
||||
|
||||
# add sell to f_asset_amount_tax_able or f_asset_amount_tax_free
|
||||
mapfile -t f_assetlines_sell_array < <(egrep ",$f_exchange,sell,$f_asset," ALL_TRANSACTIONS_OVERVIEW.csv.tmp)
|
||||
for f_assetlinesell in ${f_assetlines_sell_array[@]}
|
||||
do
|
||||
mapfile -d, -t f_assetline_sell_array < <(echo $f_assetlinesell)
|
||||
f_assetline_amount=${f_assetline_sell_array[4]}
|
||||
g_calc "$f_asset_amount_tax_free-$f_assetline_amount"
|
||||
f_assetline_amount_left=$g_calc_result
|
||||
if g_num_is_lower_equal $f_assetline_amount_left 0
|
||||
then
|
||||
g_calc "$f_asset_amount_tax_able+$f_assetline_amount_left"
|
||||
f_asset_amount_tax_able=$g_calc_result
|
||||
else
|
||||
f_asset_amount_tax_free=$f_assetline_amount_left
|
||||
fi
|
||||
done
|
||||
IFS=$oldIFS
|
||||
|
||||
if g_num_is_higher_equal $f_asset_amount_tax_free $f_asset_amount
|
||||
then
|
||||
## completely tax free if over 1 year
|
||||
f_taxable=0
|
||||
f_one_year_ago="yes"
|
||||
# reduce tax free volume
|
||||
g_calc "$f_asset_amount_tax_free-$f_asset_amount"
|
||||
f_asset_amount_tax_free=$g_calc_result
|
||||
elif g_num_is_lower_equal $f_asset_amount_tax_free 0
|
||||
then
|
||||
## complete taxable if under 1 year
|
||||
f_one_year_ago="no"
|
||||
f_taxable=$f_sell_result
|
||||
f_tax_type="Verkauf (Einkommenssteuersatz)"
|
||||
g_calc "$f_asset_amount_tax_able-$f_asset_amount"
|
||||
f_asset_amount_tax_able=$g_calc_result
|
||||
else
|
||||
## partially taxable
|
||||
f_one_year_ago="partially"
|
||||
# calculate taxable num of e.g. ETH
|
||||
g_calc "$f_asset_amount-$f_asset_amount_tax_free"
|
||||
f_taxable_asset=$g_calc_result
|
||||
|
||||
# calculate in percentage from sell sum
|
||||
g_calc "100/$f_asset_amount*$f_taxable_asset"
|
||||
f_percentage_taxable=$g_calc_result
|
||||
|
||||
# calculate part of sell_result from percentage from sell sum
|
||||
g_calc "$f_sell_result/100*$f_percentage_taxable"
|
||||
f_tax_able=$g_calc_result
|
||||
|
||||
f_tax_type="Verkauf (Einkommenssteuersatz)"
|
||||
g_calc "$f_asset_amount_tax_able-$f_taxable_asset"
|
||||
|
||||
fi
|
||||
fi
|
||||
|
||||
# refesh amount on sell
|
||||
g_calc "$f_asset_quantity-$f_asset_amount"
|
||||
f_asset_quantity=$g_calc_result
|
||||
g_calc "$f_currency_spent-($f_currency_spent/100*$f_sold_percentage)"
|
||||
f_currency_spent=$g_calc_result
|
||||
|
||||
#g_calc "$f_trade_result_asset+$f_sell_result"
|
||||
f_trade_result_asset=$g_calc_result
|
||||
|
||||
fi
|
||||
|
||||
echo "$f_date,$f_exchange,$f_type,$f_asset,$f_asset_amount,$f_currency,$f_currency_amount,$f_one_year_ago,$f_currency_spent,$f_asset_quantity,$f_result,$f_sell_result,$f_tax_type,$f_taxable" >>ALL_TRANSACTIONS_OVERVIEW.csv.tmp
|
||||
echo "$f_date,$f_exchange,$f_type,$f_asset,$f_asset_amount,$f_currency,$f_currency_amount,$f_one_year_ago,$f_currency_spent,$f_asset_quantity,$f_result,$f_sell_result,$f_tax_type,$f_taxable"
|
||||
|
||||
done
|
||||
|
||||
# calculate totals by exchange/asset
|
||||
f_staking_rewards_asset=$(cat ALL_TRANSACTIONS_OVERVIEW.csv.tmp | egrep ",$f_exchange,reward-staking,$f_asset," | cut -d, -f7 | awk "{ SUM += \$1} END { printf(\"%.2f\", SUM) }")
|
||||
f_giveaway_asset=$(cat ALL_TRANSACTIONS_OVERVIEW.csv.tmp | egrep ",$f_exchange,giveaway,$f_asset," | cut -d, -f7 | awk "{ SUM += \$1} END { printf(\"%.2f\", SUM) }")
|
||||
f_instant_trade_bonus_asset=$(cat ALL_TRANSACTIONS_OVERVIEW.csv.tmp | egrep ",$f_exchange,instant_trade_bonus,$f_asset," | cut -d, -f7 | awk "{ SUM += \$1} END { printf(\"%.2f\", SUM) }")
|
||||
|
||||
echo "Straking Rewards: $f_staking_rewards_asset"
|
||||
echo "Giveaways: $f_giveaway_asset"
|
||||
echo "Instand Trade Bonus: $f_instant_trade_bonus_asset"
|
||||
echo ""
|
||||
|
||||
#echo "$f_asset $f_exchange" | grep "ETH JustTrade" && exit 0
|
||||
|
||||
done
|
||||
|
||||
mv ALL_TRANSACTIONS_OVERVIEW.csv.tmp ALL_TRANSACTIONS_OVERVIEW.csv
|
||||
|
||||
# calculate totals from csv
|
||||
f_instant_trade_bonus=$(cat ALL_TRANSACTIONS_OVERVIEW.csv | grep ',instant_trade_bonus,' | cut -d, -f7 | awk "{ SUM += \$1} END { printf(\"%.2f\", SUM) }")
|
||||
f_staking_rewards=$(cat ALL_TRANSACTIONS_OVERVIEW.csv | grep ',reward-staking,' | cut -d, -f7 | awk "{ SUM += \$1} END { printf(\"%.2f\", SUM) }")
|
||||
f_giveaway=$(cat ALL_TRANSACTIONS_OVERVIEW.csv | grep ',giveaway,' | cut -d, -f7 | awk "{ SUM += \$1} END { printf(\"%.2f\", SUM) }")
|
||||
|
||||
|
||||
echo "========== Total Results ==========="
|
||||
echo "Trade Result: $f_trade_result"
|
||||
echo "Staking Result: $f_staking_rewards"
|
||||
echo "Giveaway Result: $f_giveaway"
|
||||
echo "Instand Trade Bonus: $f_instant_trade_bonus"
|
||||
echo ""
|
||||
|
||||
# generate and go through list of years and Exchange/Tax-Types
|
||||
cat ALL_TRANSACTIONS_OVERVIEW.csv | cut -d- -f1 | sort -u | while read f_tax_year
|
||||
do
|
||||
echo "========== Tax year $f_tax_year (German Tax Law) =========="
|
||||
cat ALL_TRANSACTIONS_OVERVIEW.csv | grep "^$f_tax_year-" | egrep -v ',,0' | cut -d, -f 2,13 | sort -u | while read f_exchange_tax_type
|
||||
do
|
||||
f_tax=$(cat ALL_TRANSACTIONS_OVERVIEW.csv | grep "^$f_tax_year-" | egrep -v ',,0' | cut -d, -f 2,13,14 | grep "$f_exchange_tax_type" | cut -d, -f3 | awk "{ SUM += \$1} END { printf(\"%.2f\", SUM) }")
|
||||
echo "$f_exchange_tax_type: $f_tax"
|
||||
done
|
||||
echo ""
|
||||
done
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user