Skip to content

Commit 113a477

Browse files
Merge pull request #47 from InjectiveLabs/refactor
use **kwargs for optional arguments
2 parents 6fb8a62 + 672f438 commit 113a477

File tree

4 files changed

+113
-126
lines changed

4 files changed

+113
-126
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ python pyinjective/fetch_metadata.py
8686

8787

8888
### Changelogs
89+
0.5.5
90+
* Added MsgBid to the Composer and provided an example
91+
* Refactored the clients and composer with kwargs for optional arguments
92+
8993
0.5.4
9094
* Added PortfolioRequest, GetTxByHashRequest, AuctionRequest, AuctionsRequest, StreamBidsRequest and provided examples
9195
* Updated the composer with MsgIncreasePosition and MsgLiquidatePosition

pyinjective/async_client.py

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -201,22 +201,21 @@ async def get_subaccount_balances_list(self, subaccount_id: str):
201201
req = exchange_accounts_rpc_pb.SubaccountBalancesListRequest(subaccount_id=subaccount_id)
202202
return await self.stubExchangeAccount.SubaccountBalancesList(req)
203203

204-
async def get_subaccount_history(self, subaccount_id: str, denom: str = '', transfer_types: List = []):
205-
req = exchange_accounts_rpc_pb.SubaccountHistoryRequest(subaccount_id=subaccount_id, denom=denom, transfer_types=transfer_types)
204+
async def get_subaccount_history(self, subaccount_id: str, **kwargs):
205+
req = exchange_accounts_rpc_pb.SubaccountHistoryRequest(subaccount_id=subaccount_id, denom=kwargs.get("denom"), transfer_types=kwargs.get("transfer_types"))
206206
return await self.stubExchangeAccount.SubaccountHistory(req)
207207

208-
async def get_subaccount_order_summary(self, subaccount_id: str, order_direction: str = '', market_id: str = ''):
209-
req = exchange_accounts_rpc_pb.SubaccountOrderSummaryRequest(subaccount_id=subaccount_id, order_direction=order_direction, market_id=market_id)
208+
async def get_subaccount_order_summary(self, subaccount_id: str, **kwargs):
209+
req = exchange_accounts_rpc_pb.SubaccountOrderSummaryRequest(subaccount_id=subaccount_id, order_direction=kwargs.get("order_direction"), market_id=kwargs.get("market_id"))
210210
return await self.stubExchangeAccount.SubaccountOrderSummary(req)
211211

212212
async def get_order_states(
213213
self,
214-
spot_order_hashes: List[str] = [""],
215-
derivative_order_hashes: List[str] = [""],
214+
**kwargs
216215
):
217216
req = exchange_accounts_rpc_pb.OrderStatesRequest(
218-
spot_order_hashes=spot_order_hashes,
219-
derivative_order_hashes=derivative_order_hashes,
217+
spot_order_hashes=kwargs.get("spot_order_hashes"),
218+
derivative_order_hashes=kwargs.get("derivative_order_hashes"),
220219
)
221220
return await self.stubExchangeAccount.OrderStates(req)
222221

@@ -246,8 +245,8 @@ async def get_insurance_funds(self):
246245
req = insurance_rpc_pb.FundsRequest()
247246
return await self.stubInsurance.Funds(req)
248247

249-
async def get_redemptions(self, redeemer: str = '', redemption_denom: str = '', status: str = ''):
250-
req = insurance_rpc_pb.RedemptionsRequest(redeemer=redeemer, redemption_denom=redemption_denom, status=status)
248+
async def get_redemptions(self, **kwargs):
249+
req = insurance_rpc_pb.RedemptionsRequest(redeemer=kwargs.get("redeemer"), redemption_denom=kwargs.get("redemption_denom"), status=kwargs.get("status"))
251250
return await self.stubInsurance.Redemptions(req)
252251

253252

@@ -257,8 +256,8 @@ async def get_spot_market(self, market_id: str):
257256
req = spot_exchange_rpc_pb.MarketRequest(market_id=market_id)
258257
return await self.stubSpotExchange.Market(req)
259258

