跳转至

API 概述

Sera API 是一个 RESTful API,用于程序化访问 Sera 的交易和账户管理功能。

基础 URL

https://api.sera.cx/api/v1

内容类型

所有请求和响应使用 JSON:

Content-Type: application/json

身份验证

API 支持两种身份验证方式:

方式 用途 请求头
API Key 账户读取端点和交易构建辅助端点 Authorization: Bearer {key}:{secret}
EIP-712 签名 交易写入、取消、提款和 API Key 管理 包含在请求体或查询参数中

详情请参阅身份验证

频率限制

公网匿名限速由边缘代理/CDN 处理。携带 API Key 的请求会在应用内按钱包地址再做限速:

分组 典型端点 限制
read GET /ordersGET /balancesGET /fills 10 req/s
trade POST /ordersPOST /swap 5 req/s
cancel POST /orders/cancelDELETE /orders/cancel-all 2 req/s
transfer 充值、授权、提现、转账与交易广播辅助端点 2 req/s

端点

系统

方法 路径 认证 说明
GET /health 服务健康、executor_id 与签名就绪状态
GET /system/time 服务器时间戳
GET /tokens 代币注册表
GET /markets 活跃市场元数据
GET /fx/rate ISO 货币对的聚合汇率与 24 小时涨跌幅
GET /permit/metadata API Key EIP-2612 permit 域、nonce 与额度探测
GET /config 公共链上与合约引导配置
POST /verify-signature 验证 EIP-712 订单签名

交易

方法 路径 认证 说明
POST /swap/quote 获取兑换报价
POST /swap EIP-712 执行已签名的兑换
POST /orders EIP-712 下限价单
POST /orders/cancel EIP-712 取消订单
DELETE /orders/cancel-all API Key 取消所有未结订单
POST /orders/vl/batch EIP-712 提交虚拟流动性批量订单
POST /orders/vl/cancel EIP-712 取消虚拟流动性批次

账户

方法 路径 认证 说明
GET /orders/{id} API Key 获取订单状态
GET /orders API Key 列出订单
GET /fills/{order_id} API Key 获取单笔订单成交明细
GET /fills API Key 获取账户范围成交明细
GET /balances API Key 获取账户余额
POST /approve API Key 构建未签名的 ERC-20 approve(spender, amount) 交易
POST /deposit API Key 构建未签名的 depositFunddepositFundWithPermit 交易
POST /tx/send API Key 广播已签名的授权/存款交易
POST /withdraw 可选 获取提款联合签名
POST /withdraw/build 可选 构建未签名的提款交易
POST /withdraw/send 可选 广播已签名的提款交易
POST /transfer API Key 构建未签名的 ERC-20 转账
POST /transfer/send API Key 广播已签名的转账

API Key 管理

方法 路径 认证 说明
POST /api-keys EIP-712 创建只读 API Key
GET /api-keys EIP-712 列出 API Key(带签名的查询参数)
POST /api-keys/list EIP-712 列出 API Key(带签名的 JSON 请求体)
DELETE /api-keys EIP-712 撤销 API Key(带签名的查询参数)
POST /api-keys/revoke EIP-712 撤销 API Key(带签名的 JSON 请求体)
POST /api-keys/revoke-all EIP-712 通过一次签名批量撤销该钱包下所有有效 API Key
POST /api-keys/self-revoke API Key 用当前凭据撤销该 API Key 自身
POST /api-keys/verify 校验 API Key/Secret 对,且不消耗速率限制

错误响应

所有错误返回包含 detail 字段的 JSON 体:

{
  "detail": "Human-readable error message"
}

服务端故障(原 5xx)会统一映射为 503 且响应体改写为通用文案 —— 客户端看到的是 {"detail": "Service temporarily unavailable; please retry"}Retry-After: 1 响应头;具体原因仅记录在服务端日志,不回传给调用方。

状态码

状态码 含义
200 成功
201 资源已创建
400 请求无效(参数错误、签名不匹配)
401 身份验证失败
403 禁止访问(访问其他用户的数据)
404 资源未找到
409 冲突(重复签名、自成交拒绝等)
410 已过期(报价过期、已消费或不存在)
422 校验失败
429 触发限速或取消冷却
503 服务暂时不可用;请按 Retry-After 重试

代码示例

// Public endpoint (no auth)
const tokens = await fetch('https://api.sera.cx/api/v1/tokens')
  .then(r => r.json());

// Authenticated endpoint (API key)
const orders = await fetch('https://api.sera.cx/api/v1/orders?owner_address=0x...', {
  headers: { 'Authorization': 'Bearer sera_abc123:secret456' }
}).then(r => r.json());
import requests

# Public endpoint
tokens = requests.get("https://api.sera.cx/api/v1/tokens").json()

# Authenticated endpoint
headers = {"Authorization": "Bearer sera_abc123:secret456"}
orders = requests.get(
    "https://api.sera.cx/api/v1/orders",
    params={"owner_address": "0x..."},
    headers=headers
).json()
# Public endpoint
curl https://api.sera.cx/api/v1/tokens

# Authenticated endpoint
curl -H "Authorization: Bearer sera_abc123:secret456" \
  "https://api.sera.cx/api/v1/orders?owner_address=0x..."