Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 16 additions & 8 deletions pyinjective/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ def __init__(
self,
network: Network,
):
warn(
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing import statement for the warn function. The code uses warn() but there's no corresponding import statement visible. This will cause a NameError at runtime.

Copilot uses AI. Check for mistakes.

"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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
license = "Apache-2.0"
Expand Down
57 changes: 57 additions & 0 deletions tests/test_async_client_deprecation_warnings.py
Original file line number Diff line number Diff line change
@@ -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
Loading