pnl, tax, transactions
This commit is contained in:
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
function calc_fifo_pnl {
|
||||
# Initialize variables
|
||||
local f_csv_file="$1"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user