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 used for trading
CURRENCY="USDT" CURRENCY="USDT"
TRANSFER_CURRENCY="NONE" TRANSFER_CURRENCY="USD"
# Only use currencies under the first X currencies sorted by market capitalization # Only use currencies under the first X currencies sorted by market capitalization
LARGEST_MARKETCAP="250" LARGEST_MARKETCAP="250"

View File

@ -18,7 +18,7 @@ function f_ccxt {
local g_ccxt_jobs local g_ccxt_jobs
mapfile -t g_ccxt_jobs < <(jobs -r) mapfile -t g_ccxt_jobs < <(jobs -r)
# Initialize ccxt in python if not initialized # 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" ] if [ -z "$f_ccxt_initialized" ]
then then
g_python 'import os' || return 1 g_python 'import os' || return 1

View File

@ -8,8 +8,8 @@ function currency_converter {
local f_currency_date=$4 local f_currency_date=$4
unset f_currency_converter_result 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 # get current date if none given
[ -z "$f_currency_date" ] && printf -v f_currency_date '%(%Y-%m-%d %H:%M:%S)T' [ -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_day" "$f_histfile" | tail -n1)
[ -z "$f_line" ] && f_line=$(egrep "^$f_currency_date_month" "$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) [ -n "$f_line" ] && f_rate=$(echo "$f_line" | cut -d, -f2)
f_reverse=false
if [ -n "$f_rate" ] if [ -n "$f_rate" ]
then then
[[ $f_histfile =~ ${f_currency}${f_currency_target} ]] && f_reverse=true [[ $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" .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 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) # 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 cat BITPANDA.csv.tmp | grep -v ",reward.best," | sort >TRANSACTIONS-BITPANDA.csv
rm -f BITPANDA.csv.tmp 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 = "USD-EUR" ]] && f_item="USDEUR=X"
[[ $f_item = "EUR-USD" ]] && f_item="EURUSD=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 # end if already failed the last hour
if [ -f FAILED_YAHOO_${f_name}_HISTORIC_DOWNLOAD ] if [ -f FAILED_YAHOO_${f_name}_HISTORIC_DOWNLOAD ]

View File

@ -47,7 +47,7 @@ function get_transactions {
# fetch only if not exists # fetch only if not exists
[ -f "$f_symbol_file" ] && continue [ -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}))" f_ccxt "print(${STOCK_EXCHANGE}.fetchMyTrades(symbol='$f_symbol', limit=500, params={'paginate': True}))"
# write to file # write to file

View File

@ -6,11 +6,13 @@ function transactions_overview {
get_justtrade_csv_transactions get_justtrade_csv_transactions
get_onetrading_csv_transactions get_onetrading_csv_transactions
#get_transactions get_transactions
>ALL_TRANSACTIONS_OVERVIEW.csv.tmp >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) 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_asset=${f_asset_per_exchange_array[0]}
f_exchange=${f_asset_per_exchange_array[1]%$'\n'} f_exchange=${f_asset_per_exchange_array[1]%$'\n'}
# Ignore stableCoins, EUR, USD # Ignore stableCoins, EUR, USD
[[ $f_asset = USDT ]] && continue [[ $f_asset = USDT ]] && continue
[[ $f_asset = USDC ]] && continue [[ $f_asset = USDC ]] && continue
@ -28,7 +29,8 @@ function transactions_overview {
[[ $f_asset = USD ]] && continue [[ $f_asset = USD ]] && continue
[[ $f_asset = EUR ]] && 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=0
f_result_eur=0 f_result_eur=0
@ -37,6 +39,7 @@ function transactions_overview {
f_currency_quantity=0 f_currency_quantity=0
f_currency_quantity_sold=0 f_currency_quantity_sold=0
f_currency_quantity_sold_eur=0 f_currency_quantity_sold_eur=0
f_asset_quantity_remaining=0
f_currency_spent=0 f_currency_spent=0
f_currency_spent_eur=0 f_currency_spent_eur=0
@ -58,6 +61,7 @@ function transactions_overview {
f_taxable=0 f_taxable=0
f_tax_type="" f_tax_type=""
f_one_year_ago="" f_one_year_ago=""
f_note=""
# if there is a fee change to f_currency_amount and deduct f_currency_amount # if there is a fee change to f_currency_amount and deduct f_currency_amount
if [ -n "$f_fee_amount" ] if [ -n "$f_fee_amount" ]
@ -71,7 +75,8 @@ function transactions_overview {
f_fee_amount=$f_currency_converter_result f_fee_amount=$f_currency_converter_result
f_fee_currency=$f_currency f_fee_currency=$f_currency
else 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 continue
fi fi
fi fi
@ -85,7 +90,7 @@ function transactions_overview {
g_calc "$f_currency_spent+($f_fee_amount)" g_calc "$f_currency_spent+($f_fee_amount)"
f_currency_spent=$g_calc_result f_currency_spent=$g_calc_result
f_currency_amount=$f_fee_amount f_currency_amount=$f_fee_amount
f_tax_type="Note: Included in purchase price" f_tax_type="Included in purchase price"
else else
g_calc "$f_currency_amount+($f_fee_amount)" g_calc "$f_currency_amount+($f_fee_amount)"
f_currency_amount=$g_calc_result f_currency_amount=$g_calc_result
@ -119,7 +124,7 @@ 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 ]]
then then
g_calc "$f_currency_spent+$f_currency_amount" g_calc "$f_currency_spent+$f_currency_amount"
f_currency_spent=$g_calc_result f_currency_spent=$g_calc_result
@ -133,6 +138,8 @@ function transactions_overview {
then then
g_calc "$f_asset_quantity+$f_asset_amount" g_calc "$f_asset_quantity+$f_asset_amount"
f_asset_quantity=$g_calc_result f_asset_quantity=$g_calc_result
g_calc "$f_asset_quantity_remaining+$f_asset_amount"
f_asset_quantity_remaining=$g_calc_result
fi fi
@ -181,13 +188,15 @@ function transactions_overview {
# if sell on never buyed!? # if sell on never buyed!?
if [ $f_currency_spent = 0 ] if [ $f_currency_spent = 0 ]
then 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 continue
fi fi
# if sell wahats not exists!? # if sell wahats not exists!?
if [ $f_asset_quantity = 0 ] if [ $f_asset_quantity = 0 ]
then 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 continue
fi fi
fi fi
@ -208,7 +217,7 @@ function transactions_overview {
g_calc "$f_currency_quantity_sold_eur+$f_currency_amount_eur" g_calc "$f_currency_quantity_sold_eur+$f_currency_amount_eur"
f_currency_quantity_sold_eur=$g_calc_result 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 # if all is sold trade ended and calculate PNL
local f_trade_end=0 local f_trade_end=0
local f_dust=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 # Alterntively check for remaining dust only to find end of trade and calculate PNL
if [ ${g_calc_result} -eq 0 ] if [ ${g_calc_result} -eq 0 ]
then 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}" 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 if g_num_is_between $f_currency_remaining -5 5
then then
f_dust=$f_currency_remaining f_dust=$f_currency_remaining
currency_converter $f_asset_quantity_remaining $f_asset EUR "${f_date}" currency_converter $f_asset_quantity_remaining $f_asset EUR "${f_date}"
f_dust_eur=$f_currency_converter_result 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 f_trade_end=1
# add to sold quantity # add to sold quantity
@ -236,30 +246,36 @@ function transactions_overview {
# add to sold quantity EUR # add to sold quantity EUR
g_calc "$f_currency_quantity_sold_eur+($f_dust_eur)" g_calc "$f_currency_quantity_sold_eur+($f_dust_eur)"
f_currency_quantity_sold_eur=$g_calc_result 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 else
g_echo_note "Tade 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_tax_type="Note: Trade not closed - partial sale. Remaining $f_asset_quantity_remaining $f_asset ($f_currency_remaining $f_currency)" f_note="Trade not closed - partial sale. Remaining $f_asset_quantity_remaining $f_asset ($f_currency_remaining $f_currency)"
fi fi
fi fi
if [ ${f_trade_end} -eq 1 ] if [ ${f_trade_end} -eq 1 ]
then then
echo "Buy price: $f_currency_spent $f_currency ($f_currency_spent_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)" echo "Sell price: $f_currency_quantity_sold $f_currency ($f_currency_quantity_sold_eur EUR)" >>ALL_TRANSACTIONS_OVERVIEW.log
# calculate result of trade # calculate result of trade
g_calc "$f_currency_quantity_sold-$f_currency_spent" g_calc "$f_currency_quantity_sold-$f_currency_spent"
f_sell_result=$g_calc_result f_sell_result=$g_calc_result
g_calc "$f_currency_quantity_sold_eur-$f_currency_spent_eur" g_calc "$f_currency_quantity_sold_eur-$f_currency_spent_eur"
f_sell_result_eur=$g_calc_result 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 g_percentage-diff $f_currency_spent $f_currency_quantity_sold
f_sell_result_percentage=$g_percentage_diff_result f_sell_result_percentage=$g_percentage_diff_result
g_percentage-diff $f_currency_spent_eur $f_currency_quantity_sold_eur g_percentage-diff $f_currency_spent_eur $f_currency_quantity_sold_eur
f_sell_result_percentage_eur=$g_percentage_diff_result 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 # calculate complete result
g_calc "$f_result+($f_sell_result)" g_calc "$f_result+($f_sell_result)"
@ -348,6 +364,7 @@ function transactions_overview {
f_tax_type="Verkauf (Einkommenssteuersatz)" f_tax_type="Verkauf (Einkommenssteuersatz)"
g_calc "$f_asset_amount_tax_able-$f_asset_amount" g_calc "$f_asset_amount_tax_able-$f_asset_amount"
f_asset_amount_tax_able=$g_calc_result 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 else
## partially taxable ## partially taxable
f_one_year_ago="partially" f_one_year_ago="partially"
@ -366,39 +383,40 @@ function transactions_overview {
f_tax_type="Verkauf (Einkommenssteuersatz)" f_tax_type="Verkauf (Einkommenssteuersatz)"
g_calc "$f_asset_amount_tax_able-$f_taxable_asset" g_calc "$f_asset_amount_tax_able-$f_taxable_asset"
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
fi
fi
## Fields ## Fields
# 1 date # 1 date - f_date
# 2 exchange # 2 exchange - f_exchange
# 3 type # 3 type - f_type
# 4 krypto asset # 4 krypto asset - f_asset
# 5 krypto asset amount # 5 krypto asset amount - f_asset_amount
# 6 mutual currency # 6 mutual currency - f_currency
# 7 mutual currency amount # 7 mutual currency amount - f_currency_amount
# 8 tax 1 year ago yes/no/partially? # 8 tax 1 year ago yes/no/partially? - f_one_year_ago
# 9 totally mutal currency amount (spent money for trade) # 9 totally mutal currency amount (money for trade) spent - f_currency_spent
# 10 totally krypto asset amount (got krypto in trade) # 10 totally krypto asset amount (got krypto in trade) - f_asset_quantity
# 11 total result profit/loss for exchange/krypto asset # 11 total result profit/loss for exchange/krypto asset - f_result
# 12 total result of trade (from/until krypto asset amount is 0 again) # 12 total result of trade (from/until krypto asset amount is 0 again) - f_sell_result
# 13 type of tax if to pay # 13 type of tax if to pay - f_tax_type
# 14 taxable amount of trade # 14 taxable amount of trade - f_taxable
# 15 mutual currency amount in EUR # 15 mutual currency amount in EUR - f_currency_amount_eur
# 16 total result profit/loss for exchange/krypto asset calculated in 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 # 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 # 18 remaining krypto asset amount - f_asset_quantity_remaining
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 # 19 Optional Note - f_note
# 20 totally mutal currency amount (money for trade) spent in EUR - f_currency_spent_eur
#printf -v f_currency_amount_rounded %.2f $f_currency_amount # 21 totally mutal currency amount (money for trade) sold - f_currency_quantity_sold
#printf -v f_sell_result_rounded %.2f $f_sell_result # 22 totally mutal currency amount (money for trade) sold in EUR - f_currency_quantity_sold_eur
#printf -v f_taxable_rounded %.2f $f_taxable 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 ]] if [[ $f_type =~ sell|leverage-sell ]]
then then
echo -e "\n" echo -e "\n" >>ALL_TRANSACTIONS_OVERVIEW.log
fi fi
done 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) }") 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 -e "\n $f_exchange $f_asset Results:" >>ALL_TRANSACTIONS_OVERVIEW.log
echo " Remaining $f_asset_quantity_remaining $f_asset" echo " Remaining $f_asset_quantity_remaining $f_asset" >>ALL_TRANSACTIONS_OVERVIEW.log
echo " Straking Rewards: $f_staking_rewards_asset $f_currency" echo " Straking Rewards: $f_staking_rewards_asset $f_currency" >>ALL_TRANSACTIONS_OVERVIEW.log
echo " Giveaways: $f_giveaway_asset $f_currency" echo " Giveaways: $f_giveaway_asset $f_currency" >>ALL_TRANSACTIONS_OVERVIEW.log
echo " Instand Trade Bonus: $f_instant_trade_bonus_asset $f_currency" 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)" echo " Result: $f_result $f_currency ($f_result_eur EUR)" >>ALL_TRANSACTIONS_OVERVIEW.log
echo " German Tax: $f_tax_total EUR" echo " German Tax: $f_tax_total EUR" >>ALL_TRANSACTIONS_OVERVIEW.log
echo "======================================" echo "======================================" >>ALL_TRANSACTIONS_OVERVIEW.log
done done
mv ALL_TRANSACTIONS_OVERVIEW.csv.tmp ALL_TRANSACTIONS_OVERVIEW.csv 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 { function webpage {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
webpage_transactions
# Get charts.css # 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 [ -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>State of Dabo-Bot! on ${STOCK_EXCHANGE} - ${URL} (ReadOnly)</h1>
<h1>Last update $(date '+%F %T')</h1>" >../index.html.tmp <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_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) local f_COMPLETE_BALANCE=$(tail -n1 "asset-histories/BALANCECOMPLETE${CURRENCY}.history.csv" | cut -d, -f2)
echo '<h2>Overview</h2>' >>../index.html.tmp echo '<h2>Overview</h2>' >>../index.html.tmp
@ -82,8 +86,7 @@ function webpage {
</tr> </tr>
</table>" >>../index.html.tmp </table>" >>../index.html.tmp
echo '<h2>Open Positions</h2>' >>../index.html.tmp
echo '<h2>Open Trades (Invested Assets)</h2>' >>../index.html.tmp
echo "<table width='100%'>" >>../index.html.tmp echo "<table width='100%'>" >>../index.html.tmp
local line local line
cat EXCHANGE_GET_BALANCES_CMD_OUT | grep -v ${CURRENCY} | sort | while read line cat EXCHANGE_GET_BALANCES_CMD_OUT | grep -v ${CURRENCY} | sort | while read line
@ -97,6 +100,45 @@ function webpage {
done done
echo "</table>" >>../index.html.tmp 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 "<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 "<table width='100%'><tr><td><details><summary>Charts</summary>" >>../index.html.tmp
echo "<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 while true
do do
get_transactions
transactions_overview transactions_overview
transactions_summary
sleep 3600 sleep 3600
done done