File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
src/frequenz/client/electricity_trading Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -1316,8 +1316,11 @@ def from_pb(cls, order_detail: electricity_trading_pb2.OrderDetail) -> Self:
13161316
13171317 Returns:
13181318 OrderDetail object corresponding to the protobuf message.
1319+
1320+ Raises:
1321+ ValueError: If the order price and quantity are not specified for a non-canceled order.
13191322 """
1320- return cls (
1323+ od = cls (
13211324 order_id = order_detail .order_id ,
13221325 order = Order .from_pb (order_detail .order ),
13231326 state_detail = StateDetail .from_pb (order_detail .state_detail ),
@@ -1329,6 +1332,19 @@ def from_pb(cls, order_detail: electricity_trading_pb2.OrderDetail) -> Self:
13291332 ),
13301333 )
13311334
1335+ # Only cancelled orders are allowed to have missing price or quantity
1336+ missing_price_or_quantity = (
1337+ od .order .price .amount .is_nan ()
1338+ or od .order .price .currency == Currency .UNSPECIFIED
1339+ or od .order .quantity .mw .is_nan ()
1340+ )
1341+ if missing_price_or_quantity and od .state_detail .state != OrderState .CANCELED :
1342+ raise ValueError (
1343+ f"Price and quantity must be specified for a non-canceled order (`{ od } `)."
1344+ )
1345+
1346+ return od
1347+
13321348 def to_pb (self ) -> electricity_trading_pb2 .OrderDetail :
13331349 """Convert an OrderDetail object to protobuf OrderDetail.
13341350
You can’t perform that action at this time.
0 commit comments