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 = 精确输出 |
对于原生 KAS,请使用 WKAS 地址,不要使用零地址。
{
"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 | 输出与输入的比率 |
# 我想卖出 1 个代币——能换到多少?
curl "https://dex.kasplex.org/swap-api/api/v1/quote?\
tokenIn=0xB190a6A7fC2873f1Abf145279eD664348d5Ef630&\
tokenOut=0x3Ac3B30b7f18AEFD4590D7FE4d9C5944aaeB7220&\
amountIn=1000000000000000000&\
tradeType=0"
多跳路由
当不存在直接池子或多跳路径能提供更优价格时,API 会返回多跳路由:
{
"route": {
"path": ["0xb190...", "0x0baf...", "0x3ac3..."],
"protocol": "mixed",
"hops": 2,
"fees": [0, 500]
}
}
含义为:代币 A → (V2 池子)→ 中间代币 → (V3 0.05% 池子)→ 代币 B。