API文档
安全认证
ApiKey为API 访问密钥,ApiSecret为用户对请求进行签名的密钥。
重要提示:这两个密钥与账号安全紧密相关,无论何时都请勿向其它人透露
合法请求结构
基于安全考虑,除行情API 外的 API 请求都必须进行签名运算。一个合法的请求由以下几部分组成:
方法请求地址,即访问服务器地址:服务地址后面跟上方法名,比如服务地址/v1/order/place。
API 访问密钥(ApiKey) 您申请的 APIKEY 中的ApiSecret。
签名方法(SignatureMethod) 用户计算签名的基于哈希的协议,此处使用 MD5。
时间戳(timestamp) 您发出请求的时间戳。在查询请求中包含此值有助于防止第三方截取您的请求。
调用的必需参数和可选参数。可以在每个方法的说明中查看这些参数及其含义。签名计算得出的值,用于确保签名有效和未被篡改。
例:
https://服务地址/api/v1/place?
ApiKey=111
&sign=5cff3789b3f124a75b235edf03166cac
&number=1
&pair=BTC_USDT
&price=8000
×tamp=1593970637365
&type=sell
签名运算
API 请求在通过 Internet 发送的过程中极有可能被篡改。为了确保请求未被更改,我们会要求用户在每个请求中带上签名,来校验参数或参数值在传输途中是否发生了更改。
计算签名所需的步骤:
规范要计算签名的请求
因为使用 MD5进行签名计算时,使用不同内容计算得到的结果会完全不同。所以在进行签名计算前,请先对请求进行规范化处理。下面以下单请求为例进行说明
https://服务地址/api/v1/place?
number=1
×tamp=1593970637365
&ApiKey=111
&ApiSecret=222
&pair=BTC_USDT
&price=8000
&type=sell
按照ASCII码的顺序对参数名进行排序(使用 UTF-8 编码,且进行了 URI 编码,十六进制字符必须大写,如‘:’会被编码为'%3A',空格被编码为'%20')。
例如,下面是请求参数的原始顺序,进行过编码后。
&ApiSecret=222
&number=1
&pair=BTC_USDT
×tamp=1593970637365
ApiKey=111
&price=8000
&type=sell
这些参数会被排序为:
ApiKey=111
&ApiSecret=222
&number=1
&pair=BTC_USDT
&price=8000
×tamp=1593970637365
&type=sell
按照以上顺序,将各参数使用字符’&’连接。
ApiKey=111&ApiSecret=222&number=1&pair=BTC_USDT&price=8000×tamp=1593970637365&type=sell
组成最终的要进行签名计算的字符串如下:
ApiKey=111&ApiSecret=222&number=1&pair=BTC_USDT&price=8000×tamp=1593970637365&type=sell
计算签名,将以下两个参数传入加密哈希函数MD5:
要进行签名计算的字符串
ApiKey=111&ApiSecret=222&number=1&pair=BTC_USDT&price=8000×tamp=1593970637365&type=sell
进行签名得到
5cff3789b3f124a75b235edf03166cac
将上述值作为参数sign的取值添加到 API 请求中。 将此参数添加到请求时,必须将该值进行 URI 编码。
最终,发送到服务器的 API 请求应该为:
接口列表
api明细
下单:
POST /api/v1/place
参数:
参数名称
是否必须
类型
描述
默认值
取值范围
ApiKey
y
string
访问key
sign
y
string
签名
timestamp
y
long
时间戳
pair
y
string
交易对
例:BTC_USDT
type
y
string
类型
"buy" ,”sell"
number
y
decimal
数量
price
y
decimal
价钱
返回:
参数名称
是否必须
类型
描述
默认值
取值范围
status
y
int
状态码
成功:200
message
y
string
消息
data
y
object
数据
data
参数名称
是否必须
类型
描述
默认值
取值范围
ID
y
bigint
订单id
返回json
{
"data":"1280041943011512320",
"message":"success",
"status":200
}
批量下单:
POST /api/v1/placeOrders
参数:
参数名称
是否必须
类型
描述
默认值
取值范围
ApiKey
y
string
访问key
sign
y
string
签名
timestamp
y
long
时间戳
orders
y
string
下单订单json数组
[{"number":1,"pair":"BTC_USDT","price":9000,"type":"buy"}]
返回:
参数名称
是否必须
类型
描述
默认值
取值范围
status
y
int
状态码
成功:200
message
y
string
消息
data
y
object
数据
data
参数名称
是否必须
类型
描述
默认值
取值范围
ID
y
bigint
订单id数组
返回json
{
"data":[
"1279974675523129344",
"1279974675535712256"
],
"message":"success",
"status":200
}
订单取消:
POST /api/v1/cancel
参数:
参数名称
是否必须
类型
描述
默认值
取值范围
ApiKey
y
string
访问key
sign
y
string
签名
timestamp
y
long
时间戳
orderId
y
decimal
订单id
返回:
参数名称
是否必须
类型
描述
默认值
取值范围
status
y
int
状态码
成功:200,失败:300
message
y
string
消息
data
y
object
数据
返回json
{
"data":null,
"message":"success",
"status":200
}
订单批量取消:
POST /v1/order/batchCancel
参数:
参数名称
是否必须
类型
描述
默认值
取值范围
ApiKey
y
string
访问key
sign
y
string
签名
timestamp
y
long
时间戳
ids
n
string
订单id数组
['123123']
pair
n
string
交易对
返回:
参数名称
是否必须
类型
描述
默认值
取值范围
status
y
int
状态码
成功:200
message
y
string
消息
data
y
object
数据
返回json
{
"code":200,
"msg":"取消成功",
"time":1536306495984,
"data":null
}
订单详情以及撮合记录:
POST /api/v1/detailById
参数:
参数名称
是否必须
类型
描述
默认值
取值范围
ApiKey
y
string
访问key
sign
y
string
签名
timestamp
y
long
时间戳
orderId
n
string
订单id
返回:
参数名称
是否必须
类型
描述
默认值
取值范围
status
y
int
状态码
成功:200
message
y
string
消息
data
y
object
数据
返回json
{
"data":{
"id":"21343454563456",
"amount":1,
"fee":0,
"completed":1,
"type":"LIMIT",
"pair":"BTC_USDT",
"feeCoinCode":"USDT",
"total":9079.0481807,
"totalCoinCode":"USDT",
"price":8000,
"record":[
{
"direction":"sell",
"fee":0,
"feeCoinCode":"USDT",
"id":"1279843145256235008",
"number":0.257,
"orderId":"1279843145183948800",
"pair":"BTC_USDT",
"price":9080.4711,
"timestamp":1593973358806,
"type":"TAKER"
},
{
"direction":"sell",
"fee":0,
"feeCoinCode":"USDT",
"id":"1279843145256235010",
"number":0.743,
"orderId":"1279843145183948800",
"pair":"BTC_USDT",
"price":9078.556,
"timestamp":1593973358806,
"type":"TAKER"
}
],
"averagePrice":9079.0481807,
"status":"FULL_COMPLETED",
"direction":"sell"
},
"message":"success",
"status":200
}
data
参数名称
是否必须
类型
描述
默认值
取值范围
amount
y
decimal
数量
fee
y
decimal
手续费
completed
y
decimal
已经成交
type
y
string
订单类型
limit就是限价单
pair
y
string
交易对
feeCoinCode
y
string
手续费币种
total
y
decimal
成交额
totalCoinCode
y
string
成交额币种类型
price
y
decimal
价钱
direction
n
string
买或者卖
but 或者 sell
status
n
string
订单状态
PENDING:未成交 PARTIAL_COMPLETED:部分成交 PARTIAL_CANCELLED部分成交已取消 FULL_CANCELLED:全部取消 FULL_COMPLETED:全部成交
time
y
string
创建时间
时间戳
id
y
string
订单id
averagePrice
y
decimal
成交 均价
批量订单详情以及撮合记录:
POST /api/v1/detailByIds
参数:
参数名称
是否必须
类型
描述
默认值
取值范围
ApiKey
y
string
访问key
sign
y
string
签名
timestamp
y
long
时间戳
orderIds
n
string
订单id得json数组
返回:
参数名称
是否必须
类型
描述
默认值
取值范围
status
y
int
状态码
成功:200
message
y
string
消息
data
y
object
数据
返回json
{
"data":[{
"id":"202353464523121342",
"amount":1,
"fee":0,
"completed":1,
"type":"LIMIT",
"pair":"BTC_USDT",
"feeCoinCode":"USDT",
"total":9079.0481807,
"totalCoinCode":"USDT",
"price":8000,
"record":[
{
"direction":"sell",
"fee":0,
"feeCoinCode":"USDT",
"id":"1279843145256235008",
"number":0.257,
"orderId":"1279843145183948800",
"pair":"BTC_USDT",
"price":9080.4711,
"timestamp":1593973358806,
"type":"TAKER"
},
{
"direction":"sell",
"fee":0,
"feeCoinCode":"USDT",
"id":"1279843145256235010",
"number":0.743,
"orderId":"1279843145183948800",
"pair":"BTC_USDT",
"price":9078.556,
"timestamp":1593973358806,
"type":"TAKER"
}
],
"averagePrice":9079.0481807,
"status":"FULL_COMPLETED",
"direction":"sell"
}
],
"message":"success",
"status":200
}
data
参数名称
是否必须
类型
描述
默认值
取值范围
amount
y
decimal
数量
fee
y
decimal
手续费
completed
y
decimal
已经成交
type
y
string
订单类型
limit就是限价单
pair
y
string
交易对
feeCoinCode
y
string
手续费币种
total
y
decimal
成交额
totalCoinCode
y
string
成交额币种类型
price
y
decimal
价钱
direction
n
string
买或者卖
buy 或者 sell
status
n
string
订单状态
PENDING:未成交 PARTIAL_COMPLETED:部分成交 PARTIAL_CANCELLED部分成交已取消 FULL_CANCELLED:全部取消 FULL_COMPLETED:全部成交
time
y
string
创建时间
时间戳
id
y
string
订单id
averagePrice
y
decimal
成交 均价
获取委单列表:
POST /api/v1/entrust
参数:
参数名称
是否必须
类型
描述
默认值
取值范围
ApiKey
y
string
访问key
sign
y
string
签名
timestamp
y
long
时间戳
pair
y
string
交易对
size
n
int
列表大小
isPending
n
int
1:正在进行得订单 0:历史订单
返回:
参数名称
是否必须
类型
描述
默认值
取值范围
status
y
int
状态码
成功:200
message
y
string
消息
data
y
object
数据
data
参数名称
是否必须
类型
描述
默认值
取值范围
entrutsCur
n
array(object)
当前委单
entrutsHis
n
array(object)
历史委单
entrutsCur 及 entrutsHis类型相同
参数名称
是否必须
类型
描述
默认值
取值范围
id
y
bigint
委单id
time
y
string
下单时间
types
y
string
委单类型
买单、卖单
source
y
string
委单来源
"WEB","APP","API"
price
y
decimal
下单价格
count
y
decimal
下单数量
leftcount
y
decimal
未成交数量
last
y
decimal
成交价格
successamount
y
decimal
成交总价
fees
y
decimal
手续费
status
y
string
委单状态
未成交、部分成交、完全成交、撤单处理中、已撤销
type
y
int
委单类型
0( "买单"),1( "卖单")
buysymbol
y
string
币种类型符号
sellsymbol
y
string
币种类型符号
返回json
{
"data":[
{
"averagePrice":9001,
"balanceId":"",
"direction":"buy",
"feeRate":0,
"id":"1279974675535712256",
"number":1,
"pair":"BTC_USDT",
"price":9001,
"remain":1,
"script":false,
"status":"PENDING",
"timestamp":1594004718084,
"type":"LIMIT",
"userId":"379"
},
{
"averagePrice":9000,
"balanceId":"",
"direction":"buy",
"feeRate":0,
"id":"1279974675523129344",
"number":1,
"pair":"BTC_USDT",
"price":9000,
"remain":1,
"script":false,
"status":"PENDING",
"timestamp":1594004718082,
"type":"LIMIT",
"userId":"379"
},
{
"averagePrice":9421.5999,
"balanceId":"",
"direction":"buy",
"feeRate":0,
"id":"1279973743552143360",
"number":2.181,
"pair":"BTC_USDT",
"price":9421.5999,
"remain":2.181,
"script":false,
"status":"PENDING",
"timestamp":1594004495882,
"type":"LIMIT",
"userId":"379"
}
],
"message":"success",
"status":200
}
获取k线数据:
POST api/v1/kline
参数:
参数名称
是否必须
类型
描述
默认值
取值范围
pair
n
string
交易对
limit
n
int
列表大小
type
y
int
时间
1m(1分钟),5m(5分钟),15m(15分钟),30m(30分钟),1h(1小时),4h(4小时),6h(6小时),8h(8小时),12h(12小时),1d(1天),1w(1周),1M(1月)
返回 :
参数名称
是否必须
类型
描述
默认值
取值范围
status
y
int
状态码
成功:200
message
y
string
消息
data
y
object
data
[[
1527820200000, //int 时间
54598.5, //float 开
54598.5, //float 高
54598.5, //float 低
54598.5, //float 收
0.0000 //float 量
],
......
]
返回json
{
"code":200,
"msg":"成功",
"time":1527838104874,
"data":[
[1597743240000,0.620809,0.620809,0.620809,0.620809,0.0]
]
}
获取深度数据:
POST api/v1/depth
参数:
参数名称
是否必须
类型
描述
默认值
取值范围
pair
y
string
交易对
length
n
int
列表大小
scale
y
int
精度
返回 :
参数名称
是否必须
类型
描述
默认值
取值范围
status
y
int
状态码
成功:200
message
y
string
消息
data
y
object
返回数据格式:
参数名称|是否必须|类型|描述|默认值|取值范围
------------- | ------------- | ------------- | ------------- | ------------- | -------------
ask|y|array|卖盘数据 [价格,数量]||
bids|y|array|买盘数据 [价格,数量]||
返回json
{
"data":{
"ask":[
[
9270.3,
0
],
[
9267.6048,
0.007
],
[
9265.11,
0
],
[
9263.022,
0
],
[
9257.4282,
0
]
],
"bids":[
[
9253.372,
5.757
],
[
9248.471,
9.03
],
[
9245.9015,
8.5345
],
[
9241.4667,
6.11098
],
[
9241.1928,
0.03
]
]
},
"message":"success",
"status":200
}
获取实时成交:
POST api/v1/trade
参数:
参数名称
是否必须
类型
描述
默认值
取值范围
pair
n
string
交易对
size
n
int
列表大小
返回 :
参数名称
是否必须
类型
描述
默认值
取值范围
status
y
int
状态码
成功:200
message
y
string
消息
data
y
object
返回数据格式:
参数名称|是否必须|类型|描述|默认值|取值范围
------------- | ------------- | ------------- | ------------- | ------------- | -------------
direction|y|string|买或者卖||
number|y|decimal|成交数量||
price|y|decimal|成交价格||
timestamp|y|int|时间戳||
返回json
{
"data":[
{
"direction":"sell",
"number":0.00285,
"price":9281.1517,
"timestamp":1594127712939
}
],
"message":"success",
"status":200
}
获取余额:
POST /api/v1/balance
参数:
参数名称
是否必须
类型
描述
默认值
取值范围
ApiKey
y
string
访问key
sign
y
string
签名
timestamp
y
long
时间戳
coinCode
y
string
币种名称
返回:
参数名称
是否必须
类型
描述
默认值
取值范围
status
y
int
状态码
成功:200
message
y
string
消息
data
y
object
数据
data
参数名称
是否必须
类型
描述
默认值
取值范围
balanceAvailable
y
decimal
可用余额
balanceFrozen
y
decimal
冻结余额
worth
y
decimal
值多少美金,非USDT会有值
coinCode
y
string
币种名称
返回json
{
"data":[
{
"balanceAvailable":9819082470896.950192420426,
"balanceFrozen":4362405458.218929855757,
"coinCode":"USDT",
"worth":null
}
],
"message":"success",
"status":200
}
获取用户所有余额:
POST /api/v1/balanceList
参数:
参数名称
是否必须
类型
描述
默认值
取值范围
ApiKey
y
string
访问key
sign
y
string
签名
timestamp
y
long
时间戳
返回:
参数名称
是否必须
类型
描述
默认值
取值范围
status
y
int
状态码
成功:200
message
y
string
消息
data
y
List
数据
data
参数名称
是否必须
类型
描述
默认值
取值范围
balanceAvailable
y
decimal
可用余额
balanceFrozen
y
decimal
冻结余额
lock
y
decimal
锁仓余额
worth
y
decimal
值多少美金,非USDT会有值
coinCode
y
string
币种名称
返回json
{
"data":[
{
"balanceAvailable":0,
"balanceFrozen":0,
"coinCode":"ALGO",
"lock":0,
"worth":0.534
},
{
"balanceAvailable":0,
"balanceFrozen":0,
"coinCode":"AMP",
"lock":0,
"worth":0.059605
},
{
"balanceAvailable":0,
"balanceFrozen":0,
"coinCode":"ANT",
"lock":0,
"worth":0
}
],
"message":"success",
"status":200
}