Search…
Limit Order
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.

InitMsg

Rust
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
pub struct InitMsg {}
Copied!

HandleMsg

Receive

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.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum HandleMsg {
4
Receive {
5
amount: Uint128,
6
sender: HumanAddr
7
msg: Binary,
8
}
9
}
Copied!
1
{
2
"receive": {
3
"amount": "10000000",
4
"sender": "terra1...",
5
"msg": "eyAiZXhlY3V0ZV9tc2ciOiAiYmxhaCBibGFoIiB9"
6
}
7
}
Copied!
Key
Type
Description
amount
Uint128
Token amount received
sender
HumanAddr
Sender of token transaction
msg
Binary
Base64-encoded string of JSON of Receive Hook

SubmitOrder

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.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum HandleMsg {
4
SubmitOrder {
5
offer_asset: Asset,
6
ask_asset: Asset,
7
}
8
}
Copied!
1
{
2
"submit_order": {
3
"offer_asset": {
4
"info": {
5
"token": {
6
"contract_address": "terra1..."
7
}
8
},
9
"amount": "1000000"
10
},
11
"ask_asset": {
12
"info": {
13
"native_token": {
14
"denom": "uusd",
15
}
16
},
17
"amount": "10000000"
18
}
19
}
Copied!
Key
Type
Description
offer_asset
Asset
Asset to be submitted to Limit Order
ask_asset
Asset
Asset to receive when order is executed

CancelOrder

Order is canceled by the creator. offer_asset locked in this order is released and returned to the owner.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum HandleMsg {
4
CancelOrder {
5
order_id: u64,
6
}
7
}
Copied!
1
{
2
"cancel_order": {
3
"order_id": 10,
4
},
5
}
Copied!
Key
Type
Description
order_id
u64
Order ID

ExecuteOrder

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.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum HandleMsg {
4
ExecuteOrder {
5
execute_asset: Asset,
6
order_id: u64,
7
}
8
}
Copied!
1
{
2
"execute_order": {
3
"execute_asset": {
4
"info": {
5
"token": {
6
"contract_address": "terra1..."
7
}
8
},
9
"amount": "1000000"
10
},
11
"order_id": 8
12
}
Copied!
Key
Type
Description
execute_asset
Asset
Asset to be executed from Limit Order
order_id
u64
Order ID

Receive Hooks

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.

SubmitOrder

Issued when user sends CW20 tokens to Limit Order contract.
Locks the sent amount to create a new order.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum Cw20HookMsg {
4
SubmitOrder {
5
ask_asset: Asset,
6
}
7
}
Copied!
1
{
2
"submit_order": {
3
"ask_asset": {
4
"info": {
5
"token": {
6
"contract_addr": "terra1..."
7
}
8
}
9
},
10
"amount": "10000000"
11
}
12
}
Copied!
Key
Type
Description
ask_asset
Asset
Asset to be executed from Limit Order

ExecuteOrder

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.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum Cw20HookMsg {
4
ExecuteOrder {
5
order_id: u64,
6
}
7
}
Copied!
1
{
2
"execute_order": {
3
"order_id": 10
4
}
5
}
Copied!
Key
Type
Description
order_id
u64
Order ID

QueryMsg

Order

Gets information about specified order ID’s details.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
Order: {
5
order_id: u64,
6
}
7
}
Copied!
Key
Type
Description
order_id
u64
Order ID

Response

1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
pub struct OrderResponse {
3
pub order_id: u64,
4
pub bidder_addr: HumanAddr,
5
pub offer_asset: Asset,
6
pub ask_asset: Asset,
7
pub filled_offer_amount: Uint128,
8
pub filled_ask_amount: Uint128,
Copied!
Key
Type
Description
order_id
u64
Order ID
bidder_addr
HumanAddr
Address of bidder
offer_asset
Asset
Amount of asset offered in order
ask_asset
Asset
Amount of asset asked in order
filled_offer_amount
Uint128
Amount of offer asset already executed
filled_ask_amount
Uint128
Amount of ask asset already executed
1
{
2
"order": {
3
"order_id": 10
4
}
5
}
Copied!
Key
Type
Description
order_id
u64
Order ID

Response

1
{
2
"OrderResponse": {
3
"order_id": 10,
4
"bidder_addr": "terra1...",
5
"offer_asset": {
6
"info": {
7
"token": {
8
"contract_address": "terra1..."
9
}
10
},
11
"amount": "10000000"
12
},
13
"ask_asset": {
14
"info": {
15
"native_token": {
16
"denom": "uusd",
17
}
18
},
19
"amount": "10000000"
20
},
21
"filled_offer_amount": "10000000",
22
"filled_ask_amount": "10000000"
23
}
24
}
Copied!
Key
Type
Description
order_id
u64
Order ID
bidder_addr
HumanAddr
Address of bidder
offer_asset
Asset
Amount of asset offered in order
ask_asset
Asset
Amount of asset asked in order
filled_offer_amount
Uint128
Amount of offer asset already executed
filled_ask_amount
Uint128
Amount of ask asset already executed

Orders

Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
Orders: {
5
bidder_addr: Option<HumanAddr>,
6
start_after: Option<u64>,
7
limit: Option<u32>,
8
order_by: Option<OrderBy>,
9
10
}
11
}
Copied!
Key
Type
Description
bidder_addr*
HumanAddr
Address of the order bidder
start_after*
u64
Begins search query at specific Order ID
limit*
u32
Limit of results to fetch
order_by*
OrderBy
Can be ASC or DESC

Response

1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
pub struct OrdersResponse {
3
pub orders: Vec<OrderResponse>,
4
}
Copied!
Key
Type
Description
orders
Vec<OrderResponse>
Vector of user's order information
Key
Type
Description
order_id
u64
Order ID
bidder_addr
HumanAddr
Address of bidder
offer_asset
Asset
Amount of asset offered in order
ask_asset
Asset
Amount of asset asked in order
filled_offer_amount
Uint128
Amount of offer asset already executed
filled_ask_amount
Uint128
Amount of ask asset already executed
1
{
2
"orders": {
3
"bidder_addr": "terra1...",
4
"limit": 8,
5
"order_by": "asc"
6
"start_after": 8
7
}
8
}
Copied!
Key
Type
Description
bidder_addr*
HumanAddr
Address of the order bidder
start_after*
u64
Begins search query at specific Order ID
limit*
u32
Limit of results to fetch
order_by*
OrderBy
Can be ASC or DESC

Response

1
{
2
"OrdersResponse": [
3
{
4
"order_id": 10
5
"bidder_addr": "terra1...",
6
"offer_asset": {
7
"info": {
8
"token": {
9
"contract_address": "terra1..."
10
}
11
},
12
"amount": "10000000"
13
},
14
"ask_asset": {
15
"info": {
16
"native_token": {
17
"denom": "uusd",
18
}
19
},
20
"amount": "10000000"
21
},
22
"filled_offer_amount": "10000000",
23
"filled_ask_amount": "10000000",
24
"order_id": 10
25
},
26
{
27
"order_id": 10
28
"bidder_addr": "terra1...",
29
"offer_asset": {
30
"info": {
31
"token": {
32
"contract_address": "terra1..."
33
}
34
},
35
"amount": "10000000"
36
},
37
"ask_asset": {
38
"info": {
39
"native_token": {
40
"denom": "uusd",
41
}
42
},
43
"amount": "10000000"
44
},
45
"filled_offer_amount": "10000000",
46
"filled_ask_amount": "10000000",
47
}
48
]
49
}
Copied!
Key
Type
Description
order_id
u64
Order ID
bidder_addr
HumanAddr
Address of bidder
offer_asset
Asset
Amount of asset offered in order
ask_asset
Asset
Amount of asset asked in order
filled_offer_amount
Uint128
Amount of offer asset already executed
filled_ask_amount
Uint128
Amount of ask asset already executed
*=optional

LastOrderID

Gets the most recently submitted order ID.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
LastOrderID: {}
5
}
Copied!

Response

1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
pub struct LastOrderIDResponse {
3
pub last_order_id:u64
4
}
Copied!
Key
Type
Description
last_order_id
u64
Index of the most recent order
1
{
2
"last_order_id": {}
3
}
Copied!

Response

1
{
2
"last_order_id_response": {
3
"last_order_id": 10
4
}
Copied!
Key
Type
Description
last_order_id
u64
Index of the most recent order
Last modified 5mo ago