> ## Documentation Index
> Fetch the complete documentation index at: https://docs.krokoswap.io/llms.txt
> Use this file to discover all available pages before exploring further.

# 报价

> 获取包含路由信息的最优交换报价

# Quote API

获取代币对的最优交换报价。API 会在 V2 和 V3 池子中寻找最优路由，包括多跳路径。

## GET /api/v1/quote

### 参数

| 参数          | 类型       | 必填   | 描述                           |
| ----------- | -------- | ---- | ---------------------------- |
| `tokenIn`   | `string` | 是    | 输入代币地址                       |
| `tokenOut`  | `string` | 是    | 输出代币地址                       |
| `amountIn`  | `string` | 条件必填 | 输入数量（原始单位），`tradeType=0` 时必填 |
| `amountOut` | `string` | 条件必填 | 输出数量（原始单位），`tradeType=1` 时必填 |
| `tradeType` | `string` | 否    | `0` = 精确输入（默认），`1` = 精确输出    |

<Note>
  对于原生 KAS，请使用 **WKAS 地址**，不要使用零地址。
</Note>

### 响应

```json theme={null}
{
  "tokenIn": "0xb190...",
  "tokenOut": "0x3ac3...",
  "amountIn": "1000000000000000000",
  "amountOut": "1007249042881810956",
  "tradeType": 0,
  "route": {
    "path": ["0xb190...", "0x3ac3..."],
    "protocol": "v2",
    "hops": 1,
    "fees": [0]
  },
  "priceImpact": 0.3,
  "gasCost": "100000",
  "executionPrice": 1.007249
}
```

| 字段               | 描述                                        |
| ---------------- | ----------------------------------------- |
| `amountIn`       | 输入数量（精确输入时为用户指定值，精确输出时为计算值）               |
| `amountOut`      | 输出数量（精确输入时为计算值，精确输出时为用户指定值）               |
| `route.path`     | 交换路径中代币地址的有序列表                            |
| `route.protocol` | `"v2"`、`"v3"` 或 `"mixed"`                 |
| `route.hops`     | 路径中经过的池子数量                                |
| `route.fees`     | 每一跳的手续费等级（V2 为 0，V3 为 100/500/3000/10000） |
| `priceImpact`    | 预估价格影响（百分比）                               |
| `gasCost`        | 预估 Gas 费用                                 |
| `executionPrice` | 输出与输入的比率                                  |

### 示例

<CodeGroup>
  ```bash Exact Input theme={null}
  # 我想卖出 1 个代币——能换到多少？
  curl "https://dex.kasplex.org/swap-api/api/v1/quote?\
  tokenIn=0xB190a6A7fC2873f1Abf145279eD664348d5Ef630&\
  tokenOut=0x3Ac3B30b7f18AEFD4590D7FE4d9C5944aaeB7220&\
  amountIn=1000000000000000000&\
  tradeType=0"
  ```

  ```bash Exact Output theme={null}
  # 我想买入 1 个代币——需要支付多少？
  curl "https://dex.kasplex.org/swap-api/api/v1/quote?\
  tokenIn=0xB190a6A7fC2873f1Abf145279eD664348d5Ef630&\
  tokenOut=0x3Ac3B30b7f18AEFD4590D7FE4d9C5944aaeB7220&\
  amountOut=1000000000000000000&\
  tradeType=1"
  ```
</CodeGroup>

### 多跳路由

当不存在直接池子或多跳路径能提供更优价格时，API 会返回多跳路由：

```json theme={null}
{
  "route": {
    "path": ["0xb190...", "0x0baf...", "0x3ac3..."],
    "protocol": "mixed",
    "hops": 2,
    "fees": [0, 500]
  }
}
```

含义为：代币 A → （V2 池子）→ 中间代币 → （V3 0.05% 池子）→ 代币 B。