260-
async def get_spot_markets(self, market_status: str = '', base_denom: str = '', quote_denom: str = ''):
261-
req = spot_exchange_rpc_pb.MarketsRequest(market_status=market_status, base_denom=base_denom, quote_denom=quote_denom)
259+
async def get_spot_markets(self, **kwargs):
260+
req = spot_exchange_rpc_pb.MarketsRequest(market_status=kwargs.get("market_status"), base_denom=kwargs.get("base_denom"), quote_denom=kwargs.get("quote_denom"))
262261
return await self.stubSpotExchange.Markets(req)
263262

264263
async def stream_spot_markets(self):
@@ -269,12 +268,12 @@ async def get_spot_orderbook(self, market_id: str):
269268
req = spot_exchange_rpc_pb.OrderbookRequest(market_id=market_id)
270269
return await self.stubSpotExchange.Orderbook(req)
271270

272-
async def get_spot_orders(self, market_id: str, order_side: str = '', subaccount_id: str = ''):
273-
req = spot_exchange_rpc_pb.OrdersRequest(market_id=market_id, order_side=order_side, subaccount_id=subaccount_id)
271+
async def get_spot_orders(self, market_id: str, **kwargs):
272+
req = spot_exchange_rpc_pb.OrdersRequest(market_id=market_id, order_side=kwargs.get("order_side"), subaccount_id=kwargs.get("subaccount_id"))
274273
return await self.stubSpotExchange.Orders(req)
275274

276-
async def get_spot_trades(self, market_id: str, execution_side: str = '', direction: str = '', subaccount_id: str = '', skip: int = 0, limit: int = 0):
277-
req = spot_exchange_rpc_pb.TradesRequest(market_id=market_id, execution_side=execution_side, direction=direction, subaccount_id=subaccount_id, skip=skip, limit=limit)
275+
async def get_spot_trades(self, market_id: str, **kwargs):
276+
req = spot_exchange_rpc_pb.TradesRequest(market_id=market_id, execution_side=kwargs.get("execution_side"), direction=kwargs.get("direction"), subaccount_id=kwargs.get("subaccount_id"), skip=kwargs.get("skip"), limit=kwargs.get("limit"))
278277
return await self.stubSpotExchange.Trades(req)
279278

280279
async def stream_spot_orderbook(self, market_id: str):
@@ -286,20 +285,20 @@ async def stream_spot_orderbooks(self, market_ids: List[str]):
286285
return self.stubSpotExchange.StreamOrderbook(req)
287286

288287

289-
async def stream_spot_orders(self, market_id: str, order_side: str = '', subaccount_id: str = ''):
290-
req = spot_exchange_rpc_pb.StreamOrdersRequest(market_id=market_id, order_side=order_side, subaccount_id=subaccount_id)
288+
async def stream_spot_orders(self, market_id: str, **kwargs):
289+
req = spot_exchange_rpc_pb.StreamOrdersRequest(market_id=market_id, order_side=kwargs.get("order_side"), subaccount_id=kwargs.get("subaccount_id"))
291290
return self.stubSpotExchange.StreamOrders(req)
292291

293-
async def stream_spot_trades(self, market_id: str, execution_side: str = '', direction: str = '', subaccount_id: str = '', skip: int = 0, limit: int = 0):
294-
req = spot_exchange_rpc_pb.StreamTradesRequest(market_id=market_id, execution_side=execution_side, direction=direction, subaccount_id=subaccount_id, skip=skip, limit=limit)
292+
async def stream_spot_trades(self, market_id: str, **kwargs):
293+
req = spot_exchange_rpc_pb.StreamTradesRequest(market_id=market_id, execution_side=kwargs.get("execution_side"), direction=kwargs.get("direction"), subaccount_id=kwargs.get("subaccount_id"), skip=kwargs.get("skip"), limit=kwargs.get("limit"))
295294
return self.stubSpotExchange.StreamTrades(req)
296295

