From 06bfc85485cc33ed790e8d092d11390d5964b591 Mon Sep 17 00:00:00 2001 From: olli Date: Fri, 28 Feb 2025 17:22:42 +0100 Subject: [PATCH] pnl, tax, transactions --- dabo/functions/calc_fifo_pnl.sh | 20 +++++++++++++++ dabo/functions/get_phemex_csv_transactions.sh | 21 ++++++++++++++-- dabo/functions/get_transactions.sh | 25 +++++++++---------- 3 files changed, 51 insertions(+), 15 deletions(-) diff --git a/dabo/functions/calc_fifo_pnl.sh b/dabo/functions/calc_fifo_pnl.sh index 6d3897a..c72f017 100644 --- a/dabo/functions/calc_fifo_pnl.sh +++ b/dabo/functions/calc_fifo_pnl.sh @@ -1,3 +1,23 @@ +#!/bin/bash + +# Copyright (c) 2022-2024 olli +# +# This file is part of dabo (crypto bot). +# +# dabo is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# dabo is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with dabo. If not, see . + + function calc_fifo_pnl { # Initialize variables local f_csv_file="$1" diff --git a/dabo/functions/get_phemex_csv_transactions.sh b/dabo/functions/get_phemex_csv_transactions.sh index 9543e00..75b3720 100644 --- a/dabo/functions/get_phemex_csv_transactions.sh +++ b/dabo/functions/get_phemex_csv_transactions.sh @@ -41,8 +41,25 @@ function get_phemex_csv_transactions { cat TRANSACTIONS-phemex/*.csv | egrep 'funding' | sort -u >>TRANSACTIONS-phemex.csv.tmp # put together - cat TRANSACTIONS-phemex-LONG.csv.tmp TRANSACTIONS-phemex.csv.tmp TRANSACTIONS-phemex-liquidations-LONG.csv.tmp | sort >TRANSACTIONS-phemex.csv - cat TRANSACTIONS-phemex-SHORT.csv.tmp TRANSACTIONS-phemex-liquidations-SHORT.csv.tmp | sort >>TRANSACTIONS-phemex.csv + local f_line f_id + touch "TRANSACTIONS-phemex.csv" + + cat TRANSACTIONS-phemex-LONG.csv.tmp TRANSACTIONS-phemex.csv.tmp TRANSACTIONS-phemex-liquidations-LONG.csv.tmp | sort | while read f_line + do + f_id=$(echo "$f_line" | cut -d, -f10) + grep -q "$f_id" "TRANSACTIONS-phemex.csv" || echo $f_line >>"TRANSACTIONS-phemex.csv" + done + + cat TRANSACTIONS-phemex-SHORT.csv.tmp TRANSACTIONS-phemex-liquidations-SHORT.csv.tmp | sort | while read f_line + do + f_id=$(echo "$f_line" | cut -d, -f10) + grep -q "$f_id" "TRANSACTIONS-phemex.csv" || echo $f_line >>"TRANSACTIONS-phemex.csv" + done + + + + #cat TRANSACTIONS-phemex-LONG.csv.tmp TRANSACTIONS-phemex.csv.tmp TRANSACTIONS-phemex-liquidations-LONG.csv.tmp | sort >TRANSACTIONS-phemex.csv + #cat TRANSACTIONS-phemex-SHORT.csv.tmp TRANSACTIONS-phemex-liquidations-SHORT.csv.tmp | sort >>TRANSACTIONS-phemex.csv # cleanup rm -f TRANSACTIONS-phemex-LONG.csv.tmp TRANSACTIONS-phemex-SHORT.csv.tmp TRANSACTIONS-phemex.csv.tmp TRANSACTIONS-phemex-liquidations-LONG.csv.tmp TRANSACTIONS-phemex-liquidations-SHORT.csv.tmp fi diff --git a/dabo/functions/get_transactions.sh b/dabo/functions/get_transactions.sh index bee176a..c6e8aab 100644 --- a/dabo/functions/get_transactions.sh +++ b/dabo/functions/get_transactions.sh @@ -127,7 +127,8 @@ function get_transactions { cat "$f_symbol_file" | jq -r " .[] | select(.side==\"buy\" or .side==\"sell\") | - select(.symbol!= null) | + select(.symbol != null) | + select(.type != null) | .datetime + \",$f_leverage\" + .side + \",$f_asset,\" + (.amount|tostring) + \",$f_currency,\" + (.cost|tostring) + \",$f_exchange,\" + .fee.currency + \",\" + (.fee.cost|tostring) + \",\" + .id " >>"$f_symbol_file_csv_tmp" @@ -206,22 +207,20 @@ function get_transactions { done fi - # put all sorted n one file by id - local f_line f_id + # put all sorted in one file. duplicates check with id + local f_line f_date f_sym touch "TRANSACTIONS-$f_exchange.csv" - cat "TRANSACTIONS-$f_exchange/"*.csv | while read f_line + grep -vh ,fundingfee, "TRANSACTIONS-$f_exchange/"*.csv | while read f_line do - echo $f_line - f_id=$(echo "$line" | cut -d, -f10) + f_id=$(echo "$f_line" | cut -d, -f10) grep -q "$f_id" "TRANSACTIONS-$f_exchange.csv" || echo $f_line >>"TRANSACTIONS-$f_exchange.csv" done - #if [ -s TRANSACTIONS-$f_exchange.csv ] - #then - # cat "TRANSACTIONS-$f_exchange/"*.csv TRANSACTIONS-$f_exchange.csv | sort -u >TRANSACTIONS-$f_exchange.csv.tmp - # mv TRANSACTIONS-$f_exchange.csv.tmp TRANSACTIONS-$f_exchange.csv - #else - # cat "TRANSACTIONS-$f_exchange/"*.csv | sort -u >TRANSACTIONS-$f_exchange.csv - #fi + grep -h ,fundingfee, "TRANSACTIONS-$f_exchange/"*.csv | while read f_line + do + f_date=$(echo "$f_line" | cut -d: -f1) + f_sym=$(echo "$f_line" | cut -d, -f3) + egrep -q "^$f_date:.+,$f_sym," "TRANSACTIONS-$f_exchange.csv" || echo $f_line >>"TRANSACTIONS-$f_exchange.csv" + done # Switch sides if Fiat is in Krypto side f_fiats="USD EUR"