Skip to content

Commit e68db6f

Browse files
authored
Merge pull request #341 from InjectiveLabs/feat/add_exchange_messages_from_v1_13
Feat/add exchange messages from v1.13
2 parents 7f39b06 + 8c70ac7 commit e68db6f

File tree

343 files changed

+2686
-4284
lines changed

Some content is hidden

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

343 files changed

+2686
-4284
lines changed

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ jobs:
4040
poetry run pytest --cov --cov-report=xml
4141
4242
- name: Upload coverage to Codecov
43-
uses: codecov/codecov-action@v3
43+
uses: codecov/codecov-action@v4
4444
with:
4545
env_vars: OS,PYTHON

CHANGELOG.md

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

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

5+
## [1.6.1] - 2024-08-07
6+
### Added
7+
- Added support for the following messages in the chain "exchange" module:
8+
- MsgDecreasePositionMargin
9+
- MsgUpdateSpotMarket
10+
- MsgUpdateDerivativeMarket
11+
- MsgAuthorizeStakeGrants
12+
- MsgActivateStakeGrant
13+
514
## [1.6.0] - 2024-07-30
615
### Added
716
- Support for all queries in the chain "tendermint" module

buf.gen.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ version: v2
22
managed:
33
enabled: true
44
plugins:
5-
- remote: buf.build/protocolbuffers/python
5+
- remote: buf.build/protocolbuffers/python:v26.1
66
out: ./pyinjective/proto/
7-
- remote: buf.build/grpc/python
7+
- remote: buf.build/grpc/python:v1.65.4
88
out: ./pyinjective/proto/
99
inputs:
1010
- module: buf.build/cosmos/cosmos-proto

examples/chain_client/exchange/14_MsgCreateBinaryOptionsLimitOrder.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,14 @@ async def main() -> None:
3838
fee_recipient = "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"
3939

4040
# set custom denom to bypass ini file load (optional)
41-
denom = Denom(description="desc", base=0, quote=6, min_price_tick_size=1000, min_quantity_tick_size=0.0001)
41+
denom = Denom(
42+
description="desc",
43+
base=0,
44+
quote=6,
45+
min_price_tick_size=1000,
46+
min_quantity_tick_size=0.0001,
47+
min_notional=0,
48+
)
4249

