Skip to content

Commit 17524af

Browse files
author
abel
committed
(feat) Added support for all chain exchange module messages in Composer. Added unit tests for new messages. Refactored example scripts to move them into separated subfolders for each module.
1 parent 364f022 commit 17524af

File tree

83 files changed

+3740
-934
lines changed

Some content is hidden

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

83 files changed

+3740
-934
lines changed
Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22
import os
33
import uuid
4+
from decimal import Decimal
45

56
import dotenv
67

@@ -40,57 +41,59 @@ async def main() -> None:
4041
fee_recipient = "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"
4142

4243
spot_orders = [
43-
composer.SpotOrder(
44+
composer.spot_order(
4445
market_id=spot_market_id,
4546
subaccount_id=subaccount_id,
4647
fee_recipient=fee_recipient,
47-
price=0.524,
48-
quantity=0.01,
49-
is_buy=True,
50-
is_po=False,
48+
price=Decimal("0.524"),
49+
quantity=Decimal("0.01"),
50+
order_type="BUY",
5151
cid=str(uuid.uuid4()),
5252
),
53-
composer.SpotOrder(
53+
composer.spot_order(
5454
market_id=spot_market_id,
5555
subaccount_id=subaccount_id,
5656
fee_recipient=fee_recipient,
57-
price=27.92,
58-
quantity=0.01,
59-
is_buy=False,
60-
is_po=False,
57+
price=Decimal("27.92"),
58+
quantity=Decimal("0.01"),
59+
order_type="SELL",
6160
cid=str(uuid.uuid4()),
6261
),
6362
]
6463

6564
derivative_orders = [
66-
composer.DerivativeOrder(
65+
composer.derivative_order(
6766
market_id=deriv_market_id,
6867
subaccount_id=subaccount_id,
6968
fee_recipient=fee_recipient,
70-
price=10500,
71-
quantity=0.01,
72-
leverage=1.5,
73-
is_buy=True,
74-
is_po=False,
69+
price=Decimal(10500),
70+
quantity=Decimal(0.01),
71+
margin=composer.calculate_margin(
72+
quantity=Decimal(0.01), price=Decimal(10500), leverage=Decimal(2), is_reduce_only=False
73+
),
74+
order_type="BUY",
7575
cid=str(uuid.uuid4()),
7676
),
77-
composer.DerivativeOrder(
77+
composer.derivative_order(
7878
market_id=deriv_market_id,
7979
subaccount_id=subaccount_id,
8080
fee_recipient=fee_recipient,
81-
price=65111,
82-
quantity=0.01,
83-
leverage=2,
84-
is_buy=False,
85-
is_reduce_only=False,
81+
price=Decimal(65111),
82+
quantity=Decimal(0.01),
83+
margin=composer.calculate_margin(
84+
quantity=Decimal(0.01), price=Decimal(65111), leverage=Decimal(2), is_reduce_only=False
85+
),
86+
order_type="SELL",
8687
cid=str(uuid.uuid4()),
8788
),
8889
]
8990

9091
# prepare tx msg
91-
spot_msg = composer.MsgBatchCreateSpotLimitOrders(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)
9293

93-
deriv_msg = composer.MsgBatchCreateDerivativeLimitOrders(sender=address.to_acc_bech32(), orders=derivative_orders)
94+
deriv_msg = composer.msg_batch_create_derivative_limit_orders(
95+
sender=address.to_acc_bech32(), orders=derivative_orders
96+
)
9497

9598
# compute order hashes
9699
order_hashes = order_hash_manager.compute_order_hashes(
@@ -167,57 +170,59 @@ async def main() -> None:
167170
print("gas fee: {} INJ".format(gas_fee))
168171

169172
spot_orders = [
170-
composer.SpotOrder(
173+
composer.spot_order(
171174
market_id=spot_market_id,
172175
subaccount_id=subaccount_id_2,
173176
fee_recipient=fee_recipient,
174-
price=1.524,
175-
quantity=0.01,
176-
is_buy=True,
177-
is_po=True,
177+
price=Decimal("1.524"),
178+
quantity=Decimal("0.01"),
179+
order_type="BUY_PO",
178180
cid=str(uuid.uuid4()),
179181
),
180-
composer.SpotOrder(
182+
composer.spot_order(
181183
market_id=spot_market_id,
182184
subaccount_id=subaccount_id_2,
183185
fee_recipient=fee_recipient,
184-
price=27.92,
185-
quantity=0.01,
186-
is_buy=False,
187-
is_po=False,
186+
price=Decimal("27.92"),
187+
quantity=Decimal("0.01"),
188+
order_type="SELL_PO",
188189
cid=str(uuid.uuid4()),
189190
),
190191
]
191192

192193
derivative_orders = [
193-
composer.DerivativeOrder(
194+
composer.derivative_order(
194195
market_id=deriv_market_id,
195196
subaccount_id=subaccount_id_2,
196197
fee_recipient=fee_recipient,
197-
price=25111,
198-
quantity=0.01,
199-
leverage=1.5,
200-
is_buy=True,
201-
is_po=False,
198+
price=Decimal(25111),
199+
quantity=Decimal(0.01),
200+
margin=composer.calculate_margin(
201+
quantity=Decimal(0.01), price=Decimal(25111), leverage=Decimal("1.5"), is_reduce_only=False
202+
),
203+
order_type="BUY",
202204
cid=str(uuid.uuid4()),
203205
),
204-
composer.DerivativeOrder(
206+
composer.derivative_order(
205207
market_id=deriv_market_id,
206208
subaccount_id=subaccount_id_2,
207209
fee_recipient=fee_recipient,
208-
price=65111,
209-
quantity=0.01,
210-
leverage=2,
211-
is_buy=False,
212-
is_reduce_only=False,
210+
price=Decimal(65111),
211+
quantity=Decimal(0.01),
212+
margin=composer.calculate_margin(
213+
quantity=Decimal(0.01), price=Decimal(25111), leverage=Decimal(2), is_reduce_only=False
214+
),
215+
order_type="SELL",
213216
cid=str(uuid.uuid4()),
214217
),
215218
]
216219

217220
# prepare tx msg
218-
spot_msg = composer.MsgBatchCreateSpotLimitOrders(sender=address.to_acc_bech32(), orders=spot_orders)
221+
spot_msg = composer.msg_batch_create_spot_limit_orders(sender=address.to_acc_bech32(), orders=spot_orders)
219222

220-
deriv_msg = composer.MsgBatchCreateDerivativeLimitOrders(sender=address.to_acc_bech32(), orders=derivative_orders)
223+
deriv_msg = composer.msg_batch_create_derivative_limit_orders(
224+
sender=address.to_acc_bech32(), orders=derivative_orders
225+
)
221226

222227
# compute order hashes
223228
order_hashes = order_hash_manager.compute_order_hashes(
File renamed without changes.

examples/chain_client/35_MsgInstantBinaryOptionsMarketLaunch.py

Lines changed: 0 additions & 98 deletions
This file was deleted.

examples/chain_client/44_MessageBroadcaster.py renamed to examples/chain_client/3_MessageBroadcaster.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22
import os
33
import uuid
4+
from decimal import Decimal
45

56
import dotenv
67

@@ -34,24 +35,22 @@ async def main() -> None:
3435
spot_market_id_create = "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"
3536

3637
spot_orders_to_create = [
37-
composer.SpotOrder(
38+
composer.spot_order(
3839
market_id=spot_market_id_create,
3940
subaccount_id=subaccount_id,
4041
fee_recipient=fee_recipient,
41-
price=3,
42-
quantity=55,
43-
is_buy=True,
44-
is_po=False,
45-
cid=str(uuid.uuid4()),
42+
price=Decimal("3"),
43+
quantity=Decimal("55"),
44+
order_type="BUY",
45+
cid=(str(uuid.uuid4())),
4646
),
47-
composer.SpotOrder(
47+
composer.spot_order(
4848
market_id=spot_market_id_create,
4949
subaccount_id=subaccount_id,
5050
fee_recipient=fee_recipient,
51-
price=300,
52-
quantity=55,
53-
is_buy=False,
54-
is_po=False,
51+
price=Decimal("300"),
52+
quantity=Decimal("55"),
53+
order_type="SELL",
5554
cid=str(uuid.uuid4()),
5655
),
5756
]

examples/chain_client/45_MessageBroadcasterWithGranteeAccount.py renamed to examples/chain_client/4_MessageBroadcasterWithGranteeAccount.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22
import os
33
import uuid
4+
from decimal import Decimal
45

56
import dotenv
67

@@ -40,15 +41,14 @@ async def main() -> None:
4041
granter_address = Address.from_acc_bech32(granter_inj_address)
4142
granter_subaccount_id = granter_address.get_subaccount_id(index=0)
4243

43-
msg = composer.MsgCreateSpotLimitOrder(
44-
sender=granter_inj_address,
44+
msg = composer.msg_create_spot_limit_order(
4545
market_id=market_id,
46+
sender=granter_inj_address,
4647
subaccount_id=granter_subaccount_id,
4748
fee_recipient=address.to_acc_bech32(),
48-
price=7.523,
49-
quantity=0.01,
50-
is_buy=True,
51-
is_po=False,
49+
price=Decimal("7.523"),
50+
quantity=Decimal("0.01"),
51+
order_type="BUY",
5252
cid=str(uuid.uuid4()),
5353
)
5454

examples/chain_client/46_MessageBroadcasterWithoutSimulation.py renamed to examples/chain_client/5_MessageBroadcasterWithoutSimulation.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22
import os
33
import uuid
4+
from decimal import Decimal
45

56
import dotenv
67

@@ -34,24 +35,22 @@ async def main() -> None:
3435
spot_market_id_create = "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"
3536

3637
spot_orders_to_create = [
37-
composer.SpotOrder(
38+
composer.spot_order(
3839
market_id=spot_market_id_create,
3940
subaccount_id=subaccount_id,
4041
fee_recipient=fee_recipient,
41-
price=3,
42-
quantity=55,
43-
is_buy=True,
44-
is_po=False,
42+
price=Decimal("3"),
43+
quantity=Decimal("55"),
44+
order_type="BUY",
4545
cid=str(uuid.uuid4()),
4646
),
47-
composer.SpotOrder(
47+
composer.spot_order(
4848
market_id=spot_market_id_create,
4949
subaccount_id=subaccount_id,
5050
fee_recipient=fee_recipient,
51-
price=300,
52-
quantity=55,
53-
is_buy=False,
54-
is_po=False,
51+
price=Decimal("300"),
52+
quantity=Decimal("55"),
53+
order_type="SELL",
5554
cid=str(uuid.uuid4()),
5655
),
5756
]

0 commit comments

Comments
 (0)