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

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct InitMsg {}

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.

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum HandleMsg {
    Receive {
        amount: Uint128,
        sender: HumanAddr
        msg: Binary,
    }
}
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.

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum HandleMsg {
    SubmitOrder {
        offer_asset: Asset,
        ask_asset: Asset,
    }
}
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.

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum HandleMsg {
    CancelOrder {
        order_id: u64,
    }
}
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.

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum HandleMsg {
    ExecuteOrder {
        execute_asset: Asset,
        order_id: u64,
    }
}
Key
Type
Description

execute_asset

Asset

Asset to be executed from Limit Order

order_id

u64

Order ID

Receive Hooks

SubmitOrder

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,
    }
}
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.

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum Cw20HookMsg {
    ExecuteOrder {
        order_id: u64,
    }
}
Key
Type
Description

order_id

u64

Order ID

QueryMsg

Order

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,
    }
}
Key
Type
Description

order_id

u64

Order ID

Response

#[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,
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

#[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>,

    }
}
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

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct OrdersResponse {
    pub orders: Vec<OrderResponse>,
}
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

*=optional

LastOrderID

Gets the most recently submitted order ID.

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum QueryMsg {
    LastOrderID: {}
}

Response

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct LastOrderIDResponse {
    pub last_order_id:u64
}
Key
Type
Description

last_order_id

u64

Index of the most recent order

Last updated