Skip to content

Commit 291fe99

Browse files
committed
(feat) Added methods in AsyncClient and Composer for Exchange V2 queries and messages. Added tests for the deprecated V1 methods. Updated all example scripts related to Exchange module
1 parent 5e70823 commit 291fe99

File tree

97 files changed

+9542
-543
lines changed

Some content is hidden

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

97 files changed

+9542
-543
lines changed

examples/chain_client/1_LocalOrderHash.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async def main() -> None:
4141
fee_recipient = "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"
4242

4343
spot_orders = [
44-
composer.spot_order(
44+
composer.create_v2_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.spot_order(
53+
composer.create_v2_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.derivative_order(
65+
composer.create_v2_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.derivative_order(
77+
composer.create_v2_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(sender=address.to_acc_bech32(), orders=spot_orders)
92+
spot_msg = composer.msg_batch_create_spot_limit_orders_v2(sender=address.to_acc_bech32(), orders=spot_orders)
9393

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

@@ -218,9 +218,9 @@ async def main() -> None:
218218
]
219219

220220
# prepare tx msg
221-
spot_msg = composer.msg_batch_create_spot_limit_orders(sender=address.to_acc_bech32(), orders=spot_orders)
221+
spot_msg = composer.msg_batch_create_spot_limit_orders_v2(sender=address.to_acc_bech32(), orders=spot_orders)
222222

223-
deriv_msg = composer.msg_batch_create_derivative_limit_orders(
223+
deriv_msg = composer.msg_batch_create_derivative_limit_orders_v2(
224224
sender=address.to_acc_bech32(), orders=derivative_orders
225225
)
226226

examples/chain_client/2_StreamEventOrderFail.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ async def main() -> None:
1111
network = Network.mainnet()
1212
event_filter = (
1313
"tm.event='Tx' AND message.sender='inj1rwv4zn3jptsqs7l8lpa3uvzhs57y8duemete9e' "
14-
"AND message.action='/injective.exchange.v1beta1.MsgBatchUpdateOrders' "
15-
"AND injective.exchange.v1beta1.EventOrderFail.flags EXISTS"
14+
"AND message.action='/injective.exchange.v2.MsgBatchUpdateOrders' "
15+
"AND injective.exchange.v2.EventOrderFail.flags EXISTS"
1616
)
1717
query = json.dumps(
1818
{
@@ -32,8 +32,8 @@ async def main() -> None:
3232
if result == {}:
3333
continue
3434

35-
failed_order_hashes = json.loads(result["events"]["injective.exchange.v1beta1.EventOrderFail.hashes"][0])
36-
failed_order_codes = json.loads(result["events"]["injective.exchange.v1beta1.EventOrderFail.flags"][0])
35+
failed_order_hashes = json.loads(result["events"]["injective.exchange.v2.EventOrderFail.hashes"][0])
36+
failed_order_codes = json.loads(result["events"]["injective.exchange.v2.EventOrderFail.flags"][0])
3737

3838
dict = {}
3939
for i, order_hash in enumerate(failed_order_hashes):

examples/chain_client/3_MessageBroadcaster.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async def main() -> None:
3535
spot_market_id_create = "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"
3636

3737
spot_orders_to_create = [
38-
composer.spot_order(
38+
composer.create_v2_spot_order(
3939
market_id=spot_market_id_create,
4040
subaccount_id=subaccount_id,
4141
fee_recipient=fee_recipient,
@@ -44,7 +44,7 @@ async def main() -> None:
4444
order_type="BUY",
4545
cid=(str(uuid.uuid4())),
4646
),
47-
composer.spot_order(
47+
composer.create_v2_spot_order(
4848
market_id=spot_market_id_create,
4949
subaccount_id=subaccount_id,
5050
fee_recipient=fee_recipient,
@@ -56,7 +56,7 @@ async def main() -> None:
5656
]
5757

5858
# prepare tx msg
59-
msg = composer.msg_batch_update_orders(
59+
msg = composer.msg_batch_update_orders_v2(
6060
sender=address.to_acc_bech32(),
6161
spot_orders_to_create=spot_orders_to_create,
6262
)

examples/chain_client/4_MessageBroadcasterWithGranteeAccount.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async def main() -> None:
4141
granter_address = Address.from_acc_bech32(granter_inj_address)
4242
granter_subaccount_id = granter_address.get_subaccount_id(index=0)
4343

44-
msg = composer.msg_create_spot_limit_order(
44+
msg = composer.msg_create_spot_limit_order_v2(
4545
market_id=market_id,
4646
sender=granter_inj_address,
4747
subaccount_id=granter_subaccount_id,

examples/chain_client/5_MessageBroadcasterWithoutSimulation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async def main() -> None:
3535
spot_market_id_create = "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"
3636

3737
spot_orders_to_create = [
38-
composer.spot_order(
38+
composer.create_v2_spot_order(
3939
market_id=spot_market_id_create,
4040
subaccount_id=subaccount_id,
4141
fee_recipient=fee_recipient,
@@ -44,7 +44,7 @@ async def main() -> None:
4444
order_type="BUY",
4545
cid=str(uuid.uuid4()),
4646
),
47-
composer.spot_order(
47+
composer.create_v2_spot_order(
4848
market_id=spot_market_id_create,
4949
subaccount_id=subaccount_id,
5050
fee_recipient=fee_recipient,
@@ -56,7 +56,7 @@ async def main() -> None:
5656
]
5757

5858
# prepare tx msg
59-
msg = composer.msg_batch_update_orders(
59+
msg = composer.msg_batch_update_orders_v2(
6060
sender=address.to_acc_bech32(),
6161
spot_orders_to_create=spot_orders_to_create,
6262
)

examples/chain_client/6_MessageBroadcasterWithGranteeAccountWithoutSimulation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async def main() -> None:
4040
granter_address = Address.from_acc_bech32(granter_inj_address)
4141
granter_subaccount_id = granter_address.get_subaccount_id(index=0)
4242

43-
msg = composer.msg_create_spot_limit_order(
43+
msg = composer.msg_create_spot_limit_order_v2(
4444
market_id=market_id,
4545
sender=granter_inj_address,
4646
subaccount_id=granter_subaccount_id,

examples/chain_client/7_ChainStream.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,29 @@ async def main() -> None:
3131
inj_usdt_market = "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"
3232
inj_usdt_perp_market = "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6"
3333

34-
bank_balances_filter = composer.chain_stream_bank_balances_filter(
34+
bank_balances_filter = composer.chain_stream_bank_balances_v2_filter(
3535
accounts=["inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"]
3636
)
37-
subaccount_deposits_filter = composer.chain_stream_subaccount_deposits_filter(subaccount_ids=[subaccount_id])
38-
spot_trades_filter = composer.chain_stream_trades_filter(subaccount_ids=["*"], market_ids=[inj_usdt_market])
39-
derivative_trades_filter = composer.chain_stream_trades_filter(
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(
4040
subaccount_ids=["*"], market_ids=[inj_usdt_perp_market]
4141
)
42-
spot_orders_filter = composer.chain_stream_orders_filter(
42+
spot_orders_filter = composer.chain_stream_orders_v2_filter(
4343
subaccount_ids=[subaccount_id], market_ids=[inj_usdt_market]
4444
)
45-
derivative_orders_filter = composer.chain_stream_orders_filter(
45+
derivative_orders_filter = composer.chain_stream_orders_v2_filter(
4646
subaccount_ids=[subaccount_id], market_ids=[inj_usdt_perp_market]
4747
)
48-
spot_orderbooks_filter = composer.chain_stream_orderbooks_filter(market_ids=[inj_usdt_market])
49-
derivative_orderbooks_filter = composer.chain_stream_orderbooks_filter(market_ids=[inj_usdt_perp_market])
50-
positions_filter = composer.chain_stream_positions_filter(
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(
5151
subaccount_ids=[subaccount_id], market_ids=[inj_usdt_perp_market]
5252
)
53-
oracle_price_filter = composer.chain_stream_oracle_price_filter(symbols=["INJ", "USDT"])
53+
oracle_price_filter = composer.chain_stream_oracle_price_v2_filter(symbols=["INJ", "USDT"])
5454

5555
task = asyncio.get_event_loop().create_task(
56-
client.listen_chain_stream_updates(
56+
client.listen_chain_stream_v2_updates(
5757
callback=chain_stream_event_processor,
5858
on_end_callback=stream_closed_processor,
5959
on_status_callback=stream_error_processor,

examples/chain_client/authz/1_MsgGrant.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async def main() -> None:
3838
msg = composer.MsgGrantGeneric(
3939
granter=address.to_acc_bech32(),
4040
grantee=grantee_public_address,
41-
msg_type="/injective.exchange.v1beta1.MsgCreateSpotLimitOrder",
41+
msg_type="/injective.exchange.v2.MsgCreateSpotLimitOrder",
4242
expire_in=31536000, # 1 year
4343
)
4444

examples/chain_client/authz/2_MsgExec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async def main() -> None:
3838

3939
granter_address = Address.from_acc_bech32(granter_inj_address)
4040
granter_subaccount_id = granter_address.get_subaccount_id(index=0)
41-
msg0 = composer.msg_create_spot_limit_order(
41+
msg0 = composer.msg_create_spot_limit_order_v2(
4242
sender=granter_inj_address,
4343
market_id=market_id,
4444
subaccount_id=granter_subaccount_id,

examples/chain_client/authz/3_MsgRevoke.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async def main() -> None:
3434
msg = composer.MsgRevoke(
3535
granter=address.to_acc_bech32(),
3636
grantee=grantee_public_address,
37-
msg_type="/injective.exchange.v1beta1.MsgCreateSpotLimitOrder",
37+
msg_type="/injective.exchange.v2.MsgCreateSpotLimitOrder",
3838
)
3939

4040
# build sim tx

0 commit comments

Comments
 (0)