Skip to content

Commit c2de8e5

Browse files
Replace Energy with Power for the quantity representation (#60)
This PR replaces `Energy` with `Power` for the `quantity` representation, as a result of a change in the API specs described [here](frequenz-floss/frequenz-api-electricity-trading#102).
2 parents 1279657 + 60c7e1d commit c2de8e5

File tree

7 files changed

+81
-82
lines changed

7 files changed

+81
-82
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* Move documentation and code examples to the documentation website
1616
* Replace the local `PaginationParams` type with the `frequenz-client-common` one
1717
* Remove dependency to `googleapis-common-protos`
18+
* Replace `Energy` with `Power` for the `quantity` representation
1819

1920
## Bug Fixes
2021

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ classifiers = [
2727
requires-python = ">= 3.11, < 4"
2828
# TODO(cookiecutter): Remove and add more dependencies if appropriate
2929
dependencies = [
30-
"frequenz-api-common >= 0.6.2, < 0.7.0",
30+
"frequenz-api-common >= 0.6.3, < 0.7.0",
3131
"grpcio >= 1.66.2, < 2",
3232
"frequenz-channels >= 1.0.0, < 2",
3333
"frequenz-client-base >= 0.6.1, < 0.7.0",
3434
"frequenz-client-common >= 0.1.0, < 0.3.0",
35-
"frequenz-api-electricity-trading >= 0.2.3, < 1",
36-
"protobuf >= 5.27.2, < 6",
35+
"frequenz-api-electricity-trading >= 0.2.4, < 1",
36+
"protobuf >= 5.28.0, < 6",
3737
]
3838
dynamic = ["version"]
3939

src/frequenz/client/electricity_trading/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@
165165
DeliveryArea,
166166
DeliveryDuration,
167167
DeliveryPeriod,
168-
Energy,
169168
EnergyMarketCodeType,
170169
GridpoolOrderFilter,
171170
GridpoolTradeFilter,
@@ -176,6 +175,7 @@
176175
OrderExecutionOption,
177176
OrderState,
178177
OrderType,
178+
Power,
179179
Price,
180180
PublicTrade,
181181
PublicTradeFilter,
@@ -192,7 +192,6 @@
192192
"DeliveryArea",
193193
"DeliveryDuration",
194194
"DeliveryPeriod",
195-
"Energy",
196195
"EnergyMarketCodeType",
197196
"GridpoolOrderFilter",
198197
"GridpoolTradeFilter",
@@ -203,6 +202,7 @@
203202
"OrderExecutionOption",
204203
"OrderState",
205204
"OrderType",
205+
"Power",
206206
"Price",
207207
"PublicTrade",
208208
"PublicTradeFilter",

src/frequenz/client/electricity_trading/_client.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from ._types import (
2525
DeliveryArea,
2626
DeliveryPeriod,
27-
Energy,
2827
GridpoolOrderFilter,
2928
GridpoolTradeFilter,
3029
MarketSide,
@@ -33,6 +32,7 @@
3332
OrderExecutionOption,
3433
OrderState,
3534
OrderType,
35+
Power,
3636
Price,
3737
PublicTrade,
3838
PublicTradeFilter,
@@ -321,10 +321,10 @@ def validate_params(
321321
# pylint: disable=too-many-arguments, too-many-positional-arguments, too-many-branches
322322
self,
323323
price: Price | None | _Sentinel = NO_VALUE,
324-
quantity: Energy | None | _Sentinel = NO_VALUE,
324+
quantity: Power | None | _Sentinel = NO_VALUE,
325325
stop_price: Price | None | _Sentinel = NO_VALUE,
326326
peak_price_delta: Price | None | _Sentinel = NO_VALUE,
327-
display_quantity: Energy | None | _Sentinel = NO_VALUE,
327+
display_quantity: Power | None | _Sentinel = NO_VALUE,
328328
delivery_period: DeliveryPeriod | None = None,
329329
valid_until: datetime | None | _Sentinel = NO_VALUE,
330330
execution_option: OrderExecutionOption | None | _Sentinel = NO_VALUE,
@@ -355,9 +355,7 @@ def validate_params(
355355
if not isinstance(price, _Sentinel) and price is not None:
356356
validate_decimal_places(price.amount, PRECISION_DECIMAL_PRICE, "price")
357357
if not isinstance(quantity, _Sentinel) and quantity is not None:
358-
validate_decimal_places(
359-
quantity.mwh, PRECISION_DECIMAL_QUANTITY, "quantity"
360-
)
358+
validate_decimal_places(quantity.mw, PRECISION_DECIMAL_QUANTITY, "quantity")
361359
if not isinstance(stop_price, _Sentinel) and stop_price is not None:
362360
raise NotImplementedError(
363361
"STOP_LIMIT orders are not supported yet, so stop_price cannot be set."
@@ -402,10 +400,10 @@ async def create_gridpool_order(
402400
order_type: OrderType,
403401
side: MarketSide,
404402
price: Price,
405-
quantity: Energy,
403+
quantity: Power,
406404
stop_price: Price | None = None,
407405
peak_price_delta: Price | None = None,
408-
display_quantity: Energy | None = None,
406+
display_quantity: Power | None = None,
409407
execution_option: OrderExecutionOption | None = None,
410408
valid_until: datetime | None = None,
411409
payload: dict[str, struct_pb2.Value] | None = None,
@@ -486,10 +484,10 @@ async def update_gridpool_order(
486484
gridpool_id: int,
487485
order_id: int,
488486
price: Price | None | _Sentinel = NO_VALUE,
489-
quantity: Energy | None | _Sentinel = NO_VALUE,
487+
quantity: Power | None | _Sentinel = NO_VALUE,
490488
stop_price: Price | None | _Sentinel = NO_VALUE,
491489
peak_price_delta: Price | None | _Sentinel = NO_VALUE,
492-
display_quantity: Energy | None | _Sentinel = NO_VALUE,
490+
display_quantity: Power | None | _Sentinel = NO_VALUE,
493491
execution_option: OrderExecutionOption | None | _Sentinel = NO_VALUE,
494492
valid_until: datetime | None | _Sentinel = NO_VALUE,
495493
payload: dict[str, struct_pb2.Value] | None | _Sentinel = NO_VALUE,
@@ -503,7 +501,7 @@ async def update_gridpool_order(
503501
order_id: Order ID.
504502
price: The updated limit price at which the contract is to be traded.
505503
This is the maximum price for a BUY order or the minimum price for a SELL order.
506-
quantity: The updated quantity of the contract being traded, specified in MWh.
504+
quantity: The updated quantity of the contract being traded, specified in MW.
507505
stop_price: Applicable for STOP_LIMIT orders. This is the updated stop price that
508506
triggers the limit order.
509507
peak_price_delta: Applicable for ICEBERG orders. This is the updated price difference

src/frequenz/client/electricity_trading/_types.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
# pylint: disable=no-member
1818
from frequenz.api.common.v1.grid import delivery_area_pb2, delivery_duration_pb2
19-
from frequenz.api.common.v1.market import energy_pb2, price_pb2
19+
from frequenz.api.common.v1.market import power_pb2, price_pb2
2020
from frequenz.api.common.v1.types import decimal_pb2
2121
from frequenz.api.electricity_trading.v1 import electricity_trading_pb2
2222
from google.protobuf import json_format, struct_pb2, timestamp_pb2
@@ -117,32 +117,32 @@ def to_pb(self) -> price_pb2.Price:
117117

118118

119119
@dataclass(frozen=True)
120-
class Energy:
121-
"""Represents energy unit in Megawatthours (MWh)."""
120+
class Power:
121+
"""Represents power unit in Megawatthours (MW)."""
122122

123-
mwh: Decimal
123+
mw: Decimal
124124

125125
@classmethod
126-
def from_pb(cls, energy: energy_pb2.Energy) -> Self:
127-
"""Convert a protobuf Energy to Energy object.
126+
def from_pb(cls, power: power_pb2.Power) -> Self:
127+
"""Convert a protobuf Power to Power object.
128128
129129
Args:
130-
energy: Energy to convert.
130+
power: Power to convert.
131131
132132
Returns:
133-
Energy object corresponding to the protobuf message.
133+
Power object corresponding to the protobuf message.
134134
"""
135-
return cls(mwh=Decimal(energy.mwh.value))
135+
return cls(mw=Decimal(power.mw.value))
136136

137-
def to_pb(self) -> energy_pb2.Energy:
138-
"""Convert a Energy object to protobuf Energy.
137+
def to_pb(self) -> power_pb2.Power:
138+
"""Convert a Power object to protobuf Power.
139139
140140
Returns:
141-
Protobuf message corresponding to the Energy object.
141+
Protobuf message corresponding to the Power object.
142142
"""
143-
decimal_mwh = decimal_pb2.Decimal()
144-
decimal_mwh.value = str(self.mwh)
145-
return energy_pb2.Energy(mwh=decimal_mwh)
143+
decimal_mw = decimal_pb2.Decimal()
144+
decimal_mw.value = str(self.mw)
145+
return power_pb2.Power(mw=decimal_mw)
146146

147147

148148
class EnergyMarketCodeType(enum.Enum):
@@ -872,7 +872,7 @@ class Order: # pylint: disable=too-many-instance-attributes
872872
price: Price
873873
"""The limit price at which the contract is to be traded."""
874874

875-
quantity: Energy
875+
quantity: Power
876876
"""The quantity of the contract being traded."""
877877

878878
stop_price: Price | None = None
@@ -882,7 +882,7 @@ class Order: # pylint: disable=too-many-instance-attributes
882882
"""Applicable for ICEBERG orders. The price difference between the peak price and
883883
the limit price."""
884884

885-
display_quantity: Energy | None = None
885+
display_quantity: Power | None = None
886886
"""Applicable for ICEBERG orders. The quantity of the order to be displayed in the order
887887
book."""
888888

@@ -924,7 +924,7 @@ def from_pb(cls, order: electricity_trading_pb2.Order) -> Self:
924924
type=OrderType.from_pb(order.type),
925925
side=MarketSide.from_pb(order.side),
926926
price=Price.from_pb(order.price),
927-
quantity=Energy.from_pb(order.quantity),
927+
quantity=Power.from_pb(order.quantity),
928928
stop_price=(
929929
Price.from_pb(order.stop_price)
930930
if order.HasField("stop_price")
@@ -936,7 +936,7 @@ def from_pb(cls, order: electricity_trading_pb2.Order) -> Self:
936936
else None
937937
),
938938
display_quantity=(
939-
Energy.from_pb(order.display_quantity)
939+
Power.from_pb(order.display_quantity)
940940
if order.HasField("display_quantity")
941941
else None
942942
),
@@ -1019,7 +1019,7 @@ class Trade: # pylint: disable=too-many-instance-attributes
10191019
price: Price
10201020
"""The price at which the trade was executed."""
10211021

1022-
quantity: Energy
1022+
quantity: Power
10231023
"""The executed quantity of the trade."""
10241024

10251025
state: TradeState
@@ -1051,7 +1051,7 @@ def from_pb(cls, trade: electricity_trading_pb2.Trade) -> Self:
10511051
delivery_period=DeliveryPeriod.from_pb(trade.delivery_period),
10521052
execution_time=trade.execution_time.ToDatetime(tzinfo=timezone.utc),
10531053
price=Price.from_pb(trade.price),
1054-
quantity=Energy.from_pb(trade.quantity),
1054+
quantity=Power.from_pb(trade.quantity),
10551055
state=TradeState.from_pb(trade.state),
10561056
)
10571057

@@ -1143,8 +1143,8 @@ class OrderDetail:
11431143
order_id: int
11441144
order: Order
11451145
state_detail: StateDetail
1146-
open_quantity: Energy
1147-
filled_quantity: Energy
1146+
open_quantity: Power
1147+
filled_quantity: Power
11481148
create_time: datetime
11491149
modification_time: datetime
11501150

@@ -1184,8 +1184,8 @@ def from_pb(cls, order_detail: electricity_trading_pb2.OrderDetail) -> Self:
11841184
order_id=order_detail.order_id,
11851185
order=Order.from_pb(order_detail.order),
11861186
state_detail=StateDetail.from_pb(order_detail.state_detail),
1187-
open_quantity=Energy.from_pb(order_detail.open_quantity),
1188-
filled_quantity=Energy.from_pb(order_detail.filled_quantity),
1187+
open_quantity=Power.from_pb(order_detail.open_quantity),
1188+
filled_quantity=Power.from_pb(order_detail.filled_quantity),
11891189
create_time=order_detail.create_time.ToDatetime(tzinfo=timezone.utc),
11901190
modification_time=order_detail.modification_time.ToDatetime(
11911191
tzinfo=timezone.utc
@@ -1236,7 +1236,7 @@ class PublicTrade: # pylint: disable=too-many-instance-attributes
12361236
price: Price
12371237
"""The limit price at which the contract is to be traded."""
12381238

1239-
quantity: Energy
1239+
quantity: Power
12401240
"""The quantity of the contract being traded."""
12411241

12421242
state: TradeState
@@ -1267,7 +1267,7 @@ def from_pb(cls, public_trade: electricity_trading_pb2.PublicTrade) -> Self:
12671267
delivery_period=DeliveryPeriod.from_pb(public_trade.delivery_period),
12681268
execution_time=public_trade.execution_time.ToDatetime(tzinfo=timezone.utc),
12691269
price=Price.from_pb(public_trade.price),
1270-
quantity=Energy.from_pb(public_trade.quantity),
1270+
quantity=Power.from_pb(public_trade.quantity),
12711271
state=TradeState.from_pb(public_trade.state),
12721272
)
12731273

@@ -1659,8 +1659,8 @@ class UpdateOrder: # pylint: disable=too-many-instance-attributes
16591659
"""The updated limit price at which the contract is to be traded.
16601660
This is the maximum price for a BUY order or the minimum price for a SELL order."""
16611661

1662-
quantity: Energy | None = None
1663-
"""The updated quantity of the contract being traded, specified in MWh."""
1662+
quantity: Power | None = None
1663+
"""The updated quantity of the contract being traded, specified in MW."""
16641664

16651665
stop_price: Price | None = None
16661666
"""Applicable for STOP_LIMIT orders. This is the updated stop price that triggers
@@ -1670,7 +1670,7 @@ class UpdateOrder: # pylint: disable=too-many-instance-attributes
16701670
"""Applicable for ICEBERG orders. This is the updated price difference
16711671
between the peak price and the limit price."""
16721672

1673-
display_quantity: Energy | None = None
1673+
display_quantity: Power | None = None
16741674
"""Applicable for ICEBERG orders. This is the updated quantity of the order
16751675
to be displayed in the order book."""
16761676

@@ -1717,7 +1717,7 @@ def from_pb(
17171717
else None
17181718
),
17191719
quantity=(
1720-
Energy.from_pb(update_order.quantity)
1720+
Power.from_pb(update_order.quantity)
17211721
if update_order.HasField("quantity")
17221722
else None
17231723
),
@@ -1732,7 +1732,7 @@ def from_pb(
17321732
else None
17331733
),
17341734
display_quantity=(
1735-
Energy.from_pb(update_order.display_quantity)
1735+
Power.from_pb(update_order.display_quantity)
17361736
if update_order.HasField("display_quantity")
17371737
else None
17381738
),

0 commit comments

Comments
 (0)