Skip to content

Commit 2c0152a

Browse files
committed
CLI: Print gridpool ID for gridpool trades and orders
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>
1 parent 588c43e commit 2c0152a

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

src/frequenz/client/electricity_trading/cli/etrading.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ async def list_gridpool_trades(
162162
lst = client.list_gridpool_trades(gid, delivery_time_filter=delivery_time_filter)
163163

164164
async for trade in lst:
165-
print_trade(trade)
165+
print_trade(trade, gid)
166166

167167
if delivery_start and delivery_start <= datetime.now(timezone.utc):
168168
return
@@ -171,7 +171,7 @@ async def list_gridpool_trades(
171171
gid, delivery_time_filter=delivery_time_filter
172172
).new_receiver()
173173
async for trade in stream:
174-
print_trade(trade)
174+
print_trade(trade, gid)
175175

176176

177177
async def list_gridpool_orders(
@@ -216,7 +216,7 @@ async def list_gridpool_orders(
216216
lst = client.list_gridpool_orders(gid, delivery_time_filter=delivery_time_filter)
217217

218218
async for order in reverse_iterator(lst):
219-
print_order(order)
219+
print_order(order, gid)
220220

221221
if delivery_start and delivery_start <= datetime.now(timezone.utc):
222222
return
@@ -225,7 +225,7 @@ async def list_gridpool_orders(
225225
gid, delivery_time_filter=delivery_time_filter
226226
).new_receiver()
227227
async for order in stream:
228-
print_order(order)
228+
print_order(order, gid)
229229

230230

231231
# pylint: disable=too-many-arguments
@@ -287,7 +287,7 @@ async def create_order(
287287
tag=tag,
288288
)
289289

290-
print_order(order)
290+
print_order(order, gid)
291291

292292

293293
async def cancel_order(
@@ -406,12 +406,13 @@ def print_trade_header() -> None:
406406
"quantity_mw,"
407407
"currency,"
408408
"price,"
409-
"state "
409+
"state,"
410+
"gridpool_id"
410411
)
411412
print(header)
412413

413414

414-
def print_trade(trade: Trade) -> None:
415+
def print_trade(trade: Trade, gid: int) -> None:
415416
"""Print trade details to stdout in CSV format."""
416417
values = (
417418
trade.id,
@@ -426,6 +427,7 @@ def print_trade(trade: Trade) -> None:
426427
trade.price.currency,
427428
trade.price.amount,
428429
trade.state,
430+
gid,
429431
)
430432
print(",".join(v.name if isinstance(v, Enum) else str(v) for v in values))
431433

@@ -447,12 +449,13 @@ def print_order_header() -> None:
447449
"currency,"
448450
"price,"
449451
"state,"
450-
"tag"
452+
"tag,"
453+
"gridpool_id"
451454
)
452455
print(header)
453456

454457

455-
def print_order(order: OrderDetail) -> None:
458+
def print_order(order: OrderDetail, gid: int) -> None:
456459
"""
457460
Print order details to stdout in CSV format.
458461
@@ -469,6 +472,7 @@ def print_order(order: OrderDetail) -> None:
469472
470473
Args:
471474
order: OrderDetail object
475+
gid: Gridpool ID
472476
"""
473477
values = [
474478
order.order_id,
@@ -486,6 +490,7 @@ def print_order(order: OrderDetail) -> None:
486490
order.order.price.amount,
487491
order.state_detail.state,
488492
order.order.tag,
493+
gid,
489494
]
490495
print(",".join(v.name if isinstance(v, Enum) else str(v) for v in values))
491496

0 commit comments

Comments
 (0)