Skip to content

Commit 7aba4d2

Browse files
committed
(feat) Created a new Composer and a new AsyncClient to support exchange v2 endpoints. The original Composer and AsyncClient are still supported. Created an IndexerClient for all indexer endpoints
1 parent aa6bbfb commit 7aba4d2

File tree

329 files changed

+9422
-5722
lines changed

Some content is hidden

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

329 files changed

+9422
-5722
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 newe 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

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.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.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,

examples/chain_client/7_ChainStream.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
from grpc import RpcError
55

6-
from pyinjective.async_client import AsyncClient
7-
from pyinjective.composer import Composer
6+
from pyinjective.async_client_v2 import AsyncClient
87
from pyinjective.core.network import Network
98

109

@@ -24,36 +23,36 @@ async def main() -> None:
2423
network = Network.testnet()
2524

2625
client = AsyncClient(network)
27-
composer = Composer(network=network.string())
26+
composer = await client.composer()
2827

2928
subaccount_id = "0xbdaedec95d563fb05240d6e01821008454c24c36000000000000000000000000"
3029

3130
inj_usdt_market = "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"
3231
inj_usdt_perp_market = "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6"
3332

34-
bank_balances_filter = composer.chain_stream_bank_balances_v2_filter(
33+
bank_balances_filter = composer.chain_stream_bank_balances_filter(
3534
accounts=["inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"]
3635
)
37-
subaccount_deposits_filter = composer.chain_stream_subaccount_deposits_v2_filter(subaccount_ids=[subaccount_id])
38-
spot_trades_filter = composer.chain_stream_trades_v2_filter(subaccount_ids=["*"], market_ids=[inj_usdt_market])
39-
derivative_trades_filter = composer.chain_stream_trades_v2_filter(
36+
subaccount_deposits_filter = composer.chain_stream_subaccount_deposits_filter(subaccount_ids=[subaccount_id])
37+
spot_trades_filter = composer.chain_stream_trades_filter(subaccount_ids=["*"], market_ids=[inj_usdt_market])
38+
derivative_trades_filter = composer.chain_stream_trades_filter(
4039
subaccount_ids=["*"], market_ids=[inj_usdt_perp_market]
4140
)
42-
spot_orders_filter = composer.chain_stream_orders_v2_filter(
41+
spot_orders_filter = composer.chain_stream_orders_filter(
4342
subaccount_ids=[subaccount_id], market_ids=[inj_usdt_market]
4443
)
45-
derivative_orders_filter = composer.chain_stream_orders_v2_filter(
44+
derivative_orders_filter = composer.chain_stream_orders_filter(
4645
subaccount_ids=[subaccount_id], market_ids=[inj_usdt_perp_market]
4746
)
48-
spot_orderbooks_filter = composer.chain_stream_orderbooks_v2_filter(market_ids=[inj_usdt_market])
49-
derivative_orderbooks_filter = composer.chain_stream_orderbooks_v2_filter(market_ids=[inj_usdt_perp_market])
50-
positions_filter = composer.chain_stream_positions_v2_filter(
47+
spot_orderbooks_filter = composer.chain_stream_orderbooks_filter(market_ids=[inj_usdt_market])
48+
derivative_orderbooks_filter = composer.chain_stream_orderbooks_filter(market_ids=[inj_usdt_perp_market])
49+
positions_filter = composer.chain_stream_positions_filter(
5150
subaccount_ids=[subaccount_id], market_ids=[inj_usdt_perp_market]
5251
)
53-
oracle_price_filter = composer.chain_stream_oracle_price_v2_filter(symbols=["INJ", "USDT"])
52+
oracle_price_filter = composer.chain_stream_oracle_price_filter(symbols=["INJ", "USDT"])
5453

5554
task = asyncio.get_event_loop().create_task(
56-
client.listen_chain_stream_v2_updates(
55+
client.listen_chain_stream_updates(
5756
callback=chain_stream_event_processor,
5857
on_end_callback=stream_closed_processor,
5958
on_status_callback=stream_error_processor,

examples/chain_client/9_PaginatedRequestExample.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import asyncio
22

3-
from pyinjective.async_client import AsyncClient
3+
from pyinjective.async_client_v2 import AsyncClient
44
from pyinjective.client.model.pagination import PaginationOption
55
from pyinjective.core.network import Network
66

examples/chain_client/auction/1_MsgBid.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import dotenv
55
from grpc import RpcError
66

7-
from pyinjective.async_client import AsyncClient
7+
from pyinjective.async_client_v2 import AsyncClient
88
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
99
from pyinjective.core.network import Network
1010
from pyinjective.transaction import Transaction
@@ -30,7 +30,7 @@ async def main() -> None:
3030
await client.fetch_account(address.to_acc_bech32())
3131

3232
# prepare tx msg
33-
msg = composer.MsgBid(sender=address.to_acc_bech32(), round=16250, bid_amount=1)
33+
msg = composer.msg_bid(sender=address.to_acc_bech32(), round=16250, bid_amount=1)
3434

3535
# build sim tx
3636
tx = (

0 commit comments

Comments
 (0)