Exchange OS Open API 全局约定#
欢迎使用 Exchange OS Open API。
本 API 聚合 perp 与 spot,为外部开发者提供统一的 REST、WebSocket 和交易签名接口。业务线不通过 URL 路径区分,而是通过请求参数或 assetId 路由:
- 写接口通过
marketType指定市场类型。 - 账户和交易读接口通常通过
assetId推导市场类型。 - 市场产品查询接口可通过
marketType进行筛选。
基础路径#
text
/api/v5/exchangeos/完整 URL:
text
https://{host}/api/v5/exchangeos/{endpoint}示例:
http
POST /api/v5/exchangeos/trade/place-order
GET /api/v5/exchangeos/market/instruments
环境信息#
| 环境 | Base URL |
|---|---|
| Production | https://www.okx.com |
标识约定#
| 标识 | 说明 |
|---|---|
assetId | 复合资产 ID,类型为 String。其编码包含市场类型:assetId % 100 == 1 表示 spot,assetId % 100 == 2 表示 perp。由 assetId 路由的账户和交易读接口不需要另外传入 marketType。 |
tokenId | 币种 Token ID,类型为 String。保证金币种 USDS 的 tokenId 为 "0"。账户类接口统一使用 tokenId 标识币种。 |
oid | 链上订单 ID,类型为十进制 String。普通订单通常由撮合引擎分配;清算、ADL、结算等系统订单可能使用虚拟 oid。 |
clientOrderId | 用户自定义订单 ID,格式为 0x{region}{env}{30hex},共 34 个字符。普通订单下单时必填;Trigger/TPSL 订单不应传入。可用于撤单、改单和异步结果匹配。 |
计量单位#
perp 和 spot 的订单数量均以 Base Token 计量,不使用合约张数概念。
响应格式#
所有 REST 接口使用以下响应外壳:
json
{
"code": "0",
"msg": "",
"data": []
}
写接口鉴权#
所有写接口必须携带以下请求头:
| 请求头 | 说明 |
|---|---|
OK-ACCESS-KEY | API Key |
OK-ACCESS-SIGN | 请求签名:Base64(HMAC-SHA256(timestamp + method + requestPath + body, SecretKey)) |
OK-ACCESS-TIMESTAMP | UTC 时间戳 |
OK-ACCESS-PASSPHRASE | 创建 API Key 时设置的 Passphrase |
写操作签名模型#
所有写操作,包括下单、撤单、改单、调整杠杆、调整保证金、切换持仓模式和账户划转,都使用 EIP-712 Action 签名。
请求体结构:
json
{
"action": {},
"nonce": 1704067200000,
"user": "0x...",
"vaultAddress": "0x...",
"signature": {
"Ecdsa": {
"r": "0x...",
"s": "0x...",
"v": 1
}
},
"expiresAfter": 1704067260000
}
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
action | Object | 是 | 业务动作对象,是 EIP-712 的签名对象。所有业务参数都位于 action 内。 |
nonce | Long | 是 | 当前毫秒时间戳,用于签名和防重放。 |
user | String | 否 | 业务主体账户地址。未显式指定时,按签名主体或接口规则处理。 |
vaultAddress | String | 否 | 子账户地址。操作主账户时省略;操作子账户时填写子账户地址。 |
signature | Object | 是 | Agent 对完整 action 的 ECDSA 签名。r 和 s 为十六进制字符串,v 为 0 或 1。 |
expiresAfter | Long | 否 | Action 的有效截止时间,超过该时间后请求会被拒绝。cancel-all-after 心跳请求必须携带。 |
签名流程:
- 组装完整的 canonical
action。 - 使用当前毫秒时间戳生成
nonce。 - 使用已授权 Agent 的 ECDSA 私钥对
action进行 EIP-712 签名。 - 将签名后的请求提交至对应接口,并附带
OK-ACCESS-*请求头。
服务端不会代替客户端组装或修改 action。签名完成后,任何字段修改都会导致签名校验失败。
子账户查询#
以下读接口支持可选参数 vaultAddress:
- 省略
vaultAddress:查询主账户数据。 - 传入
vaultAddress:查询指定子账户数据。
网关会验证该地址是否属于当前认证用户。
适用接口:
text
/account/balance
/account/positions
/account/max-size
/account/leverage-info
/account/position-tiers
/account/bills
/trade/order
/trade/orders-pending
/trade/orders-history
/trade/fills以下接口固定使用主账户维度,不支持 vaultAddress:
text
/account/detail
/account/trade-feeRate Limit 总览#
Trade 接口
限流维度:按用户。
| 接口 | Rate Limit |
|---|---|
POST /trade/noop | 50 RPS |
POST /trade/place-order | 50 RPS |
POST /trade/cancel-order | 50 RPS |
POST /trade/modify-order | 50 RPS |
POST /trade/cancel-all-after | 1 RPS |
GET /trade/transaction | 30 RPS |
GET /trade/order | 30 RPS |
GET /trade/orders-pending | 30 RPS |
GET /trade/orders-history | 20 RPS |
GET /trade/fills | 30 RPS |
Account 接口
限流维度:按用户。
| 接口 | Rate Limit |
|---|---|
POST /account/account-transfer | 10 RPS |
GET /account/balance | 10 RPS |
GET /account/positions | 10 RPS |
GET /account/max-size | 10 RPS |
GET /account/position-tiers | 5 RPS |
POST /account/set-leverage | 10 RPS |
POST /account/set-margin-mode | 10 RPS |
POST /account/adjust-isolated-margin | 10 RPS |
POST /account/set-position-mode | 5 RPS |
GET /account/leverage-info | 5 RPS |
GET /account/trade-fee | 3 RPS |
GET /account/bills | 5 RPS |
GET /account/detail | 3 RPS |
POST /account/create-sub-account | 3 RPS |
GET /account/limits | 10 RPS |
Market 接口
限流维度:按 IP。
| 接口 | Rate Limit |
|---|---|
GET /market/instruments | 10 RPS |
GET /market/tickers | 10 RPS |
GET /market/order-book | 10 RPS |
GET /market/candles | 20 RPS |
GET /market/mark-prices | 10 RPS |
GET /market/position-tiers | 10 RPS |
GET /market/funding-rate-history | 5 RPS |
GET /market/funding-rate | 10 RPS |
GET /market/open-interest | 10 RPS |
GET /market/price-limit | 10 RPS |
GET /market/index-tickers | 10 RPS |
GET /market/token-info | 10 RPS |
GET /market/security-fund | 5 RPS |
