From d635faea35496433f1498655cb249011288cc386 Mon Sep 17 00:00:00 2001 From: uvok Date: Mon, 14 Apr 2025 19:55:59 +0200 Subject: Add price-per-coin property --- trade.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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})" -- cgit v1.2.3