Skip to content

Commit

Permalink
Fix issue with fees in sell transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderLill committed May 17, 2023
1 parent 48acb67 commit 6dfaf64
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
Binary file modified doc/depot_transactions_normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/depot_transactions_special.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/depot_transactions_special2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion src/ledger_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,10 @@ def _process_trade(self, transaction_id, transaction):
fee_crypto = tcrypto["fee"]

if isinstance(fiat_amount, numbers.Number) and isinstance(fee_fiat, numbers.Number):
total = fiat_amount + fee_fiat
if is_buy_transaction:
total = fiat_amount + fee_fiat
else:
total = fiat_amount - fee_fiat
elif isinstance(fiat_amount, numbers.Number):
total = fiat_amount
else:
Expand Down
24 changes: 24 additions & 0 deletions src/test/process_ledger_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,30 @@ def test_import_buy(self):
result_csv = result_csv + t.to_csv() + "\n"

self.assertEquals(result_csv, expected_depot_csv)

def test_import_sell(self):
kraken_csv = dedent("""
"txid","refid","time","type","subtype","aclass","asset","amount","fee","balance"
"LFAVC7-TR6BH-KQMRMG","TDT7NF-OITYA-C2V7KD","2021-01-02 19:14:00","trade","","currency","XXBT",-0.0041520000,0.0000000000,0.0000011800
"L4Q26U-35JVG-EJGUOR","TDT7NF-OITYA-C2V7KD","2021-01-02 19:14:00","trade","","currency","ZEUR",110.4427,0.28716,9183.4334
""")

expected_depot_csv = dedent("""
2021-01-02;19:14:00;Verkauf;XBT;0,004152;26.599,879576;110,442700;0,287160;;110,155540;DEPOT;ACCOUNT;TDT7NF-OITYA-C2V7KD,L4Q26U-35JVG-EJGUOR,LFAVC7-TR6BH-KQMRMG;
""")

df = pd.read_csv(StringIO(kraken_csv))

lp = LedgerProcessor(dataframe=df, depot_current=self.DEPOT_CURRENT, depot_new=self.DEPOT_NEW, account=self.ACCOUNT)
transactions = lp.get_transactions()

dt = transactions["depot_normal_transactions"]

result_csv = "\n"
for t in dt:
result_csv = result_csv + t.to_csv() + "\n"

self.assertEquals(result_csv, expected_depot_csv)

def test_import_spend_receive(self):
kraken_csv = dedent("""
Expand Down

0 comments on commit 6dfaf64

Please sign in to comment.