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.

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.