Skip to content

Commit fbe418c

Browse files
authored
Merge pull request #382 from InjectiveLabs/cp-446/created_v2_client_for_exchange_v2_endpoints
[CP-446] created v2 client for exchange v2 endpoints
2 parents aa6bbfb + 8a57e99 commit fbe418c

File tree

349 files changed

+9943
-6004
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

349 files changed

+9943
-6004
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,4 @@ cython_debug/
145145
.exchange_cookie
146146

147147
.flakeheaven_cache
148+
.vscode/settings.json

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ All notable changes to this project will be documented in this file.
1010
- Updated all chain exchange module examples to use the new Exchange V2 proto queries and types
1111
- Added examples for ERC20 queries and messages
1212
- Added examples for EVM queries
13+
- Created a new AsyncClient in the pyinjective.async_client_v2 module. This new AsyncClient provides support for the new v2 exchange endpoints. AsyncClient in pyinjective.async_client module still provides access to the v1 exchange endpoints.
14+
- Created a new Composer in the pyinjective.composer_v2 module. This new Composer provides support to create exchange v2 objects. Composer in pyinjective.composer module still provides access to the v1 exchange objects.
15+
- Created the IndexerClient class to have all indexer queries. AsyncClient v2 now does not include any logic related to the indexer endpoints. The original AsyncClient still does support indexer endpoints (for backwards compatibility) but it does that by using an instance of the IndexerClient
1316

1417
### Removed
1518
- Removed all methods marked as deprecated in AsyncClient and Composer

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ clean-all:
3131
$(call clean_repos)
3232

3333
clone-injective-indexer:
34-
git clone https://github.com/InjectiveLabs/injective-indexer.git -b v1.16.3 --depth 1 --single-branch
34+
git clone https://github.com/InjectiveLabs/injective-indexer.git -b v1.16.20 --depth 1 --single-branch
3535

