Skip to content

Commit

Permalink
Update subaccount examples with custom JSON decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
samtin0x committed Jul 8, 2024
1 parent 6bf1ed3 commit 0de8abd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 2 additions & 3 deletions v4-client-py-v2/dydx_v4_client/node/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ async def get_subaccount(
response = stub.Subaccount(
QueryGetSubaccountRequest(owner=address, number=account_number)
)
return self.encode_response(response)
return response.subaccount

async def get_subaccounts(self) -> QuerySubaccountAllResponse:
"""
Expand All @@ -249,8 +249,7 @@ async def get_subaccounts(self) -> QuerySubaccountAllResponse:
QuerySubaccountAllResponse: The response containing all subaccounts.
"""
stub = subaccounts_query_grpc.QueryStub(self.channel)
response = stub.SubaccountAll(QueryAllSubaccountRequest())
return self.encode_response(response)
return stub.SubaccountAll(QueryAllSubaccountRequest())

async def get_clob_pair(self, pair_id: int) -> clob_pair_type.ClobPair:
"""
Expand Down
6 changes: 4 additions & 2 deletions v4-client-py-v2/examples/validator_get_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,18 @@ async def test():

try:
subaccount = await node_client.get_subaccount(TEST_ADDRESS, 0)
decoded = node_client.encode_response(subaccount)
print("Get Subaccount:")
print(subaccount)
print(decoded)
except Exception as e:
print("Error in get_subaccount:")
print(f"Error: {e}")

try:
subaccounts = await node_client.get_subaccounts()
decoded = node_client.encode_response(subaccounts)
print("Get Subaccounts:")
print(subaccounts)
print(decoded)
except Exception as e:
print("Error in get_subaccounts:")
print(f"Error: {e}")
Expand Down

0 comments on commit 0de8abd

Please sign in to comment.