summaryrefslogtreecommitdiff
path: root/trade.py
diff options
context:
space:
mode:
authoruvok2025-04-17 11:20:01 +0200
committeruvok2025-04-17 11:20:01 +0200
commitecea606533550d8d53a65daa6eeef583788448f4 (patch)
tree6ad17761e9ddede12da40e638d6f0d917ed3e4c4 /trade.py
parent5ed67c88b608a3ee10381635fcff799eebbfc201 (diff)
Enforce use of Decimal, formatting
Diffstat (limited to 'trade.py')
-rw-r--r--trade.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/trade.py b/trade.py
index ed646d1..a07efe7 100644
--- a/trade.py
+++ b/trade.py
@@ -1,6 +1,7 @@
from decimal import Decimal
from enum import Enum
+
class PriceAdaption(Enum):
KeepTotalCost = 1
KeepPricePerCoin = 2
@@ -11,7 +12,8 @@ class Trade:
Represents a cryptocurrency trade, including the amount traded, total cost, and the date of trade.
Provides methods to modify the trade and access various attributes.
"""
- def __init__(self, amount: float|Decimal, total_cost: float|Decimal, date: str) -> None:
+
+ def __init__(self, amount: Decimal, total_cost: Decimal, date: str) -> None:
"""
Initialize a new Trade instance.
@@ -28,7 +30,11 @@ class Trade:
self.__total_cost: Decimal = Decimal(total_cost)
self.__date: str = date
- def remove_coins(self, amount: float|Decimal, adapt: PriceAdaption = PriceAdaption.KeepPricePerCoin) -> None:
+ def remove_coins(
+ self,
+ amount: float | Decimal,
+ adapt: PriceAdaption = PriceAdaption.KeepPricePerCoin,
+ ) -> None:
"""
Reduce the amount of cryptocurrency in the trade by a specified amount.
@@ -42,7 +48,7 @@ class Trade:
"""
if amount > self.__amount:
raise ValueError(f"Can't remove more than {self.__amount}")
-
+
if adapt == PriceAdaption.KeepPricePerCoin:
amount = Decimal(amount)
self.__total_cost -= amount * self.price_per_coin
@@ -95,7 +101,9 @@ class Trade:
ZeroDivisionError: If the current amount is zero.
"""
if self.amount == 0:
- raise ZeroDivisionError("Price per coin cannot be calculated when the amount is zero")
+ raise ZeroDivisionError(
+ "Price per coin cannot be calculated when the amount is zero"
+ )
return self.total_cost / self.amount