summaryrefslogtreecommitdiff
path: root/trade.py
diff options
context:
space:
mode:
authoruvok2025-04-14 19:55:59 +0200
committeruvok2025-04-14 19:55:59 +0200
commitd635faea35496433f1498655cb249011288cc386 (patch)
tree6c522fb51cbcfe29e17895271aa08ed7aa6c151c /trade.py
parent82e8dc4f34ab8546db96788467f6866246f4adac (diff)
Add price-per-coin property
Diffstat (limited to 'trade.py')
-rw-r--r--trade.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/trade.py b/trade.py
index f4f0870..bddc65f 100644
--- a/trade.py
+++ b/trade.py
@@ -4,5 +4,12 @@ class Trade:
self.total_cost: float = total_cost
self.date: str = date
+ @property
+ def price_per_coin(self) -> float:
+ """
+ Calculate the price per coin based on the total cost and the current amount
+ """
+ return self.total_cost / self.amount
+
def __repr__(self) -> str:
- return f"Trade(amount={self.amount}, total_cost={self.total_cost}, date={self.date})"
+ return f"Trade(amount={self.amount}, price_per_coin={self.price_per_coin:.2f}, total_cost={self.total_cost:.2f}, date={self.date})"