Compare commits

...

8 Commits

Author SHA1 Message Date
ecd6f3d7ff webpage for transaction history and tax 2024-06-04 15:17:24 +02:00
2417df2317 fixes,.. 2024-06-04 15:16:40 +02:00
0341ba683a fixes tax and giveaways,... 2024-06-04 15:16:04 +02:00
35b7ba12c2 fixes tax and giveaways,... 2024-06-04 15:15:33 +02:00
b71ab4a931 fix specific tokens 2024-06-04 15:13:15 +02:00
398daf619f fix 2024-06-04 15:13:00 +02:00
c0fe474c19 background job fix 2024-06-04 15:12:29 +02:00
29156fbac6 TRANSFER_CURRENCY default to USD 2024-06-04 15:12:00 +02:00
10 changed files with 239 additions and 169 deletions

View File

@ -14,7 +14,7 @@ INTERVAL="900"
## Currency used for trading
CURRENCY="USDT"
TRANSFER_CURRENCY="NONE"
TRANSFER_CURRENCY="USD"
# Only use currencies under the first X currencies sorted by market capitalization
LARGEST_MARKETCAP="250"

View File

@ -18,7 +18,7 @@ function f_ccxt {
local g_ccxt_jobs
mapfile -t g_ccxt_jobs < <(jobs -r)
# Initialize ccxt in python if not initialized
[[ ${g_ccxt_jobs[*]} != *python-pipeexec.py* ]] || unset f_ccxt_initialized
[[ ${g_ccxt_jobs[*]} =~ *python-pipeexec.py* ]] || unset f_ccxt_initialized
if [ -z "$f_ccxt_initialized" ]
then
g_python 'import os' || return 1

View File

@ -8,8 +8,8 @@ function currency_converter {
local f_currency_date=$4
unset f_currency_converter_result
local f_reverse=false
local f_line f_rate f_histfile f_date_array f_stablecoin
local f_line f_rate f_histfile f_date_array f_stablecoin f_reverse
# get current date if none given
[ -z "$f_currency_date" ] && printf -v f_currency_date '%(%Y-%m-%d %H:%M:%S)T'
@ -83,6 +83,7 @@ function currency_converter {
[ -z "$f_line" ] && f_line=$(egrep "^$f_currency_date_day" "$f_histfile" | tail -n1)
[ -z "$f_line" ] && f_line=$(egrep "^$f_currency_date_month" "$f_histfile" | tail -n1)
[ -n "$f_line" ] && f_rate=$(echo "$f_line" | cut -d, -f2)
f_reverse=false
if [ -n "$f_rate" ]
then
[[ $f_histfile =~ ${f_currency}${f_currency_target} ]] && f_reverse=true

View File

@ -39,7 +39,7 @@ function get_bitpanda_api_transactions {
.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
[ -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
rm -f BITPANDA.csv.tmp

View File

@ -9,6 +9,13 @@ function get_marketdata_yahoo_historic {
[[ $f_item = "USD-EUR" ]] && f_item="USDEUR=X"
[[ $f_item = "EUR-USD" ]] && f_item="EURUSD=X"
[[ $f_item = "ARB-USD" ]] && f_item="ARB11841-USD"
[[ $f_item = "DUEL-USD" ]] && f_item="DUEL28868-USD"
[[ $f_item = "GMX-USD" ]] && f_item="GMX11857-USD"
[[ $f_item = "MEW-USD" ]] && f_item="MEW30126-USD"
[[ $f_item = "TAO-USD" ]] && f_item="TAO22974-USD"
[[ $f_item = "UNI-USD" ]] && f_item="UNI7083-USD"
[[ $f_item = "SUI-USD" ]] && f_item="SUI20947-USD"
# end if already failed the last hour
if [ -f FAILED_YAHOO_${f_name}_HISTORIC_DOWNLOAD ]

View File

@ -47,7 +47,7 @@ function get_transactions {
# fetch only if not exists
[ -f "$f_symbol_file" ] && continue
g_echo_note "fetchng closed orders of $f_symbol"
g_echo_note "fetching closed orders of $f_symbol on $f_exchange"
f_ccxt "print(${STOCK_EXCHANGE}.fetchMyTrades(symbol='$f_symbol', limit=500, params={'paginate': True}))"
# write to file

View File

@ -6,11 +6,13 @@ function transactions_overview {
get_justtrade_csv_transactions
get_onetrading_csv_transactions
#get_transactions
get_transactions
>ALL_TRANSACTIONS_OVERVIEW.csv.tmp
>ALL_TRANSACTIONS_OVERVIEW_WARN.csv.tmp
>TRANSACTIONS_OVERVIEW-trade-result_tax_german_eur.tmp
local f_exchange f_asset f_transactions_array f_transaction f_result f_asset_quantity f_asset_quantity_sold f_currency_quantity f_currency_quantity_sold f_currency_spent f_date f_type f_asset_amount f_currency f_currency_amount f_fee_currency f_fee_amount f_sell_result f_taxable f_tax_type f_one_year_ago f_currency_amount_eur f_currency_spent_eur f_currency_quantity_sold_eur
local f_exchange f_asset f_transactions_array f_transaction f_result f_asset_quantity f_asset_quantity_sold f_currency_quantity f_currency_quantity_sold f_currency_spent f_date f_type f_asset_amount f_currency f_currency_amount f_fee_currency f_fee_amount f_sell_result f_taxable f_tax_type f_one_year_ago f_currency_amount_eur f_currency_spent_eur f_currency_quantity_sold_eur f_note f_asset_quantity_remaining f_currency_remaining f_year
f_assets_per_exchange=$(egrep -h -v '^DATE,TYPE,ASSET,ASSET_AMOUNT,CURRENCY,CURRENCY_AMOUNT,EXCHANGE|^#|^$|^ +$|^$' TRANSACTIONS-*.csv | cut -d, -f3,7 | sort -u)
@ -20,7 +22,6 @@ function transactions_overview {
f_asset=${f_asset_per_exchange_array[0]}
f_exchange=${f_asset_per_exchange_array[1]%$'\n'}
# Ignore stableCoins, EUR, USD
[[ $f_asset = USDT ]] && continue
[[ $f_asset = USDC ]] && continue
@ -28,7 +29,8 @@ function transactions_overview {
[[ $f_asset = USD ]] && continue
[[ $f_asset = EUR ]] && continue
echo -e "\n\n=== Asset $f_asset on Exchange $f_exchange"
echo -e "\n\n=== Asset $f_asset on Exchange $f_exchange" >>ALL_TRANSACTIONS_OVERVIEW.log
g_echo_note "transactions_overview: Asset $f_asset on Exchange $f_exchange"
f_result=0
f_result_eur=0
@ -37,6 +39,7 @@ function transactions_overview {
f_currency_quantity=0
f_currency_quantity_sold=0
f_currency_quantity_sold_eur=0
f_asset_quantity_remaining=0
f_currency_spent=0
f_currency_spent_eur=0
@ -58,6 +61,7 @@ function transactions_overview {
f_taxable=0
f_tax_type=""
f_one_year_ago=""
f_note=""
# if there is a fee change to f_currency_amount and deduct f_currency_amount
if [ -n "$f_fee_amount" ]
@ -71,7 +75,8 @@ function transactions_overview {
f_fee_amount=$f_currency_converter_result
f_fee_currency=$f_currency
else
g_echo_warn "!!!!!! Could not convert currency $f_fee_currency to $f_currency"
#g_echo_warn "!!!!!! Could not convert currency $f_fee_currency to $f_currency"
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,$f_currency_amount_eur,$f_result_eur,$f_sell_result_eur,$f_asset_quantity_remaining,$f_note,Could not convert currency $f_fee_currency to $f_currency"
continue
fi
fi
@ -85,7 +90,7 @@ function transactions_overview {
g_calc "$f_currency_spent+($f_fee_amount)"
f_currency_spent=$g_calc_result
f_currency_amount=$f_fee_amount
f_tax_type="Note: Included in purchase price"
f_tax_type="Included in purchase price"
else
g_calc "$f_currency_amount+($f_fee_amount)"
f_currency_amount=$g_calc_result
@ -119,7 +124,7 @@ function transactions_overview {
[[ $f_type =~ stake ]] && continue
# 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 ]]
then
g_calc "$f_currency_spent+$f_currency_amount"
f_currency_spent=$g_calc_result
@ -133,6 +138,8 @@ function transactions_overview {
then
g_calc "$f_asset_quantity+$f_asset_amount"
f_asset_quantity=$g_calc_result
g_calc "$f_asset_quantity_remaining+$f_asset_amount"
f_asset_quantity_remaining=$g_calc_result
fi
@ -181,13 +188,15 @@ function transactions_overview {
# if sell on never buyed!?
if [ $f_currency_spent = 0 ]
then
g_echo_warn "!!!!!! Sell never buyed!? Spent currency on $f_asset is 0"
#g_echo_warn "!!!!!! Sell never buyed!? Spent currency on $f_asset is 0"
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,$f_currency_amount_eur,$f_result_eur,$f_sell_result_eur,$f_asset_quantity_remaining,$f_note,Sell never buyed!? Spent currency on $f_asset is 0"
continue
fi
# if sell wahats not exists!?
if [ $f_asset_quantity = 0 ]
then
g_echo_warn "!!!!!! Sell never buyed!? Buyed asset $f_asset is 0"
#g_echo_warn "!!!!!! Sell never buyed!? Buyed asset $f_asset is 0"
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,$f_currency_amount_eur,$f_result_eur,$f_sell_result_eur,$f_asset_quantity_remaining,$f_note,Sell never buyed!? Buyed asset $f_asset is 0"
continue
fi
fi
@ -208,7 +217,7 @@ function transactions_overview {
g_calc "$f_currency_quantity_sold_eur+$f_currency_amount_eur"
f_currency_quantity_sold_eur=$g_calc_result
## Check for ended trade (asset-quantity=0 or dust)
## Check for ended trade (asset-quantity=0 or tttt)
# if all is sold trade ended and calculate PNL
local f_trade_end=0
local f_dust=0
@ -219,15 +228,16 @@ function transactions_overview {
# Alterntively check for remaining dust only to find end of trade and calculate PNL
if [ ${g_calc_result} -eq 0 ]
then
echo currency_converter $f_asset_quantity_remaining $f_asset $f_currency "${f_date}"
currency_converter $f_asset_quantity_remaining $f_asset $f_currency "${f_date}"
local f_currency_remaining=$f_currency_converter_result
f_currency_remaining=$f_currency_converter_result
if g_num_is_between $f_currency_remaining -5 5
then
f_dust=$f_currency_remaining
currency_converter $f_asset_quantity_remaining $f_asset EUR "${f_date}"
f_dust_eur=$f_currency_converter_result
g_echo_note "Quantity ($f_asset_quantity $f_asset - $f_dust (USD) looks like dust - Ending trade"
g_echo_note "Quantity ($f_asset_quantity $f_asset - $f_dust (USD) looks like dust - Ending trade" >>ALL_TRANSACTIONS_OVERVIEW.log
f_note="$f_asset_quantity $f_asset - $f_dust (USD) looks like dust - Ending trade"
f_trade_end=1
# add to sold quantity
@ -236,30 +246,36 @@ function transactions_overview {
# add to sold quantity EUR
g_calc "$f_currency_quantity_sold_eur+($f_dust_eur)"
f_currency_quantity_sold_eur=$g_calc_result
# correct positions
f_currency_amount=$f_currency_quantity_sold
f_currency_amount_eur=$f_currency_quantity_sold_eur
f_asset_amount=$f_asset_quantity
else
g_echo_note "Tade not closed - partial sale!? Remaining $f_asset_quantity_remaining $f_asset ($f_currency_remaining $f_currency)!?"
f_tax_type="Note: Trade not closed - partial sale. Remaining $f_asset_quantity_remaining $f_asset ($f_currency_remaining $f_currency)"
g_echo_note "Tade not closed - partial sale!? Remaining $f_asset_quantity_remaining $f_asset ($f_currency_remaining $f_currency)!?" >>ALL_TRANSACTIONS_OVERVIEW.log
f_note="Trade not closed - partial sale. Remaining $f_asset_quantity_remaining $f_asset ($f_currency_remaining $f_currency)"
fi
fi
if [ ${f_trade_end} -eq 1 ]
then
echo "Buy price: $f_currency_spent $f_currency ($f_currency_spent_eur EUR)"
echo "Sell price: $f_currency_quantity_sold $f_currency ($f_currency_quantity_sold_eur EUR)"
echo "Buy price: $f_currency_spent $f_currency ($f_currency_spent_eur EUR)" >>ALL_TRANSACTIONS_OVERVIEW.log
echo "Sell price: $f_currency_quantity_sold $f_currency ($f_currency_quantity_sold_eur EUR)" >>ALL_TRANSACTIONS_OVERVIEW.log
# calculate result of trade
g_calc "$f_currency_quantity_sold-$f_currency_spent"
f_sell_result=$g_calc_result
g_calc "$f_currency_quantity_sold_eur-$f_currency_spent_eur"
f_sell_result_eur=$g_calc_result
echo "Sell result: $f_sell_result $f_currency ($f_sell_result_eur EUR)"
echo "Sell result: $f_sell_result $f_currency ($f_sell_result_eur EUR)" >>ALL_TRANSACTIONS_OVERVIEW.log
g_percentage-diff $f_currency_spent $f_currency_quantity_sold
f_sell_result_percentage=$g_percentage_diff_result
g_percentage-diff $f_currency_spent_eur $f_currency_quantity_sold_eur
f_sell_result_percentage_eur=$g_percentage_diff_result
echo "Sell result percentage: ${f_sell_result_percentage}% (EUR ${f_sell_result_percentage_eur}%)"
echo "Sell result percentage: ${f_sell_result_percentage}% (EUR ${f_sell_result_percentage_eur}%)" >>ALL_TRANSACTIONS_OVERVIEW.log
# calculate complete result
g_calc "$f_result+($f_sell_result)"
@ -348,6 +364,7 @@ function transactions_overview {
f_tax_type="Verkauf (Einkommenssteuersatz)"
g_calc "$f_asset_amount_tax_able-$f_asset_amount"
f_asset_amount_tax_able=$g_calc_result
echo "$f_date,$f_exchange,$f_currency_spent_eur,$f_currency_quantity_sold_eur" >> "TRANSACTIONS_OVERVIEW-trade-result_tax_german_eur.tmp"
else
## partially taxable
f_one_year_ago="partially"
@ -366,39 +383,40 @@ function transactions_overview {
f_tax_type="Verkauf (Einkommenssteuersatz)"
g_calc "$f_asset_amount_tax_able-$f_taxable_asset"
fi
fi
fi
echo "$f_date,$f_exchange,$f_currency_spent_eur,$f_currency_quantity_sold_eur,$f_percentage_taxable" >> "TRANSACTIONS_OVERVIEW-trade-result_tax_german_eur.tmp"
fi
fi
fi
## Fields
# 1 date
# 2 exchange
# 3 type
# 4 krypto asset
# 5 krypto asset amount
# 6 mutual currency
# 7 mutual currency amount
# 8 tax 1 year ago yes/no/partially?
# 9 totally mutal currency amount (spent money for trade)
# 10 totally krypto asset amount (got krypto in trade)
# 11 total result profit/loss for exchange/krypto asset
# 12 total result of trade (from/until krypto asset amount is 0 again)
# 13 type of tax if to pay
# 14 taxable amount of trade
# 15 mutual currency amount in EUR
# 16 total result profit/loss for exchange/krypto asset calculated in EUR
# 17 total result of trade (from/until krypto asset amount is 0 again) calculated in EUR
# 18 remaining krypto asset amount
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,$f_currency_amount_eur,$f_result_eur,$f_sell_result_eur,$f_asset_quantity_remaining" | tee -a ALL_TRANSACTIONS_OVERVIEW.csv.tmp
#printf -v f_currency_amount_rounded %.2f $f_currency_amount
#printf -v f_sell_result_rounded %.2f $f_sell_result
#printf -v f_taxable_rounded %.2f $f_taxable
# 1 date - f_date
# 2 exchange - f_exchange
# 3 type - f_type
# 4 krypto asset - f_asset
# 5 krypto asset amount - f_asset_amount
# 6 mutual currency - f_currency
# 7 mutual currency amount - f_currency_amount
# 8 tax 1 year ago yes/no/partially? - f_one_year_ago
# 9 totally mutal currency amount (money for trade) spent - f_currency_spent
# 10 totally krypto asset amount (got krypto in trade) - f_asset_quantity
# 11 total result profit/loss for exchange/krypto asset - f_result
# 12 total result of trade (from/until krypto asset amount is 0 again) - f_sell_result
# 13 type of tax if to pay - f_tax_type
# 14 taxable amount of trade - f_taxable
# 15 mutual currency amount in EUR - f_currency_amount_eur
# 16 total result profit/loss for exchange/krypto asset calculated in EUR - f_result_eur
# 17 total result of trade (from/until krypto asset amount is 0 again) calculated in EUR - f_sell_result_eur
# 18 remaining krypto asset amount - f_asset_quantity_remaining
# 19 Optional Note - f_note
# 20 totally mutal currency amount (money for trade) spent in EUR - f_currency_spent_eur
# 21 totally mutal currency amount (money for trade) sold - f_currency_quantity_sold
# 22 totally mutal currency amount (money for trade) sold in EUR - f_currency_quantity_sold_eur
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,$f_currency_amount_eur,$f_result_eur,$f_sell_result_eur,$f_asset_quantity_remaining,$f_note,$f_currency_spent_eur,$f_currency_quantity_sold,$f_currency_quantity_sold_eur" | tee -a ALL_TRANSACTIONS_OVERVIEW.csv.tmp >>ALL_TRANSACTIONS_OVERVIEW.log
if [[ $f_type =~ sell|leverage-sell ]]
then
echo -e "\n"
echo -e "\n" >>ALL_TRANSACTIONS_OVERVIEW.log
fi
done
@ -410,115 +428,21 @@ function transactions_overview {
f_tax_total=$(cat ALL_TRANSACTIONS_OVERVIEW.csv.tmp | egrep ",$f_exchange,.+,$f_asset," | cut -d, -f14 | awk "{ SUM += \$1} END { printf(\"%.10f\", SUM) }")
echo -e "\n $f_exchange $f_asset Results:"
echo " Remaining $f_asset_quantity_remaining $f_asset"
echo " Straking Rewards: $f_staking_rewards_asset $f_currency"
echo " Giveaways: $f_giveaway_asset $f_currency"
echo " Instand Trade Bonus: $f_instant_trade_bonus_asset $f_currency"
echo " Result: $f_result $f_currency ($f_result_eur EUR)"
echo " German Tax: $f_tax_total EUR"
echo "======================================"
echo -e "\n $f_exchange $f_asset Results:" >>ALL_TRANSACTIONS_OVERVIEW.log
echo " Remaining $f_asset_quantity_remaining $f_asset" >>ALL_TRANSACTIONS_OVERVIEW.log
echo " Straking Rewards: $f_staking_rewards_asset $f_currency" >>ALL_TRANSACTIONS_OVERVIEW.log
echo " Giveaways: $f_giveaway_asset $f_currency" >>ALL_TRANSACTIONS_OVERVIEW.log
echo " Instand Trade Bonus: $f_instant_trade_bonus_asset $f_currency" >>ALL_TRANSACTIONS_OVERVIEW.log
echo " Result: $f_result $f_currency ($f_result_eur EUR)" >>ALL_TRANSACTIONS_OVERVIEW.log
echo " German Tax: $f_tax_total EUR" >>ALL_TRANSACTIONS_OVERVIEW.log
echo "======================================" >>ALL_TRANSACTIONS_OVERVIEW.log
done
mv ALL_TRANSACTIONS_OVERVIEW.csv.tmp ALL_TRANSACTIONS_OVERVIEW.csv
mv ALL_TRANSACTIONS_OVERVIEW_WARN.csv.tmp ALL_TRANSACTIONS_OVERVIEW_WARN.csv
mv TRANSACTIONS_OVERVIEW-trade-result_tax_german_eur.tmp TRANSACTIONS_OVERVIEW-trade-result_tax_german_eur.csv
}
function transactions_summary {
# calculate totals from csv
local f_instant_trade_bonus=$(cat ALL_TRANSACTIONS_OVERVIEW.csv | grep ',instant_trade_bonus,' | cut -d, -f7 | awk "{ SUM += \$1} END { printf(\"%.2f\", SUM) }")
local f_staking_rewards=$(cat ALL_TRANSACTIONS_OVERVIEW.csv | grep ',reward-staking,' | cut -d, -f7 | awk "{ SUM += \$1} END { printf(\"%.2f\", SUM) }")
local f_giveaway=$(cat ALL_TRANSACTIONS_OVERVIEW.csv | grep ',giveaway,' | cut -d, -f7 | awk "{ SUM += \$1} END { printf(\"%.2f\", SUM) }")
echo -e "\n\n========== Total Results ==========="
#echo "Trade Result: $f_trade_result EUR"
echo "Staking Result: $f_staking_rewards EUR"
echo "Giveaway Result: $f_giveaway EUR"
echo -e "Instand Trade Bonus: $f_instant_trade_bonus EUR\n"
rm -f ${g_tmp}/tax_summary_*
# generate and go through list of years and Exchange/Tax-Types
local f_tax_year
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) =========="
local f_exchange_tax_type
cat ALL_TRANSACTIONS_OVERVIEW.csv | grep "^$f_tax_year-" | cut -d, -f 2,13 | sort -u | egrep -v ',$' | grep -v "Note: " | while read f_exchange_tax_type
do
local f_exchange=$(echo $f_exchange_tax_type | cut -d, -f1)
local f_tax_type=$(echo $f_exchange_tax_type | cut -d, -f2)
local f_tax=$(cat ALL_TRANSACTIONS_OVERVIEW.csv | grep "^$f_tax_year-" | cut -d, -f 2,13,14 | egrep -v ',,0$' | grep "$f_exchange_tax_type" | cut -d, -f3 | awk "{ SUM += \$1} END { printf(\"%.2f\", SUM) }")
echo "$f_exchange_tax_type: $f_tax"
echo "$f_tax_type: $f_tax EUR<br>" >>${g_tmp}/tax_summary_$f_exchange-$f_tax_year
echo "<html>
<head>
<meta charset='UTF-8'>
<meta http-equiv='refresh' content='${INTERVAL}'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link rel='stylesheet' type='text/css' href='/browser.css'>
<link rel='stylesheet' type='text/css' href='/charts.min.css'>
<title>Detailed Transactions on $f_exchange from ${f_tax_year}</title>
</head>
<body>
<h1>Detailed Transactions on $f_exchange from ${f_tax_year}</h1>
<h2>Summary</h2>
$(cat ${g_tmp}/tax_summary_$f_exchange-$f_tax_year)
<h2>List of trades</h2>
- Fees included<br>
- EUR values were calculated using the exchange rate at the time of trading<br>
- Fiat rounded to two decimal places. Internally, further decimal places are used in the calculation<br>
<table>
<tr><td>Date</td><td>Type of transaction</td><td>Crypto value</td><td>Fiat value</td><td>Result</td><td>Tax type</td><td>Tax amount</td></tr>
" >TRANSACTIONS_OVERVIEW-${f_exchange}-${f_tax_year}.html.tmp
cat ALL_TRANSACTIONS_OVERVIEW.csv | grep "^${f_tax_year}-" | grep ",${f_exchange}," | awk -F, '
{printf "<tr><td>"$1"</td><td>"$3"</td><td>"$5" "$4"</td><td>"}
{printf("%.2f", $7)}
{printf " EUR </td><td>"}
{printf("%.2f", $16)}
{printf " EUR</td><td>"$13"</td><td>"}
{printf("%.2f", $14)}
{print " EUR</td></tr>"}' >>TRANSACTIONS_OVERVIEW-${f_exchange}-${f_tax_year}.html.tmp
echo "</table></body></html>" >>TRANSACTIONS_OVERVIEW-${f_exchange}-${f_tax_year}.html.tmp
mv TRANSACTIONS_OVERVIEW-${f_exchange}-${f_tax_year}.html.tmp ../TRANSACTIONS_OVERVIEW-${f_exchange}-${f_tax_year}.html
done
echo ""
done
## Overview over Overviews
echo "<html>
<head>
<meta charset='UTF-8'>
<meta http-equiv='refresh' content='${INTERVAL}'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link rel='stylesheet' type='text/css' href='/browser.css'>
<link rel='stylesheet' type='text/css' href='/charts.min.css'>
<title>Trading Overview</title>
</head>
<body>
<h1>Transaction Overviews</h1>" >../TRANSACTIONS_OVERVIEWS.html
local f_html f_name
ls ../TRANSACTIONS_OVERVIEW-* | while read f_html
do
f_html=$(basename $f_html)
f_name=$(echo $f_html | cut -d- -f2,3 | cut -d. -f1)
echo "<a href='${f_html}'>$f_name</a><br>" >>../TRANSACTIONS_OVERVIEWS.html
done
echo "</body></html>" >>../TRANSACTIONS_OVERVIEWS.htm
}

View File

@ -1,8 +1,9 @@
function webpage {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
webpage_transactions
# Get charts.css
[ -e ../charts.min.css ] || wget ${g_wget_opts} -q https://raw.githubusercontent.com/ChartsCSS/charts.css/main/dist/charts.min.css -O ../charts.min.css
@ -20,6 +21,9 @@ function webpage {
<h1>State of Dabo-Bot! on ${STOCK_EXCHANGE} - ${URL} (ReadOnly)</h1>
<h1>Last update $(date '+%F %T')</h1>" >../index.html.tmp
# historic overview
echo '<a href=TRANSACTIONS_OVERVIEWS.html><h2>Historic Overview</h2></a>' >>../index.html.tmp
local f_SPOT_BALANCE=$(tail -n1 "asset-histories/BALANCESPOT${CURRENCY}.history.csv" | cut -d, -f2)
local f_COMPLETE_BALANCE=$(tail -n1 "asset-histories/BALANCECOMPLETE${CURRENCY}.history.csv" | cut -d, -f2)
echo '<h2>Overview</h2>' >>../index.html.tmp
@ -82,8 +86,7 @@ function webpage {
</tr>
</table>" >>../index.html.tmp
echo '<h2>Open Trades (Invested Assets)</h2>' >>../index.html.tmp
echo '<h2>Open Positions</h2>' >>../index.html.tmp
echo "<table width='100%'>" >>../index.html.tmp
local line
cat EXCHANGE_GET_BALANCES_CMD_OUT | grep -v ${CURRENCY} | sort | while read line
@ -97,6 +100,45 @@ function webpage {
done
echo "</table>" >>../index.html.tmp
## Open Positions
echo "<h2>Open Positions - From Trade Histories</h2>" >>../index.html.tmp
echo "<table width='100%'>" >>../index.html.tmp
echo "<tr><td>Amount</td><td>Spent Amount</td><td>Sold Amount</td><td>Profit/Loss</td><td>Asset Amount</td><td>Exchange</td></tr>" >>../index.html.tmp
rm -f ../index.html.tmp.tmp
cat ALL_TRANSACTIONS_OVERVIEW.csv | cut -d, -f2,4 | sort -u | while read f_asset_per_exchange
do
mapfile -d, -t f_asset_per_exchange_array < <(echo $f_asset_per_exchange)
f_asset=${f_asset_per_exchange_array[1]%$'\n'}
f_exchange=${f_asset_per_exchange_array[0]}
[[ "$f_exchange" =~ JustTrade|Bitpanda ]] || continue
f_amount=$(egrep "$f_exchange,.+,$f_asset" ALL_TRANSACTIONS_OVERVIEW.csv | tail -n1 | cut -d, -f18)
f_spent=$(egrep "$f_exchange,.+,$f_asset" ALL_TRANSACTIONS_OVERVIEW.csv | tail -n1 | cut -d, -f20)
f_sold=$(egrep "$f_exchange,.+,$f_asset" ALL_TRANSACTIONS_OVERVIEW.csv | tail -n1 | cut -d, -f22)
if ! [ "$f_amount" = 0 ]
then
currency_converter $f_amount $f_asset $TRANSFER_CURRENCY || continue
f_currency_amount=$f_currency_converter_result
g_calc "$f_currency_amount+($f_sold)"
f_currency_amount=$g_calc_result
g_calc "$f_spent-($f_sold)"
f_spent=$g_calc_result
if [ "$f_spent" = 0 ]
then
f_result_percent=0
else
g_percentage-diff $f_spent $f_currency_amount
f_result_percent=$g_percentage_diff_result
fi
g_calc "$f_currency_amount-($f_spent)"
f_result=$g_calc_result
echo "<tr><td>$f_currency_amount $TRANSFER_CURRENCY</td><td>$f_spent $TRANSFER_CURRENCY</td><td>$f_sold $TRANSFER_CURRENCY</td><td>$f_result $TRANSFER_CURRENCY ( ${f_result_percent}%)</td><td>$f_amount $f_asset</td><td>$f_exchange</td></tr>" >>../index.html.tmp.tmp
fi
done
sort -n -k3 -t'>' -r ../index.html.tmp.tmp >>../index.html.tmp
rm ../index.html.tmp.tmp
echo "</table>" >>../index.html.tmp
echo "<h2>Market Performance ( $(cat MARKET_PERFORMANCE_LATEST)%)</h2>" >>../index.html.tmp
#echo "<table width='100%'><tr><td><details><summary>Charts</summary>" >>../index.html.tmp
echo "<details><summary>Charts</summary>" >>../index.html.tmp

View File

@ -0,0 +1,98 @@
function webpage_transactions {
# calculate totals from csv
local f_instant_trade_bonus=$(cat ALL_TRANSACTIONS_OVERVIEW.csv | grep ',instant_trade_bonus,' | cut -d, -f7 | awk "{ SUM += \$1} END { printf(\"%.2f\", SUM) }")
local f_staking_rewards=$(cat ALL_TRANSACTIONS_OVERVIEW.csv | grep ',reward-staking,' | cut -d, -f7 | awk "{ SUM += \$1} END { printf(\"%.2f\", SUM) }")
local f_giveaway=$(cat ALL_TRANSACTIONS_OVERVIEW.csv | grep ',giveaway,' | cut -d, -f7 | awk "{ SUM += \$1} END { printf(\"%.2f\", SUM) }")
#echo -e "\n\n========== Total Results ==========="
##echo "Trade Result: $f_trade_result EUR"
#echo "Staking Result: $f_staking_rewards EUR"
#echo "Giveaway Result: $f_giveaway EUR"
#echo -e "Instand Trade Bonus: $f_instant_trade_bonus EUR\n"
# generate and go through list of years and Exchange/Tax-Types
rm -f ${g_tmp}/tax_summary_*
local f_tax_year
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) =========="
local f_exchange_tax_type
cat ALL_TRANSACTIONS_OVERVIEW.csv | grep "^$f_tax_year-" | cut -d, -f 2,13 | sort -u | egrep -v ',$' | grep -v "Note: " | while read f_exchange_tax_type
do
local f_exchange=$(echo $f_exchange_tax_type | cut -d, -f1)
local f_tax_type=$(echo $f_exchange_tax_type | cut -d, -f2)
local f_tax=$(cat ALL_TRANSACTIONS_OVERVIEW.csv | grep "^$f_tax_year-" | cut -d, -f 2,13,14 | egrep -v ',,0$' | grep "$f_exchange_tax_type" | cut -d, -f3 | awk "{ SUM += \$1} END { printf(\"%.2f\", SUM) }")
echo "$f_exchange_tax_type: $f_tax"
echo "$f_tax_type: $f_tax EUR<br>" >>${g_tmp}/tax_summary_$f_exchange-$f_tax_year
echo "<html>
<head>
<meta charset='UTF-8'>
<meta http-equiv='refresh' content='${INTERVAL}'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link rel='stylesheet' type='text/css' href='/browser.css'>
<link rel='stylesheet' type='text/css' href='/charts.min.css'>
<title>Detailed Transactions on $f_exchange from ${f_tax_year} - Created: $(date)</title>
</head>
<body>
<h1>Detailed Transactions on $f_exchange from ${f_tax_year}</h1>
<h2>Summary</h2>
$(cat ${g_tmp}/tax_summary_$f_exchange-$f_tax_year)
<h2>List of trades</h2>
- Fees included<br>
- EUR values were calculated using the exchange rate at the time of trading<br>
- Fiat rounded to two decimal places. Internally, further decimal places are used in the calculation<br>
<table>
<tr><td>Date</td><td>Type of transaction</td><td>Crypto value</td><td>Fiat value</td><td>Result</td><td>Tax type</td><td>Tax amount</td></tr>
" >TRANSACTIONS_OVERVIEW-${f_exchange}-${f_tax_year}.html.tmp
cat ALL_TRANSACTIONS_OVERVIEW.csv | grep "^${f_tax_year}-" | grep ",${f_exchange}," | awk -F, '
{printf "<tr><td>"$1"</td><td>"$3"</td><td>"$5" "$4"</td><td>"}
{printf("%.2f", $15)}
{printf " EUR </td><td>"}
{printf("%.2f", $17)}
{printf " EUR</td><td>"$13"</td><td>"}
{printf("%.2f", $14)}
{print " EUR</td></tr>"}' >>TRANSACTIONS_OVERVIEW-${f_exchange}-${f_tax_year}.html.tmp
echo "</table></body></html>" >>TRANSACTIONS_OVERVIEW-${f_exchange}-${f_tax_year}.html.tmp
mv TRANSACTIONS_OVERVIEW-${f_exchange}-${f_tax_year}.html.tmp ../TRANSACTIONS_OVERVIEW-${f_exchange}-${f_tax_year}.html
done
echo ""
done
## Overview over Overviews
echo "<html>
<head>
<meta charset='UTF-8'>
<meta http-equiv='refresh' content='${INTERVAL}'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link rel='stylesheet' type='text/css' href='/browser.css'>
<link rel='stylesheet' type='text/css' href='/charts.min.css'>
<title>Trading Overview</title>
</head>
<body>
<h1>Transaction Overviews</h1>" >../TRANSACTIONS_OVERVIEWS.html
local f_html f_name
ls ../TRANSACTIONS_OVERVIEW-* | while read f_html
do
f_html=$(basename $f_html)
f_name=$(echo $f_html | cut -d- -f2,3 | cut -d. -f1)
echo "<a href='${f_html}'>$f_name</a><br>" >>../TRANSACTIONS_OVERVIEWS.html
done
echo "$(cat ALL_TRANSACTIONS_OVERVIEW_WARN.csv | cut -d, -f1,2,20)<br>" >>../TRANSACTIONS_OVERVIEWS.html
echo "</body></html>" >>../TRANSACTIONS_OVERVIEWS.html
}

View File

@ -4,9 +4,7 @@
while true
do
get_transactions
transactions_overview
transactions_summary
sleep 3600
done