diff --git a/examples/exchange_client/accounts_rpc/4_SubaccountBalancesList.py b/examples/exchange_client/accounts_rpc/4_SubaccountBalancesList.py index 501d327e..7df3be17 100644 --- a/examples/exchange_client/accounts_rpc/4_SubaccountBalancesList.py +++ b/examples/exchange_client/accounts_rpc/4_SubaccountBalancesList.py @@ -9,7 +9,7 @@ async def main() -> None: client = AsyncClient(network) subaccount = "0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000" denoms = ["inj", "peggy0x87aB3B4C8661e07D6372361211B96ed4Dc36B1B5"] - subacc_balances_list = await client.get_subaccount_balances_list(subaccount_id=subaccount, denoms=denoms) + subacc_balances_list = await client.fetch_subaccount_balances_list(subaccount_id=subaccount, denoms=denoms) print(subacc_balances_list) diff --git a/examples/exchange_client/accounts_rpc/5_SubaccountHistory.py b/examples/exchange_client/accounts_rpc/5_SubaccountHistory.py index 610b0723..a71951cf 100644 --- a/examples/exchange_client/accounts_rpc/5_SubaccountHistory.py +++ b/examples/exchange_client/accounts_rpc/5_SubaccountHistory.py @@ -1,6 +1,7 @@ import asyncio from pyinjective.async_client import AsyncClient +from pyinjective.client.model.pagination import PaginationOption from pyinjective.core.network import Network @@ -13,8 +14,12 @@ async def main() -> None: skip = 1 limit = 15 end_time = 1665118340224 + pagination = PaginationOption(skip=skip, limit=limit, end_time=end_time) subacc_history = await client.fetch_subaccount_history( - subaccount_id=subaccount, denom=denom, transfer_types=transfer_types, skip=skip, limit=limit, end_time=end_time + subaccount_id=subaccount, + denom=denom, + transfer_types=transfer_types, + pagination=pagination, ) print(subacc_history) diff --git a/examples/exchange_client/meta_rpc/4_StreamKeepAlive.py b/examples/exchange_client/meta_rpc/4_StreamKeepAlive.py index 7724f46e..84a22eb8 100644 --- a/examples/exchange_client/meta_rpc/4_StreamKeepAlive.py +++ b/examples/exchange_client/meta_rpc/4_StreamKeepAlive.py @@ -44,9 +44,14 @@ async def keepalive_event_processor(event: Dict[str, Any]): async def get_markets(client): - stream = await client.stream_spot_markets() - async for market in stream: - print(market) + async def print_market_updates(event: Dict[str, Any]): + print(event) + + await client.listen_spot_markets_updates( + callback=print_market_updates, + on_end_callback=stream_closed_processor, + on_status_callback=stream_error_processor, + ) if __name__ == "__main__": diff --git a/pyinjective/async_client.py b/pyinjective/async_client.py index 9c4c2080..388e7457 100644 --- a/pyinjective/async_client.py +++ b/pyinjective/async_client.py @@ -458,6 +458,9 @@ async def send_tx_async_mode(self, tx_byte: bytes) -> abci_type.TxResponse: result = await self.stubTx.BroadcastTx(request=req, metadata=metadata) return result.tx_response + async def broadcast_tx_async_mode(self, tx_bytes: bytes) -> Dict[str, Any]: + return await self.tx_api.broadcast(tx_bytes=tx_bytes, mode=tx_service.BroadcastMode.BROADCAST_MODE_ASYNC) + async def send_tx_block_mode(self, tx_byte: bytes) -> abci_type.TxResponse: """ This method is deprecated and will be removed soon. BLOCK broadcast mode should not be used @@ -960,17 +963,13 @@ async def fetch_subaccount_history( subaccount_id: str, denom: Optional[str] = None, transfer_types: Optional[List[str]] = None, - skip: Optional[int] = None, - limit: Optional[int] = None, - end_time: Optional[int] = None, + pagination: Optional[PaginationOption] = None, ) -> Dict[str, Any]: return await self.exchange_account_api.fetch_subaccount_history( subaccount_id=subaccount_id, denom=denom, transfer_types=transfer_types, - skip=skip, - limit=limit, - end_time=end_time, + pagination=pagination, ) async def get_subaccount_order_summary(self, subaccount_id: str, **kwargs): diff --git a/pyinjective/client/indexer/grpc/indexer_grpc_account_api.py b/pyinjective/client/indexer/grpc/indexer_grpc_account_api.py index e0296b87..8fc387c1 100644 --- a/pyinjective/client/indexer/grpc/indexer_grpc_account_api.py +++ b/pyinjective/client/indexer/grpc/indexer_grpc_account_api.py @@ -2,6 +2,7 @@ from grpc.aio import Channel +from pyinjective.client.model.pagination import PaginationOption from pyinjective.proto.exchange import ( injective_accounts_rpc_pb2 as exchange_accounts_pb, injective_accounts_rpc_pb2_grpc as exchange_accounts_grpc, @@ -66,17 +67,16 @@ async def fetch_subaccount_history( subaccount_id: str, denom: Optional[str] = None, transfer_types: Optional[List[str]] = None, - skip: Optional[int] = None, - limit: Optional[int] = None, - end_time: Optional[int] = None, + pagination: Optional[PaginationOption] = None, ) -> Dict[str, Any]: + pagination = pagination or PaginationOption() request = exchange_accounts_pb.SubaccountHistoryRequest( subaccount_id=subaccount_id, denom=denom, transfer_types=transfer_types, - skip=skip, - limit=limit, - end_time=end_time, + skip=pagination.skip, + limit=pagination.limit, + end_time=pagination.end_time, ) response = await self._execute_call(call=self._stub.SubaccountHistory, request=request) diff --git a/pyinjective/core/broadcaster.py b/pyinjective/core/broadcaster.py index 379afdaa..45ca0fca 100644 --- a/pyinjective/core/broadcaster.py +++ b/pyinjective/core/broadcaster.py @@ -256,11 +256,11 @@ async def configure_gas_fee_for_transaction( # simulate tx try: - sim_res = await self._client.simulate_tx(sim_tx_raw_bytes) + sim_res = await self._client.simulate(sim_tx_raw_bytes) except RpcError as ex: raise RuntimeError(f"Transaction simulation error: {ex}") - gas_limit = math.ceil(Decimal(str(sim_res.gas_info.gas_used)) * self._gas_limit_adjustment_multiplier) + gas_limit = math.ceil(Decimal(str(sim_res["gasInfo"]["gasUsed"])) * self._gas_limit_adjustment_multiplier) fee = [ self._composer.Coin( diff --git a/tests/client/indexer/grpc/test_indexer_grpc_account_api.py b/tests/client/indexer/grpc/test_indexer_grpc_account_api.py index 3d076caf..8466c29b 100644 --- a/tests/client/indexer/grpc/test_indexer_grpc_account_api.py +++ b/tests/client/indexer/grpc/test_indexer_grpc_account_api.py @@ -1,9 +1,8 @@ -import time - import grpc import pytest from pyinjective.client.indexer.grpc.indexer_grpc_account_api import IndexerGrpcAccountApi +from pyinjective.client.model.pagination import PaginationOption from pyinjective.core.network import Network from pyinjective.proto.exchange import injective_accounts_rpc_pb2 as exchange_accounts_pb from tests.client.indexer.configurable_account_query_servicer import ConfigurableAccountQueryServicer @@ -256,9 +255,11 @@ async def test_subaccount_history( subaccount_id=transfer.dst_subaccount_id, denom=transfer.amount.denom, transfer_types=[transfer.transfer_type], - skip=0, - limit=5, - end_time=int(time.time() * 1e3), + pagination=PaginationOption( + skip=0, + limit=100, + end_time=1699744939364, + ), ) expected_subaccount_history = { "transfers": [