Skip to main content

查询池

本节介绍如何查询池和订单状态。

1. 订单状态

对于限价订单,用户可以使用以下 API 函数查询其信息。

在 Move 合约中查询订单信息的函数签名

/// Parameters expected by this func
///
/// 0. `[pool]` Object ID refers to the pool containing the trading pair
/// 1. `[order_id]` order id of the order being queried
/// 2. `[account_cap]` Object ID of the account_cap authorizing the
/// accessilility to the escrow account

/// Returns the order info of the order being queried
public fun get_order_status<BaseAsset, QuoteAsset>(
pool: &Pool<BaseAsset, QuoteAsset>,
order_id: u64,
account_cap: &AccountCap
): &Order

2. 池状态

我们提供 API 函数来查询卖方和买方的 level2 订单深度。

在 Move 合约中获取 level2 订单深度(卖方)的函数签名

/// Parameters expected by this func
///
/// 0. `[pool]` Object ID refers to the pool containing the trading pair
/// 1. `[price_low]` the lower price of the price interval to query, inclusive
/// 2. `[price_high]` the upper price of the price interval to query, inclusive
/// 3. `[clock]` Object ID of global system clock

/// Returns the list of all valid prices and corresponding depthes
public fun get_level2_book_status_bid_side<BaseAsset, QuoteAsset>(
pool: &Pool<BaseAsset, QuoteAsset>,
price_low: u64,
price_high: u64,
clock: &Clock
): (vector<u64>, vector<u64>)

3 用户账户状态

3.1 未结订单

我们提供 API 函数来列出一个账户下的所有未结订单。

在 Move 合约中列出所有未结订单的函数签名

/// Parameters expected by this func
///
/// 0. `[pool]` Object ID refers to the pool containing the trading pair
/// 1. `[account_cap]` Object ID of the account_cap authorizing the
/// accessilility to the escrow account

/// Returns list of user's all open orders
public fun list_open_orders<BaseAsset, QuoteAsset>(
pool: &Pool<BaseAsset, QuoteAsset>,
account_cap: &AccountCap
): vector<Order>

3.2 账户余额

我们提供 API 函数来查询用户的托管账户余额。请注意,每个池都将有自己的托管账户。

在 Move 合约中查询用户余额的函数签名

/// Parameters expected by this func
///
/// 0. `[pool]` Object ID refers to the pool containing the trading pair
/// 1. `[account_cap]` Object ID of the account_cap authorizing the
/// accessilility to the escrow account

/// Returns user's base_asset_available, base_asset_locked,
/// quote_asset_available, quote_asset_locked
public fun usr_balance<BaseAsset, QuoteAsset>(
pool: &Pool<BaseAsset, QuoteAsset>,
account_cap: &AccountCap
): (u64, u64, u64, u64)