diff options
Diffstat (limited to 'trade.py')
-rw-r--r-- | trade.py | 17 |
1 files changed, 13 insertions, 4 deletions
@@ -1,3 +1,4 @@ +from datetime import datetime from decimal import Decimal from enum import Enum @@ -14,7 +15,7 @@ class Trade: """ def __init__( - self, amount: Decimal, total_cost: Decimal, date: str, refid: str | None = None + self, amount: Decimal, total_cost: Decimal, timestamp: str, refid: str | None = None ) -> None: """ Initialize a new Trade instance. @@ -22,7 +23,7 @@ class Trade: Args: amount (Decimal): The amount of cryptocurrency traded. total_cost (Decimal): The total cost of the trade. - date (str): The date of the trade, formatted as a string. + timestamp (str): The date or timestamp of the trade, formatted as a string. """ if amount < 0 and total_cost < 0: @@ -32,9 +33,17 @@ class Trade: else: raise ValueError("Amount and tota> cost must be same sign") + # force timestamp + try: + datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S") + except ValueError: + datetime.strptime(timestamp, "%Y-%m-%d") + timestamp = timestamp + " 00:00:00" + + self.__amount: Decimal = Decimal(amount) self.__total_cost: Decimal = Decimal(total_cost) - self.__date: str = date + self.__timestamp: str = timestamp self.__refid: str | None = refid def remove_coins( @@ -94,7 +103,7 @@ class Trade: Returns: str: The trade date as a string. """ - return self.__date + return self.__timestamp.split(" ")[0] @property def price_per_coin(self) -> Decimal: |