summaryrefslogtreecommitdiff
path: root/bla.py
diff options
context:
space:
mode:
Diffstat (limited to 'bla.py')
-rw-r--r--bla.py13
1 files 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)