Skip to main content
The Trader SDK lets an approved OneSwap account trade its own wallet from a server-side application. It is separate from the integrator SDK: a trader key is bound to one existing wallet and cannot onboard users or withdraw funds.

Install

Get a trader key

A OneSwap administrator enables Trader SDK access and issues a key for the approved account and wallet. A trader cannot enable access, create a key, change its wallet binding, or enable three-token fees through the SDK. Contact OneSwap when you need a new or replacement key. The key, account, bound wallet, and requested pool must all remain approved. OneSwap can revoke access immediately.
A trader key can execute trades with real wallet funds. Keep it in a server-side secret manager. Never embed it in a website, browser extension, mobile app, repository, log, or analytics event. Ask OneSwap to revoke and replace an exposed key.

Create the client

The wallet is resolved from the administrator-issued key, so SDK methods do not accept a walletId. Self-custody wallets also require an active OneSwap user mandate; the trader key never contains or replaces the self-custody key.

Discover pools, tokens, and balances

A pool has an ordered pair of assets. xToY: true spends assetX and receives assetY; false reverses the direction.

Quote and swap

Quote immediately before a swap and use the quote to set the output floor:
Use a unique idempotencyKey for each intended swap. Reuse it only when retrying that exact swap, so a timeout or process restart cannot execute the order twice.

Three-token network fees

When a OneSwap administrator has enabled the trader and configured a distinct fee instrument for a synchronous atomic pool, select it explicitly on both calls:
For Trader SDK quotes, tokenFee.amount is derived from the live Canton traffic cost, including the extra fee-token allocation. OneSwap subtracts measured reward recovery, applies the best applicable global, pool, account, or wallet network-fee promotion, and then converts CC → USDCx → the configured fee token at live prices. The quote reports the final amount and authoritative fee-token balance checks. A trader with a 100% promotion receives amount: 0 and promotionalWaiver: true; settlement omits the fee allocation. A trader without that promotion pays the converted amount shown in the final quote. When charged, the swap input, output, and fee-token allocation settle atomically.
Use the same pool, direction, amount, and feeMode for the quote and swap. Do not reuse a prepaid quote for a token-fee swap or switch fee modes after calculating minAmountOut.

History and asynchronous intents

Synchronous pools return their settlement result directly. For an asynchronous pool, poll the returned intent until it reaches a terminal state. Three-token settlement is available only on synchronous atomic pools.

Trade launchpad coins

The same key trades launchpad coins on its bound wallet through trader.launchpad. Buys spend CC and sells spend the coin’s token. Graduated coins trade on their pool through the same calls.
To sell, quote with side: 'sell' and pass quote.ccOut as the floor:
  • idempotencyKey is required: 8–200 letters, digits, ., _, :, or -. Reuse it only to retry the same order.
  • slippageBps defaults to 100 and accepts 0–5000.
  • networkFee.cc is billed to the wallet’s prepaid CC balance when the order settles.
  • A buy quote can name the exact tokens to receive with tokensOut instead of amount.
  • trader.launchpad.positions() lists the wallet’s launchpad holdings, and trader.launchpad.intent(id) reads one order.
  • Self-custody wallets need an active mandate, as for pool swaps.

What a trader key can see

A trader key trades its own wallet, so it sees only what it needs to trade: It never shows other holders, holder counts, or other people’s trades. Version 0.4.0 removed the trade feed and holder data from the trader SDK. For market data such as holder counts and the trade feed, use the Launchpad SDK.

Disable access

Contact OneSwap to revoke a key, disable Trader SDK access, or change three-token eligibility. Revoked access is rejected on subsequent SDK calls.