Skip to content

Commit 020bcfc

Browse files
committed
use **kwargs for optional arguments in the client
1 parent 2374d3a commit 020bcfc

File tree

1 file changed

+58
-72
lines changed

1 file changed

+58
-72
lines changed

pyinjective/client.py

Lines changed: 58 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -231,31 +231,29 @@ def get_subaccount_balances_list(self, subaccount_id: str):
231231
return self.stubExchangeAccount.SubaccountBalancesList(req)
232232

233233
def get_subaccount_history(
234-
self, subaccount_id: str, denom: str = "", transfer_types: List = []
234+
self, subaccount_id: str, **kwargs
235235
):
236236
req = exchange_accounts_rpc_pb.SubaccountHistoryRequest(
237-
subaccount_id=subaccount_id, denom=denom, transfer_types=transfer_types
237+
subaccount_id=subaccount_id, denom=kwargs.get("denom"), transfer_types=kwargs.get("transfer_types")
238238
)
239239
return self.stubExchangeAccount.SubaccountHistory(req)
240240

241241
def get_subaccount_order_summary(
242-
self, subaccount_id: str, order_direction: str = "", market_id: str = ""
242+
self, subaccount_id: str, **kwargs
243243
):
244244
req = exchange_accounts_rpc_pb.SubaccountOrderSummaryRequest(
245245
subaccount_id=subaccount_id,
246-
order_direction=order_direction,
247-
market_id=market_id,
246+
order_direction=kwargs.get("order_direction"),
247+
market_id=kwargs.get("market_id"),
248248
)
249249
return self.stubExchangeAccount.SubaccountOrderSummary(req)
250250

251251
def get_order_states(
252-
self,
253-
spot_order_hashes: List[str] = [""],
254-
derivative_order_hashes: List[str] = [""],
252+
self, **kwargs
255253
):
256254
req = exchange_accounts_rpc_pb.OrderStatesRequest(
257-
spot_order_hashes=spot_order_hashes,
258-
derivative_order_hashes=derivative_order_hashes,
255+
spot_order_hashes=kwargs.get("spot_order_hashes"),
256+
derivative_order_hashes=kwargs.get("derivative_order_hashes"),
259257
)
260258
return self.stubExchangeAccount.OrderStates(req)
261259

@@ -299,10 +297,10 @@ def get_insurance_funds(self):
299297
return self.stubInsurance.Funds(req)
300298

301299
def get_redemptions(
302-
self, redeemer: str = "", redemption_denom: str = "", status: str = ""
300+
self, **kwargs
303301
):
304302
req = insurance_rpc_pb.RedemptionsRequest(
305-
redeemer=redeemer, redemption_denom=redemption_denom, status=status
303+
redeemer=kwargs.get("redeemer"), redemption_denom=kwargs.get("redemption_denom"), status=kwargs.get("status")
306304
)
307305
return self.stubInsurance.Redemptions(req)
308306

@@ -313,10 +311,10 @@ def get_spot_market(self, market_id: str):
313311
return self.stubSpotExchange.Market(req)
314312

315313
def get_spot_markets(
316-
self, market_status: str = "", base_denom: str = "", quote_denom: str = ""
314+
self, **kwargs
317315
):
318316
req = spot_exchange_rpc_pb.MarketsRequest(
319-
market_status=market_status, base_denom=base_denom, quote_denom=quote_denom
317+
market_status=kwargs.get("market_status"), base_denom=kwargs.get("base_denom"), quote_denom=kwargs.get("quote_denom")
320318
)
321319
return self.stubSpotExchange.Markets(req)
322320

@@ -329,29 +327,25 @@ def get_spot_orderbook(self, market_id: str):
329327
return self.stubSpotExchange.Orderbook(req)
330328

331329
def get_spot_orders(
332-
self, market_id: str, order_side: str = "", subaccount_id: str = ""
330+
self, market_id: str, **kwargs
333331
):
334332
req = spot_exchange_rpc_pb.OrdersRequest(
335-
market_id=market_id, order_side=order_side, subaccount_id=subaccount_id
333+
market_id=market_id, order_side=kwargs.get("order_side"), subaccount_id=kwargs.get("subaccount_id")
336334
)
337335
return self.stubSpotExchange.Orders(req)
338336

339337
def get_spot_trades(
340338
self,
341339
market_id: str,
342-
execution_side: str = "",
343-
direction: str = "",
344-
subaccount_id: str = "",
345-
skip: int = 0,
346-
limit: int = 0
340+
**kwargs
347341
):
348342
req = spot_exchange_rpc_pb.TradesRequest(
349343
market_id=market_id,
350-
execution_side=execution_side,
351-
direction=direction,
352-
subaccount_id=subaccount_id,
353-
skip=skip,
354-
limit=limit
344+
execution_side=kwargs.get("execution_side"),
345+
direction=kwargs.get("direction"),
346+
subaccount_id=kwargs.get("subaccount_id"),
347+
skip=kwargs.get("skip"),
348+
limit=kwargs.get("limit")
355349
)
356350
return self.stubSpotExchange.Trades(req)
357351