297-
async def get_spot_subaccount_orders(self, subaccount_id: str, market_id: str = ''):
298-
req = spot_exchange_rpc_pb.SubaccountOrdersListRequest(subaccount_id=subaccount_id, market_id=market_id)
296+
async def get_spot_subaccount_orders(self, subaccount_id: str, **kwargs):
297+
req = spot_exchange_rpc_pb.SubaccountOrdersListRequest(subaccount_id=subaccount_id, market_id=kwargs.get("market_id"))
299298
return await self.stubSpotExchange.SubaccountOrdersList(req)
300299

301-
async def get_spot_subaccount_trades(self, subaccount_id: str, market_id: str = '', execution_type: str = '', direction: str = ''):
302-
req = spot_exchange_rpc_pb.SubaccountTradesListRequest(subaccount_id=subaccount_id, market_id=market_id, execution_type=execution_type, direction=direction)
300+
async def get_spot_subaccount_trades(self, subaccount_id: str, **kwargs):
301+
req = spot_exchange_rpc_pb.SubaccountTradesListRequest(subaccount_id=subaccount_id, market_id=kwargs.get("market_id"), execution_type=kwargs.get("execution_type"), direction=kwargs.get("direction"))
303302
return await self.stubSpotExchange.SubaccountTradesList(req)
304303

305304
# DerivativeRPC
@@ -308,8 +307,8 @@ async def get_derivative_market(self, market_id: str):
308307
req = derivative_exchange_rpc_pb.MarketRequest(market_id=market_id)
309308
return await self.stubDerivativeExchange.Market(req)
310309

311-
async def get_derivative_markets(self, market_status: str = '', quote_denom: str = ''):
312-
req = derivative_exchange_rpc_pb.MarketsRequest(market_status=market_status, quote_denom=quote_denom)
310+
async def get_derivative_markets(self, **kwargs):
311+
req = derivative_exchange_rpc_pb.MarketsRequest(market_status=kwargs.get("market_status"), quote_denom=kwargs.get("quote_denom"))
313312
return await self.stubDerivativeExchange.Markets(req)
314313

315314
async def stream_derivative_markets(self):
@@ -320,12 +319,12 @@ async def get_derivative_orderbook(self, market_id: str):
320319
req = derivative_exchange_rpc_pb.OrderbookRequest(market_id=market_id)
321320
return await self.stubDerivativeExchange.Orderbook(req)
322321

323-
async def get_derivative_orders(self, market_id: str, order_side: str = '', subaccount_id: str = ''):
324-
req = derivative_exchange_rpc_pb.OrdersRequest(market_id=market_id, order_side=order_side, subaccount_id=subaccount_id)
322+
async def get_derivative_orders(self, market_id: str, **kwargs):
323+
req = derivative_exchange_rpc_pb.OrdersRequest(market_id=market_id, order_side=kwargs.get("order_side"), subaccount_id=kwargs.get("subaccount_id"))
325324
return await self.stubDerivativeExchange.Orders(req)
326325