4350
# prepare tx msg
4451
msg = composer.msg_create_binary_options_limit_order(
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import asyncio
2+
import os
3+
from decimal import Decimal
4+
5+
import dotenv
6+
7+
from pyinjective.async_client import AsyncClient
8+
from pyinjective.core.broadcaster import MsgBroadcasterWithPk
9+
from pyinjective.core.network import Network
10+
from pyinjective.wallet import PrivateKey
11+
12+
13+
async def main() -> None:
14+
dotenv.load_dotenv()
15+
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")
16+
17+
# select network: local, testnet, mainnet
18+
network = Network.testnet()
19+
20+
# initialize grpc client
21+
client = AsyncClient(network)
22+
composer = await client.composer()
23+
await client.sync_timeout_height()
24+
25+
message_broadcaster = MsgBroadcasterWithPk.new_using_simulation(
26+
network=network,
27+
private_key=configured_private_key,
28+
)
29+
30+
# load account
31+
priv_key = PrivateKey.from_hex(configured_private_key)
32+
pub_key = priv_key.to_public_key()
33+
address = pub_key.to_address()
34+
await client.fetch_account(address.to_acc_bech32())
35+
subaccount_id = address.get_subaccount_id(index=0)
36+
37+
# prepare trade info
38+
market_id = "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6"
39+
40+
# prepare tx msg
41+
msg = composer.msg_decrease_position_margin(
42+
sender=address.to_acc_bech32(),
43+
market_id=market_id,
44+
source_subaccount_id=subaccount_id,
45+
destination_subaccount_id=subaccount_id,
46+
amount=Decimal(2),
47+
)
48+
49+
# broadcast the transaction
50+
result = await message_broadcaster.broadcast([msg])
51+
print("---Transaction Response---")
52+
print(result)
53+
54+
55+
if __name__ == "__main__":
56+
asyncio.get_event_loop().run_until_complete(main())
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import asyncio
2+
import os
3+
from decimal import Decimal
4+
5+
import dotenv
6+
7+
from pyinjective.async_client import AsyncClient
8+
from pyinjective.core.broadcaster import MsgBroadcasterWithPk
9+
from pyinjective.core.network import Network
10+
from pyinjective.wallet import PrivateKey
11+
12+
13+
async def main() -> None:
14+
dotenv.load_dotenv()
15+
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")
16+
17+
# select network: local, testnet, mainnet
18+
network = Network.testnet()
19+
20+
# initialize grpc client
21+
client = AsyncClient(network)
22+
await client.initialize_tokens_from_chain_denoms()
23+
composer = await client.composer()
24+
await client.sync_timeout_height()
25+
26+
message_broadcaster = MsgBroadcasterWithPk.new_using_simulation(
27+
network=network,
28+
private_key=configured_private_key,
29+
)
30+
31+
# load account
32+
priv_key = PrivateKey.from_hex(configured_private_key)
33+
pub_key = priv_key.to_public_key()
34+
address = pub_key.to_address()
35+
await client.fetch_account(address.to_acc_bech32())
36+
37+
# prepare tx msg
38+
message = composer.msg_update_spot_market(
39+
admin=address.to_acc_bech32(),
40+
market_id="0x215970bfdea5c94d8e964a759d3ce6eae1d113900129cc8428267db5ccdb3d1a",
41+
new_ticker="INJ/USDC 2",
42+
new_min_price_tick_size=Decimal("0.01"),
43+
new_min_quantity_tick_size=Decimal("0.01"),
44+
new_min_notional=Decimal("2"),
45+
)
46+
47+
# broadcast the transaction
48+
result = await message_broadcaster.broadcast([message])
49+
print("---Transaction Response---")
50+
print(result)
51+
52+
53+
if __name__ == "__main__":
54+
asyncio.get_event_loop().run_until_complete(main())
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import asyncio
2+
import os
3+
from decimal import Decimal
4+
5+
import dotenv
6+
7+
from pyinjective.async_client import AsyncClient
8+
from pyinjective.core.broadcaster import MsgBroadcasterWithPk
9+
from pyinjective.core.network import Network
10+
from pyinjective.wallet import PrivateKey
11+
12+
13+
async def main() -> None:
14+
dotenv.load_dotenv()
15+
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")
16+
17+
# select network: local, testnet, mainnet
18+
network = Network.testnet()
19+
20+
# initialize grpc client
21+
client = AsyncClient(network)
22+
await client.initialize_tokens_from_chain_denoms()
23+
composer = await client.composer()
24+
await client.sync_timeout_height()
25+
26+
message_broadcaster = MsgBroadcasterWithPk.new_using_simulation(
27+
network=network,
28+
private_key=configured_private_key,
29+
)
30+
31+
# load account
32+
priv_key = PrivateKey.from_hex(configured_private_key)
33+
pub_key = priv_key.to_public_key()
34+
address = pub_key.to_address()
35+
await client.fetch_account(address.to_acc_bech32())
36+
37+
# prepare tx msg
38+
message = composer.msg_update_derivative_market(
39+
admin=address.to_acc_bech32(),
40+
market_id="0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6",
41+
new_ticker="INJ/USDT PERP 2",
42+
new_min_price_tick_size=Decimal("1"),
43+
new_min_quantity_tick_size=Decimal("1"),
44+
new_min_notional=Decimal("2"),
45+
new_initial_margin_ratio=Decimal("0.40"),
46+
new_maintenance_margin_ratio=Decimal("0.085"),
47+
)
48+
49+
# broadcast the transaction
50+
result = await message_broadcaster.broadcast([message])
51+
print("---Transaction Response---")
52+
print(result)
53+
54+
55+
if __name__ == "__main__":
56+
asyncio.get_event_loop().run_until_complete(main())
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import asyncio
2+
import os
3+
from decimal import Decimal
4+
5+
import dotenv
6+
7+
from pyinjective.async_client import AsyncClient
8+
from pyinjective.core.broadcaster import MsgBroadcasterWithPk
9+
from pyinjective.core.network import Network
10+
from pyinjective.wallet import PrivateKey
11+
12+
13+
async def main() -> None:
14+
dotenv.load_dotenv()
15+
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")
16+
17+
# select network: local, testnet, mainnet
18+
network = Network.testnet()
19+
20+
# initialize grpc client
21+
client = AsyncClient(network)
22+
await client.initialize_tokens_from_chain_denoms()
23+
composer = await client.composer()
24+
await client.sync_timeout_height()
25+
26+
message_broadcaster = MsgBroadcasterWithPk.new_using_simulation(
27+
network=network,
28+
private_key=configured_private_key,
29+
)
30+
31+
# load account
32+
priv_key = PrivateKey.from_hex(configured_private_key)
33+
pub_key = priv_key.to_public_key()
34+
address = pub_key.to_address()
35+
await client.fetch_account(address.to_acc_bech32())
36+
37+
# prepare tx msg
38+
grant_authorization = composer.create_grant_authorization(
39+
grantee="inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r",
40+
amount=Decimal("1"),
41+
)
42+
message = composer.msg_authorize_stake_grants(sender=address.to_acc_bech32(), grants=[grant_authorization])
43+
44+
# broadcast the transaction
45+
result = await message_broadcaster.broadcast([message])
46+
print("---Transaction Response---")
47+
print(result)
48+
49+
50+
if __name__ == "__main__":
51+
asyncio.get_event_loop().run_until_complete(main())
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import asyncio
2+
import os
3+
4+
import dotenv
5+
6+
from pyinjective.async_client import AsyncClient
7+
from pyinjective.core.broadcaster import MsgBroadcasterWithPk
8+
from pyinjective.core.network import Network
9+
from pyinjective.wallet import PrivateKey
10+
11+
12+
async def main() -> None:
13+
dotenv.load_dotenv()
14+
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")
15+
16+
# select network: local, testnet, mainnet
17+
network = Network.testnet()
18+
19+
# initialize grpc client
20+
client = AsyncClient(network)
21+
await client.initialize_tokens_from_chain_denoms()
22+
composer = await client.composer()
23+
await client.sync_timeout_height()
24+
25+
message_broadcaster = MsgBroadcasterWithPk.new_using_simulation(
26+
network=network,
27+
private_key=configured_private_key,
28+
)
29+
30+
# load account
31+
priv_key = PrivateKey.from_hex(configured_private_key)
32+
pub_key = priv_key.to_public_key()
33+
address = pub_key.to_address()
34+
await client.fetch_account(address.to_acc_bech32())
35+
36+
# prepare tx msg
37+
message = composer.msg_activate_stake_grant(
38+
sender=address.to_acc_bech32(), granter="inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"
39+
)
40+
41+
# broadcast the transaction
42+
result = await message_broadcaster.broadcast([message])
43+
print("---Transaction Response---")
44+
print(result)
45+
46+
47+
if __name__ == "__main__":
48+
asyncio.get_event_loop().run_until_complete(main())

0 commit comments

Comments
 (0)