Skip to content

Commit 251ae51

Browse files
committed
(fix) Fixed the v1 AsyncClient orderbooks queries to include the depth parameter
1 parent bdd321b commit 251ae51

File tree

3 files changed

+80
-8
lines changed

3 files changed

+80
-8
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased] - 9999-99-99
66

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

pyinjective/async_client.py

Lines changed: 14 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,11 @@ 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(self, market_ids: List[str], depth: Optional[int] = None) -> Dict[str, Any]:
1621+
return await self.indexer_client.fetch_derivative_orderbooks_v2(market_ids=market_ids, depth=depth or 0)
16161622

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

0 commit comments

Comments
 (0)