Skip to content

Commit c1e13af

Browse files
Add an equality function to the Order type
Signed-off-by: camille-bouvy-frequenz <[email protected]>
1 parent 1f3de9a commit c1e13af

File tree

1 file changed

+39
-0
lines changed
  • src/frequenz/client/electricity_trading

1 file changed

+39
-0
lines changed

src/frequenz/client/electricity_trading/_types.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,45 @@ def to_pb(self) -> electricity_trading_pb2.Order:
10181018
tag=self.tag if self.tag else None,
10191019
)
10201020

1021+
def __eq__(self, other: object) -> bool:
1022+
"""
1023+
Check if two orders are equal.
1024+
1025+
Args:
1026+
other: The other order to compare to.
1027+
1028+
Returns:
1029+
True if the orders are equal, False otherwise.
1030+
"""
1031+
if not isinstance(other, Order):
1032+
return NotImplemented
1033+
return (
1034+
self.delivery_area == other.delivery_area
1035+
and self.delivery_period.start == other.delivery_period.start
1036+
and self.delivery_period.duration == other.delivery_period.duration
1037+
and self.type == other.type
1038+
and self.side == other.side
1039+
and self.price == other.price
1040+
and self.quantity == other.quantity
1041+
and self.stop_price == other.stop_price
1042+
and self.peak_price_delta == other.peak_price_delta
1043+
and self.display_quantity == other.display_quantity
1044+
and (
1045+
self.execution_option == other.execution_option
1046+
or (
1047+
self.execution_option is None
1048+
and other.execution_option == OrderExecutionOption.UNSPECIFIED
1049+
)
1050+
or (
1051+
self.execution_option == OrderExecutionOption.UNSPECIFIED
1052+
and other.execution_option is None
1053+
)
1054+
)
1055+
and self.valid_until == other.valid_until
1056+
and self.payload == other.payload
1057+
and self.tag == other.tag
1058+
)
1059+
10211060

10221061
@dataclass()
10231062
class Trade: # pylint: disable=too-many-instance-attributes

0 commit comments

Comments
 (0)