kk_limit_sdk
TypeScript icon, indicating that this package has built-in type declarations

0.0.0-experimental-20250414180358 • Public • Published

kk_limit-sdk

Cetus Limit Order SDK is a powerful tool that enables developers to integrate limit order trading functionality into their applications. With this SDK, users can place orders at a specific price, ensuring more control over their trades compared to market orders.

Getting Started

How to Use the Limit SDK ?

Installation

To start using the Limit SDK, you first need to install it in your TypeScript project. You can add it using npm, yarn, or bun:

npm link: https://www.npmjs.com/package/kk_limit-sdk

npm install kk_limit-sdk

or

yarn add kk_limit-sdk

or

bun install kk_limit-sdk

Setup

Import the SDK into the TypeScript file where you intend to use it:

import { CetusLimitSDK } from 'kk_limit-sdk'

or

import { initMainnetSDK, initTestnetSDK } from 'kk_limit-sdk'

Initializing the SDK

Initialize the SDK with the required configuration parameters. This typically includes setting up the network and API keys, if needed.

  • Mainnet:
const sdk = CetusLimitSDK.createSDK({ env: 'mainnet' })

or

const sdk = initMainnetSDK()
  • Testnet:
const sdk = CetusLimitSDK.createSDK({ env: 'testnet' })

or

const sdk = initTestnetSDK()

Features & Usage

if you want to use test account, your can do this:

import { buildTestAccount } from 'kk_common_sdk'
sendKeypair = buildTestAccount()
sdk.setSenderAddress(sendKeypair.toSuiAddress())

or you can use your own wallet address.

Place a limit order

const pool = {
  pay_coin_type: '0x26b3bc67befc214058ca78ea9a2690298d731a2d4309485ec3d40198063c4abc::usdc::USDC',
  target_coin_type: '0x26b3bc67befc214058ca78ea9a2690298d731a2d4309485ec3d40198063c4abc::usdt::USDT',
  indexer_id: '0xc420fb32c3dd279d20b55daeb08973e577df5fed1b758b839d4eec22da54bde8',
}

enum LimitOrderStatus {
  Running = 'Running',
  PartialCompleted = 'PartialCompleted',
  Completed = 'Completed',
  Cancelled = 'Cancelled',
}

const pay_coin_amount = 2000000
const price = 1.7
const expired_ts = Date.parse(new Date().toString()) + 7 * 24 * 60 * 60 * 1000

const payload = await sdk.LimitOrder.placeLimitOrder({
  pay_coin_amount,
  price,
  expired_ts,
  pay_coin_type: pool.pay_coin_type,
  target_coin_type: pool.target_coin_type,
  target_decimal: 6,
  pay_decimal: 6,
})

const txResult = await sdk.FullClient.executeTx(sendKeypair, payload, false)

Cancel a limit order

const order = await sdk.LimitOrder.getLimitOrder('0xcadb63c2ffabd9ef7112cacb92304e660e2e...')

if (order && order.status === LimitOrderStatus.Running) {
  const payload = await sdk.LimitOrder.cancelOrdersByOwner([
    {
      order_id: order.id,
      pay_coin_type: order.pay_coin_type,
      target_coin_type: order.target_coin_type,
    },
  ])
  const txResult = await sdk.FullClient.executeTx(sendKeypair, payload, false)
}

Claim target coin

const order = await sdk.LimitOrder.getLimitOrder('0x24aaffb2f9785c110da3b670e0...')
if (order && order.status === LimitOrderStatus.Running) {
  const payload = await sdk.LimitOrder.claimTargetCoin({
    order_id: order.id,
    pay_coin_type: order.pay_coin_type,
    target_coin_type: order.target_coin_type,
  })
  const txResult = await sdk.FullClient.executeTx(sendKeypair, payload, false)
}

Get the list of tokens that support limit orders

const tokenList = await sdk.LimitOrder.getLimitOrderTokenList()

Get the list of limit order pools

const poolList = await sdk.LimitOrder.getLimitOrderPoolList()

Get the limit order pool based on token pairs

const pool = await sdk.LimitOrder.getLimitOrderPool(
  '0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN',
  '0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5::coin::COIN'
)

Get the indexer_id of limit order pool based on token pairs

const id = await sdk.LimitOrder.getPoolIndexerId(
  '0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN',
  '0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5::coin::COIN'
)

Get the list of limit order by your wallet address

const orderList = await sdk.LimitOrder.getOwnerLimitOrderList("0x0..")

Get the limit order info by order id

const order = await sdk.LimitOrder.getLimitOrder('0x24aaffb2f9785c110da3b670e0f50e8a30...')

Get order operation log

const order = await sdk.LimitOrder.getLimitOrderLogs('0x24aaffb2f9785c110da3b670e0f50e8a30...')

Get the claim logs of the order

const order = await sdk.LimitOrder.getLimitOrderClaimLogs('0x24aaffb2f9785c110da3b670e0f50e8a30...')

More About Cetus

Use the following links to learn more about Cetus:

Learn more about working with Cetus in the Cetus Documentation.

Join the Cetus community on Cetus Discord.

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i kk_limit_sdk

Weekly Downloads

3

Version

0.0.0-experimental-20250414180358

License

Apache-2.0

Unpacked Size

1.88 MB

Total Files

25

Last publish

Collaborators

  • libin52008