Dex 模块教程 (Dex Module Tutorial)

The dex module is responsible for order placement and related trading functionality. The source code can be found here: https://github.com/sei-protocol/sei-chain/tree/master/x/dex

dex 模块负责下单和相关交易功能。源代码可以在这里找到:https://github.com/sei-protocol/sei-chain/tree/master/x/dex

To interact with the dex module, one can use either a query or tx message. Below are examples of how to interact, along with a brief overview of some common enums and structs used. Note that these commands have the usual other flags such as --from, --chain_id, -fees, --gas, --broadcast-mode, etc.

要与 dex 模块交互,可以使用 querytx 消息。下面是如何交互的示例,以及一些常用枚举和结构的简要概述。请注意,这些命令具有通常的其他标志,例如 `--from、--chain_id、-fees、--gas、--broadcast-mode 等。

查询 (Queries):

GetTwaps

Description: gets time weighted average prices for specific assets 描述:获取特定资产的时间加权平均价格

Usage: seid q get-twaps $contract_addr $lookback 用法:seid q get-twaps $contract_addr $lookback

Arguments: 1) contract address (string), 2) lookback (uint64) 参数:1)合约地址(字符串),2)回溯(uint64)

Returns: Twap[] 返回:Twap[]

Example: seid q get-twaps $contract_addr 100 --from=$key_name --chain_id=sei_chain --fees=1000000usei --gas=50000000 --broadcast-mode=block 示例:seid q get-twaps $contract_addr 100 --from=$key_name --chain_id=sei_chain --fees=1000000usei --gas=50000000 --broadcast-mode=block

GetOrders

Description: get orders by a specific account on the order book 描述:通过订单簿上的特定账户获取订单

Usage: seid q get-orders $contract_addr $account 用法:seid q get-orders $contract_addr $account

Arguments: 1) contract address (string), 2) account (string) 参数:1)合约地址(字符串),2)账户(字符串)

Returns: Orders[] 返回:订单(Orders)[]

Example: seid q get-orders $contract_addr $acc_addr --from=$key_name --chain_id=sei_chain --fees=1000000usei --gas=50000000 --broadcast-mode=block 示例:seid q get-orders $contract_addr $acc_addr --from=$key_name --chain_id=sei_chain --fees=1000000usei --gas=50000000 --broadcast-mode=block

GetOrderById

Description: get individual order by order ID 描述:通过订单ID获取单个订单

Usage: seid q get-orders-by-id $contract_addr $price_denom $asset_denom $id 用法:seid q get-orders-by-id $contract_addr $price_denom $asset_denom $id

Arguments: 1) contract address (string), 2) price_denom (string), 3) asset_denom (string), 4) id (uint64) 参数:1)合约地址(字符串),2)price_denom(字符串),3)asset_denom(字符串),4)id(uint64)

Returns: Order 返回:订单(Order)[]

Example: seid q get-orders-by-id $contract_addr 'USDC' 'ATOM' $id --from=$key_name --chain_id=sei_chain --fees=1000000usei --gas=50000000 --broadcast-mode=block 示例:seid q get-orders-by-id $contract_addr 'USDC' 'ATOM' $id --from=$key_name --chain_id=sei_chain --fees=1000000usei --gas=50000000 --broadcast-mode=block

消息 (Messages):

PlaceOrders

Description: places orders with the order book 描述:使用订单簿下订单

Usage: seid tx place-orders $contract_addr $orders --amount $coins (optional) 用法:seid tx place-orders $contract_addr $orders --amount $coins(可选)

Arguments: 1) contract address (string), 2) list of orders 参数:1)合约地址(字符串),2)订单列表

Note: orders arguments are split by a ?, and the following holds: position direction is arg[0], price is arg[1], quantity is arg[2], price denom is args[3], asset denom is args[4], order type is args[5], and data is args[6] 注意:订单参数由 ? 分割,以下成立:仓位方向为 arg[0],价格为 arg[1],数量为 arg[2],价格 denom 为 args[3],资产 denom 为 args[ 4],订单类型为args[5],数据为args[6]

Returns: uint64[] OrderIds 返回:uint64[] OrderIds

Example: seid tx dex place-orders $contract_addr 'LONG?1.01?5?USDC?ATOM?LIMIT?{"leverage":"1","position_effect":"Open"}' --amount=1000000000uusdc -y --from=$key_name --chain_id=sei_chain --fees=1000000usei --gas=50000000 --broadcast-mode=block 示例:seid tx dex place-orders $contract_addr 'LONG?1.01?5?USDC?ATOM?LIMIT?{"leverage":"1","position_effect":"Open"}' --amount=1000000000uusdc -y - -from=$key_name --chain_id=sei_chain --fees=1000000usei --gas=50000000 --broadcast-mode=block

CancelOrders

Description: Bulk cancel orders with the dex order book 描述:使用dex订单簿批量取消订单

Usage: seid tx cancel-orders $contract_addr $cancellations 用法:seid tx cancel-orders $contract_addr $cancellations

Arguments: 1) contract address (string), 2) list of cancellations 参数:1)合约地址(字符串),2)取消列表

Note: cancellation arguments are split by a ?, and position direction is arg[0], price is arg[1], price denom is args[2], asset denom is args[3] 注意:取消参数由a分割,仓位方向为arg[0],价格为arg[1],价格denom为args[2],资产denom为args[3]

Returns: None (type MsgCancelOrdersResponse struct {}) 返回:无(type MsgCancelOrdersResponse struct {}

Example: seid tx dex cancel-orders $contract_addr 'LONG?1.01?USDC?ATOM' --from=$key_name --chain_id=sei_chain --fees=1000000usei --gas=50000000 --broadcast-mode=block 示例:seid tx dex cancel-orders $contract_addr 'LONG?1.01?USDC?ATOM' --from=$key_name --chain_id=sei_chain --fees=1000000usei --gas=50000000 --broadcast-mode=block

Appendix

枚举 Enums

enum PositionDirection {
    LONG = 0;
    SHORT = 1;
}

enum PositionEffect {
    OPEN = 0;
    CLOSE = 1;
}

enum OrderType {
    LIMIT = 0;
    MARKET = 1;
    LIQUIDATION = 2;
    FOKMARKET = 3; // fill-or-kill market order
}

enum OrderStatus {
    PLACED = 0;
    FAILED_TO_PLACE = 1;
    CANCELLED = 2;
    FULFILLED = 3;
}

enum CancellationInitiator {
    USER = 0;
    LIQUIDATED = 1;
}

结构 Structs:

Pair 交易对 :

type Pair struct {
	PriceDenom string                                  
	AssetDenom string                                  
	Ticksize   *github_com_cosmos_cosmos_sdk_types.Dec 
}

Twap 时间加权平均价格:

type Twap struct {
	Pair            *Pair                                  
	Twap            github_com_cosmos_cosmos_sdk_types.Dec 
	LookbackSeconds uint64                                 
}

Order 订单 :

type Order struct {
	Id                uint64                                 
	Status            OrderStatus                            
	Account           string                                 
	ContractAddr      string                                 
	Price             github_com_cosmos_cosmos_sdk_types.Dec 
	Quantity          github_com_cosmos_cosmos_sdk_types.Dec 
	PriceDenom        string                                 
	AssetDenom        string                                 
	OrderType         OrderType                              
	PositionDirection PositionDirection                      
	Data              string                                 
	StatusDescription string                                 
}

Cancellation 取消 :

type Cancellation struct {
	Id                uint64                                 
	Initiator         CancellationInitiator                  
	Creator           string                                 
	ContractAddr      string                                 
	PriceDenom        string                                 
	AssetDenom        string                                 
	PositionDirection PositionDirection                      
	Price             github_com_cosmos_cosmos_sdk_types.Dec 
}

最后更新于