跳转到主要内容

Quote API

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

GET /api/v1/quote

参数

参数类型必填描述
tokenInstring输入代币地址
tokenOutstring输出代币地址
amountInstring条件必填输入数量(原始单位),tradeType=0 时必填
amountOutstring条件必填输出数量(原始单位),tradeType=1 时必填
tradeTypestring0 = 精确输入(默认),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。