@@ -364,50 +358,44 @@ def stream_spot_orderbooks(self, market_ids: List):
364358
return self.stubSpotExchange.StreamOrderbook(req)
365359

366360
def stream_spot_orders(
367-
self, market_id: str, order_side: str = "", subaccount_id: str = ""
361+
self, market_id: str, **kwargs
368362
):
369363
req = spot_exchange_rpc_pb.StreamOrdersRequest(
370-
market_id=market_id, order_side=order_side, subaccount_id=subaccount_id
364+
market_id=market_id, order_side=kwargs.get("order_side"), subaccount_id=kwargs.get("subaccount_id")
371365
)
372366
return self.stubSpotExchange.StreamOrders(req)
373367

374368
def stream_spot_trades(
375369
self,
376370
market_id: str,
377-
execution_side: str = "",
378-
direction: str = "",
379-
subaccount_id: str = "",
380-
skip: int = 0,
381-
limit: int = 0
371+
**kwargs
382372
):
383373
req = spot_exchange_rpc_pb.StreamTradesRequest(
384374
market_id=market_id,
385-
execution_side=execution_side,
386-
direction=direction,
387-
subaccount_id=subaccount_id,
388-
skip=skip,
389-
limit=limit
375+
execution_side=kwargs.get("execution_side"),
376+
direction=kwargs.get("direction"),
377+
subaccount_id=kwargs.get("subaccount_id"),
378+
skip=kwargs.get("skip"),
379+
limit=kwargs.get("limit")
390380
)
391381
return self.stubSpotExchange.StreamTrades(req)
392382

393-
def get_spot_subaccount_orders(self, subaccount_id: str, market_id: str = ""):
383+
def get_spot_subaccount_orders(self, subaccount_id: str, **kwargs):
394384
req = spot_exchange_rpc_pb.SubaccountOrdersListRequest(
395-
subaccount_id=subaccount_id, market_id=market_id
385+
subaccount_id=subaccount_id, market_id=kwargs.get("market_id")
396386
)
397387
return self.stubSpotExchange.SubaccountOrdersList(req)
398388

399389
def get_spot_subaccount_trades(
400390
self,
401391
subaccount_id: str,
402-
market_id: str = "",
403-
execution_type: str = "",
404-
direction: str = "",
392+
**kwargs
405393
):
406394
req = spot_exchange_rpc_pb.SubaccountTradesListRequest(
407395
subaccount_id=subaccount_id,
408-
market_id=market_id,
409-
execution_type=execution_type,
410-
direction=direction,
396+
market_id=kwargs.get("market_id"),
397+
execution_type=kwargs.get("execution_type"),
398+
direction=kwargs.get("direction"),
411399
)
412400
return self.stubSpotExchange.SubaccountTradesList(req)
413401

@@ -417,9 +405,9 @@ def get_derivative_market(self, market_id: str):
417405
req = derivative_exchange_rpc_pb.MarketRequest(market_id=market_id)
418406
return self.stubDerivativeExchange.Market(req)
419407

420-
def get_derivative_markets(self, market_status: str = "", quote_denom: str = ""):
408+
def get_derivative_markets(self, **kwargs):
421409
req = derivative_exchange_rpc_pb.MarketsRequest(
422-
market_status=market_status, quote_denom=quote_denom
410+
market_status=kwargs.get("market_status"), quote_denom=kwargs.get("quote_denom")
423411
)
424412
return self.stubDerivativeExchange.Markets(req)
425413

@@ -432,16 +420,16 @@ def get_derivative_orderbook(self, market_id: str):
432420
return self.stubDerivativeExchange.Orderbook(req)
433421

434422
def get_derivative_orders(
435-
self, market_id: str, order_side: str = "", subaccount_id: str = ""
423+
self, market_id: str, **kwargs
436424
):
437425
req = derivative_exchange_rpc_pb.OrdersRequest(
438-
market_id=market_id, order_side=order_side, subaccount_id=subaccount_id
426+
market_id=market_id, order_side=kwargs.get("order_side"), subaccount_id=kwargs.get("subaccount_id")
439427
)
440428
return self.stubDerivativeExchange.Orders(req)
441429

442-
def get_derivative_trades(self, market_id: str, subaccount_id: str = "", execution_side: str = "", direction: str = "", skip: int = 0, limit: int = 0):
430+
def get_derivative_trades(self, market_id: str, **kwargs):
443431
req = derivative_exchange_rpc_pb.TradesRequest(
444-
market_id=market_id, subaccount_id=subaccount_id, execution_side=execution_side, direction=direction, skip=skip, limit=limit
432+
market_id=market_id, subaccount_id=kwargs.get("subaccount_id"), execution_side=kwargs.get("execution_side"), direction=kwargs.get("direction"), skip=kwargs.get("skip"), limit=kwargs.get("limit")
445433
)
446434
return self.stubDerivativeExchange.Trades(req)
447435