3636
clone-all: clone-injective-indexer
3737

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,62 @@ Upgrade `pip` to the latest version, if you see these warnings:
7070
poetry run pytest -v
7171
```
7272

73+
---
74+
75+
## Choose Exchange V1 or Exchange V2 queries
76+
77+
The Injective Python SDK provides two different clients for interacting with the exchange:
78+
79+
1. **Exchange V1 Client** (`async_client` module):
80+
- Use this client if you need to interact with the original Injective Exchange API
81+
- Import using: `from injective.async_client import AsyncClient`
82+
- Suitable for applications that need to maintain compatibility with the original exchange interface
83+
- Example:
84+
```python
85+
from injective.async_client import AsyncClient
86+
from injective.network import Network
87+
88+
async def main():
89+
# Initialize client with mainnet
90+
client = AsyncClient(network=Network.mainnet())
91+
# Or use testnet
92+
# client = AsyncClient(network=Network.testnet())
93+
# Use V1 exchange queries here
94+
```
95+
96+
2. **Exchange V2 Client** (`async_client_v2` module):
97+
- Use this client for the latest exchange features and improvements
98+
- Import using: `from injective.async_client_v2 import AsyncClient`
99+
- Recommended for new applications and when you need access to the latest exchange features
100+
- Example:
101+
```python
102+
from injective.async_client_v2 import AsyncClient
103+
from injective.network import Network
104+
105+
async def main():
106+
# Initialize client with mainnet
107+
client = AsyncClient(network=Network.mainnet())
108+
# Or use testnet
109+
# client = AsyncClient(network=Network.testnet())
110+
# Use V2 exchange queries here
111+
```
112+
113+
Both clients provide similar interfaces but with different underlying implementations. Choose V2 for new projects unless you have specific requirements for V1 compatibility.
114+
115+
> **Market Format Differences**:
116+
> - V1 AsyncClient: Markets are initialized with values in chain format (raw blockchain values)
117+
> - V2 AsyncClient: Markets are initialized with values in human-readable format (converted to standard decimal numbers)
118+
>
119+
> **Exchange Endpoint Format Differences**:
120+
> - V1 Exchange endpoints: All values (amounts, prices, margins, notionals) are returned in chain format
121+
> - V2 Exchange endpoints:
122+
> - Human-readable format for: amounts, prices, margins, and notionals
123+
> - Chain format for: deposit-related information (to maintain consistency with the Bank module)
124+
>
125+
> **Important Note**: The ChainClient (V1) will not receive any new endpoints added to the Exchange module. If you need access to new exchange-related endpoints or features, you should migrate to the V2 client. The V2 client ensures you have access to all the latest exchange functionality and improvements.
126+
127+
___
128+
73129
## License
74130

75131
Copyright © 2021 - 2025 Injective Labs Inc. (https://injectivelabs.org/)

buf.gen.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ inputs:
1414
- git_repo: https://github.com/InjectiveLabs/ibc-go
1515
tag: v8.7.0-evm-comet1-inj
1616
- git_repo: https://github.com/InjectiveLabs/wasmd
17-
tag: v0.53.2-evm-comet1-inj
17+
tag: v0.53.3-evm-comet1-inj
1818
- git_repo: https://github.com/InjectiveLabs/cometbft
1919
tag: v1.0.1-inj.2
2020
- git_repo: https://github.com/InjectiveLabs/cosmos-sdk
@@ -23,7 +23,7 @@ inputs:
2323
# branch: v0.51.x-inj
2424
# subdir: proto
2525
- git_repo: https://github.com/InjectiveLabs/injective-core
26-
tag: v1.16.0-beta.2
26+
tag: v1.16.0-beta.3
2727
subdir: proto
2828
# - git_repo: https://github.com/InjectiveLabs/injective-core
2929
# branch: master

examples/chain_client/1_LocalOrderHash.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import dotenv
77

8-
from pyinjective.async_client import AsyncClient
8+
from pyinjective.async_client_v2 import AsyncClient
99
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
1010
from pyinjective.core.network import Network
1111
from pyinjective.orderhash import OrderHashManager
@@ -41,7 +41,7 @@ async def main() -> None:
4141
fee_recipient = "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"
4242

4343
spot_orders = [
44-
composer.create_spot_order_v2(
44+
composer.spot_order(
4545
market_id=spot_market_id,
4646
subaccount_id=subaccount_id,
4747
fee_recipient=fee_recipient,
@@ -50,7 +50,7 @@ async def main() -> None:
5050
order_type="BUY",
5151
cid=str(uuid.uuid4()),
5252
),
53-
composer.create_spot_order_v2(
53+
composer.spot_order(
5454
market_id=spot_market_id,
5555
subaccount_id=subaccount_id,
5656
fee_recipient=fee_recipient,
@@ -62,7 +62,7 @@ async def main() -> None:
6262
]
6363

6464
derivative_orders = [
65-
composer.create_derivative_order_v2(
65+
composer.derivative_order(
6666
market_id=deriv_market_id,
6767
subaccount_id=subaccount_id,
6868
fee_recipient=fee_recipient,
@@ -74,7 +74,7 @@ async def main() -> None:
7474
order_type="BUY",
7575
cid=str(uuid.uuid4()),
7676
),
77-
composer.create_derivative_order_v2(
77+
composer.derivative_order(
7878
market_id=deriv_market_id,
7979
subaccount_id=subaccount_id,
8080
fee_recipient=fee_recipient,
@@ -89,9 +89,9 @@ async def main() -> None:
8989
]
9090

9191
# prepare tx msg
92-
spot_msg = composer.msg_batch_create_spot_limit_orders_v2(sender=address.to_acc_bech32(), orders=spot_orders)
92+
spot_msg = composer.msg_batch_create_spot_limit_orders(sender=address.to_acc_bech32(), orders=spot_orders)
9393

94-
deriv_msg = composer.msg_batch_create_derivative_limit_orders_v2(
94+
deriv_msg = composer.msg_batch_create_derivative_limit_orders(
9595
sender=address.to_acc_bech32(), orders=derivative_orders
9696
)
9797

@@ -178,7 +178,7 @@ async def main() -> None:
178178
print("gas fee: {} INJ".format(gas_fee))
179179

180180
spot_orders = [
181-
composer.create_spot_order_v2(
181+
composer.spot_order(
182182
market_id=spot_market_id,
183183
subaccount_id=subaccount_id_2,
184184
fee_recipient=fee_recipient,
@@ -187,7 +187,7 @@ async def main() -> None:
187187
order_type="BUY_PO",
188188
cid=str(uuid.uuid4()),
189189
),
190-
composer.create_spot_order_v2(
190+
composer.spot_order(
191191
market_id=spot_market_id,
192192
subaccount_id=subaccount_id_2,
193193
fee_recipient=fee_recipient,
@@ -199,7 +199,7 @@ async def main() -> None:
199199
]
200200

201201
derivative_orders = [
202-
composer.create_derivative_order_v2(
202+
composer.derivative_order(
203203
market_id=deriv_market_id,
204204
subaccount_id=subaccount_id_2,
205205
fee_recipient=fee_recipient,
@@ -211,7 +211,7 @@ async def main() -> None:
211211
order_type="BUY",
212212
cid=str(uuid.uuid4()),
213213
),
214-
composer.create_derivative_order_v2(
214+
composer.derivative_order(
215215
market_id=deriv_market_id,
216216
subaccount_id=subaccount_id_2,
217217
fee_recipient=fee_recipient,
@@ -226,9 +226,9 @@ async def main() -> None:
226226
]
227227

228228
# prepare tx msg
229-
spot_msg = composer.msg_batch_create_spot_limit_orders_v2(sender=address.to_acc_bech32(), orders=spot_orders)
229+
spot_msg = composer.msg_batch_create_spot_limit_orders(sender=address.to_acc_bech32(), orders=spot_orders)
230230

231-
deriv_msg = composer.msg_batch_create_derivative_limit_orders_v2(
231+
deriv_msg = composer.msg_batch_create_derivative_limit_orders(
232232
sender=address.to_acc_bech32(), orders=derivative_orders
233233
)
234234

examples/chain_client/3_MessageBroadcaster.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import dotenv
88

9-
from pyinjective.async_client import AsyncClient
9+
from pyinjective.async_client_v2 import AsyncClient
1010
from pyinjective.core.broadcaster import MsgBroadcasterWithPk
1111
from pyinjective.core.network import Network
1212
from pyinjective.wallet import PrivateKey
@@ -45,7 +45,7 @@ async def main() -> None:
4545
spot_market_id_create = "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"
4646

4747
spot_orders_to_create = [
48-
composer.create_spot_order_v2(
48+
composer.spot_order(
4949
market_id=spot_market_id_create,
5050
subaccount_id=subaccount_id,
5151
fee_recipient=fee_recipient,
@@ -54,7 +54,7 @@ async def main() -> None:
5454
order_type="BUY",
5555
cid=(str(uuid.uuid4())),
5656
),
57-
composer.create_spot_order_v2(
57+
composer.spot_order(
5858
market_id=spot_market_id_create,
5959
subaccount_id=subaccount_id,
6060
fee_recipient=fee_recipient,
@@ -66,7 +66,7 @@ async def main() -> None:
6666
]
6767

6868
# prepare tx msg
69-
msg = composer.msg_batch_update_orders_v2(
69+
msg = composer.msg_batch_update_orders(
7070
sender=address.to_acc_bech32(),
7171
spot_orders_to_create=spot_orders_to_create,
7272
)

examples/chain_client/4_MessageBroadcasterWithGranteeAccount.py

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

77
import dotenv
88

9-
from pyinjective.async_client import AsyncClient
9+
from pyinjective.async_client_v2 import AsyncClient
1010
from pyinjective.core.broadcaster import MsgBroadcasterWithPk
1111
from pyinjective.core.network import Network
1212
from pyinjective.wallet import Address, PrivateKey
@@ -48,7 +48,7 @@ async def main() -> None:
4848
granter_address = Address.from_acc_bech32(granter_inj_address)
4949
granter_subaccount_id = granter_address.get_subaccount_id(index=0)
5050

51-
msg = composer.msg_create_spot_limit_order_v2(
51+
msg = composer.msg_create_spot_limit_order(
5252
market_id=market_id,
5353
sender=granter_inj_address,
5454
subaccount_id=granter_subaccount_id,

examples/chain_client/5_MessageBroadcasterWithoutSimulation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import dotenv
88

9-
from pyinjective.async_client import AsyncClient
9+
from pyinjective.async_client_v2 import AsyncClient
1010
from pyinjective.core.broadcaster import MsgBroadcasterWithPk
1111
from pyinjective.core.network import Network
1212
from pyinjective.wallet import PrivateKey
@@ -46,7 +46,7 @@ async def main() -> None:
4646
spot_market_id_create = "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"
4747

4848
spot_orders_to_create = [
49-
composer.create_spot_order_v2(
49+
composer.spot_order(
5050
market_id=spot_market_id_create,
5151
subaccount_id=subaccount_id,
5252
fee_recipient=fee_recipient,
@@ -55,7 +55,7 @@ async def main() -> None:
5555
order_type="BUY",
5656
cid=str(uuid.uuid4()),
5757
),
58-
composer.create_spot_order_v2(
58+
composer.spot_order(
5959
market_id=spot_market_id_create,
6060
subaccount_id=subaccount_id,
6161
fee_recipient=fee_recipient,
@@ -67,7 +67,7 @@ async def main() -> None:
6767
]
6868

6969
# prepare tx msg
70-
msg = composer.msg_batch_update_orders_v2(
70+
msg = composer.msg_batch_update_orders(
7171
sender=address.to_acc_bech32(),
7272
spot_orders_to_create=spot_orders_to_create,
7373
)

examples/chain_client/6_MessageBroadcasterWithGranteeAccountWithoutSimulation.py

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

77
import dotenv
88

9-
from pyinjective.async_client import AsyncClient
9+
from pyinjective.async_client_v2 import AsyncClient
1010
from pyinjective.core.broadcaster import MsgBroadcasterWithPk
1111
from pyinjective.core.network import Network
1212
from pyinjective.wallet import Address, PrivateKey
@@ -46,7 +46,7 @@ async def main() -> None:
4646
granter_address = Address.from_acc_bech32(granter_inj_address)
4747
granter_subaccount_id = granter_address.get_subaccount_id(index=0)
4848

49-
msg = composer.msg_create_spot_limit_order_v2(
49+
msg = composer.msg_create_spot_limit_order(
5050
market_id=market_id,
5151
sender=granter_inj_address,
5252
subaccount_id=granter_subaccount_id,

0 commit comments

Comments
 (0)