Skip to content

Commit 8fa612c

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

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
@@ -992,6 +992,45 @@ def to_pb(self) -> electricity_trading_pb2.Order:
992992
tag=self.tag if self.tag else None,
993993
)
994994

995+
def __eq__(self, other: object) -> bool:
996+
"""
997+
Check if two orders are equal.
998+
999+
Args:
1000+
other: The other order to compare to.
1001+
1002+
Returns:
1003+
True if the orders are equal, False otherwise.
1004+
"""
1005+
if not isinstance(other, Order):
1006+
return NotImplemented
1007+
return (
1008+
self.delivery_area == other.delivery_area
1009+
and self.delivery_period.start == other.delivery_period.start
1010+
and self.delivery_period.duration == other.delivery_period.duration
1011+
and self.type == other.type
1012+
and self.side == other.side
1013+
and self.price == other.price
1014+
and self.quantity == other.quantity
1015+
and self.stop_price == other.stop_price
1016+
and self.peak_price_delta == other.peak_price_delta
1017+
and self.display_quantity == other.display_quantity
1018+
and (
1019+
self.execution_option == other.execution_option
1020+
or (
1021+
self.execution_option is None
1022+
and other.execution_option == OrderExecutionOption.UNSPECIFIED
1023+
)
1024+
or (
1025+
self.execution_option == OrderExecutionOption.UNSPECIFIED
1026+
and other.execution_option is None
1027+
)
1028+
)
1029+
and self.valid_until == other.valid_until
1030+
and self.payload == other.payload
1031+
and self.tag == other.tag
1032+
)
1033+
9951034

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

0 commit comments

Comments
 (0)