@@ -454,58 +442,56 @@ def stream_derivative_orderbooks(self, market_ids: List):
454442
return self.stubDerivativeExchange.StreamOrderbook(req)
455443

456444
def stream_derivative_orders(
457-
self, market_id: str, order_side: str = "", subaccount_id: str = ""
445+
self, market_id: str, **kwargs
458446
):
459447
req = derivative_exchange_rpc_pb.StreamOrdersRequest(
460-
market_id=market_id, order_side=order_side, subaccount_id=subaccount_id
448+
market_id=market_id, order_side=kwargs.get("order_side"), subaccount_id=kwargs.get("subaccount_id")
461449
)
462450
return self.stubDerivativeExchange.StreamOrders(req)
463451

464-
def stream_derivative_trades(self, market_id: str, subaccount_id: str = "", execution_side: str = "", direction: str = "", skip: int = 0, limit: int = 0):
452+
def stream_derivative_trades(self, market_id: str, **kwargs):
465453
req = derivative_exchange_rpc_pb.StreamTradesRequest(
466-
market_id=market_id, subaccount_id=subaccount_id, execution_side=execution_side, direction=direction, skip=skip, limit=limit
454+
market_id=market_id, subaccount_id=kwargs.get("subaccount_id"), execution_side=kwargs.get("execution_side"), direction=kwargs.get("direction"), skip=kwargs.get("skip"), limit=kwargs.get("limit")
467455
)
468456
return self.stubDerivativeExchange.StreamTrades(req)
469457

470-
def get_derivative_positions(self, market_id: str, subaccount_id: str = ""):
458+
def get_derivative_positions(self, market_id: str, **kwargs):
471459
req = derivative_exchange_rpc_pb.PositionsRequest(
472-
market_id=market_id, subaccount_id=subaccount_id
460+
market_id=market_id, subaccount_id=kwargs.get("subaccount_id")
473461
)
474462
return self.stubDerivativeExchange.Positions(req)
475463

476-
def stream_derivative_positions(self, market_id: str, subaccount_id: str = ""):
464+
def stream_derivative_positions(self, market_id: str, **kwargs):
477465
req = derivative_exchange_rpc_pb.StreamPositionsRequest(
478-
market_id=market_id, subaccount_id=subaccount_id
466+
market_id=market_id, subaccount_id=kwargs.get("subaccount_id")
479467
)
480468
return self.stubDerivativeExchange.StreamPositions(req)
481469

482-
def get_derivative_liquidable_positions(self, market_id: str = ""):
483-
req = derivative_exchange_rpc_pb.LiquidablePositionsRequest(market_id=market_id)
470+
def get_derivative_liquidable_positions(self, **kwargs):
471+
req = derivative_exchange_rpc_pb.LiquidablePositionsRequest(market_id=kwargs.get("market_id"))
484472
return self.stubDerivativeExchange.LiquidablePositions(req)
485473

486-
def get_derivative_subaccount_orders(self, subaccount_id: str, market_id: str = ""):
474+
def get_derivative_subaccount_orders(self, subaccount_id: str, **kwargs):
487475
req = derivative_exchange_rpc_pb.SubaccountOrdersListRequest(
488-
subaccount_id=subaccount_id, market_id=market_id
476+
subaccount_id=subaccount_id, market_id=kwargs.get("market_id")
489477
)
490478
return self.stubDerivativeExchange.SubaccountOrdersList(req)
491479

492480
def get_derivative_subaccount_trades(
493481
self,
494482
subaccount_id: str,
495-
market_id: str = "",
496-
execution_type: str = "",
497-
direction: str = "",
483+
**kwargs
498484
):
499485
req = derivative_exchange_rpc_pb.SubaccountTradesListRequest(
500486
subaccount_id=subaccount_id,
501-
market_id=market_id,
502-
execution_type=execution_type,
503-
direction=direction,
487+
market_id=kwargs.get("market_id"),
488+
execution_type=kwargs.get("execution_type"),
489+
direction=kwargs.get("direction"),
504490
)
505491
return self.stubDerivativeExchange.SubaccountTradesList(req)
506492

507-
def get_funding_payments(self, subaccount_id: str, market_id: str = ""):
493+
def get_funding_payments(self, subaccount_id: str, **kwargs):
508494
req = derivative_exchange_rpc_pb.FundingPaymentsRequest(
509-
subaccount_id=subaccount_id, market_id=market_id
495+
subaccount_id=subaccount_id, market_id=kwargs.get("market_id")
510496
)
511497
return self.stubDerivativeExchange.FundingPayments(req)

0 commit comments

Comments
 (0)