Skip to content

Commit

Permalink
(feat) Added support for all chain exchange module messages in Compos…
Browse files Browse the repository at this point in the history
…er. Added unit tests for new messages. Refactored example scripts to move them into separated subfolders for each module.
  • Loading branch information
abel committed Feb 27, 2024
1 parent 4d6ce1b commit c5cb600
Show file tree
Hide file tree
Showing 83 changed files with 3,740 additions and 934 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import os
import uuid
from decimal import Decimal

import dotenv

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

spot_orders = [
composer.SpotOrder(
composer.spot_order(
market_id=spot_market_id,
subaccount_id=subaccount_id,
fee_recipient=fee_recipient,
price=0.524,
quantity=0.01,
is_buy=True,
is_po=False,
price=Decimal("0.524"),
quantity=Decimal("0.01"),
order_type="BUY",
cid=str(uuid.uuid4()),
),
composer.SpotOrder(
composer.spot_order(
market_id=spot_market_id,
subaccount_id=subaccount_id,
fee_recipient=fee_recipient,
price=27.92,
quantity=0.01,
is_buy=False,
is_po=False,
price=Decimal("27.92"),
quantity=Decimal("0.01"),
order_type="SELL",
cid=str(uuid.uuid4()),
),
]

derivative_orders = [
composer.DerivativeOrder(
composer.derivative_order(
market_id=deriv_market_id,
subaccount_id=subaccount_id,
fee_recipient=fee_recipient,
price=10500,
quantity=0.01,
leverage=1.5,
is_buy=True,
is_po=False,
price=Decimal(10500),
quantity=Decimal(0.01),
margin=composer.calculate_margin(
quantity=Decimal(0.01), price=Decimal(10500), leverage=Decimal(2), is_reduce_only=False
),
order_type="BUY",
cid=str(uuid.uuid4()),
),
composer.DerivativeOrder(
composer.derivative_order(
market_id=deriv_market_id,
subaccount_id=subaccount_id,
fee_recipient=fee_recipient,
price=65111,
quantity=0.01,
leverage=2,
is_buy=False,
is_reduce_only=False,
price=Decimal(65111),
quantity=Decimal(0.01),
margin=composer.calculate_margin(
quantity=Decimal(0.01), price=Decimal(65111), leverage=Decimal(2), is_reduce_only=False
),
order_type="SELL",
cid=str(uuid.uuid4()),
),
]

# prepare tx msg
spot_msg = composer.MsgBatchCreateSpotLimitOrders(sender=address.to_acc_bech32(), orders=spot_orders)
spot_msg = composer.msg_batch_create_spot_limit_orders(sender=address.to_acc_bech32(), orders=spot_orders)

deriv_msg = composer.MsgBatchCreateDerivativeLimitOrders(sender=address.to_acc_bech32(), orders=derivative_orders)
deriv_msg = composer.msg_batch_create_derivative_limit_orders(
sender=address.to_acc_bech32(), orders=derivative_orders
)

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

spot_orders = [
composer.SpotOrder(
composer.spot_order(
market_id=spot_market_id,
subaccount_id=subaccount_id_2,
fee_recipient=fee_recipient,
price=1.524,
quantity=0.01,
is_buy=True,
is_po=True,
price=Decimal("1.524"),
quantity=Decimal("0.01"),
order_type="BUY_PO",
cid=str(uuid.uuid4()),
),
composer.SpotOrder(
composer.spot_order(
market_id=spot_market_id,
subaccount_id=subaccount_id_2,
fee_recipient=fee_recipient,
price=27.92,
quantity=0.01,
is_buy=False,
is_po=False,
price=Decimal("27.92"),
quantity=Decimal("0.01"),
order_type="SELL_PO",
cid=str(uuid.uuid4()),
),
]

derivative_orders = [
composer.DerivativeOrder(
composer.derivative_order(
market_id=deriv_market_id,
subaccount_id=subaccount_id_2,
fee_recipient=fee_recipient,
price=25111,
quantity=0.01,
leverage=1.5,
is_buy=True,
is_po=False,
price=Decimal(25111),
quantity=Decimal(0.01),
margin=composer.calculate_margin(
quantity=Decimal(0.01), price=Decimal(25111), leverage=Decimal("1.5"), is_reduce_only=False
),
order_type="BUY",
cid=str(uuid.uuid4()),
),
composer.DerivativeOrder(
composer.derivative_order(
market_id=deriv_market_id,
subaccount_id=subaccount_id_2,
fee_recipient=fee_recipient,
price=65111,
quantity=0.01,
leverage=2,
is_buy=False,
is_reduce_only=False,
price=Decimal(65111),
quantity=Decimal(0.01),
margin=composer.calculate_margin(
quantity=Decimal(0.01), price=Decimal(25111), leverage=Decimal(2), is_reduce_only=False
),
order_type="SELL",
cid=str(uuid.uuid4()),
),
]

# prepare tx msg
spot_msg = composer.MsgBatchCreateSpotLimitOrders(sender=address.to_acc_bech32(), orders=spot_orders)
spot_msg = composer.msg_batch_create_spot_limit_orders(sender=address.to_acc_bech32(), orders=spot_orders)

deriv_msg = composer.MsgBatchCreateDerivativeLimitOrders(sender=address.to_acc_bech32(), orders=derivative_orders)
deriv_msg = composer.msg_batch_create_derivative_limit_orders(
sender=address.to_acc_bech32(), orders=derivative_orders
)

# compute order hashes
order_hashes = order_hash_manager.compute_order_hashes(
Expand Down
98 changes: 0 additions & 98 deletions examples/chain_client/35_MsgInstantBinaryOptionsMarketLaunch.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import os
import uuid
from decimal import Decimal

import dotenv

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

spot_orders_to_create = [
composer.SpotOrder(
composer.spot_order(
market_id=spot_market_id_create,
subaccount_id=subaccount_id,
fee_recipient=fee_recipient,
price=3,
quantity=55,
is_buy=True,
is_po=False,
cid=str(uuid.uuid4()),
price=Decimal("3"),
quantity=Decimal("55"),
order_type="BUY",
cid=(str(uuid.uuid4())),
),
composer.SpotOrder(
composer.spot_order(
market_id=spot_market_id_create,
subaccount_id=subaccount_id,
fee_recipient=fee_recipient,
price=300,
quantity=55,
is_buy=False,
is_po=False,
price=Decimal("300"),
quantity=Decimal("55"),
order_type="SELL",
cid=str(uuid.uuid4()),
),
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import os
import uuid
from decimal import Decimal

import dotenv

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

msg = composer.MsgCreateSpotLimitOrder(
sender=granter_inj_address,
msg = composer.msg_create_spot_limit_order(
market_id=market_id,
sender=granter_inj_address,
subaccount_id=granter_subaccount_id,
fee_recipient=address.to_acc_bech32(),
price=7.523,
quantity=0.01,
is_buy=True,
is_po=False,
price=Decimal("7.523"),
quantity=Decimal("0.01"),
order_type="BUY",
cid=str(uuid.uuid4()),
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import os
import uuid
from decimal import Decimal

import dotenv

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

spot_orders_to_create = [
composer.SpotOrder(
composer.spot_order(
market_id=spot_market_id_create,
subaccount_id=subaccount_id,
fee_recipient=fee_recipient,
price=3,
quantity=55,
is_buy=True,
is_po=False,
price=Decimal("3"),
quantity=Decimal("55"),
order_type="BUY",
cid=str(uuid.uuid4()),
),
composer.SpotOrder(
composer.spot_order(
market_id=spot_market_id_create,
subaccount_id=subaccount_id,
fee_recipient=fee_recipient,
price=300,
quantity=55,
is_buy=False,
is_po=False,
price=Decimal("300"),
quantity=Decimal("55"),
order_type="SELL",
cid=str(uuid.uuid4()),
),
]
Expand Down
Loading

0 comments on commit c5cb600

Please sign in to comment.