# API

## Trade with the CEXISWAP API

```typescript
// 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,
})
```

<table><thead><tr><th>Endpoint</th><th width="248.66666666666669">Request</th><th>Response</th></tr></thead><tbody><tr><td><strong>swap/v1/price</strong></td><td><code>chain</code>: 'ETH', 'POLYGON', 'BSC', 'THUNDERCORE', 'AVAX'<br><br><code>buyToken</code>: 'ETH', 'WBTC', 'USDT'<br><code>sellToken</code>: (same as buyToken)<br><br><code>buyAmount</code> or <code>sellAmount</code>: amount in the on-chain units of the token, e.g. <code>1000000</code> is 1 USDT<br></td><td><code>price</code>: the price of buyToken in sellToken or vice versa </td></tr><tr><td><strong>swap/v1/quote</strong></td><td><code>chain</code>: 'ETH', 'POLYGON', 'BSC', 'THUNDERCORE', 'AVAX'<br><br><code>buyToken</code>: 'ETH', 'WBTC', 'USDT'<br><code>sellToken</code>: (same as buyToken)<br><br><code>buyAmount</code> or <code>sellAmount</code>: amount in the on-chain units of the token, e.g. <code>1000000</code> is 1 USDT<br><br>(same as <strong>swap/v1/price</strong>)</td><td><code>to</code> : the address of the contract to send the blockchain transaction to<br><br><code>data</code>: the call data for the blockchain transaction<br> <br><code>allowanceTarget</code>: the target contract address for setting ERC20 sell token allowance<br><br><code>price</code>: the price of buyToken in sellToken or vice versa</td></tr><tr><td><strong>swap/v1/tokens</strong></td><td><code>chain</code>: 'ETH', 'POLYGON', 'BSC', 'THUNDERCORE', 'AVAX'</td><td>List of { "symbol", "chain", "address", "decimals", "disabled" }</td></tr></tbody></table>

### 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](https://tokenallowance.io/). The `allowanceTarget` in the response is the contract address that you should set the allowance for.\
\
For example:  `inputToken.approve(response.allowanceTarget)`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cexiswap.io/cexiswap/api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
