From 1f4ddbde87c22e5bbb295d0a0ecffda3e9699313 Mon Sep 17 00:00:00 2001 From: uvok Date: Sun, 13 Apr 2025 15:34:59 +0200 Subject: Handle deposits --- bla.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/bla.py b/bla.py index d6fbecc..3d1cfb7 100644 --- a/bla.py +++ b/bla.py @@ -35,17 +35,24 @@ def process_ledger(file_path): reader = csv.DictReader(file) for row in reader: currency = row["asset"] - # Use setdefault() for streamlined dictionary handling fifo_queues.setdefault(currency, FIFOQueue()) - if row["type"] == "trade" and row["amount"].startswith('-'): # Sale + # Handle deposits + if row["type"] == "deposit": + amount = float(row["amount"]) + price = 0 # Deposits typically have no associated cost basis + fifo_queues[currency].add(amount, price) + + # Handle trades - sales + elif row["type"] == "trade" and row["amount"].startswith('-'): amount = -float(row["amount"]) cost_basis = fifo_queues[currency].remove(amount) sale_proceeds = amount * float(row["fee"]) # Adjust fee as needed profit_or_loss = sale_proceeds - cost_basis report.append((row["time"], currency, profit_or_loss)) - elif row["type"] == "trade" and not row["amount"].startswith('-'): # Purchase + # Handle trades - purchases + elif row["type"] == "trade" and not row["amount"].startswith('-'): amount = float(row["amount"]) price = float(row["fee"]) # Adjust fee as needed fifo_queues[currency].add(amount, price) -- cgit v1.2.3