Sei中文文档(Sei Docs CHN)-by Chainguys
  • 导览(INTRODUCTION)
    • 版权声明(Copyright Notice)
    • 概览 (Overview)
    • Sei 设计空间 (Sei Design Space)
    • DEX 优化 (DEX Optimizations)
    • Sei 生态系统 (Sei Ecosystem)
  • 智能合约和本地开发 (Smart contracts & local development)
    • Sei工具指南 (Sei Tool Guide)
    • 设置一个本地节点 (Set up a local network)
    • 本地 Sei 脚本部署 (Local Sei script deployment)
    • Sei.go
    • CosmWasm合约测试 (CosmWasm Contract Testing)
    • 部署通用合约 (Deploy a generic contract)
    • 部署交易合约 (Deploy an exchange contract)
    • 非完整节点下部署和开发 (Deploy & develop without Full Node)
    • Dex 模块教程 (Dex Module Tutorial)
    • 代币工厂模块教程 (Tokenfactory Module Tutorial)
    • IBC转账 (IBC Transfers)
  • 订单匹配(order match)
    • 并行性 (Parallelism)
    • 资格 (Eligibility)
    • DEX 合约间依赖 (DEX Inter—Contract Dependencies)
    • 白名单商店 (Whitelisted Store)
  • 节点&验证者 (NODES&VALIDATORS)
    • 加入测试网 (Joining Testnets)
    • 更新 (Upgrades)
    • Seinami激励测试网 (Seinami Incentivized Testnet)
      • 加入激励测试网 (Joining Incentivized Testnet)
      • 所有测试任务 (All Testnet Missions)
      • 行为准则 (Code of Conduct)
      • 奖励发放详情 (Rewards Distribution Details)
  • 基础API端点 (Basic API Endpoints)
  • 模块化端点 (Module Endpoints)
  • 状态同步 (Statesync)
  • 恢复操作(Recovery Operations)
  • 治理(GOVERNANCE)
    • 创建提案 (Creating Proposals)
    • 管理质押 (Managing Staking)
    • 对提案投票表决 (Voting on Proposals)
  • 预言机(ORACLE)
    • 预言机参与 (Oracle Participation)
  • 钱包(WALLETS)
    • 钱包集成(Wallet Integration)
    • 转账 (Transfers)
  • 更多(More)
    • 推特(Twitter)
由 GitBook 提供支持
在本页
  • 查询 (Queries):
  • 消息 (Messages):
  • Appendix
  1. 智能合约和本地开发 (Smart contracts & local development)

Dex 模块教程 (Dex Module Tutorial)

上一页非完整节点下部署和开发 (Deploy & develop without Full Node)下一页代币工厂模块教程 (Tokenfactory Module Tutorial)

最后更新于2年前

The dex module is responsible for order placement and related trading functionality. The source code can be found here:

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 模块交互,可以使用 query 或 tx 消息。下面是如何交互的示例,以及一些常用枚举和结构的简要概述。请注意,这些命令具有通常的其他标志,例如 `--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 
}
https://github.com/sei-protocol/sei-chain/tree/master/x/dex
https://github.com/sei-protocol/sei-chain/tree/master/x/dex