@@ -1944,3 +1944,195 @@ def to_pb(self) -> electricity_trading_pb2.UpdateGridpoolOrderRequest.UpdateOrde
19441944 payload = struct_pb2 .Struct (fields = self .payload ) if self .payload else None ,
19451945 tag = self .tag if self .tag else None ,
19461946 )
1947+
1948+
1949+ @dataclass ()
1950+ class PublicOrder : # pylint: disable=too-many-instance-attributes
1951+ """Represents a public order in the market."""
1952+
1953+ public_order_id : int
1954+ """ID of the order from the public order book."""
1955+
1956+ delivery_area : DeliveryArea
1957+ """Delivery area of the order."""
1958+
1959+ delivery_period : DeliveryPeriod
1960+ """The delivery period for the contract."""
1961+
1962+ side : MarketSide
1963+ """Indicates if the order is on the Buy or Sell side of the market."""
1964+
1965+ price : Price
1966+ """The limit price at which the contract is to be traded."""
1967+
1968+ quantity : Power
1969+ """The quantity of the contract being traded."""
1970+
1971+ execution_option : OrderExecutionOption
1972+ """Order execution options such as All or None, Fill or Kill, etc."""
1973+
1974+ create_time : datetime
1975+ """UTC Timestamp when the order was created."""
1976+
1977+ update_time : datetime
1978+ """UTC Timestamp of the last update to the order."""
1979+
1980+ def __post_init__ (self ) -> None :
1981+ """Post initialization checks to ensure that all datetimes are UTC."""
1982+ if self .delivery_period .start .tzinfo is None :
1983+ raise ValueError ("Delivery period start must have timezone information" )
1984+ if self .delivery_period .start .tzinfo != timezone .utc :
1985+ _logger .warning (
1986+ "Delivery period start is not in UTC timezone. Converting to UTC."
1987+ )
1988+ self .delivery_period .start = self .delivery_period .start .astimezone (
1989+ timezone .utc
1990+ )
1991+
1992+ @classmethod
1993+ @from_pb
1994+ def from_pb (
1995+ cls , public_order : electricity_trading_pb2 .PublicOrderBookRecord
1996+ ) -> Self :
1997+ """Convert a protobuf PublicOrder to PublicOrder object.
1998+
1999+ Args:
2000+ public_order: PublicOrder to convert.
2001+
2002+ Returns:
2003+ PublicOrder object corresponding to the protobuf message.
2004+ """
2005+ return cls (
2006+ public_order_id = public_order .id ,
2007+ delivery_area = DeliveryArea .from_pb (public_order .delivery_area ),
2008+ delivery_period = DeliveryPeriod .from_pb (public_order .delivery_period ),
2009+ side = MarketSide .from_pb (public_order .side ),
2010+ price = Price .from_pb (public_order .price ),
2011+ quantity = Power .from_pb (public_order .quantity ),
2012+ execution_option = OrderExecutionOption .from_pb (
2013+ public_order .execution_option
2014+ ),
2015+ create_time = public_order .create_time .ToDatetime (tzinfo = timezone .utc ),
2016+ update_time = public_order .update_time .ToDatetime (tzinfo = timezone .utc ),
2017+ )
2018+
2019+ def to_pb (self ) -> electricity_trading_pb2 .PublicOrderBookRecord :
2020+ """Convert a PublicOrder object to protobuf PublicOrder.
2021+
2022+ Returns:
2023+ Protobuf PublicOrder corresponding to the object.
2024+ """
2025+ create_time = timestamp_pb2 .Timestamp ()
2026+ create_time .FromDatetime (self .create_time )
2027+ update_time = timestamp_pb2 .Timestamp ()
2028+ update_time .FromDatetime (self .update_time )
2029+
2030+ return electricity_trading_pb2 .PublicOrderBookRecord (
2031+ id = self .public_order_id ,
2032+ delivery_area = self .delivery_area .to_pb (),
2033+ delivery_period = self .delivery_period .to_pb (),
2034+ side = electricity_trading_pb2 .MarketSide .ValueType (self .side .value ),
2035+ price = self .price .to_pb (),
2036+ quantity = self .quantity .to_pb (),
2037+ execution_option = electricity_trading_pb2 .OrderExecutionOption .ValueType (
2038+ self .execution_option .value
2039+ ),
2040+ create_time = create_time ,
2041+ update_time = update_time ,
2042+ )
2043+
2044+
2045+ @dataclass ()
2046+ class PublicOrderBookFilter :
2047+ """Parameters for filtering the public orders in the market."""
2048+
2049+ delivery_period : DeliveryPeriod | None = None
2050+ """Delivery period to filter for."""
2051+
2052+ delivery_area : DeliveryArea | None = None
2053+ """Delivery area to filter for."""
2054+
2055+ side : MarketSide | None = None
2056+ """Market side to filter for."""
2057+
2058+ def __eq__ (self , other : object ) -> bool :
2059+ """
2060+ Check if two PublicOrderBookFilter objects are equal.
2061+
2062+ Args:
2063+ other: PublicOrderBookFilter object to compare with.
2064+
2065+ Returns:
2066+ True if the two PublicOrderBookFilter objects are equal, False otherwise.
2067+ """
2068+ if not isinstance (other , PublicOrderBookFilter ):
2069+ return NotImplemented
2070+ return (
2071+ self .delivery_period == other .delivery_period
2072+ and self .delivery_area == other .delivery_area
2073+ and self .side == other .side
2074+ )
2075+
2076+ def __hash__ (self ) -> int :
2077+ """
2078+ Create hash of the PublicOrderBookFilter object.
2079+
2080+ Returns:
2081+ Hash of the PublicOrderBookFilter object.
2082+ """
2083+ return hash (
2084+ (
2085+ self .delivery_period ,
2086+ self .delivery_area ,
2087+ self .side ,
2088+ )
2089+ )
2090+
2091+ @classmethod
2092+ @from_pb
2093+ def from_pb (
2094+ cls , public_order_filter : electricity_trading_pb2 .PublicOrderBookFilter
2095+ ) -> Self :
2096+ """Convert a protobuf PublicOrderBookFilter to PublicOrderBookFilter object.
2097+
2098+ Args:
2099+ public_order_filter: PublicOrderBookFilter to convert.
2100+
2101+ Returns:
2102+ PublicOrderBookFilter object corresponding to the protobuf message.
2103+ """
2104+ return cls (
2105+ delivery_period = (
2106+ DeliveryPeriod .from_pb (public_order_filter .delivery_period )
2107+ if public_order_filter .HasField ("delivery_period" )
2108+ else None
2109+ ),
2110+ delivery_area = (
2111+ DeliveryArea .from_pb (public_order_filter .delivery_area )
2112+ if public_order_filter .HasField ("delivery_area" )
2113+ else None
2114+ ),
2115+ side = (
2116+ MarketSide .from_pb (public_order_filter .side )
2117+ if public_order_filter .HasField ("side" )
2118+ else None
2119+ ),
2120+ )
2121+
2122+ def to_pb (self ) -> electricity_trading_pb2 .PublicOrderBookFilter :
2123+ """Convert a PublicOrderBookFilter object to protobuf PublicOrderBookFilter.
2124+
2125+ Returns:
2126+ Protobuf PublicOrderBookFilter corresponding to the object.
2127+ """
2128+ return electricity_trading_pb2 .PublicOrderBookFilter (
2129+ delivery_period = (
2130+ self .delivery_period .to_pb () if self .delivery_period else None
2131+ ),
2132+ delivery_area = self .delivery_area .to_pb () if self .delivery_area else None ,
2133+ side = (
2134+ electricity_trading_pb2 .MarketSide .ValueType (self .side .value )
2135+ if self .side
2136+ else None
2137+ ),
2138+ )
0 commit comments