Page cover image

API

Trade with the CEXISWAP API

Trade with the CEXISWAP API

// Buy one WBTC with USDT
const params = {
    toAddr: MY_WALLET_ADDR,
    chain: 'ETH',
    buyToken: 'WBTC',
    sellToken: 'USDT',
    buyAmount: '100000000',
}

const unsignedTx = await fetch(
    `https://api.cexiswap.io/swap/v1/quote?${qs.stringify(params)}`
)

const signer = new ethers.Wallet(YOUR_PRIVATE_KEY_STRING, provider)
await signer.sendTransaction({
  to: unsignedTx.to,
  chainId: unsignedTx.chainId,
  value: unsignedTx.value === '0' ? '0x0' : unsignedTx.value,
  data: unsignedTx.data,
})
Endpoint
Request
Response

swap/v1/price

chain: 'ETH', 'POLYGON', 'BSC', 'THUNDERCORE', 'AVAX' buyToken: 'ETH', 'WBTC', 'USDT' sellToken: (same as buyToken) buyAmount or sellAmount: amount in the on-chain units of the token, e.g. 1000000 is 1 USDT

price: the price of buyToken in sellToken or vice versa

swap/v1/quote

chain: 'ETH', 'POLYGON', 'BSC', 'THUNDERCORE', 'AVAX' buyToken: 'ETH', 'WBTC', 'USDT' sellToken: (same as buyToken) buyAmount or sellAmount: amount in the on-chain units of the token, e.g. 1000000 is 1 USDT (same as swap/v1/price)

to : the address of the contract to send the blockchain transaction to data: the call data for the blockchain transaction allowanceTarget: the target contract address for setting ERC20 sell token allowance price: the price of buyToken in sellToken or vice versa

swap/v1/tokens

chain: 'ETH', 'POLYGON', 'BSC', 'THUNDERCORE', 'AVAX'

List of { "symbol", "chain", "address", "decimals", "disabled" }

Allowance Targets

When your sellToken is an ERC-20 token, you will need to give CEXISWAP contracts permission to use that token by setting a token allowance. The allowanceTarget in the response is the contract address that you should set the allowance for. For example: inputToken.approve(response.allowanceTarget)

Last updated