본문으로 건너뛰기

주문 SDK

주문 배치는 모든 DeepBook 통합의 주요 기능이다. 하지만 주문을 배치하기 전에 먼저 BalanceManager를 설정해야 한다. BalanceManager 설정에 대한 정보는 DeepBookV3 SDK를 참조한다.

주문 함수​

DeepBookV3 SDK는 풀에 대해 주문을 leverage하기 위한 다음 함수를 제공한다.

placeLimitOrder​

지정가 주문을 배치하려면 placeLimitOrder를 사용한다. 이 호출은 Transaction 객체를 받는 함수를 반환한다.

매개변수

  • params: 스왑의 파라미터를 나타내는 SwapParams 객체이다.

placeMarketOrder​

시장가 주문을 배치하려면 placeMarketOrder를 사용한다. 이 호출은 Transaction 객체를 받는 함수를 반환한다.

매개변수

  • params: 스왑의 파라미터를 나타내는 SwapParams 객체이다.

cancelOrder​

cancelOrder로 식별되는 기존 주문을 취소하려면 orderId를 사용한다. 이 호출은 Transaction 객체를 받는 함수를 반환한다.

경고

orderId는 주문 배치 중 생성되는 프로토콜 orderId이며, 클라이언트 orderId와는 다르다.

매개변수

  • poolKey: 차입할 풀을 식별하는 String이다.
  • balanceManagerKey: BalanceManager를 식별하는 String이다.
  • orderId: 취소할 주문을 식별하는 프로토콜 주문 ID의 String이다.

cancelOrders​

주문 ID array를 제공하여 여러 주문을 atomic하게 취소하려면 cancelOrders를 사용한다. 이 호출은 Transaction 객체를 받는 함수를 반환한다.

매개변수

  • poolKey: 풀을 식별하는 String이다.
  • balanceManagerKey: BalanceManager를 식별하는 String이다.
  • orderIds: 취소할 프로토콜 주문 ID를 나타내는 String의 Array이다.

cancelAllOrders​

제공한 key에 해당하는 BalanceManager에 대해 모든 주문을 취소하려면 cancelAllOrders를 사용한다. 이 호출은 Transaction 객체를 받는 함수를 반환한다.

매개변수

  • poolKey: 차입할 풀을 식별하는 String이다.
  • balanceManagerKey: BalanceManager를 식별하는 String이다.

modifyOrder​

quantity를 변경하여 기존 주문을 수정하려면 modifyOrder를 사용한다. 새 quantity는 원래 quantity보다 작고 filled quantity보다 커야 한다. 이 호출은 Transaction 객체를 받는 함수를 반환한다.

매개변수

  • poolKey: 풀을 식별하는 String이다.
  • balanceManagerKey: BalanceManager를 식별하는 String이다.
  • orderId: 수정할 프로토콜 주문 ID의 String이다.
  • newQuantity: 주문의 새 quantity를 나타내는 Number이다.

withdrawSettledAmounts​

특정 풀에서 BalanceManager에 대한 모든 settled amount를 인출하려면 withdrawSettledAmounts를 사용한다. 이 호출은 Transaction 객체를 받는 함수를 반환한다.

매개변수

  • poolKey: 풀을 식별하는 String이다.
  • balanceManagerKey: BalanceManager를 식별하는 String이다.

withdrawSettledAmountsPermissionless​

어떤 BalanceManager에 대해서도 settled amount를 permissionless하게 인출하려면 withdrawSettledAmountsPermissionless를 사용한다. 누구나 호출할 수 있으며 trade proof가 필요하지 않다. 이 호출은 Transaction 객체를 받는 함수를 반환한다.

매개변수

  • poolKey: 풀을 식별하는 String이다.
  • balanceManagerKey: BalanceManager를 식별하는 String이다.

예시​

다음 예시는 DeepBookV3 주문에 대한 일부 custom 함수를 시연한다.

지정가 주문​

서로 다른 주문 type과 self matching option에 대해서는 주문를 참조한다.