327-
async def get_derivative_trades(self, market_id: str, subaccount_id: str = '', skip: int = 0, limit: int = 0):
328-
req = derivative_exchange_rpc_pb.TradesRequest(market_id=market_id, subaccount_id=subaccount_id, execution_side=execution_side, direction=direction, skip=skip, limit=limit)
326+
async def get_derivative_trades(self, market_id: str, **kwargs):
327+
req = derivative_exchange_rpc_pb.TradesRequest(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"))
329328
return await self.stubDerivativeExchange.Trades(req)
330329

331330
async def stream_derivative_orderbook(self, market_id: str):
@@ -336,34 +335,34 @@ async def stream_derivative_orderbooks(self, market_ids: List[str]):
336335
req = derivative_exchange_rpc_pb.StreamOrderbookRequest(market_ids=market_ids)
337336
return self.stubDerivativeExchange.StreamOrderbook(req)
338337

339-
async def stream_derivative_orders(self, market_id: str, order_side: str = '', subaccount_id: str = ''):
340-
req = derivative_exchange_rpc_pb.StreamOrdersRequest(market_id=market_id, order_side=order_side, subaccount_id=subaccount_id)
338+
async def stream_derivative_orders(self, market_id: str, **kwargs):
339+
req = derivative_exchange_rpc_pb.StreamOrdersRequest(market_id=market_id, order_side=kwargs.get("order_side"), subaccount_id=kwargs.get("subaccount_id"))
341340
return self.stubDerivativeExchange.StreamOrders(req)
342341

343-
async def stream_derivative_trades(self, market_id: str, subaccount_id: str = "", execution_side: str = "", direction: str = "", skip: int = 0, limit: int = 0):
344-
req = derivative_exchange_rpc_pb.StreamTradesRequest(market_id=market_id, subaccount_id=subaccount_id, execution_side=execution_side, direction=direction, skip=skip, limit=limit)
342+
async def stream_derivative_trades(self, market_id: str, **kwargs):
343+
req = derivative_exchange_rpc_pb.StreamTradesRequest(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"))
345344
return self.stubDerivativeExchange.StreamTrades(req)
346345

347-
async def get_derivative_positions(self, market_id: str, subaccount_id: str = ''):
348-
req = derivative_exchange_rpc_pb.PositionsRequest(market_id=market_id, subaccount_id=subaccount_id)
346+
async def get_derivative_positions(self, market_id: str, **kwargs):
347+
req = derivative_exchange_rpc_pb.PositionsRequest(market_id=market_id, subaccount_id=kwargs.get("subaccount_id"))
349348
return await self.stubDerivativeExchange.Positions(req)
350349

351-
async def stream_derivative_positions(self, market_id: str, subaccount_id: str = ''):
352-
req = derivative_exchange_rpc_pb.StreamPositionsRequest(market_id=market_id, subaccount_id=subaccount_id)
350+
async def stream_derivative_positions(self, market_id: str, **kwargs):
351+
req = derivative_exchange_rpc_pb.StreamPositionsRequest(market_id=market_id, subaccount_id=kwargs.get("subaccount_id"))
353352
return self.stubDerivativeExchange.StreamPositions(req)
354353

355-
async def get_derivative_liquidable_positions(self, market_id: str = ''):
356-
req = derivative_exchange_rpc_pb.LiquidablePositionsRequest(market_id=market_id)
354+
async def get_derivative_liquidable_positions(self, **kwargs):
355+
req = derivative_exchange_rpc_pb.LiquidablePositionsRequest(market_id=kwargs.get("market_id"))
357356
return await self.stubDerivativeExchange.LiquidablePositions(req)
358357

359-
async def get_derivative_subaccount_orders(self, subaccount_id: str, market_id: str = ''):
360-
req = derivative_exchange_rpc_pb.SubaccountOrdersListRequest(subaccount_id=subaccount_id, market_id=market_id)
358+
async def get_derivative_subaccount_orders(self, subaccount_id: str, **kwargs):
359+
req = derivative_exchange_rpc_pb.SubaccountOrdersListRequest(subaccount_id=subaccount_id, market_id=kwargs.get("market_id"))
361360
return await self.stubDerivativeExchange.SubaccountOrdersList(req)
362361

363-
async def get_derivative_subaccount_trades(self, subaccount_id: str, market_id: str = '', execution_type: str = '', direction: str = ''):
364-
req = derivative_exchange_rpc_pb.SubaccountTradesListRequest(subaccount_id=subaccount_id, market_id=market_id, execution_type=execution_type, direction=direction)
362+
async def get_derivative_subaccount_trades(self, subaccount_id: str, **kwargs):
363+
req = derivative_exchange_rpc_pb.SubaccountTradesListRequest(subaccount_id=subaccount_id, market_id=kwargs.get("market_id"), execution_type=kwargs.get("execution_type"), direction=kwargs.get("direction"))
365364
return await self.stubDerivativeExchange.SubaccountTradesList(req)
366365

367-
async def get_funding_payments(self, subaccount_id: str, market_id: str = ''):
368-
req = derivative_exchange_rpc_pb.FundingPaymentsRequest(subaccount_id=subaccount_id, market_id=market_id)
366+
async def get_funding_payments(self, subaccount_id: str, **kwargs):
367+
req = derivative_exchange_rpc_pb.FundingPaymentsRequest(subaccount_id=subaccount_id, market_id=kwargs.get("market_id"))
369368
return await self.stubDerivativeExchange.FundingPayments(req)

0 commit comments

Comments
 (0)