Comment on page
Query the Pool
This section shows how to query the pool and order status.
For
limit order
, users could query its info using the following API functionsFunction signature for query order info in Sui Move contract
/// 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
Typescript SDK for invoking get_order_status
inputs | type | description |
---|---|---|
token1 | string | base asset of the trading pair |
token2 | string | quote asset of the trading pair |
poolId | string | |
orderId | string | the orderId |
accountCap | string |
/**
* @description get the order status
* @param token1 token1 of a certain pair, eg: 0x5378a0e7495723f7d942366a125a6556cf56f573fa2bb7171b554a2986c4229a::weth::WETH
* @param token2 token2 of a certain pair, eg: 0x5378a0e7495723f7d942366a125a6556cf56f573fa2bb7171b554a2986c4229a::usdt::USDT
* @param poolId: the pool id, eg: 0xcaee8e1c046b58e55196105f1436a2337dcaa0c340a7a8c8baf65e4afb8823a4
* @param orderId the order id, eg: "1"
* @param accountCap: your accountCap, eg: 0x6f699fef193723277559c8f499ca3706121a65ac96d273151b8e52deb29135d3
*/
public async get_order_status(
token1: string,
token2: string,
poolId: string,
orderId: string,
accountCap: string
): Promise<DevInspectResults> {
const txb = new TransactionBlock();
txb.moveCall({
typeArguments: [token1, token2],
target: `dee9::clob::get_order_status`,
arguments: [
txb.object(poolId),
txb.object(String(orderId)),
txb.object(accountCap),
],
});
txb.setSender(this.currentAddress);
return await this.provider.devInspectTransactionBlock({
transactionBlock: txb,
sender: this.currentAddress,
});
}
We provide API functions to query the depth of level2 orders on both ask-side and bid-side.
Function signature for get depth of level2 order (ask side) in Sui Move contract
/// 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_ask_side<BaseAsset, QuoteAsset>(
pool: &Pool<BaseAsset, QuoteAsset>,
price_low: u64,
price_high: u64,
clock: &Clock
): (vector<u64>, vector<u64>)
Function signature for get depth of level2 order (bid side) in Sui Move contract
/// 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>)
Typescript SDK for invoking get_level2_book_status
inputs | type | description |
---|---|---|
token1 | string | base asset of the trading pair |
token2 | string | quote asset of the trading pair |
poolId | string | |
lowerPrice | number | lower price you want to query in the level2 book |
higherPrice | number | higher price you want to query in the level2 book |
is_bid_side | boolean | true: query bid side; false: query ask side. |
/**
* @description get level2 book status
* @param token1 token1 of a certain pair, eg: 0x5378a0e7495723f7d942366a125a6556cf56f573fa2bb7171b554a2986c4229a::weth::WETH
* @param token2 token2 of a certain pair, eg: 0x5378a0e7495723f7d942366a125a6556cf56f573fa2bb7171b554a2986c4229a::usdt::USDT
* @param poolId the pool id, eg: 0xcaee8e1c046b58e55196105f1436a2337dcaa0c340a7a8c8baf65e4afb8823a4
* @param lowerPrice lower price you want to query in the level2 book, eg: 18000000000
* @param higherPrice higher price you want to query in the level2 book, eg: 20000000000
* @param is_bid_side true: query bid side, false: query ask side
*/
public async get_level2_book_status(
token1: string,
token2: string,
poolId: string,
lowerPrice: number,
higherPrice: number,
is_bid_side: boolean
) {
const txb = new TransactionBlock();
txb.moveCall({
typeArguments: [token1, token2],
target: is_bid_side
? `dee9::clob::get_level2_book_status_bid_side`
: `dee9::clob::get_level2_book_status_ask_side`,
arguments: [
txb.object(poolId),
txb.pure(String(lowerPrice)),
txb.pure(String(higherPrice)),
txb.object(normalizeSuiObjectId("0x6")),
],
});
return await this.provider.devInspectTransactionBlock({
transactionBlock: txb,
sender: this.currentAddress,
});
}
}
We provide API function to list all open orders under one account
Function signature for list all open orders in Sui Move contract
/// 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
/// accessibility 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>
Typescript SDK for invoking list_open_orders
inputs | type | descriptions |
---|---|---|
token1 | string | base asset of the trading pair |
token2 | string | quote asset of the trading pair |
poolId | string | |
accountCap | string |
/**
* @description get the open orders of the current user
* @param token1 token1 of a certain pair, eg: 0x5378a0e7495723f7d942366a125a6556cf56f573fa2bb7171b554a2986c4229a::weth::WETH
* @param token2 token2 of a certain pair, eg: 0x5378a0e7495723f7d942366a125a6556cf56f573fa2bb7171b554a2986c4229a::usdt::USDT
* @param poolId the pool id, eg: 0xcaee8e1c046b58e55196105f1436a2337dcaa0c340a7a8c8baf65e4afb8823a4
* @param accountCap your accountCap, eg: 0x6f699fef193723277559c8f499ca3706121a65ac96d273151b8e52deb29135d3
*/
public async list_open_orders(
token1: string,
token2: string,
poolId: string,
accountCap: string
): Promise<DevInspectResults> {
const txb = new TransactionBlock();
txb.moveCall({
typeArguments: [token1, token2],
target: `dee9::clob::list_open_orders`,
arguments: [txb.object(poolId), txb.object(accountCap)],
});
txb.setSender(this.currentAddress);
return await this.provider.devInspectTransactionBlock({
transactionBlock: txb,
sender: this.currentAddress,
});
}
We provide an API function to query the custodian account balance for users. Note that each pool will have its own custodian account.
Function signature for query user balance in Sui Move contract
/// 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
/// accessibility 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)
Typescript SDK for invoking usr_balance
inputs | type | description |
---|---|---|
token1 | string | base asset of the trading pair |
token2 | string | quote asset of the trading pair |
poolId | string | |
accountCap | string |
/**
* @description: get the base and quote token in custodian account
* @param token1 token1 of a certain pair, eg: 0x5378a0e7495723f7d942366a125a6556cf56f573fa2bb7171b554a2986c4229a::weth::WETH
* @param token2 token2 of a certain pair, eg: 0x5378a0e7495723f7d942366a125a6556cf56f573fa2bb7171b554a2986c4229a::usdt::USDT
* @param poolId the pool id, eg: 0xcaee8e1c046b58e55196105f1436a2337dcaa0c340a7a8c8baf65e4afb8823a4
* @param accountCap your accountCap, eg: 0x6f699fef193723277559c8f499ca3706121a65ac96d273151b8e52deb29135d3
*/
public async get_usr_position(
token1: string,
token2: string,
poolId: string,
accountCap: string
): Promise<DevInspectResults> {
const txb = new TransactionBlock();
txb.moveCall({
typeArguments: [token1, token2],
target: `dee9::clob::account_balance`,
arguments: [txb.object(poolId), txb.object(accountCap)],
});
txb.setSender(this.currentAddress);
return await this.provider.devInspectTransactionBlock({
transactionBlock: txb,
sender: this.currentAddress,
});
}
we provide an API of getting latest market price(best bid, best ask) for users
Function signature for query market price in Sui Move contract
/// Query the market price of order book
/// returns (best_bid_price, best_ask_price)
public fun get_market_price<BaseAsset, QuoteAsset>(
pool: &Pool<BaseAsset, QuoteAsset>
): (u64, u64){
let (bid_price, _) = critbit::max_leaf(&pool.bids);
let (ask_price, _) = critbit::min_leaf(&pool.asks);
return (bid_price, ask_price)
}
Typescript SDK for invoking get_market_price
inputs | type | description |
---|---|---|
token1 | string | base asset of the trading pair |
token2 | string | quote asset of the trading pair |
poolId | string |
/**
* @description get the market price {bestBidPrice, bestAskPrice}
* @param token1 token1 of a certain pair, eg: 0x5378a0e7495723f7d942366a125a6556cf56f573fa2bb7171b554a2986c4229a::weth::WETH
* @param token2 token2 of a certain pair, eg: 0x5378a0e7495723f7d942366a125a6556cf56f573fa2bb7171b554a2986c4229a::usdt::USDT
* @param poolId the pool id, eg: 0xcaee8e1c046b58e55196105f1436a2337dcaa0c340a7a8c8baf65e4afb8823a4
*/
public async get_market_price(
token1: string,
token2: string,
poolId: string
) {
const txb = new TransactionBlock();
txb.moveCall({
typeArguments: [token1, token2],
target: `dee9::clob::get_market_price`,
arguments: [txb.object(poolId)],
});
return await this.provider.devInspectTransactionBlock({
transactionBlock: txb,
sender: this.currentAddress,
});
}
Last modified 5mo ago