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.
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
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'
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()
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.
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)
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)
}
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)
}
const tokenList = await sdk.LimitOrder.getLimitOrderTokenList()
const poolList = await sdk.LimitOrder.getLimitOrderPoolList()
const pool = await sdk.LimitOrder.getLimitOrderPool(
'0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN',
'0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5::coin::COIN'
)
const id = await sdk.LimitOrder.getPoolIndexerId(
'0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN',
'0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5::coin::COIN'
)
const orderList = await sdk.LimitOrder.getOwnerLimitOrderList("0x0..")
const order = await sdk.LimitOrder.getLimitOrder('0x24aaffb2f9785c110da3b670e0f50e8a30...')
const order = await sdk.LimitOrder.getLimitOrderLogs('0x24aaffb2f9785c110da3b670e0f50e8a30...')
const order = await sdk.LimitOrder.getLimitOrderClaimLogs('0x24aaffb2f9785c110da3b670e0f50e8a30...')
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.
MIT