diff options
author | uvok | 2025-04-14 19:55:59 +0200 |
---|---|---|
committer | uvok | 2025-04-14 19:55:59 +0200 |
commit | d635faea35496433f1498655cb249011288cc386 (patch) | |
tree | 6c522fb51cbcfe29e17895271aa08ed7aa6c151c /trade.py | |
parent | 82e8dc4f34ab8546db96788467f6866246f4adac (diff) |
Add price-per-coin property
Diffstat (limited to 'trade.py')
-rw-r--r-- | trade.py | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -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})" |