Skip to content

Update delivery time checks for gridpool streams and support delivery time filter in CLI#231

Merged
matthias-wende-frequenz merged 8 commits into
frequenz-floss:v0.x.xfrom
cwasicki:cli
Feb 3, 2026
Merged

Update delivery time checks for gridpool streams and support delivery time filter in CLI#231
matthias-wende-frequenz merged 8 commits into
frequenz-floss:v0.x.xfrom
cwasicki:cli

Conversation

@cwasicki

Copy link
Copy Markdown
Collaborator

This pull request refactors and improves the handling of delivery and execution time filters in the electricity trading CLI and client code. It standardizes the naming of time-related parameters, enhances validation for delivery time filters, and updates the CLI and output formatting to be more consistent and informative.

Parameter naming and CLI improvements:

  • Standardized CLI arguments for time filters, replacing ambiguous options like --start/--end with clearer --execution-from, --execution-to, --delivery-from, and --delivery-to across relevant commands in cli/__main__.py and cli/etrading.py. This clarifies the distinction between execution and delivery periods and improves usability.
  • Updated function signatures and internal variable names to match the new CLI arguments, ensuring consistency throughout the codebase.

Validation and robustness:

  • Added an is_valid property to the DeliveryTimeFilter class to check that the delivery time interval is logical (start < end), and updated the streaming methods in _client.py to raise a ValueError if an invalid filter is provided. This prevents invalid queries and improves error messaging.

Output formatting and clarity:

  • Enhanced output of order and trade listings by adding the gridpool_id to CSV headers and output, and updated the corresponding print functions to include this information. This makes CSV exports more informative and easier to analyze.

Code simplification and cleanup:

  • Simplified the logic for listing and streaming gridpool trades and orders by removing redundant checks and using the new delivery time filter structure, leading to cleaner and more maintainable code.

Other minor changes:

  • Removed unnecessary imports (such as timezone) to clean up the code.

Copilot AI review requested due to automatic review settings January 12, 2026 17:45
@cwasicki cwasicki requested a review from a team as a code owner January 12, 2026 17:45
@github-actions github-actions Bot added the part:docs Affects the documentation label Jan 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request refactors the CLI and client code for electricity trading to improve the handling of delivery and execution time filters. The changes standardize parameter naming, add validation for delivery time intervals, and enhance output formatting.

Changes:

  • Renamed CLI arguments from ambiguous --start/--end to clearer --execution-from/--execution-to and --delivery-from/--delivery-to
  • Added is_valid property to DeliveryTimeFilter to validate that start time is before end time
  • Updated output formatting to include gridpool_id in CSV headers for trades and orders

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

File Description
src/frequenz/client/electricity_trading/cli/__main__.py Updated CLI command definitions with renamed time filter arguments and parameter passing
src/frequenz/client/electricity_trading/cli/etrading.py Refactored functions to use new parameter names, simplified filter creation logic, updated print functions to include gridpool_id, removed timezone import
src/frequenz/client/electricity_trading/_types.py Added is_valid property to DeliveryTimeFilter class to validate time intervals
src/frequenz/client/electricity_trading/_client.py Replaced validate_params calls with inline is_valid checks in streaming methods, updated docstrings

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/frequenz/client/electricity_trading/cli/etrading.py
Comment thread src/frequenz/client/electricity_trading/cli/etrading.py
Comment thread src/frequenz/client/electricity_trading/cli/etrading.py Outdated
"""
self.validate_params(delivery_time_filter=delivery_time_filter)
if delivery_time_filter and not delivery_time_filter.is_valid:
raise ValueError("Invalid delivery_time_filter provided.")

Copilot AI Jan 12, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message "Invalid delivery_time_filter provided." is not very informative about what makes the filter invalid. Consider providing a more descriptive error message that explains the validation failure, such as "Invalid delivery_time_filter: end time must be after start time" to help users understand and fix the issue.

Suggested change
raise ValueError("Invalid delivery_time_filter provided.")
raise ValueError(
"Invalid delivery_time_filter provided: ensure the start time is "
"before the end time and that all required fields are set."
)

Copilot uses AI. Check for mistakes.
"""
self.validate_params(delivery_time_filter=delivery_time_filter)
if delivery_time_filter and not delivery_time_filter.is_valid:
raise ValueError("Invalid delivery_time_filter provided.")

Copilot AI Jan 12, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message "Invalid delivery_time_filter provided." is not very informative about what makes the filter invalid. Consider providing a more descriptive error message that explains the validation failure, such as "Invalid delivery_time_filter: end time must be after start time" to help users understand and fix the issue.

Suggested change
raise ValueError("Invalid delivery_time_filter provided.")
raise ValueError(
"Invalid delivery_time_filter: please ensure that the start time "
"is before the end time and that all required fields are set."
)

Copilot uses AI. Check for mistakes.

@matthias-wende-frequenz matthias-wende-frequenz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two small documentation suggestions

gid: Gridpool ID.
delivery_start: Start of the delivery period or None.
delivery_from: Start of the delivery period or None.
delivery_to: End of the delivery period or None.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation doesn't reflect the definition of the DeliveryTimeFilter.

@click.option("--auth_key", required=True, type=str)
@click.option("--gid", required=True, type=int)
@click.option("--start", default=None, type=iso)
@click.option("--delivery-from", default=None, type=iso)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to add a help argument.

If both are set, start timestamps have to be before end timestamps.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
Uses the new `is_valid` check that now comes with the delivery time filter.
This also drops the check that delivery start time  of the filter has to
be in the future, which is not desired for the gridpool data streaming
endpoints.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
Renaming time range CLI arguments to use from/to instead of start/end
to clearly distinguish from delivery start.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
Adds the gridpool ID as a column to the CSV output  which is useful
when outputs from multiple gridpools are merged.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
Replaces the delivery period filter to support full delivery period
start intervals. Using to/from arguments to avoid ambiguity with
delivery start.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
Replaces the delivery period filter to support full delivery period
start intervals. Using to/from arguments to avoid ambiguity with
delivery start.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
@cwasicki

Copy link
Copy Markdown
Collaborator Author

@matthias-wende-frequenz Updated

@cwasicki

Copy link
Copy Markdown
Collaborator Author

@matthias-wende-frequenz Good?

@matthias-wende-frequenz matthias-wende-frequenz added this pull request to the merge queue Feb 3, 2026
Merged via the queue into frequenz-floss:v0.x.x with commit 7494d27 Feb 3, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

part:docs Affects the documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants