blob: 4eddb7f78830f6954513e874d07f885d02e41429 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
class Trade:
def __init__(self, amount: float, total_cost: float, date: str) -> None:
self.__amount: float = amount
self.__total_cost: float = total_cost
self.__date: str = date
@property
def amount(self) -> float:
return self.__amount
@property
def total_cost(self) -> float:
return self.__total_cost
@property
def date(self) -> str:
return self.__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}, price_per_coin={self.price_per_coin:.2f}, total_cost={self.total_cost:.2f}, date={self.date})"
|