Skip to content

Commit 127cf46

Browse files
authored
Require most arguments to client methods to be kw-only (#141)
2 parents eb69cc5 + 412cda8 commit 127cf46

File tree

3 files changed

+43
-16
lines changed

3 files changed

+43
-16
lines changed

RELEASE_NOTES.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
# Frequenz Electricity Trading API Client Release Notes
22

3+
## Summary
4+
5+
<!-- Here goes a general summary of what this release is about -->
6+
7+
## Upgrading
8+
9+
- The client interface now requires that other than the `gridpool_id`, all parameters to client methods are kw-only, and can't be specified as positional arguments.
10+
311
## New Features
412

5-
- Update to API v0.7.0
13+
<!-- Here goes the main new features and examples or instructions on how to use them -->
614

715
## Bug Fixes
816

9-
- Ensure timestamp conversion errors are surfaced
10-
- Use HasField to check explicit field precedence
17+
<!-- Here goes notable bug fixes that are worth a special mention or explanation -->

src/frequenz/client/electricity_trading/_client.py

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,10 @@ def stub(self) -> electricity_trading_pb2_grpc.ElectricityTradingServiceAsyncStu
258258
return self._stub # type: ignore
259259

260260
def gridpool_orders_stream(
261-
# pylint: disable=too-many-arguments, too-many-positional-arguments
261+
# pylint: disable=too-many-arguments
262262
self,
263263
gridpool_id: int,
264+
*,
264265
order_states: list[OrderState] | None = None,
265266
market_side: MarketSide | None = None,
266267
delivery_area: DeliveryArea | None = None,
@@ -322,9 +323,10 @@ def gridpool_orders_stream(
322323
return self._gridpool_orders_streams[stream_key]
323324

324325
def gridpool_trades_stream(
325-
# pylint: disable=too-many-arguments, too-many-positional-arguments
326+
# pylint: disable=too-many-arguments
326327
self,
327328
gridpool_id: int,
329+
*,
328330
trade_states: list[TradeState] | None = None,
329331
trade_ids: list[int] | None = None,
330332
market_side: MarketSide | None = None,
@@ -386,8 +388,9 @@ def gridpool_trades_stream(
386388
return self._gridpool_trades_streams[stream_key]
387389

388390
def validate_params(
389-
# pylint: disable=too-many-arguments, too-many-positional-arguments, too-many-branches
391+
# pylint: disable=too-many-arguments, too-many-branches
390392
self,
393+
*,
391394
price: Price | None | _Sentinel = NO_VALUE,
392395
quantity: Power | None | _Sentinel = NO_VALUE,
393396
stop_price: Price | None | _Sentinel = NO_VALUE,
@@ -466,9 +469,10 @@ def validate_params(
466469
raise NotImplementedError("Currently only limit orders are supported.")
467470

468471
async def create_gridpool_order(
469-
# pylint: disable=too-many-arguments, too-many-positional-arguments, too-many-locals
472+
# pylint: disable=too-many-arguments, too-many-locals
470473
self,
471474
gridpool_id: int,
475+
*,
472476
delivery_area: DeliveryArea,
473477
delivery_period: DeliveryPeriod,
474478
order_type: OrderType,
@@ -556,9 +560,10 @@ async def create_gridpool_order(
556560
return OrderDetail.from_pb(response.order_detail)
557561

558562
async def update_gridpool_order(
559-
# pylint: disable=too-many-arguments, too-many-positional-arguments, too-many-locals
563+
# pylint: disable=too-many-arguments, too-many-locals
560564
self,
561565
gridpool_id: int,
566+
*,
562567
order_id: int,
563568
price: Price | None | _Sentinel = NO_VALUE,
564569
quantity: Power | None | _Sentinel = NO_VALUE,
@@ -674,7 +679,11 @@ async def update_gridpool_order(
674679
raise
675680

676681
async def cancel_gridpool_order(
677-
self, gridpool_id: int, order_id: int, timeout: timedelta | None = None
682+
self,
683+
gridpool_id: int,
684+
*,
685+
order_id: int,
686+
timeout: timedelta | None = None,
678687
) -> OrderDetail:
679688
"""
680689
Cancel a single order for a given Gridpool.
@@ -708,7 +717,10 @@ async def cancel_gridpool_order(
708717
raise
709718

710719
async def cancel_all_gridpool_orders(
711-
self, gridpool_id: int, timeout: timedelta | None = None
720+
self,
721+
gridpool_id: int,
722+
*,
723+
timeout: timedelta | None = None,
712724
) -> int:
713725
"""
714726
Cancel all orders for a specific Gridpool.
@@ -744,7 +756,11 @@ async def cancel_all_gridpool_orders(
744756
raise
745757

746758
async def get_gridpool_order(
747-
self, gridpool_id: int, order_id: int, timeout: timedelta | None = None
759+
self,
760+
gridpool_id: int,
761+
*,
762+
order_id: int,
763+
timeout: timedelta | None = None,
748764
) -> OrderDetail:
749765
"""
750766
Get a single order from a given gridpool.
@@ -779,9 +795,10 @@ async def get_gridpool_order(
779795
raise
780796

781797
async def list_gridpool_orders(
782-
# pylint: disable=too-many-arguments, too-many-positional-arguments, too-many-locals
798+
# pylint: disable=too-many-arguments, too-many-locals
783799
self,
784800
gridpool_id: int,
801+
*,
785802
order_states: list[OrderState] | None = None,
786803
side: MarketSide | None = None,
787804
delivery_period: DeliveryPeriod | None = None,
@@ -855,9 +872,10 @@ async def list_gridpool_orders(
855872
raise
856873

857874
async def list_gridpool_trades(
858-
# pylint: disable=too-many-arguments, too-many-positional-arguments
875+
# pylint: disable=too-many-arguments
859876
self,
860877
gridpool_id: int,
878+
*,
861879
trade_states: list[TradeState] | None = None,
862880
trade_ids: list[int] | None = None,
863881
market_side: MarketSide | None = None,
@@ -932,8 +950,9 @@ async def list_gridpool_trades(
932950
raise
933951

934952
def receive_public_trades(
935-
# pylint: disable=too-many-arguments, too-many-positional-arguments
953+
# pylint: disable=too-many-arguments
936954
self,
955+
*,
937956
states: list[TradeState] | None = None,
938957
delivery_period: DeliveryPeriod | None = None,
939958
buy_delivery_area: DeliveryArea | None = None,
@@ -1004,8 +1023,9 @@ def dt_to_pb_timestamp(dt: datetime) -> Timestamp:
10041023
return self._public_trades_streams[public_trade_filter]
10051024

10061025
def receive_public_order_book(
1007-
# pylint: disable=too-many-arguments, too-many-positional-arguments
1026+
# pylint: disable=too-many-arguments
10081027
self,
1028+
*,
10091029
delivery_period: DeliveryPeriod | None = None,
10101030
delivery_area: DeliveryArea | None = None,
10111031
side: MarketSide | None = None,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ async def cancel_order(
238238
if order_id is None:
239239
await client.cancel_all_gridpool_orders(gridpool_id)
240240
else:
241-
await client.cancel_gridpool_order(gridpool_id, order_id)
241+
await client.cancel_gridpool_order(gridpool_id, order_id=order_id)
242242

243243

244244
def print_public_trade_header() -> None:

0 commit comments

Comments
 (0)