Skip to content

Commit 88ac5ef

Browse files
authored
Catch-All signature for object initializations. (#24)
* adding **kwargs catch-all param * making unit test timezone independent
1 parent 719555c commit 88ac5ef

7 files changed

Lines changed: 465 additions & 29 deletions

File tree

coinbaseadvanced/models/accounts.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class AvailableBalance:
1919
value: str
2020
currency: str
2121

22-
def __init__(self, value: str, currency: str) -> None:
22+
def __init__(self, value: str, currency: str, **kwargs) -> None:
2323
self.value = value
2424
self.currency = currency
2525

@@ -45,7 +45,7 @@ class Account:
4545
def __init__(
4646
self, uuid: UUID, name: str, currency: str, available_balance: dict, default: bool,
4747
active: bool, created_at: datetime, updated_at: datetime, deleted_at: datetime,
48-
type: str, ready: bool, hold: dict) -> None:
48+
type: str, ready: bool, hold: dict, **kwargs) -> None:
4949
self.uuid = uuid
5050
self.name = name
5151
self.currency = currency
@@ -89,6 +89,7 @@ def __init__(self,
8989
has_next: bool,
9090
cursor: str,
9191
size: int,
92+
**kwargs
9293
) -> None:
9394

9495
self.accounts = list(map(lambda x: Account(**x), accounts))\

coinbaseadvanced/models/fees.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __init__(self,
2424
usd_from: int,
2525
usd_to: str,
2626
taker_fee_rate: str,
27-
maker_fee_rate: str) -> None:
27+
maker_fee_rate: str, **kwargs) -> None:
2828
self.pricing_tier = pricing_tier
2929
self.usd_from = usd_from
3030
self.usd_to = usd_to
@@ -40,7 +40,7 @@ class GoodsAndServicesTax:
4040
rate: str
4141
type: str
4242

43-
def __init__(self, rate: str, type: str) -> None:
43+
def __init__(self, rate: str, type: str, **kwargs) -> None:
4444
self.rate = rate
4545
self.type = type
4646

@@ -52,7 +52,7 @@ class MarginRate:
5252

5353
value: str
5454

55-
def __init__(self, value: str) -> None:
55+
def __init__(self, value: str, **kwargs) -> None:
5656
self.value = value
5757

5858

@@ -73,7 +73,7 @@ class TransactionsSummary:
7373

7474
def __init__(self, total_volume: int, total_fees: int, fee_tier: dict, margin_rate: dict,
7575
goods_and_services_tax: dict, advanced_trade_only_volume: int, advanced_trade_only_fees: int,
76-
coinbase_pro_volume: int, coinbase_pro_fees: int) -> None:
76+
coinbase_pro_volume: int, coinbase_pro_fees: int, **kwargs) -> None:
7777
self.total_volume = total_volume
7878
self.total_fees = total_fees
7979
self.fee_tier = FeeTier(**fee_tier) if fee_tier is not None else None

coinbaseadvanced/models/orders.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class OrderError:
6363
new_order_failure_reason: str
6464

6565
def __init__(self, error: str = '', message: str = '', error_details: str = '',
66-
preview_failure_reason: str = '', new_order_failure_reason: str = '') -> None:
66+
preview_failure_reason: str = '', new_order_failure_reason: str = '', **kwargs) -> None:
6767
self.error = error
6868
self.message = message
6969
self.error_details = error_details
@@ -80,7 +80,7 @@ class LimitGTC:
8080
limit_price: str
8181
post_only: bool
8282

83-
def __init__(self, base_size: str, limit_price: str, post_only: bool) -> None:
83+
def __init__(self, base_size: str, limit_price: str, post_only: bool, **kwargs) -> None:
8484
self.base_size = base_size
8585
self.limit_price = limit_price
8686
self.post_only = post_only
@@ -96,7 +96,7 @@ class LimitGTD:
9696
post_only: bool
9797
end_time: datetime
9898

99-
def __init__(self, base_size: str, limit_price: str, post_only: bool, end_time: str) -> None:
99+
def __init__(self, base_size: str, limit_price: str, post_only: bool, end_time: str, **kwargs) -> None:
100100
self.base_size = base_size
101101
self.limit_price = limit_price
102102
self.post_only = post_only
@@ -112,7 +112,7 @@ class MarketIOC:
112112
quote_size: str
113113
base_size: str
114114

115-
def __init__(self, quote_size: str = None, base_size: str = None) -> None:
115+
def __init__(self, quote_size: str = None, base_size: str = None, **kwargs) -> None:
116116
self.quote_size = quote_size
117117
self.base_size = base_size
118118

@@ -131,7 +131,7 @@ def __init__(self,
131131
base_size: str,
132132
limit_price: str,
133133
stop_price: str,
134-
stop_direction: str) -> None:
134+
stop_direction: str, **kwargs) -> None:
135135
self.base_size = base_size
136136
self.limit_price = limit_price
137137
self.stop_price = stop_price
@@ -154,7 +154,7 @@ def __init__(self,
154154
limit_price: str,
155155
stop_price: str,
156156
end_time: str,
157-
stop_direction: str) -> None:
157+
stop_direction: str, **kwargs) -> None:
158158
self.base_size = base_size
159159
self.limit_price = limit_price
160160
self.stop_price = stop_price
@@ -176,7 +176,7 @@ class OrderConfiguration:
176176

