本篇列出REST接口的baseurl https://openapi.xxx.xx
所有接口都会返回一个JSON object或者array.
响应中如有数组,数组元素以时间倒序排列,越早的数据越提前.
所有时间、时间戳均为UNIX时间,单位为毫秒.
HTTP 4XX 错误码用于指示错误的请求内容、行为、格式.
HTTP 410 错误码表示警告访问频次超限,即将被封IP.
HTTP 418 表示收到429后继续访问,会被封禁IP,频繁违反限制,封禁时间会逐渐延长,从最短2分钟到最长3天.
HTTP 5XX 返回错误码是内部系统错误;这说明这个问题是在服务器这边。在对待这个错误时,千万 不要把它当成一个失败的任务,因为执行状态 未知,有可能是成功也有可能是失败.
HTTP 504 表示API服务端已经向业务核心提交了请求但未能获取响应,特别需要注意的是504代码不代表请求失败,而是未知。很可能已经得到了执行,也有可能执行失败,需要做进一步确认.
任何接口都可能返回ERROR(错误); 错误的返回payload如下:
{"code": -1121,"msg": "Invalid symbol."}
所有请求基于Https协议,请求头信息中Content-Type需要统一设置为: 'application/json'.
GET方法的接口, 参数必须在query string中发送.
POST方法的接口, 参数必须在request body中发送.
对参数的顺序不做要求.
访问限制是基于IP或者UID的,而不是API Key.
按IP和按UID(account)两种模式分别统计, 两者互相独立.
按照IP统计的权重单接口权重总额为每分钟12000.
按照UID统计的接口权重总额是每分钟60000.
每个接口会标明是按照IP或者按照UID统计, 以及相应请求一次的权重值
在每个接口下面会有限频的说明.
违反频率限制都会收到HTTP 429,这是一个警告.
当收到429告警时,调用者应当降低访问频率或者停止访问.
每个接口都有自己的鉴权类型,鉴权类型决定了访问时应当进行何种鉴权
如果需要 API-key,应当在HTTP头中以X-CH-APIKEY字段传递
API-key 与 API-secret 是大小写敏感的
可以在网页用户中心修改API-key 所具有的权限,例如读取账户信息、发送交易指令、发送提现指令
| 鉴权类型 | 描述 |
|---|---|
| NONE | 不需要鉴权的接口 |
| TRADE | 需要有效的API-KEY和签名 |
| USER_DATA | 需要有效的API-KEY和签名 |
| USER_STREAM | 需要有效的API-KEY |
| MARKET_DATA | 需要有效的API-KEY |
调用TRADE或者USER_DATA接口时,应当在HTTP头中以X-CH-SIGN字段传递签名参数.
签名使用HMAC SHA256算法. API-KEY所对应的API-Secret作为 HMAC SHA256 的密钥.
X-CH-SIGN的请求头是以timestamp + method + requestPath + body字符串(+表示字符串连接)作为操作对象
其中timestamp的值与X-CH-TS请求头相同, method是请求方法,字母全部大写:GET/POST.
requestPath是请求接口路径 例如:/sapi/v1/order?orderId=211222334&symbol=BTCUSDT
body是请求主体的字符串(post only) 如果是GET请求则body可省略
签名大小写不敏感。
签名接口均需要在HTTP头中以X-CH-TS字段传递时间戳, 其值应当是请求发送时刻的unix时间戳(毫秒) e.g. 1528394129373
服务器收到请求时会判断请求中的时间戳,如果是5000毫秒之前发出的,则请求会被认为无效。这个时间窗口值可以通过发送可选参数recvWindow来自定义。
另外,如果服务器计算得出客户端时间戳在服务器时间的‘未来’一秒以上,也会拒绝请求。
逻辑伪代码:
xxxxxxxxxxif (timestamp < (serverTime + 1000) && (serverTime - timestamp) <= recvWindow) { // process request} else { // reject request}关于交易时效性 互联网状况并不100%可靠,不可完全依赖,因此你的程序本地到交易所服务器的时延会有抖动. 这是我们设置recvWindow的目的所在,如果你从事高频交易,对交易时效性有较高的要求,可以灵活设置recvWindow以达到你的要求。 不推荐使用5秒以上的recvWindow
以下是在linux bash环境下使用 echo openssl 和curl工具实现的一个调用接口下单的示例 apikey、secret仅供示范
| Key | Value |
|---|---|
| apiKey | vmPUZE6mv9SD5V5e14y7Ju91duEh8A |
| secretKey | 902ae3cb34ecee2779aa4d3e1d226686 |
| 参数 | 取值 |
|---|---|
| symbol | BTCUSDT |
| side | BUY |
| type | LIMIT |
| volume | 1 |
| price | 9300 |
body:
xxxxxxxxxx{"symbol":"BTCUSDT","price":"9300","volume":"1","side":"BUY","type":"LIMIT"}
HMAC SHA256 签名:
xxxxxxxxxx[linux]$ echo -n "1588591856950POST/sapi/v1/order/test{\"symbol\":\"BTCUSDT\",\"price\":\"9300\",\"volume\":\"1\",\"side\":\"BUY\",\"type\":\"LIMIT\"}" | openssl dgst -sha256 -hmac "902ae3cb34ecee2779aa4d3e1d226686"(stdin)= c50d0a74bb9427a9a03933d0eded03af9bf50115dc5b706882a4fcf07a26b761curl 调用:
xxxxxxxxxx(HMAC SHA256)[linux]$ curl -H "X-CH-APIKEY: c3b165fd5218cdd2c2874c65da468b1e" -H "X-CH-SIGN: c50d0a74
base 指一个交易对的交易对象,即写在靠前部分的资产名
quote 指一个交易对的定价资产,即写在靠后部分资产名
NEW 新建订单
PARTIALLY_FILLED 部分成交
FILLED 全部成交
CANCELED 已撤销
PENDING_CANCEL 正在撤销中
REJECTED 订单被拒绝
LIMIT 限价单
MARKET 市价单
BUY 买单
SELL 卖
xxxxxxxxxxGET https://openapi.xxx.xx/sapi/v1/ping测试REST API的连通性
200: OK
xxxxxxxxxx}
xxxxxxxxxxGET https://openapi.xxx.xx/sapi/v1/time
获取服务器时间
200: OK
xxxxxxxxxx{"timezone": "GMT+08:00","serverTime": 1595563624731}
xxxxxxxxxxGET https://openapi.xxx.xx/sapi/v1/symbols
市场支持的币对集合esponse:
名称类型例子描述timelong1595563624731当前时间(Unix Timestamp, 毫秒ms)bidslist如下订单薄买盘信息askslist如下订单薄卖盘信息bids和asks所对应的信息代表了订单薄的所有价格以及价格对应的数量的信息, 由最优价格从上倒下排列名称类型例子描述' 'float131.1价格' 'float2.3当前价格对应的数量 GET https://openapi.xxx.com/sapi/v1/ticker\
200: OK
xxxxxxxxxx{ "symbols": [ { "quantityPrecision": 3, "symbol": "sccadai", "pricePrecision": 6, "baseAsset": "SCCA", "quoteAsset": "DAI" }, { "quantityPrecision": 8, "symbol": "btcusdt", "pricePrecision": 2, "baseAsset": "BTC", "quoteAsset": "USDT" }, { "quantityPrecision": 3, "symbol": "bchusdt", "pricePrecision": 2, "baseAsset": "BCH", "quoteAsset": "USDT" }, { "quantityPrecision": 2, "symbol": "etcusdt", "pricePrecision": 2, "baseAsset": "ETC", "quoteAsset": "USDT" }, { "quantityPrecision": 2, "symbol": "ltcbtc", "pricePrecision": 6, "baseAsset": "LTC", "quoteAsset": "BTC" } ]}权重(IP/UID): 1
| 名称 | 类型 | 例子 | 描述 |
|---|---|---|---|
| symbol | string | BTCUSDT | 币对名称 |
| baseAsset | string | BTC | base货币 |
| quoteAsset | string | USDT | 计价货币 |
| pricePrecision | integer | 2 | 价格精度 |
| quantityPrecision | integer | 6 | 数量精度 |
xxxxxxxxxxGET` `https://openapi.xxx.xx/sapi/v1/depth市场订单薄深度信息
| Name | Type | Description |
|---|---|---|
| limit | integer | 默认100; 最大100 |
| symbol* | String | 币对名称 E.g. BTCUSDT |
200: OK 成功获取深度信息
xxxxxxxxxx{"bids": [["3.90000000", // 价格"431.00000000" // 数量],["4.00000000","431.00000000"]],"asks": [["4.00000200", // 价格"12.00000000" // 数量],["5.10000000","28.00000000"]]}
权重(IP/UID): 5
| time | long | 1595563624731 | 当前时间(Unix Timestamp, 毫秒ms) |
|---|---|---|---|
| bids | list | 如下 | 订单薄买盘信息 |
| asks | list | 如下 | 订单薄卖盘信息 |
bids和asks所对应的信息代表了订单薄的所有价格以及价格对应的数量的信息, 由最优价格从上倒下排列
| ' ' | float | 131.1 | 价格 |
|---|---|---|---|
| ' ' | float | 2.3 | 当前价格对应的数量 |
xxxxxxxxxxGET https://openapi.xxx.xx/sapi/v1/ticker24小时价格变化数据
| Name | Type | Description |
|---|---|---|
| symbol* | String | 币对名称 E.g.BTCUSDTResponses200 |
200: OK 成功获取ticker信息
Copy
xxxxxxxxxx{ "high": "9279.0301", "vol": "1302", "last": "9200", "low": "9279.0301", "rose": "0", "time": 1595563624731}权重(IP/UID): 5
| time | long | 1595563624731 | 时间戳 | |
|---|---|---|---|---|
| high | float | 9900 | 最高价 | |
| low | float | 8800.34 | 最低价 | |
| open | float | 8700 | 开盘价 | |
| last | float | 8900 | 最新价 | |
| vol | float | 4999 | 交易量 | |
| rose | float | 0 | 涨幅 |
xxxxxxxxxxGET https://openapi.xxx.xx/sapi/v1/trades| Name | Type | Description |
|---|---|---|
| symbol* | String | 币对名称 E.g.BTCUSDT |
| limit | String | 默认100:最大1000 |
200: OK 成功
xxxxxxxxxx{ "list":[ { "price":"3.00000100", "qty":"11.00000000", "time":1499865549590, "side":"BUY" } ]}权重(IP/UID): 5
| price | float | 0.055 | 交易价格 | |
|---|---|---|---|---|
| time | long | 1537797044116 | 当前Unix时间戳,毫秒(ms) | |
| qty | float | 5 | 数量(张数) | |
| side | string | BUY/SELL | 主动单方向 |
xxxxxxxxxxGET` `https://openapi.xxx.xx/sapi/v1/klines| Name | Type | Description |
|---|---|---|
| symbol* | 币对名称 E.g.BTCUSDT | |
| interval* | String | k线图区间, 可识别发送的值为:1min,5min,15min,30min,60min,1day,1week,1month(min=分钟,h=小时,day=天,week=星期,month=月) |
| startTime | long | 起始时间点 |
| endTime | long | 截止时间点 |
200: OK 成功
xxxxxxxxxx[ { "high": "6228.77", "vol": "111", "low": "6228.77", "idx": 1594640340, "close": "6228.77", "open": "6228.77" }, { "high": "6228.77", "vol": "222", "low": "6228.77", "idx": 1587632160, "close": "6228.77", "open": "6228.77" }, { "high": "6228.77", "vol": "333", "low": "6228.77", "idx": 1587632100, "close": "6228.77", "open": "6228.77" }]权重(IP/UID): 1
idx | long | 1538728740000 | 开始时间戳,毫秒(ms) | |
|---|---|---|---|---|
| open | float | 36.00000 | 开盘价 | |
| close | float | 33.00000 | 收盘价 | |
| high | float | 36.00000 | 最高价 | |
| low | float | 30.00000 | 最低价 | |
| vol | float | 2456.111 | 成交量 |
交易下方的接口都需要签名和API-Key验证
xxxxxxxxxxPOST https://openapi.xxx.xx/sapi/v1/order| Name | Type | Description |
|---|---|---|
| X-CH-SIGN | string | 签名 |
| X-CH-APIKEY | string | 您的API-Key |
| X-CH-TS | integer | 时间戳 |
| Name | Type | Description |
|---|---|---|
| symbol* | String | 币对名称 E.g.BTCUSDT |
| volume* | number | 订单数量 |
| side* | String | 订单方向,BUY/SELL |
| type* | String | 订单类型,LIMIT/MARKET |
| price | number | 订单价格, 对于LIMIT订单必须发送 |
| newClientOrderId | String | 客户端订单标识 |
| recvwindow | integer | 时间窗口 |
200: OK
x{ 'symbol': 'LXTUSDT', 'orderId': '150695552109032492', //Long类型的订单号 'clientOrderId': '157371322565051', 'transactTime': '1573713225668', 'price': '0.005452', 'origQty': '110', 'executedQty': '0', 'status': 'NEW', 'type': 'LIMIT', 'side': 'SELL', "orderIdString": "1642655717519015937" //字符串类型的订单号,推荐使用这个
}权重(IP/UID): 5
| orderId | long | 150695552109032492 | 订单ID(系统生成) | |
|---|---|---|---|---|
| orderIdString | string | "150695552109032492" | 字符串类型的订单ID(推荐使用) | |
| clientOrderId | string | 213443 | 订单ID(自己发送的) | |
| symbol | string | BTCUSDT | 币对名称 | |
| transactTime | integer | 1273774892913 | 订单创建时间 | |
| price | float | 4765.29 | 订单价格 | |
| origQty | float | 1.01 | 订单数量 | |
| executedQty | float | 1.01 | 已经成交订单数量 | |
| type | string | LIMIT | 订单类型LIMIT(限价)MARKET(市价) | |
| side | string | BUY | 订单方向。可能出现的值只能为:BUY(买入做多) 和 SELL(卖出做空) | |
| status | string | 0 | 0 = 新订单 |
xxxxxxxxxxPOST` `https://openapi.xxx.xx/sapi/v1/order/test创建和验证新订单, 但不会送入撮合引擎
| Name | Type | Description |
|---|---|---|
| X-CH-SIGN | String | 签名 |
| X-CH-APIKEY | String | 您的API-key |
| X-CH-TS | String | 时间戳 |
| Name | Type | Description |
|---|---|---|
| recvwindow | integer | 时间窗口 |
| symbol* | String | 币对名称 E.g.BTCUSDT |
| volume* | number | 订单数量 |
| side* | String | 订单方向,BUY/SELL |
| type* | String | 订单类型,LIMIT/MARKET |
| price* | number | 订单价格, 对于LIMIT订单必须发送 |
| newClientorderId | String | 客户端订单标识 |
200: OK
xxxxxxxxxx{ // Response}权重(IP/UID): 1
xxxxxxxxxxPOST https://openapi.xxx.xx/sapi/v1/batchOrders| Name | Type | Description |
|---|---|---|
| X-CH-SIGN | String | 签名 |
| X-CH-APIKEY | String | 您的API-key |
| X-CH-TS | String | 时间戳 |
| Name | Type | Description |
|---|---|---|
| symbol* | String | 币对名称 E.g.BTCUSDT |
| orders | number | 批量订单信息 最多10条 |
200: OK
xxxxxxxxxx{ "idsString": [ //字符串类型的订单id(推荐使用) "165964665990709251", "165964665990709252", "165964665990709253" ], "ids": [ 165964665990709251, 165964665990709252, 165964665990709253 ]}权重(IP/UID): 10
orders field:| 名称 | 类型 | 例子 | 描述 |
|---|---|---|---|
| price | folat | 1000 | 价格 |
| volume | folat | 20.1 | 数量 |
| side | String | BUY/SELL | 方向 |
| batchType | String | LIMIT/MARKET | 类型 |
| idsString | String | “3213213” | String类型的订单号集合 | |
|---|---|---|---|---|
| ids | integer | 2100 | 订单号集合 |
xxxxxxxxxxGET https://openapi.xxx.xx/sapi/v1/order| Name | Type | Description |
|---|---|---|
| orderId* | String | 订单id |
| newClientOrderId | String | 客户端订单标识 |
| symbol* | String | 币对名称 E.g.BTCUSDTHeader |
| Name | Type | Description |
|---|---|---|
| X-CH-SIGN | String | 签名 |
| X-CH-APIKEY | String | 您的API-key |
| X-CH-TS | String | 时间戳 |
200: OK
xxxxxxxxxx{ 'orderId': '499890200602846976', 'clientOrderId': '157432755564968', 'symbol': 'BHTUSDT', 'price': '0.01', 'origQty': '50', 'executedQty': '0', 'avgPrice': '0', 'status': 'NEW', 'type': 'LIMIT', 'side': 'BUY', 'transactTime': '1574327555669'}权重(IP/UID): 1
| orderId | long | 150695552109032492 | 订单ID(系统生成) | |
|---|---|---|---|---|
| clientOrderId | string | 213443 | 订单ID(自己发送的) | |
| symbol | string | BTCUSDT | 币对名称 | |
| transactTime | integer | 1273774892913 | 订单创建时间 | |
| price | float | 4765.29 | 订单价格 | |
| origQty | float | 1.01 | 订单数量 | |
| executedQty | float | 1.01 | 已经成交订单数量 | |
| avgPrice | float | 4754.24 | 订单已经成交的平均价格 | |
| side | string | BUY | 订单方向。可能出现的值只能为:BUY(买入做多) 和 SELL(卖出做空) | |
| status | string | NEW | 订单状态。可能出现的值为:NEW(新订单,无成交)、PARTIALLY_FILLED(部分成交)、FILLED(全部成交)、CANCELED(已取消)和REJECTED(订单被拒绝).POST | |
| transactTime | string | 1574327555669 | 订单创建时间 |
xxxxxxxxxxPOST https://openapi.xxx.xx/sapi/v1/cancel| Name | Type | Description |
|---|---|---|
| X-CH-SIGN | String | 签名 |
| X-CH-APIKEY | String | 您的API-key |
| X-CH-TS | String | 时间戳 |
| Name | Type | Description |
|---|---|---|
| orderId* | String | 订单id |
| newClientOrderId | String | 客户端订单标识 |
| symbol* | String | 币对名称 E.g.BTCUSDTResponses200 |
200: OK 撤销订单成功
xxxxxxxxxx{ 'symbol': 'BHTUSDT', 'clientOrderId': '0', 'orderId': '499890200602846976', 'status': 'CANCELED'}权重(IP/UID): 5
| orderId | long | 150695552109032492 | 订单ID(系统生成) | |
|---|---|---|---|---|
| clientorderId | string | 213443 | 订单ID(自己发送的) | |
| symbol | string | BTCUSDT | 币对名称 | |
| status | string | NEW | 订单状态。可能出现的值为:NEW(新订单,无成交)、PARTIALLY_FILLED(部分成交)、FILLED(全部成交)、CANCELED(已取消)和REJECTED(订单被拒绝).POST |
xxxxxxxxxxPOST https://openapi.xxx.xx/sapi/v1/batchCancel一次批量最多10个订单
| Name | Type | Description |
|---|---|---|
| X-CH-SIGN | String | 签名 |
| X-CH-APIKEY | String | 您的API-key |
| X-CH-TS | String | 时间戳 |
| Name | Type | Description |
|---|---|---|
| orderIds* | String | 要取消的订单id集合[123,456]Responses200GET |
| symbol* | String | 币对名称 E.g.BTCUSDTResponses200 |
200: OK
xxxxxxxxxx{ "success": [ 165964665990709251, 165964665990709252, 165964665990709253 ], "failed": [ //取消失败一般是因为订单不存在或订单状态已经到终态 165964665990709250 ]}权重(IP/UID): 10
xxxxxxxxxxGET https://openapi.xxx.xx/sapi/v1/openOrders| Name | Type | Description |
|---|---|---|
| symbol* | String | 币对名称 E.g.BTCUSDT |
| limit | String | 默认100; 最大1000 |
| Name | Type | Description |
|---|---|---|
| X-CH-SIGN | String | 签名 |
| X-CH-APIKEY | String | 您的API-key |
| X-CH-TS | String | 时间戳 |
200: OK
xxxxxxxxxx[ { 'orderId': '499902955766523648', 'symbol': 'BHTUSDT', 'price': '0.01', 'origQty': '50', 'executedQty': '0', 'avgPrice': '0', 'status': 'NEW', 'type': 'LIMIT', 'side': 'BUY', 'time': '1574329076202' },...]| orderId | long | 150695552109032492 | 订单ID(系统生成) | |
|---|---|---|---|---|
| orderIdString | String | "150695552109032492" | 字符串类型的订单ID(推荐使用) | |
| clientorderId | string | 213443 | 订单ID(自己发送的) | |
| symbol | string | BTCUSDT | 币对名称 | |
| price | float | 4765.29 | 订单价格 | |
| origQty | float | 1.01 | 订单数量 | |
| executedQty | float | 1.01 | 已经成交订单数量 | |
| avgPrice | float | 4754.24 | 订单已经成交的平均价格 | |
| type | string | LIMIT | 订单类型LIMIT(限价)MARKET(市价) | |
| side | string | BUY | 订单方向。可能出现的值只能为:BUY(买入做多) 和 SELL(卖出做空) | |
| status | string | NEW | 订单状态。可能出现的值为:NEW(新订单,无成交)、PARTIALLY_FILLED(部分成交)、FILLED(全部成交)、CANCELED(已取消)和REJECTED(订单被拒绝).POST | |
| time | string | 1574327555669 | 创建时间 |
xxxxxxxxxxGET https://openapi.xxx.xx/sapi/v1/myTrades| Name | Type | Description |
|---|---|---|
| symbol* | String | 币对名称 E.g.BTCUSDT |
| limit | String | 默认100; 最大1000 |
| fromId | String | 从这个tradeId开始检索 |
| Name | Type | Description |
|---|---|---|
| X-CH-SIGN | String | 签名 |
| X-CH-APIKEY | String | 您的API-key |
| X-CH-TS | String | 时间戳 |
200: OK
xxxxxxxxxx[ { "symbol": "ETHBTC", "id": 100211, "bidId": 150695552109032492, "askId": 150695552109032493, "price": "4.00000100", "qty": "12.00000000", "time": 1499865549590, "isBuyer": true, "isMaker": false, "feeCoin": "ETH", "fee":"0.001", "bidUserId":23334, "askUserId":44112 },...]权重(IP/UID): 1
| id | long | 150695552109032492 | 成交id | |
|---|---|---|---|---|
| symbol | String | 币对 | 字符串类型的订单ID(推荐使用) | ti |
| time | long | 1499865549590 | 创建时间 | |
| qty | string | 12 | 交易数量 | |
| price | float | 4765.29 | 订单价格 | |
| fee | string | 0.001 | 交易手续费币 | |
| feeCoin | String | xxx | 手续费币种 | |
| isBuyer | boolean | true | true= 买 false= 卖 | |
| isMaker | boolean | false | true=市价 false=限价 | |
| bidId | long | 1200000200 | 买单id | |
| askId | long | 1200000200 | 卖单id | |
| side | string | BUY | 订单方向。可能出现的值只能为:BUY(买入做多) 和 SELL(卖出做空) | |
| bidUserId | long | 23334 | 买方uid | |
| askUserId | long | 44112 | 卖方uid | |
| isSelf | boolean | true | 是否是自成交 |
xxxxxxxxxxGET https://openapi.xxx.xx/sapi/v1/account| Name | Type | Description |
|---|---|---|
| X-CH-SIGN | String | 签名 |
| X-CH-APIKEY | String | 您的API-key |
| X-CH-TS | String | 时间戳 |
200: OK
xxxxxxxxxx
权重(IP/UID): 1
交易下方的接口都需要签名API Key验证
xxxxxxxxxxPOST https://openapi.xxx.xx/sapi/v1/margin/order| Name | Type | Description |
|---|---|---|
| X-CH-SIGN | String | 签名 |
| X-CH-TS | String | 时间戳 |
| X-CH-APIKEY | String | 您的API-key |
| Name | Type | Description |
|---|---|---|
| type | String | 订单类型, LIMIT/MARKET |
| recwwindow | String | 时间窗口 |
| price | number | 订单价格, 对于LIMIT订单必须发送 |
| newClientOrderId | String | 客户端订单标识,不能超过32位 |
| side | String | 订单方向, BUY/SELL |
| volume | number | 订单数量 |
| symbol | String | 币对名称 E.g. BTCUSDT |
200: OK 发送杠杆订单成功
Copy
xxxxxxxxxx{ 'symbol': 'LXTUSDT', 'orderId': '494736827050147840', 'clientOrderId': '157371322565051', 'transactTime': '1573713225668', 'price': '0.005452', 'origQty': '110', 'executedQty': '0', 'status': 'NEW', 'type': 'LIMIT', 'side': 'SELL'}权重(IP/UID): 5
xxxxxxxxxxGET https://openapi.xxx.xx/sapi/v1/margin/order| Name | Type | Description |
|---|---|---|
| orderId | String | 订单ID |
| newClientOrderId | String | 客户端订单标识 |
| symbol | String | 币对名称E.g. BTCUSDTHeader |
| Name | Type | Description |
|---|---|---|
| X-CH-SIGN | String | 签名 |
| X-CH-TS | String | 时间戳 |
| X-CH-APIKEY | String | 您的API-key |
200: OK 查询杠杆订单成功
xxxxxxxxxx{ 'orderId': '499890200602846976', 'clientOrderId': '157432755564968', 'symbol': 'BHTUSDT', 'price': '0.01', 'origQty': '50', 'executedQty': '0', 'avgPrice': '0', 'status': 'NEW', 'type': 'LIMIT', 'side': 'BUY', 'transactTime': '1574327555669'}权重(IP/UID): 5
xxxxxxxxxxPOST https://openapi.xxx.xx/sapi/v1/margin/cancel| Name | Type | Description |
|---|---|---|
| X-CH-SIGN | String | 签名 |
| X-CH-TS | String | 时间戳 |
| X-CH-APIKEY | String | 您的API-key |
| Name | Type | Description |
|---|---|---|
| newClientOrderId | String | 客户端订单标识 |
| symbol | String | 币对名称 E.g. BTCUSDT |
| orderId | String | 订单id |
200: OK 发送杠杆订单成功
xxxxxxxxxx{ 'symbol': 'LXTUSDT', 'orderId': '494736827050147840', 'clientOrderId': '157371322565051', 'transactTime': '1573713225668', 'price': '0.005452', 'origQty': '110', 'executedQty': '0', 'status': 'NEW', 'type': 'LIMIT', 'side': 'SELL'}权重(IP/UID): 5
xxxxxxxxxxGET https://openapi.xxx.xx/sapi/v1/margin/openOrders权重(IP/UID): 5
| Name | Type | Description |
|---|---|---|
| symbol | String | 币对名称E.g. BTCUSDTHeader |
| limit | String | 默认100; 最大1000 |
| Name | Type | Description |
|---|---|---|
| X-CH-SIGN | String | 签名 |
| X-CH-TS | String | 时间戳 |
| X-CH-APIKEY | String | 您的API-key |
200: OK
xxxxxxxxxx[ { 'orderId': '499902955766523648', 'symbol': 'BHTUSDT', 'price': '0.01', 'origQty': '50', 'executedQty': '0', 'avgPrice': '0', 'status': 'NEW', 'type': 'LIMIT', 'side': 'BUY', 'time': '1574329076202' },...]权重(IP/UID): 1
xxxxxxxxxxGET https://openapi.xxx.xx/sapi/v1/margin/myTrades| Name | Type | Description |
|---|---|---|
| symbol | String | 币对名称 E.g. BTCUSDT |
| limit | String | 默认100;最大1000 |
| fromId | String | 从这个tradeld开始检索 |
| Name | Type | Description |
|---|---|---|
| X-CH-SIGN | String | 签名 |
| X-CH-TS | String | 时间戳 |
| X-CH-APIKEY | String | 您的API-key |
200: OK
xxxxxxxxxx[ { "symbol": "ETHBTC", "id": 100211, "bidId": 150695552109032492, "askId": 150695552109032493, "price": "4.00000100", "qty": "12.00000000", "time": 1499865549590, "isBuyer": true, "isMaker": false, "feeCoin": "ETH", "fee":"0.001" },...]权重(IP/UID): 1
公共下方的接口不需要API-key或者签名就能自由访问
xxxxxxxxxxGET https://futuresopenapi.xxx.xx/fapi/v1/ping测试REST API的连通性
200 连接正常
xxxxxxxxxx{}xxxxxxxxxxGET https://futuresopenapi.xxx.xx/fapi/v1/time200
xxxxxxxxxx{ "serverTime":1607702400000, "timezone":中国标准时间}| 名称 | 类型 | 例子 | 描述 |
|---|---|---|---|
| serverTime | long | 1607702400000 | 服务器时间戳 |
| timezone | string | 中国标准时间 | 服务器时区 |
xxxxxxxxxxGET https://futuresopenapi.xxx.xx/fapi/v1/contracts200
xxxxxxxxxx[ { "symbol": "H-HT-USDT", "pricePrecision": 8, "side": 1, "maxMarketVolume": 100000, "multiplier": 6, "minOrderVolume": 1, "maxMarketMoney": 10000000, "type": "H", "maxLimitVolume": 1000000, "maxValidOrder": 20, "multiplierCoin": "HT", "minOrderMoney": 0.001, "maxLimitMoney": 1000000, "status": 1 }]| 名称 | 类型 | 例子 | 描述 |
|---|---|---|---|
| symbol | string | E-BTC-USDT | 合约名称 |
| status | number | 1 | 合约状态(0:不可交易,1:可交易 |
| type | string | S | 合约类型,E:永续合约, S:模拟合约, 其他为混合合约 |
| side | number | 1 | 合约方向(反向:0,1:正向) |
| multiplier | number | 0.5 | 合约面值 |
| multiplierCoin | string | BTC | 合约面值单位 |
| pricePrecision | number | 4 | 价格精度 |
| minOrderVolume | number | 10 | 最小下单量 |
| minOrderMoney | number | 10 | 最小下单金额 |
| maxMarketVolume | number | 100000 | 市价单最大下单数量 |
| maxMarketMoney | number | 100000 | 市价最大下单金额 |
| maxLimitVolume | number | 100000 | 限价单最大下单数量 |
| maxValidOrder | number | 100000 | 最大有效委托的订单数量 |
行情下方的接口不需要API-Key或者签名就能自由访问
xxxxxxxxxxGET https://futuresopenapi.xxx.xx/fapi/v1/depth市场订单薄深度信息
| Name | Type | Description |
|---|---|---|
| limit | integer | 默认100; 最大100 |
| contractName | string | 合约合约名称 如 E-BTC-USDT |
200 成功获取深度信息
xxxxxxxxxx{ "bids": [ [ "3.90000000", // 价格 "431.00000000" // 数量 ], [ "4.00000000", "431.00000000" ] ], "asks": [ [ "4.00000200", // 价格 "12.00000000" // 数量 ], [ "5.10000000", "28.00000000" ] ]}| 名称 | 类型 | 例子 | 描述 |
|---|---|---|---|
| time | long | 1595563624731 | 当前时间(Unix Timestamp, 毫秒ms) |
| bids | list | 如下 | 订单薄买盘信息 |
| asks | list | 如下 | 订单薄卖盘信息 |
bids和asks所对应的信息代表了订单薄的所有价格以及价格对应的数量的信息, 由最优价格从上倒下排列
| 名称 | 类型 | 例子 | 描述 |
|---|---|---|---|
| ' ' | float | 131.1 | 价格 |
| ' ' | float | 2.3 | 当前价格对应的数量 |
xxxxxxxxxxGET https://futuersopenapi.xxx.xx/fapi/v1/ticker24小时价格变化数据
| Name | Type | Description |
|---|---|---|
| contractName | string | 合约名称 如 E-BTC-USDT |
200 成功获取ticker信息
xxxxxxxxxx{ "high": "9279.0301", "vol": "1302", "last": "9200", "low": "9279.0301", "rose": "0", "time": 1595563624731}| 名称 | 类型 | 例子 | 描述 |
|---|---|---|---|
| time | long | 1595563624731 | 时间戳 |
| high | float | 9900 | 最高价 |
| low | float | 8800.34 | 最低价 |
| last | float | 8900 | 最新价 |
| vol | float | 4999 | 交易量 |
| rose | string | +0.5 | 涨跌幅 |
xxxxxxxxxxGET https://futuersopenapi.xxx.xx/fapi/v1/index| Name | Type | Description |
|---|---|---|
| contractName | string | 合约名称 如 E-BTC-USDT |
| limit | string | 默认100; 最大1000 |
200
xxxxxxxxxx{ "markPrice": 581.5, "indexPrice": 646.3933333333333, "lastFundingRate": 0.001, "contractName": "E-ETH-USDT", "time": 1608273554063}| 名称 | 类型 | 例子 | 描述 |
|---|---|---|---|
indexPrice | float | 0.055 | 指数价格 |
markPrice | float | 0.0578 | 标记价格 |
contractName | string | E-BTC-USDT | 合约名称 |
lastFundingRate | float | 0.123 | 本期资金费率 |
xxxxxxxxxxGET https://futuresopenapi.xxx.xx/fapi/v1/klines| Name | Type | Description |
|---|---|---|
| contractName | string | 合约名称 如 E-BTC-USDT |
| interval | string | k线图区间, 可识别发送的值为: 1min,5min,15min,30min,1h,1day,1week,1month(min=分钟,h=小时,day=天,week=星期,month=月) |
| limit | integer | 默认100; 最大300 |
200
xxxxxxxxxx[ { "high": "6228.77", "vol": "111", "low": "6228.77", "idx": 1594640340, "close": "6228.77", "open": "6228.77" }, { "high": "6228.77", "vol": "222", "low": "6228.77", "idx": 1587632160, "close": "6228.77", "open": "6228.77" }, { "high": "6228.77", "vol": "333", "low": "6228.77", "idx": 1587632100, "close": "6228.77", "open": "6228.77" }]| 名称 | 类型 | 例子 | 描述 |
|---|---|---|---|
idx | long | 1538728740000 | 开始时间戳,毫秒(ms) |
open | float | 36.00000 | 开盘价 |
close | float | 33.00000 | 收盘价 |
high | float | 36.00000 | 最高价 |
low | float | 30.00000 | 最低价 |
vol | float | 2456.111 | 成交量 |
交易下方的接口都需要签名和API-key验证
xxxxxxxxxxPOST https://futuresopenapi.xxx.xx/fapi/v1/order创建单个新订单
| Name | Type | Description |
|---|---|---|
| X-CH-TS | string | 时间戳 |
| X-CH-APIKEY | string | 您的API-KEY |
| X-CH-SIGN | string | 签名 |
| Name | Type | Description |
|---|---|---|
| volume | number | 下单数量 |
| price | number | 下单价格 |
| contractName | string | 合约名称 如 E-BTC-USDT |
| type | string | 订单类型, LIMIT/MARKET |
| side | string | 买卖方向, BUY/SELL |
| open | string | 开平仓方向, OPEN/CLOSE |
| positionType | number | 持仓类型, 1全仓/2逐仓 |
| clientOrderId | string | 客户端下单标识, 长度小于32位的字符串 |
| timeInForce | string | LIMIT/MARKET |
200
xxxxxxxxxx{ "orderId": 256609229205684228}| 名称 | 类型 | 例子 | 描述 |
|---|---|---|---|
| orderId | string | 256609229205684228 | 订单ID |
xxxxxxxxxxPOST https://futuresopenapi.xxx.xx/fapi/v1/conditionOrder| Name | Type | Description |
|---|---|---|
| X-CH-TS | string | 时间戳 |
| X-CH-APIKEY | string | 您的API-KEY |
| X-CH-SIGN | string | 签名 |
| Name | Type | Description |
|---|---|---|
| volume | number | 下单数量 |
| price | number | 下单价格 |
| contractName | string | 合约名称 如 E-BTC-USDT |
| type | string | 订单类型, LIMIT/MARKET |
| side | string | 买卖方向, BUY/SELL |
| open | string | 开平仓方向, OPEN/CLOSE |
| positionType | number | 持仓类型, 1全仓/2逐仓 |
| clientOrderId | string | 客户端下单标识, 长度小于32位的字符串 |
| triggerType | string | 条件单类型,3追涨/4杀跌 |
| triggerPrice | string | 触发价 |
200: OK
xxxxxxxxxx{ "orderId": 256609229205684228}xxxxxxxxxxPOST https://futuresopenapi.xxx.xx/fapi/v1/cancel| Name | Type | Description |
|---|---|---|
| X-CH-SIGN | string | 签名 |
| X-CH-APIKEY | string | 您的API-key |
| X-CH-TS | integer | 时间戳 |
| Name | Type | Description |
|---|---|---|
| contractName | string | 合约名称如 E-BTC-USDT |
| orderId | string | 订单ID |
200
xxxxxxxxxx{ "orderId": 256609229205684228}xxxxxxxxxxGET https://futuresopenapi.xxx.xx/fapi/v1/order| Name | Type | Description |
|---|---|---|
| contractName* | string | 合约名称 |
| orderId* | string | 订单ID |
| clientOrderId | string | 客户端唯一标识 |
200
xxxxxxxxxx[ { "side": "BUY", "executedQty": 0, "orderId": 259396989397942275, "price": 10000.0000000000000000, "origQty": 1.0000000000000000, "avgPrice": 0E-8, "transactTime": "1607702400000", "action": "OPEN", "contractName": "E-BTC-USDT", "type": "LIMIT", "status": "INIT" }]| 名称 | 类型 | 例子 | 描述 |
|---|---|---|---|
orderId | long | 150695552109032492 | 订单ID(系统生成 |
contractName | string | E-BTC-USDT | 合约名称 |
price | float | 10.5 | 委托价格 |
origQty | float | 10.5 | 委托数量 |
executedQty | float | 20 | 委托数量 |
avgPrice | float | 10.5 | 成交均价 |
symbol | string | BHTUSDT | 币对名称 |
status | string | NEW | 订单状态。可能出现的值为:NEW(新订单,无成交)、PARTIALLY_FILLED(部分成交)、FILLED(全部成交)、CANCELED(已取消)和REJECTED(订单被拒绝) |
side | string | NEW | 订单方向。可能出现的值只能为:BUY(买入做多) 和 SELL(卖出做空) |
action | string | OPEN | OPEN/CLOSE |
transactTime | long | 1607702400000 | 订单创建时间 |
xxxxxxxxxxGET` `https://futuresopenapi.xxx.xx/fapi/v1/openOrders
限速规则: 获取当前合约, 该用户的当前委托
| Name | Type | Description |
|---|---|---|
| contractName | string | 合约名称 E-BTC-USDT |
| Name | Type | Description |
|---|---|---|
| X-CH-SIGN | string | 签名 |
| X-CH-APIKEY | string | 您的API-key |
| X-CH-TS | string | 时间戳 |
200
xxxxxxxxxx[ { "side": "BUY", "executedQty": 0, "orderId": 259396989397942275, "price": 10000.0000000000000000, "origQty": 1.0000000000000000, "avgPrice": 0E-8, "transactTime": "1607702400000", "action": "OPEN", "contractName": "E-BTC-USDT", "type": "LIMIT", "status": "INIT" }]| 名称 | 类型 | 例子 | 描述 |
|---|---|---|---|
orderId | long | 150695552109032492 | 订单ID(系统生成) |
contractName | string | E-BTC-USDT | 合约名称 |
price | float | 4765.29 | 订单价格 |
origQty | float | 1.01 | 订单数量 |
executedQty | float | 1.01 | 已经成交订单数量 |
avgPrice | float | 4754.24 | 订单已经成交的平均价格 |
type | string | LIMIT | 订单类型。可能出现的值只能为:LIMIT(限价)和MARKET(市价) |
side | string | BUY | 订单方向。可能出现的值只能为:BUY(买入做多) 和 SELL(卖出做空) |
status | string | NEW | 订单状态。可能出现的值为:NEW(新订单,无成交)、PARTIALLY_FILLED(部分成交)、FILLED(全部成交)、CANCELED(已取消)和REJECTED(订单被拒绝). |
action | string | OPEN | OPEN/CLOSE |
transactTime | long | 1607702400000 | 订单创建时间, |
xxxxxxxxxxPOST https://futuresopenapi.xxx.xx/fapi/v1/orderHistorical| Name | Type | Description |
|---|---|---|
| X-CH-SIGN | string | 签名 |
| X-CH-APIKEY | string | 您的API-key |
| X-CH-TS | string | 时间戳 |
| Name | Type | Description |
|---|---|---|
| contractName | string | 合约名称 E-BTC-USDT |
| limit | string | 分页条数, 默认100; 最大1000 |
| fromId | long | 从这条记录开始检索 |
200: OK
xxxxxxxxxx[ { "side":"BUY", "clientId":"0", "ctimeMs":1632903411000, "positionType":2, "orderId":777293886968070157, "avgPrice":41000, "openOrClose":"OPEN", "leverageLevel":26, "type":4, "closeTakerFeeRate":0.00065, "volume":2, "openMakerFeeRate":0.00025, "dealVolume":1, "price":41000, "closeMakerFeeRate":0.00025, "contractId":1, "ctime":"2021-09-29T16:16:51", "contractName":"E-BTC-USDT", "openTakerFeeRate":0.00065, "dealMoney":4.1, "status":4 }]xxxxxxxxxxPOST https://futuresopenapi.xxx.xx/fapi/v1/profitHistorical| Name | Type | Description |
|---|---|---|
| X-CH-SIGN | string | 签名 |
| X-CH-APIKEY | string | 您的API-key |
| X-CH-TS | string | 时间戳 |
| Name | Type | Description |
|---|---|---|
| contractName | string | 合约名称 E-BTC-USDT |
| limit | string | 分页条数, 默认100; 最大1000 |
| fromId | long | 从这条记录开始检索 |
200: OK
xxxxxxxxxx[ { "side":"SELL", "positionType":2, "tradeFee":-5.23575, "realizedAmount":0, "leverageLevel":26, "openPrice":44500, "settleProfit":0, "mtime":1632882739000, "shareAmount":0, "openEndPrice":44500, "closeProfit":-45, "volume":900, "contractId":1, "historyRealizedAmount":-50.23575, "ctime":1632882691000, "id":8764, "capitalFee":0 }]xxxxxxxxxxGET https://futuresopenapi.xxx.xx/fapi/v1/myTrades| Name | Type | Description |
|---|---|---|
| contractName | string | 合约名称 如 E-BTC-USDT |
| limit | string | 分页条数, 默认100; 最大1000 |
| fromId | long | 从这个tradeId开始检索 |
| Name | Type | Description |
|---|---|---|
| X-CH-SIGN | string | 签名 |
| X-CH-APIKEY | string | 您的API-key |
| X-CH-TS | integer | 时间戳 |
200
xxxxxxxxxx[ { "symbol": "ETHBTC", "id": 100211, "bidId": 150695552109032492, "askId": 150695552109032493, "price": "4.00000100", "qty": "12.00000000", "time": 1499865549590, "isBuyer": true, "isMaker": false, "fee":"0.001" },...]| 名称 | 类型 | 例子 | 描述 |
|---|---|---|---|
| symbol | string | ETHBTC | 币种名称(交易对) |
| tradeId | number | 28457 | 交易ID |
| bidId | long | 150695552109032492 | 买方订单ID |
| askId | long | 150695552109032493 | 卖方订单ID |
| bidUserId | integer | 10024 | 买方用户ID |
| askUserId | integer | 10025 | 卖方用户ID |
| price | float | 4.01 | 成交价格 |
| qty | float | 12 | 交易数量 |
| amount | float | 5.38 | 成交金额 |
| time | number | 1499865549590 | 交易时间戳 |
| fee | number | 0.001 | 交易手续费 |
| side | string | buy | 当前订单方向 BUY 买入, SELL 卖出 |
| contractName | string | E-BTC-USDT | 合约名称 |
| isMaker | boolean | true | 是否是maker |
| isBuyer | boolean | true | 是否买方 |
账户下方的接口都需要签名和API-key验证
xxxxxxxxxxGET https://futuresopenapi.xxx.com/fapi/v1/account| Name | Type | Description |
|---|---|---|
| X-CH-SIGN | string | 签名 |
| X-CH-APIKEY | string | 您的API-key |
| X-CH-TS | integer | 时间戳 |
200 获取账户信息成功
xxxxxxxxxx{ "account": [ { "marginCoin": "USDT", "accountNormal": 999.5606, "accountLock": 23799.5017, "partPositionNormal": 9110.7294, "totalPositionNormal": 0, "achievedAmount": 4156.5072, "unrealizedAmount": 650.6385, "totalMarginRate": 0, "totalEquity": 99964804.560, "partEquity": 13917.8753, "totalCost": 0, "sumMarginRate": 873.4608, "positionVos": [ { "contractId": 1, "contractName": "E-BTC-USDT", "contractSymbol": "BTC-USDT", "positions": [ { "id": 13603, "uid": 10023, "contractId": 1, "positionType": 2, "side": "BUY", "volume": 69642.0, "openPrice": 11840.2394, "avgPrice": 11840.3095, "closePrice": 12155.3005, "leverageLevel": 24, "holdAmount": 7014.2111, "closeVolume": 40502.0, "pendingCloseVolume": 0, "realizedAmount": 8115.9125, "historyRealizedAmount": 1865.3985, "tradeFee": -432.0072, "capitalFee": 2891.2281, "closeProfit": 8117.6903, "shareAmount": 0.1112, "freezeLock": 0, "status": 1, "ctime": "2020-12-11T17:42:10", "mtime": "2020-12-18T20:35:43", "brokerId": 21, "marginRate": 0.2097, "reducePrice": 9740.8083, "returnRate": 0.3086, "unRealizedAmount": 2164.5289, "openRealizedAmount": 2165.0173, "positionBalance": 82458.2839, "settleProfit": 0.4883, "indexPrice": 12151.1175, "keepRate": 0.005, "maxFeeRate": 0.0025 } ] } ] } ]}| 名称 | 类型 | 描述 |
|---|---|---|
account | [] | 余额集合 |
account field:
| 名称 | 类型 | 例子 | 描述 |
|---|---|---|---|
| marginCoin | string | USDT | 保证金币种 |
| accountNormal | float | 10.05 | 余额帐户 |
| accountLock | float | 10.07 | 保证金冻结帐户 |
| partPositionNormal | float | 10.07 | 逐仓保证金余额 |
| totalPositionNormal | float | 10.07 | 全仓占用的初始保证金 |
| achievedAmount | float | 10.07 | 已实现盈亏 |
| unrealizedAmount | float | 10.05 | 未实现盈亏 |
| totalMarginRate | float | 10.05 | 全仓保证金率 |
| totalEquity | float | 10.07 | 全仓权益 |
| partEquity | float | 10.07 | 逐仓权益 |
| totalCost | float | 10.07 | 全仓占用的成本 |
| sumMarginRate | float | 10.07 | 全账户的保证金率 |
| positionVos | [ ] | 仓位合约记录 |
positionVos field:
| 名称 | 类型 | 例子 | 描述 |
|---|---|---|---|
| contractId | integer | 2 | 合约id |
| contractName | string | E-BTC-USDT | 合约名称 |
| contractSymbol | string | BTC-USDT | 合约币对 |
| positions | [ ] | 仓位明细 |
positions field:
| 名称 | 类型 | 例子 | 描述 |
|---|---|---|---|
| id | integer | 2 | 仓位id |
| uid | integer | 10023 | 用户ID |
| positionType | integer | 1 | 持仓类型(1 全仓,2 仓逐) |
| side | string | SELL | 持仓方向 BUY 多仓, SELL 空仓 |
| volume | float | 1.05 | 持仓数量 |
| openPrice | float | 1.05 | 开仓价格 |
| avgPrice | float | 1.05 | 持仓均价 |
| closePrice | float | 1.05 | 平仓均价 |
| leverageLevel | float | 1.05 | 杠杆倍数 |
| holdAmount | float | 1.05 | 持仓保证金 |
| closeVolume | float | 1.05 | 已平仓数量 |
| pendingCloseVolume | float | 1.05 | 已挂出平仓单的数量 |
| realizedAmount | float | 1.05 | 已实现盈亏 |
| historyRealizedAmount | float | 1.05 | 历史累计已实现盈亏 |
| tradeFee | float | 1.05 | 交易手续费 |
| capitalFee | float | 1.05 | 资金费用 |
| closeProfit | float | 1.05 | 平仓盈亏 |
| shareAmount | float | 1.05 | 分摊金额 |
| freezeLock | integer | 0 | 持仓冻结状态:0 正常,1爆仓冻结,2 交割冻结 |
| status | integer | 0 | 仓位有效性,0无效 1有效 |
| ctime | time | 创建时间 | |
| mtime | time | 更新时间 | |
| brokerId | integer | 1023 | 商户id |
| lockTime | time | 爆仓锁仓时间 | |
| marginRate | float | 1.05 | 保证金率 |
| reducePrice | float | 1.05 | 强减价格 |
| returnRate | float | 1.05 | 回报率(收益率) |
| unRealizedAmount | float | 1.05 | 未实现盈亏 |
| openRealizedAmount | float | 1.05 | 开仓未实现盈亏 |
| positionBalance | float | 1.05 | 仓位价值 |
| indexPrice | float | 1.05 | 最新标记价格 |
| keepRate | float | 1.05 | 阶梯最低维持保证金率 |
| maxFeeRate | float | 1.05 | 平仓最大手续费率 |
xxxxxxxxxxPOST https://futuresopenapi.xxx.xx/fapi/v1/tpslOrder创建单个新订单
| Name | Type | Description |
|---|---|---|
| X-CH-TS | string | 时间戳 |
| X-CH-APIKEY | string | 您的API-KEY |
| X-CH-SIGN | string | 签名 |
| Name | Type | Description |
|---|---|---|
| contractName | string | 合约名称 如 E-BTC-USDT |
| type | string | 订单类型(1 limit, 2 market) |
| side | string | 买卖方向, BUY/SELL |
| open | string | 开平仓方向, OPEN/CLOSE |
| positionType | number | 持仓类型, 1全仓/2逐仓 |
| leverageLevel | number | 杠杆倍数, 10 |
| orderListStr | string | 下单列表 |
OrderListStr
| Name | Type | Description |
|---|---|---|
| triggerType | number | 止盈止损订单类型(1止损, 2 止盈) |
| volume | number | 下单数量 |
| price | number | 下单价格 |
| type | string | 订单类型(1 limit, 2 market) |
| expiredTime | number | 有效时间 单位: 天 |
| triggerPrice | number | 触发价格 |
xxxxxxxxxx{ "orderId": 256609229205684228}| 名称 | 类型 | 例子 | 描述 |
|---|---|---|---|
| orderId | string | 256609229205684228 | 订单ID |
xxxxxxxxxxPOST https://futuresopenapi.xxx.xx/fapi/v1/tpslOrderCancel创建单个新订单
| Name | Type | Description |
|---|---|---|
| X-CH-TS | string | 时间戳 |
| X-CH-APIKEY | string | 您的API-KEY |
| X-CH-SIGN | string | 签名 |
| Name | Type | Description |
|---|---|---|
| contractName | string | 合约名称 如 E-BTC-USDT |
| orderIds | string | 订单ID, 多笔订单使用,分隔 |
xxxxxxxxxx{ "code": "0, "msg": "success"}| 名称 | 类型 | 例子 | 描述 |
|---|---|---|---|
| code | string | 0 | 状态 0 成功 |
xxxxxxxxxxPOST https://futuresopenapi.xxx.xx/fapi/v1/lightClose| Name | Type | Description |
|---|---|---|
| X-CH-SIGN | string | 签名 |
| X-CH-APIKEY | string | 您的API-key |
| X-CH-TS | integer | 时间戳 |
| Name | Type | Description |
|---|---|---|
| contractName | string | 合约名称如 E-BTC-USDT |
| side | string | 买卖方向, BUY/SELL |
| open | string | 开平仓方向, OPEN/CLOSE |
| positionType | number | 持仓类型, 1全仓/2逐仓 |
xxxxxxxxxx{ "orderId": 256609229205684228}| 名称 | 类型 | 例子 | 描述 |
|---|---|---|---|
| orderId | string | 256609229205684228 | 订单ID |
xxxxxxxxxxPOST https://futuresopenapi.xxx.xx/fapi/v1/tpsl/order
查询用户有效的止盈止损订单
| Name | Type | Description |
|---|---|---|
| X-CH-TS | string | 时间戳 |
| X-CH-APIKEY | string | 您的API-KEY |
| X-CH-SIGN | string | 签名 |
| Name | Type | Description |
|---|---|---|
| contractName | string | 合约名称 如 E-BTC-USDT |
xxxxxxxxxx{"takeProfitList": [{"id": "12345","contractName": "E-BTC-USDT","triggerPrice": 42000,"price": 41500,"pricePrecision": 2,"volume": 1.5,"base": "BTC","quote": "USDT"}],"stopLossList": [{"id": "12346","contractId": "E-BTC-USDT","triggerPrice": 38000,"price": 37500,"pricePrecision": 2,"volume": 1.5,"base": "BTC","quote": "USDT"}],"takeProfitCount": 1,"stopLossCount": 1,"count": 2}
| 字段名 | 类型 | 说明 |
|---|---|---|
| takeProfitList | Array | 止盈订单列表 |
| stopLossList | Array | 止损订单列表 |
| takeProfitCount | Integer | 止盈订单数量 |
| stopLossCount | Integer | 止损订单数量 |
| count | Integer | 总订单数 |
| 字段名 | 类型 | 说明 |
|---|---|---|
| id | String | 订单ID |
| contractName | String | 合约名 |
| triggerPrice | BigDecimal | 触发价格 |
| price | BigDecimal | 委托价格 |
| pricePrecision | Integer | 价格精度(小数位数) |
| volume | BigDecimal | 委托数量 |
| base | String | 基础币种(如BTC) |
| quote | String | 计价币种(如USDT) |
xxxxxxxxxxPOST https://openapi.xxx.xx/sapi/v1/withdraw/apply| Name | Type | Description |
|---|---|---|
| X-CH-APIKEY* | String | 您的API-Key |
| X-CH-SIGN* | String | 签名 |
| X-CH-TS* | Integer | 时间戳 |
| Name | Type | Description |
|---|---|---|
| withdrawOrderId* | String | 自定义提现id,保证唯一 |
| amount* | String | 数量 |
| address* | String | 提币地址 |
| label | String | 某些币种例如 XRP,XMR 允许填写次级地址标签 |
| symbol | String | 币种,支持多主链的币需要传实际的币种名称,参照附录1 |
200: OK
xxxxxxxxxx{ "code":"Ѳ",//返回码,0代表成功,其他失败 "msg":"sucess",//返回信息 "data":{ "id":518353 //提现id }}权重(IP/UID): 100
xxxxxxxxxxPOST https://openapi.xxx.xx/sapi/v1/withdraw/query| Name | Type | Description |
|---|---|---|
| X-CH-APIKEY* | String | 您的API-Key |
| X-CH-SIGN* | String | 签名 |
| X-CH-TS* | String | 时间戳 |
| Name | Type | Description |
|---|---|---|
| symbol | String | 币种,支持多主链的币需要传实际的币种名称,参照附录1 |
| withdrawId | String | 平台提现id |
| withdrawOrderId | String | 自定义提现id |
| startTime | Number | 开始时间,时间戳,默认90天前 |
| endTime | Number | 结束时间,时间戳,默认当前时间 |
| page | String | 页码,从1开始 |
200: OK
xxxxxxxxxx{ "code": "0", "msg": "成功", "data": { "withdrawList": [ { "symbol": "TUSDT", "amount": 19.99999, "address": "TFFrjNfBAagmFWypE3Hnv6zPKAFhd3VcDf", "withdrawOrderId": "abc123", "fee": 0.00001, "ctime": 1605585397000, "txId": "749864_20201117115930", "id": 749864, "applyTime": 1666754820000, "status": 5, "info": "" }, { "symbol": "TUSDT", "amount": 10.50999, "address": "TYsTiVVDU5VmnUPufzGD52CD1hSbPATT3Q", "withdrawOrderId": "abc456", "fee": 0.00001, "ctime": 1607089149000, "txId": "764294_20201204094130", "id": 764294, "applyTime": 1666754820000, "status": 5, "info": "" } ], "count": 2 }}权重(IP/UID): 100
| 参数 | 类型 | 示例 | 备注 |
|---|---|---|---|
| symbol | String | USDT | 提币币种 |
| amount | Number | 9.99 | 数量 |
| address | String | TFFrjNfBAagmFWypE3Hnv6zPKAFhd3VcDf | 提币地址 |
| withdrawOrderId | String | abc123 | 自定义提现id |
| fee | Number | 0.01 | 手续费 |
| ctime | Number | 1605585397000 | 创建时间 |
| txId | String | 749864_20201117115930 | 提现交易id |
| id | Number | 749864 | 平台提现id |
| applyTime | Number | 1605585397000 | 上链时间 |
| status | Number | 2 | 提币状态,0-未审核 1-审核通过 2-审核拒绝 3-支付中 4-支付失败 5-已完成 6-已撤销 |
| info | String | 提币地址错误 | 审核拒绝原因 |
WebSocket是HTML5一种新的协议(Protocol)。它实现了客户端与服务器全双工通信, 使得数据可以快速地双向传播。通过一次简单的握手就可以建立客户端和服务器连接, 服务器根据业务规则可以主动推送信息给客户端。其优点如下:
客户端和服务器进行数据传输时,请求头信息比较小,大概2个字节。
客户端和服务器皆可以主动地发送数据给对方。
不需要多次创建TCP请求和销毁,节约宽带和服务器的资源。
强烈建议开发者使用WebSocket API获取市场行情和买卖深度等信息。
行情基础站点: wss://ws.xxx.com/kline-api/ws
返回数据都会二进制压缩(用户需要通过Gzip算法进行解压)
服务器每10秒主动推送ping消息,客户端接收到后可自行决定是否处理(服务器并不对客户端的pong回复进行严格的一对一校验和时间校验)。 为了保障链接的有效性,建议客户端在收到服务器的ping消息后立即回复pong。 服务端发送ping消息格式: {"ping": 时间戳(秒级)} 客户端回复pong消息格式: {"pong": 时间戳(秒级)} 示例: {"pong":1694416595}
| sub | market_$symbol_depth_step0 | 订阅深度 | 描述 | |
|---|---|---|---|---|
| unsub | market_$symbol_depth_step0 | 取消订阅深度 | 币对名称 | |
| sub | market_$symbol_trade_ticker | 订阅实时成交 | base货币 | |
| unsub | market_$symbol_trade_ticker | 取消订阅实时成交 | 计价货币 | |
| sub | market_$symbol_ticker | 订阅24h行情数据 | 价格精度 | |
| unsub | market_$symbol_ticker | 取消订阅24h行情数据 | 数量精度 | |
| sub | market_$symbol_kline_1min | 订阅1min实时k线信息 | ||
| reg | market_$symbol_kline_1month | 请求1month历史k线记录 |
xxxxxxxxxx{ "event":"sub", "params":{ "channel":"market_$symbol_kline_[1min/5min/15min/30min/60min/1day/1week/1month]", // $symbol E.g. btcusdt "cb_id":"1" // 业务id 非必填 }}返回
xxxxxxxxxx{ "channel":"market_$symbol_kline_1min", //1min代表1分钟k线 "ts":1506584998239,//请求时间 "tick":{ "id":1506602880,//时间刻度起始值 "vol":1212.12211,//交易量 "open":2233.22,//开盘价 "close":1221.11,//收盘价 "high":22322.22,//最高价 "low":2321.22//最低价 }}订阅数据样例
xxxxxxxxxx{ "event":"sub", "params":{ "channel":"market_$symbol_ticker", // $symbol E.g. btcusdt "cb_id":"1" // 业务id 非必填 }}返回
xxxxxxxxxx{ "channel":"market_$symbol_ticker", "ts":1506584998239,//请求时间 "tick":{ "amount":123.1221,//交易额 "vol":1212.12211,//交易量 "open":2233.22,//开盘价 "close":1221.11,//收盘价 "high":22322.22,//最高价 "low":2321.22,//最低价 "rose":-0.2922,//涨幅 }}请求数据样例
xxxxxxxxxx{ "event":"req", "params":{ "channel":"market_$symbol_kline_[1min/5min/15min/30min/60min/1day/1week/1month]", "cb_id":"1", "endIdx":"1506602880", //返回endIdx前pageSize条数据 非必填 "pageSize":100 // 非必填 }}返回
xxxxxxxxxx{ "event_rep":"rep","channel":"market_$symbol_kline_5min","cb_id":"原路返回", "ts":1506584998239,//请求时间 "data":[ //最多300条 { "id":1506602880,//时间刻度起始值 "amount":123.1221,//交易额 "vol":1212.12211,//交易量 "open":2233.22,//开盘价 "close":1221.11,//收盘价 "high":22322.22,//最高价 "low":2321.22//最低价 }, { "id":1506602880,//时间刻度起始值 "amount":123.1221,//交易额 "vol":1212.12211,//交易量 "open":2233.22,//开盘价 "close":1221.11,//收盘价 "high":22322.22,//最高价 "low":2321.22//最低价 } ]}请求数据样例
xxxxxxxxxx{ "event":"req", "params":{ "channel":"market_$symbol_trade_ticker", // $symbol E.g. btcusdt "cb_id":"1" // 业务id 非必填 }}返回
xxxxxxxxxx{ "event_rep":"rep","channel":"market_$symbol_trade_ticker", "cb_id":"原路返回", "ts":1506584998239,"status":"ok", "data":[ { "side":"buy",//买卖方向buy,sell "price":32.233,//单价 "vol":232,//数量 "amount":323//总额 }, { "side":"buy",//买卖方向buy,sell "price":32.233,//单价 "vol":232,//数量 "amount":323//总额 } ]}
错误码解释说明
返回报错一般由两个部分组成:错误码和错误信息。错误码是通用的,但是错误信息会有所不同。如下是一个报错JSON Payload示例:
xxxxxxxxxx{ "code":-1121, "msg":"Invalid symbol."}
| code | 描述 |
|---|---|
| -1000 | 处理请求时发生未知错误 |
| -1001 | 内部错误,无法处理您的请求,请再试一次 |
| -1002 | 您无权执行此请求. 请求需要发送API key,我们建议在所有的请求头附加APIkey |
| -1003 | 请求过于频繁超过限制 |
| -1004 | 您无权执行此请求,User not exit Company |
| -1006 | 接收到了不符合预设格式的消息,下单状态未知 |
| -1007 | 等待后端服务器响应超时.发送状态未知,执行状态未知 |
| -1014 | 不支持的订单组合 |
| -1015 | 新订单太多,请减少你的请求频率 |
| -1016 | 服务器下线 |
| -1017 | 我们建议在所有的请求头附加Content-Type,并设置成application/json |
| -1020 | 不支持此操作 |
| -1021 | 时延过大,服务器根据接请求中的时间戳判定耗时已经超出了recevWindow。请改善网络条件或者增大recevWindow 时间偏移过大,服务器根据请求中的时间戳判定客户端时间比服务器时间提前了1秒钟以上 |
| -1022 | 此请求的签名无效 |
| -1023 | 您无权执行此请求, 我们建议您在所有的请求头附加X-CH-TS |
| -1024 | 您无权执行此请求, 我们建议您在请求头附加X-CH-SIGN |
| code | 描述 |
|---|---|
| -1100 | 在参数中发现非法字符 |
| -1101 | 发送的参数太多。 检测到的参数值重复 |
| -1102 | 未发送强制性参数,该参数为空/空或格式错误。 强制参数'%s'未发送,为空/空或格式错误。 必须发送参数'%s'或'%s',但两者均为空 |
| -1103 | 发送了未知参数。每条请求需要至少一个参数{Timestamp} |
| -1104 | 并非所有发送的参数都被读取。并非所有发送的参数都被读取; 读取了'%s'参数,但被发送了'%s' |
| -1105 | 参数为空。参数'%s'为空。 |
| -1106 | 不需要时已发送参数。不需要时发送参数'%s'。 |
| -1111 | 精度超过为此资产定义的最大值。 |
| -1112 | 交易对没有挂单 |
| -1116 | 无效订单类型。 |
| -1117 | 无效买卖方向 |
| -1118 | 新的客户订单ID为空 |
| -1121 | 无效的symbol |
| -1136 | 订单quantity小于最小值 |
| -1138 | 订单价格超出允许范围 |
| -1139 | 该交易对不支持市价交易 |
| -1145 | 该订单类型不支持撤销 |
| -2013 | Order不存在 |
| -2015 | 无效的API密钥,IP或操作权限 |
| -2016 | 交易被冻结 |
| -2017 | 余额不足 |
https://github.com/exchange2021window.location='https://github.com/exchange2021')
签名规则请参考签名示例
Java
xxxxxxxxxxOkHttpClient client = new OkHttpClient().newBuilder() .build();MediaType mediaType = MediaType.parse("application/json");RequestBody body = RequestBody.create(mediaType, "{\"symbol\":\"BTCUSDT\",\"volume\":1,\"side\":\"BUY\",\"type\":\"LIMIT\",\"price\":10000,\"newClientOrderId\":\"\",\"recvWindow\":5000}");Request request = new Request.Builder() .url("https://openapi.xxx.com") .method("POST", body) .addHeader("X-CH-APIKEY", "Your API key") .addHeader("X-CH-TS", "1596543296058") .addHeader("Content-Type", "application/json") .addHeader("X-CH-SIGN", "encrypt sign") .build();Response response = client.newCall(request).execute();Go
xxxxxxxxxxpackage main
import ( "fmt" "strings" "net/http" "io/ioutil")
func main() {
url := "https://openapi.xxx.com" method := "POST"
payload := strings.NewReader("{\"symbol\":\"BTCUSDT\",\"volume\":1,\"side\":\"BUY\",\"type\":\"LIMIT\",\"price\":10000,\"newClientOrderId\":\"\",\"recvWindow\":5000}")
client := &http.Client { } req, err := http.NewRequest(method, url, payload)
if err != nil { fmt.Println(err) } req.Header.Add("X-CH-APIKEY", "Your API key") req.Header.Add("X-CH-TS", "1596543881257") req.Header.Add("Content-Type", "application/json") req.Header.Add("X-CH-SIGN", "encrypt sign")
res, err := client.Do(req) defer res.Body.Close() body, err := ioutil.ReadAll(res.Body)
fmt.Println(string(body))}Python
xxxxxxxxxximport requests
url = "https://openapi.xxx.com"
payload = "{\"symbol\":\"BTCUSDT\",\"volume\":1,\"side\":\"BUY\",\"type\":\"LIMIT\",\"price\":10000,\"newClientOrderId\":\"\",\"recvWindow\":5000}"headers = { 'X-CH-APIKEY': 'Your API key', 'X-CH-TS': '1596543881257', 'Content-Type': 'application/json', 'X-CH-SIGN': 'encrypt sign'}
response = requests.request("POST", url, headers=headers, data = payload)
print(response.text.encode('utf8'))Php
xxxxxxxxxx<?phprequire_once 'HTTP/Request2.php';$request = new HTTP_Request2();$request->setUrl('https://openapi.xxx.com');$request->setMethod(HTTP_Request2::METHOD_POST);$request->setConfig(array( 'follow_redirects' => TRUE));$request->setHeader(array( 'X-CH-APIKEY' => 'Your API key', 'X-CH-TS' => '1596543881257', 'Content-Type' => 'application/json', 'X-CH-SIGN' => 'encrypt sign'));$request->setBody('{"symbol":"BTCUSDT","volume":1,"side":"BUY","type":"LIMIT","price":10000,"newClientOrderId":"","recvWindow":5000}');try { $response = $request->send(); if ($response->getStatus() == 200) { echo $response->getBody(); } else { echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' . $response->getReasonPhrase(); }}catch(HTTP_Request2_Exception $e) { echo 'Error: ' . $e->getMessage();}NodeJs
xxxxxxxxxxvar request = require('request');var options = { 'method': 'POST', 'url': 'https://openapi.xxx.com', 'headers': { 'X-CH-APIKEY': 'Your API key', 'X-CH-TS': '1596543881257', 'Content-Type': 'application/json', 'X-CH-SIGN': 'encrypt sign' }, body: JSON.stringify({"symbol":"BTCUSDT","volume":1,"side":"BUY","type":"LIMIT","price":10000,"newClientOrderId":"","recvWindow":5000})
};request(options, function (error, response) { if (error) throw new Error(error); console.log(response.body);});
服务器收到请求时会判断请求中的时间戳,如果是5000毫秒之前发出的,则请求会被认为无效。这个时间窗口值可以通过发送可选参数recvWindow来自定义。
首先建议用户打印一下X-CH-TS,出现异常时检查X-CH-TS是否为空,另外建议用户代码优化,每次请求前先判断X-CH-TS是否为空。
可以打印出请求头信息和签名前字符串,重点有以下几点:
将您的请求头和下面的请求头示例一一对比
xxxxxxxxxx请求头示例:
Content-Type: application/json
X-CH-APIKEY: 44c541a1-****-****-****-10fe390df2
X-CH-SIGN: ssseLeefrffraoEQ3yI9qEtI1CZ82ikZ4xSG5Kj8gnl3uw=
X-CH-TS: 1574327555669是否在程序中正确的配置了API-key
签名前字符串是否符合标准格式, 所有要素的顺序要保持一致. 可以复制如下示例跟您的签名前字符串进行比对:
xxxxxxxxxxGET示例: 1588591856950GET/sapi/v1/account
POST示例:1588591856950POST/sapi/v1/order/test{"symbol":"BTCUSDT","price":"9300","volume":"1","side通常情况下不会的,降低访问频率就可以。
未添加心跳,WebSocket连接需客户端需要回pong,保证连接的稳定。
网络原因造成客户端发送的pong消息,但服务端并未接收到,或其他网络原因也会导致自动断开连接。
建议用户做好WebSocket断开重连机制,在确保心跳(ping/pong)连接意外断开时,程序能够自动重新进行连接。
网络无法连接服务器,建议您检查下网络是否通畅。
币币的 /sapi/v1/symbols 接口可以拿到
是的, 批量接口会限制10条订单
newClientOrderId是您自定义的订单号,可以用来标识您的一笔订单,当下单完成后,可以使newClientOrderId调用 “订单信息“接口,查看订单状态;
用户需要自己保证此ID不重复,我方不会进行排重提示,如有重复,撤单和查询订单时只能撤销或者查询最新的一条数据
可以通过获取ticker信息, last就是最新成交价
会的。因为24小时成交量,为24小时滚动数据(平移窗口大小24小时),有可能会出现后一个窗口内的累计成交量、累计成交额小于前一窗口的情况。