// Params for limit order
interface PlaceLimitOrderParams {
poolKey: string;
balanceManagerKey: string;
clientOrderId: string;
price: number;
quantity: number;
isBid: boolean;
expiration?: number | bigint; // Default no expiration
orderType?: OrderType; // Default no restrictions
selfMatchingOption?: SelfMatchingOptions; // Default self matching allowed
payWithDeep?: boolean; // Default true
}

/**
* @description Place a limit order
* @param {PlaceLimitOrderParams} params Parameters for placing a limit order
* @returns A function that takes a Transaction object
*/
placeLimitOrder = (params: PlaceLimitOrderParams) => (tx: Transaction) => {};

// Example usage in DeepBookMarketMaker class
// Place a bid of 10 DEEP at $0.1
customPlaceLimitOrder = (tx: Transaction) => {
const poolKey = 'DEEP_DBUSDC'; // Pool key, check constants.ts for more
const managerKey = 'MANAGER_1'; // Balance manager key, initialized during client creation by user
tx.add(
this.deepBook.placeLimitOrder({
poolKey: poolKey,
balanceManagerKey: managerKey,
clientOrderId: '1',
price: 0.1,
quantity: 10,
isBid: true,
payWithDeep: true,
}),
);
};

Place 시장가 주문​

시장가 주문을 배치하는 예시이다.

// Params for market order
interface PlaceMarketOrderParams {
poolKey: string;
balanceManagerKey: string;
clientOrderId: string;
quantity: number;
isBid: boolean;
selfMatchingOption?: SelfMatchingOptions;
payWithDeep?: boolean;
}

// Example usage in DeepBookMarketMaker class
// Place a market sell of 10 SUI in the SUI_DBUSDC pool
customPlaceMarketOrder = (tx: Transaction) => {
const poolKey = 'SUI_DBUSDC'; // Pool key, check constants.ts for more
const managerKey = 'MANAGER_1'; // Balance manager key, initialized during client creation by user
tx.add(
this.deepBook.placeMarketOrder({
poolKey: poolKey,
balanceManagerKey: managerKey,
clientOrderId: '2',
quantity: 10,
isBid: true,
payWithDeep: true,
}),
);
};

주문 cancel​

BalanceManager에 대해 풀에서 단일 주문을 취소하는 예시이다.

/**
* @description Cancel an existing order
* @param {string} poolKey The key to identify the pool
* @param {string} balanceManagerKey The key to identify the BalanceManager
* @param {number} orderId Order ID to cancel
* @returns A function that takes a Transaction object
*/
cancelOrder =
(poolKey: string, balanceManagerKey: string, orderId: number) => (tx: Transaction) => {};

// Example usage in DeepBookMarketMaker class
// Cancel order 12345678 in SUI_DBUSDC pool
cancelOrder = (tx: Transaction) => {
const poolKey = 'SUI_DBUSDC'; // Pool key, check constants.ts for more
const managerKey = 'MANAGER_1'; // Balance manager key, initialized during client creation by user
tx.add(this.deepBook.cancelOrder(poolKey, managerKey, 12345678));
};

모든 주문 cancel​

BalanceManager에 대해 풀에서 모든 주문을 취소하는 예시이다.

/**
* @description Cancel all open orders for a balance manager
* @param {string} poolKey The key to identify the pool
* @param {string} balanceManagerKey The key to identify the BalanceManager
* @returns A function that takes a Transaction object
*/
cancelAllOrders = (poolKey: string, balanceManagerKey: string) => (tx: Transaction) => {};

// Example usage in DeepBookMarketMaker class
// Cancel order 12345678 in SUI_DBUSDC pool
cancelOrder = (tx: Transaction) => {
const poolKey = 'SUI_DBUSDC'; // Pool key, check constants.ts for more
const managerKey = 'MANAGER_1'; // Balance manager key, initialized during client creation by user
tx.add(this.deepBook.cancelAllOrders(poolKey, managerKey));
};