Skip to content

Commit a5f0a41

Browse files
authored
Add trading-cli tool to query DA prices from entsoe API (#94)
Initial version of trading CLI tool, which for now can only query DA prices from the entsoe API. Will be extended to support the real endpoints of the trading API later. Example: ``` $trading-cli --entsoe_key=$ENTOSOE_API_KEY --start "2025-01-06T00:00:00+01:00" --end "2025-01-06T06:00:00+01:00" --country_code "DE_LU" timestamp,price 2025-01-06 00:00:00+01:00,27.52 2025-01-06 01:00:00+01:00,19.26 2025-01-06 02:00:00+01:00,11.35 2025-01-06 03:00:00+01:00,9.2 2025-01-06 04:00:00+01:00,10.0 2025-01-06 05:00:00+01:00,14.81 2025-01-06 06:00:00+01:00,23.82 ```
2 parents 59b0434 + 96c1d56 commit a5f0a41

File tree

5 files changed

+91
-1
lines changed

5 files changed

+91
-1
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: 6 additions & 1 deletion
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.cli.__main__:main"
43+
4044
[[project.authors]]
4145
name = "Frequenz Energy-as-a-Service GmbH"
4246
@@ -66,6 +70,7 @@ dev-mkdocs = [
6670
dev-mypy = [
6771
"mypy == 1.13.0",
6872
"grpc-stubs == 1.53.0.5",
73+
"pandas-stubs == 2.2.2.240807",
6974
"types-Markdown == 3.7.0.20241204",
7075
"types-protobuf == 5.28.3.20241030",
7176
# For checking the noxfile, docs/ script, and tests
@@ -174,7 +179,7 @@ packages = ["frequenz.client.electricity_trading"]
174179
strict = true
175180

176181
[[tool.mypy.overrides]]
177-
module = ["mkdocs_macros.*", "sybil", "sybil.*", "deepdiff"]
182+
module = ["mkdocs_macros.*", "sybil", "sybil.*", "deepdiff", "entsoe", "entsoe."]
178183
ignore_missing_imports = true
179184

180185
[tool.setuptools_scm]
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: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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
8+
from zoneinfo import ZoneInfo
9+
10+
from frequenz.client.electricity_trading.cli.day_ahead import list_day_ahead_prices
11+
12+
13+
def main() -> None:
14+
"""Run main entry point for the CLI tool."""
15+
tz = ZoneInfo("Europe/Berlin")
16+
midnight = datetime.combine(datetime.now(tz), datetime.min.time(), tzinfo=tz)
17+
parser = argparse.ArgumentParser()
18+
parser.add_argument("--entsoe_key", type=str, required=True)
19+
parser.add_argument(
20+
"--start",
21+
type=datetime.fromisoformat,
22+
required=False,
23+
default=midnight,
24+
)
25+
parser.add_argument(
26+
"--end",
27+
type=datetime.fromisoformat,
28+
required=False,
29+
default=midnight + timedelta(days=2),
30+
)
31+
parser.add_argument("--country_code", type=str, required=False, default="DE_LU")
32+
args = parser.parse_args()
33+
34+
list_day_ahead_prices(
35+
entsoe_key=args.entsoe_key,
36+
start=args.start,
37+
end=args.end,
38+
country_code=args.country_code,
39+
)
40+
41+
42+
if __name__ == "__main__":
43+
main()
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 = client.query_day_ahead_prices(country_code, start=start_ts, end=end_ts)
32+
33+
da_prices.name = "price"
34+
da_prices.index.name = "timestamp"
35+
36+
print(da_prices.to_csv())

0 commit comments

Comments
 (0)