Skip to content

Commit

Permalink
Add a validation rule for the combination of execution rule and valid…
Browse files Browse the repository at this point in the history
…_until

Signed-off-by: camille-bouvy-frequenz <camille.bouvy@frequenz.com>
  • Loading branch information
camille-bouvy-frequenz committed Sep 12, 2024
1 parent 20f9536 commit c49ee00
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/frequenz/client/electricity_trading/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ def validate_params( # pylint: disable=too-many-arguments
display_quantity: Energy | None | _Sentinel = NO_VALUE,
delivery_period: DeliveryPeriod | None = None,
valid_until: datetime | None | _Sentinel = NO_VALUE,
execution_option: OrderExecutionOption | None | _Sentinel = NO_VALUE,
) -> None:
"""
Validate the parameters of an order.
Expand All @@ -311,6 +312,7 @@ def validate_params( # pylint: disable=too-many-arguments
display_quantity: The display quantity of the order.
delivery_period: The delivery period of the order.
valid_until: The valid until of the order.
execution_option: The execution option of the order.
Raises:
ValueError: If the parameters are invalid.
Expand Down Expand Up @@ -339,6 +341,18 @@ def validate_params( # pylint: disable=too-many-arguments
if not isinstance(valid_until, _Sentinel) and valid_until is not None:
if valid_until < datetime.now(timezone.utc):
raise ValueError("valid_until must be in the future")
if (
not isinstance(execution_option, _Sentinel)
and execution_option is not None
):
if execution_option in [
OrderExecutionOption.AON,
OrderExecutionOption.FOK,
OrderExecutionOption.IOC,
]:
raise ValueError(
"valid_until must be None when execution_option is set to AON, FOK, or IOC"
)

async def create_gridpool_order( # pylint: disable=too-many-arguments, too-many-locals
self,
Expand Down Expand Up @@ -390,6 +404,7 @@ async def create_gridpool_order( # pylint: disable=too-many-arguments, too-many
display_quantity=display_quantity,
delivery_period=delivery_period,
valid_until=valid_until,
execution_option=execution_option,
)
order = Order(
delivery_area=delivery_area,
Expand Down Expand Up @@ -473,6 +488,7 @@ async def update_gridpool_order( # pylint: disable=too-many-arguments, too-many
peak_price_delta=peak_price_delta,
display_quantity=display_quantity,
valid_until=valid_until,
execution_option=execution_option,
)

params = {
Expand Down

0 comments on commit c49ee00

Please sign in to comment.