diff --git a/dabo/functions/get_bitpanda_api_transactions.sh b/dabo/functions/get_bitpanda_api_transactions.sh new file mode 100644 index 0000000..4df98da --- /dev/null +++ b/dabo/functions/get_bitpanda_api_transactions.sh @@ -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 + +} +