> For the complete documentation index, see [llms.txt](https://roqqu-api-services.gitbook.io/ras/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://roqqu-api-services.gitbook.io/ras/trade/swap.md).

# Swap

Swap one cryptocurrency for another.

**Endpoint:** `POST /trade/swap`

**Fees**

Fees are taken from the token you swap from (`from`).

#### Request Parameters <a href="#request-parameters-13" id="request-parameters-13"></a>

| Parameter | Type    | Required | Description                                                              |
| --------- | ------- | -------- | ------------------------------------------------------------------------ |
| amount    | integer | Yes      | Amount of the source token to convert (must be greater than 0)           |
| from      | string  | Yes      | Token to convert (e.g. `btc`, `eth`). USDT is not allowed — use buy/sell |
| to        | string  | Yes      | Token to receive after conversion. USDT is not allowed, use buy/sell     |

#### Example Request <a href="#example-request-23" id="example-request-23"></a>

```
curl -X POST https://service.roqqu.com/v1/trade/swap \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "amount=200" \
  -d "from=usdt" \
  -d "to=btc"
```

#### Example Response <a href="#example-response-23" id="example-response-23"></a>

```
{
  "status": "success",
  "message": "swap operation successful",
  "data": null
}
```

> Swap is a ledger operation. It does **not** emit a webhook. Confirm via balances / history.

#### **Error Responses**

**USDT not allowed in swap:**

```
{
  "status": "fail",
  "message": "USDT cannot be used in swap; use buy or sell instead"
}
```

**Invalid from token:**

```
{
  "status": "fail",
  "message": "invalid <from> token parsed"
}
```

**Invalid to token:**

```
{
  "status": "fail",
  "message": "invalid <to> token parsed"
}
```

**Swap not enabled for from token:**

```
{
  "status": "fail",
  "message": "swap not currently enabled for <from> token"
}
```

**Swap not enabled for to token:**

```
{
  "status": "fail",
  "message": "swap not currently enabled for <to> token"
}
```

**Insufficient balance:**

```
{
  "status": "fail",
  "message": "insufficient USDC balance"
}
```

**Fee too high:**

```
{
  "status": "fail",
  "message": "fee cannot be greater than or equal to amount"
}
```

**Below minimum / above maximum:**

```
{
  "status": "fail",
  "message": "amount cannot be less than <minimum_amount>"
}
```

```
{
  "status": "fail",
  "message": "amount cannot be more than <maximum_amount>"
}
```

**Amount must be positive:**

```
{
  "status": "fail",
  "message": "amount must be greater than 0"
}
```
