diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ad72282..cee1e91f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. +## [1.11.1] - 2025-08-20 +### Changed +- Marked the v1 AsyncClient as deprecated + +### Fixed +- Fixed the Indexer orderbooks queries in the v1 AsyncClient to include the depth parameter + ## [1.11.0] - 2025-07-29 ### Added - Added support for Exchange V2 proto queries and types diff --git a/pyinjective/async_client.py b/pyinjective/async_client.py index 31f41a9d..dd0fc7ff 100644 --- a/pyinjective/async_client.py +++ b/pyinjective/async_client.py @@ -58,6 +58,12 @@ def __init__( self, network: Network, ): + warn( + "AsyncClient from pyinjective.async_client is deprecated. " + "Please use AsyncClient from pyinjective.async_client_v2 instead.", + DeprecationWarning, + stacklevel=2, + ) self.addr = "" self.number = 0 self.sequence = 0 @@ -1337,11 +1343,11 @@ async def listen_spot_markets_updates( market_ids=market_ids, ) - async def fetch_spot_orderbook_v2(self, market_id: str) -> Dict[str, Any]: - return await self.indexer_client.fetch_spot_orderbook_v2(market_id=market_id) + async def fetch_spot_orderbook_v2(self, market_id: str, depth: Optional[int] = None) -> Dict[str, Any]: + return await self.indexer_client.fetch_spot_orderbook_v2(market_id=market_id, depth=depth or 0) - async def fetch_spot_orderbooks_v2(self, market_ids: List[str]) -> Dict[str, Any]: - return await self.indexer_client.fetch_spot_orderbooks_v2(market_ids=market_ids) + async def fetch_spot_orderbooks_v2(self, market_ids: List[str], depth: Optional[int] = None) -> Dict[str, Any]: + return await self.indexer_client.fetch_spot_orderbooks_v2(market_ids=market_ids, depth=depth or 0) async def fetch_spot_orders( self, @@ -1608,11 +1614,13 @@ async def listen_derivative_market_updates( market_ids=market_ids, ) - async def fetch_derivative_orderbook_v2(self, market_id: str) -> Dict[str, Any]: - return await self.indexer_client.fetch_derivative_orderbook_v2(market_id=market_id) + async def fetch_derivative_orderbook_v2(self, market_id: str, depth: Optional[int] = None) -> Dict[str, Any]: + return await self.indexer_client.fetch_derivative_orderbook_v2(market_id=market_id, depth=depth or 0) - async def fetch_derivative_orderbooks_v2(self, market_ids: List[str]) -> Dict[str, Any]: - return await self.indexer_client.fetch_derivative_orderbooks_v2(market_ids=market_ids) + async def fetch_derivative_orderbooks_v2( + self, market_ids: List[str], depth: Optional[int] = None + ) -> Dict[str, Any]: + return await self.indexer_client.fetch_derivative_orderbooks_v2(market_ids=market_ids, depth=depth or 0) async def fetch_derivative_orders( self, diff --git a/pyproject.toml b/pyproject.toml index 1d607918..0ba95f7a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "injective-py" -version = "1.11.0" +version = "1.11.1" description = "Injective Python SDK, with Exchange API Client" authors = ["Injective Labs "] license = "Apache-2.0" diff --git a/tests/test_async_client_deprecation_warnings.py b/tests/test_async_client_deprecation_warnings.py new file mode 100644 index 00000000..c17481fe --- /dev/null +++ b/tests/test_async_client_deprecation_warnings.py @@ -0,0 +1,57 @@ +import warnings +from unittest.mock import MagicMock, patch + +from pyinjective.core.network import Network + + +class TestAsyncClientDeprecationWarnings: + @patch("pyinjective.async_client.asyncio.get_event_loop") + @patch("pyinjective.async_client.ChainGrpcChainStream") + @patch("pyinjective.async_client.ChainGrpcExchangeApi") + @patch("pyinjective.async_client.ChainGrpcDistributionApi") + @patch("pyinjective.async_client.ChainGrpcAuthZApi") + @patch("pyinjective.async_client.ChainGrpcAuthApi") + @patch("pyinjective.async_client.ChainGrpcBankApi") + @patch("pyinjective.async_client.IndexerClient") + def test_async_client_deprecation_warning(self, *mocks): + """Test that creating an AsyncClient instance raises a deprecation warning with correct details.""" + # Create a mock network to avoid actual network initialization + mock_network = MagicMock(spec=Network) + mock_network.chain_cookie_assistant = MagicMock() + mock_network.create_chain_grpc_channel = MagicMock() + mock_network.create_chain_stream_grpc_channel = MagicMock() + mock_network.official_tokens_list_url = "https://example.com/tokens.json" + + # Import here to avoid early import issues + from pyinjective.async_client import AsyncClient + + # Capture warnings + with warnings.catch_warnings(record=True) as warning_list: + warnings.simplefilter("always") # Ensure all warnings are captured + + # Create AsyncClient instance - this should trigger the deprecation warning + client = AsyncClient(network=mock_network) + + # Find the AsyncClient deprecation warning + async_client_warnings = [ + w + for w in warning_list + if issubclass(w.category, DeprecationWarning) + and "AsyncClient from pyinjective.async_client is deprecated" in str(w.message) + ] + + # Should have exactly one warning + assert len(async_client_warnings) == 1 + + warning = async_client_warnings[0] + # Check warning message contains migration advice + assert "Please use AsyncClient from pyinjective.async_client_v2 instead" in str(warning.message) + # Check warning category + assert warning.category == DeprecationWarning + # Check stacklevel is working correctly (should point to this test file) + assert "test_async_client_deprecation_warnings.py" in warning.filename + + # Verify the client was still created successfully + assert client is not None + assert hasattr(client, "network") + assert client.network == mock_network