Skip to content

Commit 84fa02f

Browse files
committed
Add trading-cli tool to query DA prices from entsoe API
The new CLI tool is intended to be used for interaction with the trading API. However, this initial version only provides functionality to list day-ahead prices from the entsoe API. Signed-off-by: cwasicki <[email protected]>
1 parent 59b0434 commit 84fa02f

File tree

5 files changed

+88
-0
lines changed

5 files changed

+88
-0
lines changed

RELEASE_NOTES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
## New Features
1212

13+
* Add trading-cli tool to interact with the trading API. This initial version only provides a tool to list day-ahead prices from the entsoe API.
14+
1315
<!-- Here goes the main new features and examples or instructions on how to use them -->
1416

1517
## Bug Fixes

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ classifiers = [
2727
requires-python = ">= 3.11, < 4"
2828
# TODO(cookiecutter): Remove and add more dependencies if appropriate
2929
dependencies = [
30+
"entsoe-py >= 0.6.16, < 1",
3031
"frequenz-api-common >= 0.6.3, < 0.7.0",
3132
"grpcio >= 1.66.2, < 2",
3233
"frequenz-channels >= 1.0.0, < 2",
@@ -37,6 +38,9 @@ dependencies = [
3738
]
3839
dynamic = ["version"]
3940

41+
[project.scripts]
42+
trading-cli = "frequenz.client.electricity_trading.__main__:main"
43+
4044
[[project.authors]]
4145
name = "Frequenz Energy-as-a-Service GmbH"
4246
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# License: MIT
2+
# Copyright © 2025 Frequenz Energy-as-a-Service GmbH
3+
4+
"""CLI tool to interact with the trading API."""
5+
6+
import argparse
7+
from datetime import datetime, timedelta, timezone
8+
9+
from frequenz.client.electricity_trading.cli.day_ahead import list_day_ahead_prices
10+
11+
12+
def main() -> None:
13+
"""Run main entry point for the CLI tool."""
14+
parser = argparse.ArgumentParser()
15+
parser.add_argument("--entsoe_key", type=str, required=True)
16+
parser.add_argument(
17+
"--start",
18+
type=datetime.fromisoformat,
19+
required=False,
20+
default=datetime.now(timezone.utc) - timedelta(days=1),
21+
)
22+
parser.add_argument(
23+
"--end",
24+
type=datetime.fromisoformat,
25+
required=False,
26+
default=datetime.now(timezone.utc) + timedelta(days=1),
27+
)
28+
parser.add_argument("--country_code", type=str, required=False, default="DE_LU")
29+
args = parser.parse_args()
30+
31+
list_day_ahead_prices(
32+
entsoe_key=args.entsoe_key,
33+
start=args.start,
34+
end=args.end,
35+
country_code=args.country_code,
36+
)
37+
38+
39+
if __name__ == "__main__":
40+
main()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# License: MIT
2+
# Copyright © 2025 Frequenz Energy-as-a-Service GmbH
3+
4+
"""Package for CLI tool to interact with the trading API."""
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# License: MIT
2+
# Copyright © 2025 Frequenz Energy-as-a-Service GmbH
3+
4+
"""Functions for CLI tool to interact with the trading API."""
5+
6+
from datetime import datetime
7+
8+
import pandas as pd
9+
from entsoe import EntsoePandasClient
10+
11+
12+
def list_day_ahead_prices(
13+
entsoe_key: str,
14+
start: datetime,
15+
end: datetime,
16+
country_code: str,
17+
) -> None:
18+
"""
19+
List day-ahead prices for a given country code.
20+
21+
Args:
22+
entsoe_key: The API key for the Entsoe API
23+
start: The start date of the query
24+
end: The end date of the query
25+
country_code: The country code for which to query the prices
26+
"""
27+
start_ts = pd.Timestamp(start)
28+
end_ts = pd.Timestamp(end)
29+
30+
client = EntsoePandasClient(api_key=entsoe_key)
31+
da_prices: pd.Series = client.query_day_ahead_prices(
32+
country_code, start=start_ts, end=end_ts
33+
)
34+
35+
da_prices.name = "price"
36+
da_prices.index.name = "timestamp"
37+
38+
print(da_prices.to_csv())

0 commit comments

Comments
 (0)