Skip to content

Commit ac4d044

Browse files
authored
Merge pull request #396 from InjectiveLabs/fix/add_depth_to_legacy_async_client_orderbooks_queries
fix/add_depth_to_legacy_async_client_orderbooks_queries
2 parents 9519524 + ff1921d commit ac4d044

File tree

4 files changed

+81
-9
lines changed

4 files changed

+81
-9
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [1.11.1] - 2025-08-20
6+
### Changed
7+
- Marked the v1 AsyncClient as deprecated
8+
9+
### Fixed
10+
- Fixed the Indexer orderbooks queries in the v1 AsyncClient to include the depth parameter
11+
512
## [1.11.0] - 2025-07-29
613
### Added
714
- Added support for Exchange V2 proto queries and types

pyinjective/async_client.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ def __init__(
5858
self,
5959
network: Network,
6060
):
61+
warn(
62+
"AsyncClient from pyinjective.async_client is deprecated. "
63+
"Please use AsyncClient from pyinjective.async_client_v2 instead.",
64+
DeprecationWarning,
65+
stacklevel=2,
66+
)
6167
self.addr = ""
6268
self.number = 0
6369
self.sequence = 0
@@ -1337,11 +1343,11 @@ async def listen_spot_markets_updates(
13371343
market_ids=market_ids,
13381344
)
13391345

1340-
async def fetch_spot_orderbook_v2(self, market_id: str) -> Dict[str, Any]:
1341-
return await self.indexer_client.fetch_spot_orderbook_v2(market_id=market_id)
1346+
async def fetch_spot_orderbook_v2(self, market_id: str, depth: Optional[int] = None) -> Dict[str, Any]:
1347+
return await self.indexer_client.fetch_spot_orderbook_v2(market_id=market_id, depth=depth or 0)
13421348

1343-
async def fetch_spot_orderbooks_v2(self, market_ids: List[str]) -> Dict[str, Any]:
1344-
return await self.indexer_client.fetch_spot_orderbooks_v2(market_ids=market_ids)
1349+
async def fetch_spot_orderbooks_v2(self, market_ids: List[str], depth: Optional[int] = None) -> Dict[str, Any]:
1350+
return await self.indexer_client.fetch_spot_orderbooks_v2(market_ids=market_ids, depth=depth or 0)
13451351

13461352
async def fetch_spot_orders(
13471353
self,
@@ -1608,11 +1614,13 @@ async def listen_derivative_market_updates(
16081614
market_ids=market_ids,
16091615
)
16101616

1611-
async def fetch_derivative_orderbook_v2(self, market_id: str) -> Dict[str, Any]:
1612-
return await self.indexer_client.fetch_derivative_orderbook_v2(market_id=market_id)
1617+
async def fetch_derivative_orderbook_v2(self, market_id: str, depth: Optional[int] = None) -> Dict[str, Any]:
1618+
return await self.indexer_client.fetch_derivative_orderbook_v2(market_id=market_id, depth=depth or 0)
16131619

1614-
async def fetch_derivative_orderbooks_v2(self, market_ids: List[str]) -> Dict[str, Any]:
1615-
return await self.indexer_client.fetch_derivative_orderbooks_v2(market_ids=market_ids)
1620+
async def fetch_derivative_orderbooks_v2(
1621+
self, market_ids: List[str], depth: Optional[int] = None
1622+
) -> Dict[str, Any]:
1623+
return await self.indexer_client.fetch_derivative_orderbooks_v2(market_ids=market_ids, depth=depth or 0)
16161624

16171625
async def fetch_derivative_orders(
16181626
self,

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "injective-py"
3-
version = "1.11.0"
3+
version = "1.11.1"
44
description = "Injective Python SDK, with Exchange API Client"
55
authors = ["Injective Labs <[email protected]>"]
66
license = "Apache-2.0"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import warnings
2+
from unittest.mock import MagicMock, patch
3+
4+
from pyinjective.core.network import Network
5+
6+
7+
class TestAsyncClientDeprecationWarnings:
8+
@patch("pyinjective.async_client.asyncio.get_event_loop")
9+
@patch("pyinjective.async_client.ChainGrpcChainStream")
10+
@patch("pyinjective.async_client.ChainGrpcExchangeApi")
11+
@patch("pyinjective.async_client.ChainGrpcDistributionApi")
12+
@patch("pyinjective.async_client.ChainGrpcAuthZApi")
13+
@patch("pyinjective.async_client.ChainGrpcAuthApi")
14+
@patch("pyinjective.async_client.ChainGrpcBankApi")
15+
@patch("pyinjective.async_client.IndexerClient")
16+
def test_async_client_deprecation_warning(self, *mocks):
17+
"""Test that creating an AsyncClient instance raises a deprecation warning with correct details."""
18+
# Create a mock network to avoid actual network initialization
19+
mock_network = MagicMock(spec=Network)
20+
mock_network.chain_cookie_assistant = MagicMock()
21+
mock_network.create_chain_grpc_channel = MagicMock()
22+
mock_network.create_chain_stream_grpc_channel = MagicMock()
23+
mock_network.official_tokens_list_url = "https://example.com/tokens.json"
24+
25+
# Import here to avoid early import issues
26+
from pyinjective.async_client import AsyncClient
27+
28+
# Capture warnings
29+
with warnings.catch_warnings(record=True) as warning_list:
30+
warnings.simplefilter("always") # Ensure all warnings are captured
31+
32+
# Create AsyncClient instance - this should trigger the deprecation warning
33+
client = AsyncClient(network=mock_network)
34+
35+
# Find the AsyncClient deprecation warning
36+
async_client_warnings = [
37+
w
38+
for w in warning_list
39+
if issubclass(w.category, DeprecationWarning)
40+
and "AsyncClient from pyinjective.async_client is deprecated" in str(w.message)
41+
]
42+
43+
# Should have exactly one warning
44+
assert len(async_client_warnings) == 1
45+
46+
warning = async_client_warnings[0]
47+
# Check warning message contains migration advice
48+
assert "Please use AsyncClient from pyinjective.async_client_v2 instead" in str(warning.message)
49+
# Check warning category
50+
assert warning.category == DeprecationWarning
51+
# Check stacklevel is working correctly (should point to this test file)
52+
assert "test_async_client_deprecation_warnings.py" in warning.filename
53+
54+
# Verify the client was still created successfully
55+
assert client is not None
56+
assert hasattr(client, "network")
57+
assert client.network == mock_network

0 commit comments

Comments
 (0)