Skip to content

Commit 6aa7ece

Browse files
committed
Refactor exception message TradeStatus
1 parent 750d351 commit 6aa7ece

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

investing_algorithm_framework/domain/models/trade/trade.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def __init__(
8888
self.last_reported_price_datetime = last_reported_price_datetime
8989
self.high_water_mark = high_water_mark
9090
self.high_water_mark_datetime = high_water_mark_datetime
91-
self.status = status
91+
self.status = TradeStatus.from_value(status).value
9292
self.updated_at = updated_at
9393
self.stop_losses = stop_losses
9494
self.take_profits = take_profits

investing_algorithm_framework/domain/models/trade/trade_status.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from enum import Enum
2+
from investing_algorithm_framework.domain.exceptions import \
3+
OperationalException
24

35

46
class TradeStatus(Enum):
@@ -15,7 +17,9 @@ def from_string(value: str):
1517
if value.upper() == status.value:
1618
return status
1719

18-
raise ValueError("Could not convert value to TradeStatus")
20+
raise OperationalException(
21+
f"Could not convert value: '{value}' to TradeStatus"
22+
)
1923

2024
@staticmethod
2125
def from_value(value):
@@ -28,7 +32,9 @@ def from_value(value):
2832
elif isinstance(value, str):
2933
return TradeStatus.from_string(value)
3034

31-
raise ValueError("Could not convert value to TradeStatus")
35+
raise OperationalException(
36+
f"Could not convert value: {value} to TradeStatus"
37+
)
3238

3339
def equals(self, other):
3440
return TradeStatus.from_value(other) == self

0 commit comments

Comments
 (0)