Limit Order allows submission, updates and execution of buy and sell orders at a limit price specified by the users. Once the limit order is submitted and the limit price is reached, market making agents can read the orders from the Limit Order contract and execute them when it provides an arbitrage opportunity. To create a market making bot for arbitrage opportunity, refer to this Github link.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]pub struct InitMsg {}
Can be called during CW20 token transfer when the Limit Order contract is the recipient. Allows the token transfer to execute a Receive Hook as a subsequent action within the same transaction.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]#[serde(rename_all = "snake_case")]pub enum HandleMsg {Receive {amount: Uint128,sender: HumanAddrmsg: Binary,}}
{"receive": {"amount": "10000000","sender": "terra1...","msg": "eyAiZXhlY3V0ZV9tc2ciOiAiYmxhaCBibGFoIiB9"}}
Key | Type | Description |
| Uint128 | Token amount received |
| HumanAddr | Sender of token transaction |
| Binary | Base64-encoded string of JSON of Receive Hook |
Creates a new Limit Order with a types and amount of tokens to be traded, specified by the user. offer_asset
is locked until the order is executed or canceled by the creator.
When tokens other than native tokens are sent (such as CW20), it a Receive Hook must be sent to submit the order.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]#[serde(rename_all = "snake_case")]pub enum HandleMsg {SubmitOrder {offer_asset: Asset,ask_asset: Asset,}}
{"submit_order": {"offer_asset": {"info": {"token": {"contract_address": "terra1..."}},"amount": "1000000"},"ask_asset": {"info": {"native_token": {"denom": "uusd",}},"amount": "10000000"}}
Key | Type | Description |
| Asset | Asset to be submitted to Limit Order |
| Asset | Asset to receive when order is executed |
Order is canceled by the creator. offer_asset
locked in this order is released and returned to the owner.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]#[serde(rename_all = "snake_case")]pub enum HandleMsg {CancelOrder {order_id: u64,}}
{"cancel_order": {"order_id": 10,},}
Key | Type | Description |
| u64 | Order ID |
Executes order against an existing limit order. You cannot submit more than the amount defined by ask_asset - filled_asset_amounnt
in a specific order.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]#[serde(rename_all = "snake_case")]pub enum HandleMsg {ExecuteOrder {execute_asset: Asset,order_id: u64,}}
{"execute_order": {"execute_asset": {"info": {"token": {"contract_address": "terra1..."}},"amount": "1000000"},"order_id": 8}
Key | Type | Description |
| Asset | Asset to be executed from Limit Order |
| u64 | Order ID |
If you send tokens to the Limit Order contract without issuing this hook, they will not be used to create or execute order and will BE LOST FOREVER.
Issued when user sends CW20 tokens to Limit Order contract.
Locks the sent amount to create a new order.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]#[serde(rename_all = "snake_case")]pub enum Cw20HookMsg {SubmitOrder {ask_asset: Asset,}}
{"submit_order": {"ask_asset": {"info": {"token": {"contract_address": "terra1..."}}},"amount": "10000000"}}
Key | Type | Description |
| Asset | Asset to be executed from Limit Order |
Issued when arbitrageur sends and fulfills the amount of ask_asset
to a specific limit order.
Reduces the balance of the ask_asset
and offer_asset
of the specified order_id
. If all outstanding ask_asset
has been filled, then the order is completed.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]#[serde(rename_all = "snake_case")]pub enum Cw20HookMsg {ExecuteOrder {order_id: u64,}}
{"execute_order": {"order_id": 10}}
Key | Type | Description |
| u64 | Order ID |
Gets information about specified order ID’s details.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]#[serde(rename_all = "snake_case")]pub enum QueryMsg {Order: {order_id: u64,}}
{"order": {"order_id": 10}}
Key | Type | Description |
| u64 | Order ID |
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]pub struct OrderResponse {pub order_id: u64,pub bidder_addr: HumanAddr,pub offer_asset: Asset,pub ask_asset: Asset,pub filled_offer_amount: Uint128,pub filled_ask_amount: Uint128,
{"OrderResponse": {"order_id": 10,"bidder_addr": "terra1...","offer_asset": {"info": {"token": {"contract_address": "terra1..."}},"amount": "10000000"},"ask_asset": {"info": {"native_token": {"denom": "uusd",}},"amount": "10000000"},"filled_offer_amount": "10000000","filled_ask_amount": "10000000"}}
Key | Type | Description |
| u64 | Order ID |
| HumanAddr | Address of bidder |
| Asset | Amount of asset offered in order |
| Asset | Amount of asset asked in order |
| Uint128 | Amount of offer asset already executed |
| Uint128 | Amount of ask asset already executed |
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]#[serde(rename_all = "snake_case")]pub enum QueryMsg {Orders: {bidder_addr: Option<HumanAddr>,start_after: Option<u64>,limit: Option<u32>,order_by: Option<OrderBy>,}}
{"orders": {"bidder_addr": "terra1...","limit": 8,"order_by": "asc""start_after": 8}}
Key | Type | Description |
| HumanAddr | Address of the order bidder |
| u64 | Begins search query at specific Order ID |
| u32 | Limit of results to fetch |
| OrderBy | Can be ASC or DESC |
*=optional
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]pub struct OrdersResponse {pub orders: Vec<OrderResponse>,}
{"OrdersResponse": [{"order_id": 10"bidder_addr": "terra1...","offer_asset": {"info": {"token": {"contract_address": "terra1..."}},"amount": "10000000"},"ask_asset": {"info": {"native_token": {"denom": "uusd",}},"amount": "10000000"},"filled_offer_amount": "10000000","filled_ask_amount": "10000000","order_id": 10},{"order_id": 10"bidder_addr": "terra1...","offer_asset": {"info": {"token": {"contract_address": "terra1..."}},"amount": "10000000"},"ask_asset": {"info": {"native_token": {"denom": "uusd",}},"amount": "10000000"},"filled_offer_amount": "10000000","filled_ask_amount": "10000000",}]}
Key | Type | Description |
| Vec<OrderResponse> | Vector of user's order information |
Key | Type | Description |
| u64 | Order ID |
| HumanAddr | Address of bidder |
| Asset | Amount of asset offered in order |
| Asset | Amount of asset asked in order |
| Uint128 | Amount of offer asset already executed |
| Uint128 | Amount of ask asset already executed |
Gets the most recently submitted order ID.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]#[serde(rename_all = "snake_case")]pub enum QueryMsg {LastOrderID: {}}
{"last_order_id": {}}
Key | Type | Description |
| | |
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]pub struct LastOrderIDResponse {pub last_order_id:u64}
{"LastOrderIDResponse": {"last_order_id": 10}
Key | Type | Description |
| u64 | Index of the most recent order |