177177
def __init__(self, market_market_ioc: dict = None, limit_limit_gtc: dict = None,
178178
limit_limit_gtd: dict = None, stop_limit_stop_limit_gtc: dict = None,
179-
stop_limit_stop_limit_gtd: dict = None) -> None:
179+
stop_limit_stop_limit_gtd: dict = None, **kwargs) -> None:
180180
self.market_market_ioc = MarketIOC(
181181
**market_market_ioc) if market_market_ioc is not None else None
182182
self.limit_limit_gtc = LimitGTC(
@@ -258,7 +258,7 @@ def __init__(self, order_id: str, product_id: str, side: str, client_order_id: s
258258
order_placement_source: str = None,
259259
outstanding_hold_amount: str = None,
260260

261-
order_error: dict = None) -> None:
261+
order_error: dict = None, **kwargs) -> None:
262262
self.order_id = order_id
263263
self.product_id = product_id
264264
self.side = side
@@ -348,7 +348,7 @@ def __init__(self,
348348
orders: List[dict],
349349
has_next: bool,
350350
cursor: str,
351-
sequence: int,
351+
sequence: int, **kwargs
352352
) -> None:
353353

354354
self.orders = list(map(lambda x: Order(**x), orders)) if orders is not None else None
@@ -379,7 +379,7 @@ class OrderCancellation:
379379
failure_reason: str
380380
order_id: str
381381

382-
def __init__(self, success: bool, failure_reason: str, order_id: str) -> None:
382+
def __init__(self, success: bool, failure_reason: str, order_id: str, **kwargs) -> None:
383383
self.success = success
384384
self.failure_reason = failure_reason
385385
self.order_id = order_id
@@ -392,7 +392,7 @@ class OrderBatchCancellation:
392392

393393
results: List[OrderCancellation]
394394

395-
def __init__(self, results: List[OrderCancellation]) -> None:
395+
def __init__(self, results: List[OrderCancellation], **kwargs) -> None:
396396
self.results = results
397397

398398
@classmethod
@@ -444,7 +444,7 @@ def __init__(
444444
liquidity_indicator: str,
445445
size_in_quote: bool,
446446
user_id: str,
447-
side: str) -> None:
447+
side: str, **kwargs) -> None:
448448
self.entry_id = entry_id
449449
self.trade_id = trade_id
450450
self.order_id = order_id
@@ -475,7 +475,7 @@ class FillsPage:
475475

476476
def __init__(self,
477477
fills: List[dict],
478-
cursor: str,
478+
cursor: str, **kwargs
479479
) -> None:
480480

481481
self.fills = list(map(lambda x: Fill(**x), fills)) if fills is not None else None

coinbaseadvanced/models/products.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def __init__(self,
105105
alias: str,
106106
alias_to: list,
107107
base_display_symbol: str,
108-
quote_display_symbol: str,
108+
quote_display_symbol: str, **kwargs
109109
) -> None:
110110
self.product_id = product_id
111111
self.price = price
@@ -161,7 +161,7 @@ class ProductsPage:
161161
products: List[Product]
162162
num_products: int
163163

164-
def __init__(self, products: List[Product], num_products: int) -> None:
164+
def __init__(self, products: List[Product], num_products: int, **kwargs) -> None:
165165
self.products = list(map(lambda x: Product(**x), products)) \
166166
if products is not None else None
167167

@@ -192,7 +192,7 @@ class Candle:
192192
close: str
193193
volume: int
194194

195-
def __init__(self, start: int, low: str, high: str, open: str, close: str, volume: int) -> None:
195+
def __init__(self, start: int, low: str, high: str, open: str, close: str, volume: int, **kwargs) -> None:
196196
self.start = start
197197
self.low = low
198198
self.high = high
@@ -208,7 +208,7 @@ class CandlesPage:
208208

209209
candles: List[Candle]
210210

211-
def __init__(self, candles: List[Candle]) -> None:
211+
def __init__(self, candles: List[Candle], **kwargs) -> None:
212212
self.candles = list(map(lambda x: Candle(**x), candles)) if candles is not None else None
213213

214214
@classmethod
@@ -246,7 +246,7 @@ def __init__(self,
246246
time: datetime,
247247
side: str,
248248
bid: str,
249-
ask: str) -> None:
249+
ask: str, **kwargs) -> None:
250250
self.trade_id = trade_id
251251
self.product_id = product_id
252252
self.price = price
@@ -269,7 +269,7 @@ class TradesPage:
269269
def __init__(self,
270270
trades: List[Trade],
271271
best_bid: str,
272-
best_ask: str,
272+
best_ask: str, **kwargs
273273
) -> None:
274274
self.trades = list(map(lambda x: Trade(**x), trades)) if trades is not None else None
275275
self.best_bid = best_bid

tests/fixtures/fixtures.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ def fixture_list_orders_success_response() -> str:
9898
text=content)
9999

100100

101+
def fixture_list_orders_with_extra_unnamed_success_response() -> str:
102+
with open('tests/fixtures/list_orders_with_extra_unnamed_success_response.json', 'r', encoding="utf-8") as file:
103+
content = file.read()
104+
return fixtured_mock_response(
105+
ok=True,
106+
text=content)
107+
108+
101109
def fixture_list_fills_success_response() -> str:
102110
with open('tests/fixtures/list_fills_success_response.json', 'r', encoding="utf-8") as file:
103111
content = file.read()

0 commit comments

Comments
 (0)