合约推送订阅
接入说明
WebSocket域名
wss://wss-ct.hotcoin.fit
订阅主题
成功建立与Websocket服务器的连接后,Websocket客户端发送subscribe请求以订阅特定主题:
Request
{
"event": "subscribe",
"params": {
"biz": "perpetual", //固定传参
"type": "topic to subscribe", //主题类型
"contractCode": "contractCode", //合约代号
"zip": false, //固定压缩
"serialize": false //是否序列化
}
}
params参数说明
| 参数名称 | 是否必须 | 类型 | 描述 | 默认值 | 取值范围 |
|---|---|---|---|---|---|
| biz | y | string | 业务 | perpetual | |
| type | y | string | 类型 | depth | |
| contractCode | y | string | 合约code | ||
| zip | N | boolean | 是否压缩 | false | |
| serialize | N | boolean | 是否序列化 | false |
成功订阅后,Websocket客户端将收到确认消息:
Response
{
"biz": "perpetual",
"data": {
"result": true
},
"channel": "subscribe",
"type": "fund_rate",
"env": 0,
"contractCode": "btcusdt"
}
订阅结果
- data对象说明
| 类型 | 字段名 | 说明 |
|---|---|---|
| boolean | result | 订阅结果(true:成功 false:失败) |
之后, 一旦所订阅的主题有数据更新,热币服务器将向Websocket客户端推送更新消息。
维持
当用户的Websocket客户端连接到热币服务器后,用户需要定期向服务器发送心跳信息,否则5分钟之后将接收不到任何推送,如下:
Request
{
"event": "ping"
}
- 请求参数
| 类型 | 字段名 | 说明 |
|---|---|---|
| String | event | ping |
成功发送后,Websocket客户端将收到确认消息,如下:
Response
{
"event": "pong"
}
- 返回结果
| 类型 | 字段名 | 说明 |
|---|---|---|
| String | event | pong:成功 |
取消订阅
Request
{
"event": "unsubscribe",
"params": {
"biz": "perpetual",
"type": "topic to subscribe",
"contractCode": "contractCode",
"zip": false,
"serialize": false
}
}
取消订阅参数说明
| 参数名称 | 是否必须 | 类型 | 描述 | 默认值 | 取值范围 |
|---|---|---|---|---|---|
| biz | y | string | 业务 | perpetual | |
| type | y | string | 类型 | depth | |
| contractCode | y | string | 合约code | ||
| zip | N | boolean | 是否压缩 | false | |
| serialize | N | boolean | 是否序列化 | false |
Response
{
"biz": "perpetual",
"data": {
"result": true
},
"channel": "unsubscribe",
"type": "fund_rate",
"contractCode": "ethusdt",
"env": 0
}
取消订阅成功确认
| 类型 | 字段名 | 说明 |
|---|---|---|
| boolean | result | 订阅结果(true:成功 false:失败) |
PING
Request
{
"event": "ping"
}
请求参数
| 类型 | 字段名 | 说明 |
|---|---|---|
| String | event | ping |
Response
{
"event": "pong"
}
返回结果
| 类型 | 字段名 | 说明 |
|---|---|---|
| String | event | pong:成功 |
ws 登录
资产WebSocket签名与Rest接口签名步骤相似。
/**
* 版本号
*/
private final static int VERSION = 2;
/**
* 加密方法
*/
private final static String HmacSHA256 = "HmacSHA256";
/**
* 请求地址
*/
private final static String HOST = "api.ws.contract.hotcoin.top";
private final static String httpMethod = "wss";
public String getWsSignature(String accessKey, String uri, String timestamp,String secretKey) {
Map<String, Object> params = new HashMap<>(4);
params.put("AccessKeyId", accessKey);
params.put("SignatureVersion", VERSION);
params.put("SignatureMethod", HmacSHA256);
params.put("Timestamp", timestamp);
return getSignature(secretKey, HOST, uri, httpMethod, params);
}
/**
* 签名
*
* @param apiSecret
* @param host 固定为"api.ws.contract.hotcoin.top"
* @param uri 例如:"signin"
* @param httpMethod 固定为"wss"
* @param params
* @return
* @throws Exception
*/
public String getSignature(String apiSecret, String host, String uri, String httpMethod, Map<String, Object> params) {
StringBuilder sb = new StringBuilder(1024);
sb.append(httpMethod.toUpperCase()).append('\n')
.append(host.toLowerCase()).append('\n')
.append(uri).append('\n');
SortedMap<String, Object> map = new TreeMap<>(params);
for (Map.Entry<String, Object> entry : map.entrySet()) {
String key = entry.getKey();
String value = entry.getValue().toString();
try {
sb.append(key).append('=').append(URLEncoder.encode(value, "UTF-8")).append('&');
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
sb.deleteCharAt(sb.length() - 1);
Mac hmacSha256;
try {
hmacSha256 = Mac.getInstance(HmacSHA256);
SecretKeySpec secKey =
new SecretKeySpec(apiSecret.getBytes(StandardCharsets.UTF_8), HmacSHA256);
hmacSha256.init(secKey);
} catch (Exception e) {
return null;
}
String payload = sb.toString();
System.out.println(payload);
byte[] hash = hmacSha256.doFinal(payload.getBytes(StandardCharsets.UTF_8));
//需要对签名进行base64的编码
String actualSign = Base64.getEncoder().encodeToString(hash);
actualSign = actualSign.replace("\n", "");
return actualSign;
}
Request
{
"event": "signin",
"params": {
"apiKey": "xxx",
"timestamp": "1593683685313",
"signature": "xxx"
}
}
请求参数
| 参数名称 | 是否必须 | 类型 | 描述 | 默认值 | 取值范围 |
|---|---|---|---|---|---|
| apiKey | y | string | 访问key | ||
| signature | y | string | 签名,签名方式请看签名示列 | ||
| timestamp | y | string | 时间戳 |
Response
{
"data": {
"result": true
},
"channel": "signin"
}
返回结果
- data对象说明
| 类型 | 字段名 | 说明 |
|---|---|---|
| boolean | result | 登陆结果(true:成功 false:失败) |
| String | error_msg | 错误信息(登陆失败会返回错误信息) |
| String | error_code | 错误码(登陆失败会返回错误码) |
ws 深度
Request
{
"event": "subscribe",
"params": {
"biz": "perpetual",
"type": "depth",
"contractCode": "ethusdt",
"zip": false,
"serialize": false
}
}
请求参数
| 参数名称 | 是否必须 | 类型 | 描述 | 默认值 | 取值范围 |
|---|---|---|---|---|---|
| biz | y | string | 业务 | perpetual | |
| type | y | string | 类型 | depth | |
| contractCode | y | string | 合约code | ||
| zip | N | boolean | 是否压缩 | false | |
| serialize | N | boolean | 是否序列化 | false |
Response
{
"biz": "perpetual",
"data": {
"result": true
},
"channel": "subscribe",
"type": "depth",
"contractCode": "ethusdt"
}
返回结果
- data对象说明
| 类型 | 字段名 | 说明 |
|---|---|---|
| boolean | result | 订阅结果(true:成功 false:失败) |
Response
{
"biz": "perpetual",
"data": {
"asks": [
[
"250.00000",
"94",
"94"
]
],
"bids": [
[
"216.01000",
"5319",
"5319"
]
]
},
"granularity": "1",
"type": "depth",
"env": 0,
"contractCode": "LTCUSDT",
"timestamp": 1712798513490
}
推送结果
- 推送数据data对象说明
| 类型 | 字段名 | 说明 |
|---|---|---|
| String[] | asks | 卖盘有序数组 [价格,数量, 总数量] |
| String[] | bids | 买盘有序数组 [价格,数量, 总数量] |
ws K线
Request
{
"event": "subscribe",
"params": {
"biz": "perpetual",
"type": "candles",
"contractCode": "ethusdt",
"granularity": "1min",
"zip": false,
"serialize": false
}
}
请求参数
| 参数名称 | 是否必须 | 类型 | 描述 | 默认值 | 取值范围 |
|---|---|---|---|---|---|
| biz | y | string | 业务 | perpetual | |
| type | y | string | 类型 | mark_candles-指数标记价格K线,candles-最新价K线 | |
| contractCode | y | string | 合约code | ||
| granularity | y | string | K线类型 | 1min,3min,5min,15min,30min,1hour,2hour,4hour,6hour,12hour,day,week | |
| zip | N | boolean | 是否压缩 | false | |
| serialize | N | boolean | 是否序列化 | false |
Response
{
"biz": "perpetual",
"data": {
"result": true
},
"granularity": "1min",
"channel": "subscribe",
"type": "candles",
"env": 0,
"contractCode": "BTCUSDT"
}
订阅结果
- data对象说明
| 类型 | 字段名 | 说明 |
|---|---|---|
| boolean | result | 登陆结果(true:成功 false:失败) |
推送结果
Response
{
"biz": "perpetual",
"data": [
[
1712803200000,
"70872.27",
"70918.11",
"70872.27",
"70895.61",
"6058",
"429456.52294"
]
],
"granularity": "1min",
"type": "candles",
"env": 0,
"contractCode": "btcusdt",
"timestamp": 1712803237414
}
- 推送数据data对象说明(最新价K线)
| 类型 | 字段名 | 说明 |
|---|---|---|
| String[] | data | 数据有序数组 [0]时间,[1]最低价,[2]最高价,[3]开盘价,[4]收盘价,[5]成交量,[6]交易价值] |
Response
{
"biz": "perpetual",
"data": [
[
1712803200000,
"70872.27",
"70918.11",
"70872.27",
"70895.61",
"6058",
"429456.52294",
"70895.61",
"6058",
"429456.52294"
]
],
"type": "mark_candles",
"contractCode": "ethusdt",
"granularity": "1min",
"env": 0,
"timestamp": 1712803237414
}
- 推送数据data对象说明(指数标记价格K线)
| 类型 | 字段名 | 说明 |
|---|---|---|
| String[] | data | 数据有序数组 [0]毫秒时间戳,[1]指数价低,[2]指数价高,[3]指数价开,[4]指数价收,[5]标记价低,[6]标记价高,[7]标记价开,[8]标记价收 |
ws行情单个币对
Request
{
"event": "subscribe",
"params": {
"serialize": false,
"biz": "perpetual",
"type": "ticker",
"contractCode": "btcusdt"
}
}
请求参数
| 参数名称 | 是否必须 | 类型 | 描述 | 默认值 | 取值范围 |
|---|---|---|---|---|---|
| biz | y | string | 业务 | perpetual | |
| type | y | string | 类型 | ticker | |
| contractCode | y | string | 合约code | ||
| zip | N | boolean | 是否压缩 | false | |
| serialize | N | boolean | 是否序列化 | false |
Response
{
"biz": "perpetual",
"data": {
"result": true
},
"channel": "subscribe",
"type": "ticker",
"contractCode": "btcusdt",
"env": 0
}
订阅结果
- data对象说明
| 类型 | 字段名 | 说明 |
|---|---|---|
| boolean | result | 订阅结果(true:成功 false:失败) |
Response
{
"biz": "perpetual",
"data": [
[
1712800975802,
"99999.00",
"60000.00",
"15021528",
"1042275165",
"69539.35",
"70615.76",
1065,
"1.55",
"70598.22",
"70607.15",
"btcusdt",
"508041.27",
0
]
],
"type": "ticker",
"env": 0,
"contractCode": "btcusdt",
"timestamp": 1712800977406
}
推送结果
- 推送数据data对象说明
| 类型 | 字段名 | 说明 |
|---|---|---|
| String[] | data | 数据有序数组 [0]数据时间戳,[1]最高价,[2]最低价,[3]成交数量,[4]成交价值,[5]开盘价,[6]最新价,[7]24小时价格涨跌幅,[8]24小时价格涨跌幅比率,[9]买一价,[10]卖一价,[11]合约代码,[12]最新价折合CNY,[13]是否测试币 |
ws行情所有币对
Request
{
"event": "subscribe",
"params": {
"biz": "perpetual",
"type": "tickers",
"zip": false,
"serialize": false
}
}
请求参数
| 参数名称 | 是否必须 | 类型 | 描述 | 默认值 | 取值范围 |
|---|---|---|---|---|---|
| biz | y | string | 业务 | perpetual | |
| type | y | string | 类型 | tickers | |
| zip | N | boolean | 是否压缩 | false | |
| serialize | N | boolean | 是否序列化 | false |
Response
{
"biz": "perpetual",
"data": {
"result": true
},
"channel": "subscribe",
"type": "tickers",
"env": 0
}
订阅结果
- data对象说明
| 类型 | 字段名 | 说明 |
|---|---|---|
| boolean | result | 订阅结果(true:成功 false:失败) |
Response
{
"biz": "perpetual",
"data": [
[
1712762705687,
"99999.00",
"60000.00",
"15179004",
"1048002762",
"69191.55",
"68444.85",
"-746",
"-0.3",
"68444.39",
"68445.31",
"btcusdt",
"491432.98",
0
]
],
"type": "tickers",
"env": 0,
"timestamp": 1712762707373
}
推送结果
- 推送数据data对象说明
| 类型 | 字段名 | 说明 |
|---|---|---|
| String[] | data | 数据有序数组 [0]数据时间戳,[1]最高价,[2]最低价,[3]成交数量,[4]成交价值,[5]开盘价,[6]最新价,[7]24小时价格涨跌幅,[8]24小时价格涨跌幅比率,[9]买一价,[10]卖一价,[11]合约代码,[12]最新价折合CNY,[13]是否测试币 |
ws 资金费率和合理价格单个币对
Request
{
"event": "subscribe",
"params": {
"biz": "perpetual",
"type": "fund_rate",
"zip": false,
"contractCode": "ethusdt",
"serialize": true
}
}
请求参数
| 参数名称 | 是否必须 | 类型 | 描述 | 默认值 | 取值范围 |
|---|---|---|---|---|---|
| biz | y | string | 业务 | perpetual | |
| type | y | string | 类型 | fund_rate | |
| contractCode | y | string | 合约code | ||
| zip | N | boolean | 是否压缩 | false | |
| serialize | N | boolean | 是否序列化 | false |
Response
{
"biz": "perpetual",
"data": {
"result": true
},
"channel": "subscribe",
"type": "fund_rate",
"contractCode": "btcusdt"
}
订阅结果
- data对象说明
| 类型 | 字段名 | 说明 |
|---|---|---|
| boolean | result | 订阅结果(true:成功 false:失败) |
Response
{
"biz": "perpetual",
"data": [],
"type": "fund_rate",
"env": 0,
"contractCode": "btcusdt"
}
推送结果对象说明
| 类型 | 字段名 | 说明 |
|---|---|---|
| String[] | data | 数据有序数组[0]合约编码,[1]标记价格,[2]指数价格,[3]费率,[4]估算费率,[5]下次结算时间,[6]当前持仓量,[7]指数价折合人民币,[8]标记价折合人民币,[9]env,[10]基础币,[11]指数币,[12]计价币,[13]基础币显示名,[14]指数币显示名,[15]计价币显示名 |
ws 资金费率和合理价格所有币对
Request
{
"event": "subscribe",
"params": {
"biz": "perpetual",
"type": "fund_rates",
"zip": false,
"serialize": true
}
}
请求参数
| 参数名称 | 是否必须 | 类型 | 描述 | 默认值 | 取值范围 |
|---|---|---|---|---|---|
| biz | y | string | 业务 | perpetual | |
| type | y | string | 类型 | fund_rates | |
| zip | N | boolean | 是否压缩 | false | |
| serialize | N | boolean | 是否序列化 | false |
Response
{
"biz": "perpetual",
"data": {
"result": true
},
"channel": "subscribe",
"type": "fund_rates"
}
订阅结果
- data对象说明
| 类型 | 字段名 | 说明 |
|---|---|---|
| boolean | result | 订阅结果(true:成功 false:失败) |
推送结果
Response
{
"biz": "perpetual",
"data": [
[
"btcusd",
"103744.95",
"103745.00",
"0.0001",
"0.0001",
28206362,
"144710",
"670400.19",
"670399.86",
0,
"",
"",
"",
"BTC",
"BTC",
"USD",
"0",
2,
"103744.95"
],
[
"ethusdt",
"1846.013285",
"2363.690000",
"0.0001",
"0.0001",
1161362,
"0",
"15274.16",
"11928.93",
0,
"",
"",
"",
"USDT",
"ETH",
"USDT",
"0",
2,
"1825.000000"
]
],
"type": "fund_rates",
"env": 1
}
推送结果对象说明
| 类型 | 字段名 | 说明 |
|---|---|---|
| String[] | data | 数据有序数组: [0]合约编码, [1]标记价格, [2]指数价格, [3]费率, [4]估算费率, [5]下次结算时间, [6]当前持仓量, [7]指数价折合人民币, [8]标记价折合人民币, [9]env, [10]基础币, [11]指数币, [12]计价币, [13]基础币显示名, [14]指数币显示名, [15]计价币显示名 [16]预估交割价格 [17]是否已经上线 [18]最新价格 |
ws 最新成交
Request
{
"event": "subscribe",
"params": {
"biz": "perpetual",
"type": "fills",
"contractCode": "btcusdt",
"zip": false,
"serialize": true
}
}
请求参数
| 参数名称 | 是否必须 | 类型 | 描述 | 默认值 | 取值范围 |
|---|---|---|---|---|---|
| biz | y | string | 业务 | perpetual | |
| type | y | string | 类型 | fills | |
| contractCode | y | string | 合约code | ||
| zip | N | boolean | 是否压缩 | false | |
| serialize | N | boolean | 是否序列化 | false |
Response
{
"biz": "perpetual",
"data": {
"result": true
},
"channel": "subscribe",
"type": "fills",
"contractCode": "btcusdt"
}
订阅结果
- data对象说明
| 类型 | 字段名 | 说明 |
|---|---|---|
| boolean | result | 订阅结果(true:成功 false:失败) |
Response
{
"biz": "perpetual",
"data": [
[
"70495.35",
"33",
"short",
1712814248594,
0
],
[
"70495.35",
"15",
"short",
1712814248594,
0
]
],
"type": "fills",
"env": 0,
"contractCode": "btcusdt",
"timestamp": 1712814248602
}
推送结果
- data对象说明
| 类型 | 字段名 | 说明 |
|---|---|---|
| String[] | data | 数据有序数组: [0]价格, [1]数量, [2]方向, [3]时间戳毫秒, [4]id |
ws用户资产(需要登录)
Request
{
"event": "subscribe",
"params": {
"biz": "perpetual",
"type": "assets",
"zip": false,
"serialize": false
}
}
请求参数
| 参数名称 | 是否必须 | 类型 | 描述 | 默认值 | 取值范围 |
|---|---|---|---|---|---|
| biz | y | string | 业务 | perpetual | |
| type | y | string | 类型 | assets | |
| zip | N | boolean | 是否压缩 | false | |
| serialize | N | boolean | 是否序列化 | false |
Response
{
"biz": "perpetual",
"data": {
"result": true
},
"channel": "subscribe",
"type": "assets"
}
订阅结果
- data对象说明
| 类型 | 字段名 | 说明 |
|---|---|---|
| boolean | result | 订阅结果(true:成功 false:失败) |
Response
{
"biz": "perpetual",
"data": {
"totalCnyAccountRights": "3283806187.35",
"totalBtcUnRealizedSurplus": "0",
"data": [
{
"cnPrice": "7451165.96",
"appLogo": "https://hotcoin-hk-static.oss-accelerate.aliyuncs.com/hotcoin/upload/coin/a417aec2fc85428aafed802649e227caUSDT.png",
"fee": "0.000000",
"orderFee": "0.001674",
"realAvailableBalance": "1000156.504790",
"realizedSurplus": "4.014119",
"availableBalance": "1000156.504790",
"positionAccountRights": "1000156.635250",
"maintenanceMargin": "0.000000",
"price": "1000156.50479026",
"realPositionAccountRights": "0.000000",
"currencyCodeDisplayName": "USDT",
"unRealizedSurplusBtcValue": "0.000000",
"unRealizedSurplusValue": "0.000000",
"accountRightsValue": "1000156.635250",
"openMargin": "0.000000",
"frozenBalance": "0.000000",
"sort": 1,
"env": 0,
"accountRightsBtcValue": "47.215127",
"accountRightsCnValue": "7451166.93",
"decimalPlaces": 6,
"currentOrderMargin": "0.130460",
"webLogo": "https://hotcoin-hk-static.oss-accelerate.aliyuncs.com/hotcoin/upload/coin/a417aec2fc85428aafed802649e227caUSDT.png",
"unRealizedSurplus": "0.000000",
"orderMargin": "0.130460",
"positionMargin": "0.000000",
"currencyCode": "USDT",
"availableMargin": "0.000000",
"btcValue": "47.21512161"
}
],
"totalBtcAccountRights": "20808.19422358",
"totalBtcAvaliableMargins": "20808.19421819",
"userId": 10061
},
"type": "assets",
"env": 0
}
推送结果
推送结果
- data对象说明
| 类型 | 字段名 | 说明 |
|---|---|---|
| string | totalCnyAccountRights | 总的账户权益CNY |
| string | totalBtcUnRealizedSurplus | 总的为实现盈亏BTC |
| string | totalBtcAccountRights | 总的可用保证金BTC |
| string | userId | 用户ID |
| object | data | 资产信息数组 |
| string | cnPrice | 人民币价格 |
| string | appLogo | app logo |
| string | fee | 费率 |
| string | orderFee | 订单手续费 |
| string | realAvailableBalance | 真实可用余额 |
| string | realizedSurplus | 已实现盈余 |
| string | availableBalance | 可用余额 |
| string | positionAccountRights | 持仓账户权益(使用用户持仓算出) |
| string | maintenanceMargin | 维持保证金 |
| string | price | 价格(美元,取的是指数价格) |
| string | realPositionAccountRights | 持仓账户权益(取AvailableBalance) |
| string | currencyCodeDisplayName | 币种显示名 |
| string | unRealizedSurplusBtcValue | 未实现盈亏(btc) |
| string | unRealizedSurplusValue | 未实现盈亏USDT |
| string | accountRightsValue | 总账户权益(USDT) |
| string | openMargin | 开仓保证金 |
| string | frozenBalance | 冻结 |
| string | sort | 排序 |
| string | env | 是否测试币 0:线上币,1:测试币 |
| string | accountRightsBtcValue | 总账户权益(btc) |
| string | accountRightsCnValue | 总账户权益(cn) |
| string | decimalPlaces | 精度 |
| string | currentOrderMargin | 当前委托保证金 |
| string | webLogo | web logo |
| string | unRealizedSurplus | 未实现盈亏 |
| string | orderMargin | 挂单保证金 |
| string | positionMargin | 开仓保证金 |
| string | currencyCode | 币种 |
| string | availableMargin | 可用保证金 |
| string | btcValue | btc估值 |
ws用户订单(需要登录)
Request
{
"event": "subscribe",
"params": {
"biz": "perpetual",
"type": "orders",
"zip": false,
"serialize": false
}
}
请求参数
| 参数名称 | 是否必须 | 类型 | 描述 | 默认值 | 取值范围 |
|---|---|---|---|---|---|
| biz | y | string | 业务 | perpetual | |
| type | y | string | 类型 | orders-普通单,condition_orders-条件单 | |
| zip | N | boolean | 是否压缩 | false | |
| serialize | N | boolean | 是否序列化 | false |
Response
{
"biz": "perpetual",
"data": {
"result": true
},
"channel": "subscribe",
"type": "orders"
}
订阅结果
- data对象说明
| 类型 | 字段名 | 说明 |
|---|---|---|
| boolean | result | 订阅结果(true:成功 false:失败) |
Request
{
"biz": "perpetual",
"data": {
"reason": 0,
"orderType": 0,
"extraMargin": "0",
"positionType": 1,
"avgPrice": "0.00000000",
"marginDigit": 4,
"orderSize": "2.5651281",
"fee": "0.000000",
"dualPosition": 0,
"quoteDisplayName": "USDT",
"quote": "usdt",
"baseDisplayName": "USDT",
"price": "0.22000000",
"indexBase": "bat",
"marketPriceDigit": 8,
"contractCodeDisplayName": "BATUSDT",
"systemType": 10,
"id": 157016654939648,
"profit": "0.000000",
"side": "long",
"amount": "1",
"modifyDate": 1668072577089,
"dealAmount": "0",
"openMargin": "0.128256",
"contractDirection": 0,
"dealSize": "0",
"lever": 20,
"avgMargin": "0.128256",
"userId": 10061,
"mustMaker": 0,
"indexBaseDisplayName": "BAT",
"detailSide": "open_long",
"createdDate": 1668072577089,
"reduceOnly": 0,
"unitAmount": "10",
"contractCode": "batusdt",
"clazz": 0,
"base": "usdt",
"status": 0
},
"type": "orders",
"env": 0
}
推送结果
- data对象说明
| 类型 | 字段名 | 说明 |
|---|---|---|
| int | id | 订单ID |
| string | contractCode | 合约CODE |
| int | contractDirection | 合约方向 0:正向,1:反向 |
| string | base | 基础货币名 |
| string | quote | 计价货币名 |
| int | userId | 用户ID |
| string | side | 仓位方向,long多,short空 |
| string | detailSide | 1.开多open_long 2.开空open_short 3.平多close_long 4.平空close_short |
| int | clazz | 0:下单 1:撤单 |
| int | mustMaker | 被动委托:0:不care 1:只做maker,如何是taker就撤单 |
| string | amount | 委托数量 |
| string | price | 用户订单委托或者破产价格 |
| string | avgPrice | 平均成交价格 |
| string | dealAmount | 已成交数量 |
| string | orderSize | 下单价值 |
| string | dealSize | 已经成交价值 |
| string | openMargin | 开仓保险金 |
| string | extraMargin | 额外价格偏移保证金 |
| string | avgMargin | 每张合约摊到的保证金 |
| int | systemType | 10:限价 11:市价 13:强平单 14:爆仓单 |
| string | profit | 该笔订单成交后对应的盈亏: 正表示盈利,负表示亏损 |
| string | fee | 该笔订单成交后交的手续费: 正表示得手续费,负表示付手续费 |
| int | reason | 该笔订单取消的理由,0是默认值,没有理由 |
| int | createdDate | 创建时间 |
| string | triggerPrice | 触发价 |
| string | indexBase | 指数基础货币,如BTC、ETH |
| int | direction | 触发方向,greater大于,less小于 |
| int | stopLimitType | 0 -止损 1-止盈 2-计划 |
| int | lever | 杠杆 |
| int | orderPriceType | 下单价格类型,对手价:opponent,最优20档:optimal_20,最优10档:optimal_10,最优5档:optimal_5 |
| string | triggerBy | 触发类型:指数价格,标记价格,最新价格 |
| int | refConditionOrderId | 关联条件单ID |
| int | marginDigit | 保证金精度 |
| int | positionType | 账户模式 0:全仓,1:逐仓,2:未知(按产品要求不显示) |
| int | status | 0 等待成交 1 部分成交 2 已经成交 -1 已经撤销 |
| object | stopLoss | 止损对象 |
| object | stopProfit | 止盈对象 |
| int | modifyDate | 修改时间 |
| int | marketPriceDigit | 价格精度 |
| int | unitAmount | 面值 |
| string | beforeClosePositionPrice | 之前平仓价 |
| string | baseDisplayName | 基础币显示名 |
| string | quoteDisplayName | 计价币显示名 |
| string | contractCodeDisplayName | 合约code显示名 |
| string | indexBaseDisplayName | 指数币显示名 |
| int | env | env |
| int | dualPosition | 单向持仓 0-单向持仓/1-双向持仓 |
| int | reduceOnly | 是否只减仓 0-否/1-是 |
| int | orderType | 0:普通单,1:止盈止损,2:计划委托 |
ws用户仓位(需要登录)
Request
{
"event": "subscribe",
"params": {
"biz": "perpetual",
"type": "position",
"zip": false,
"serialize": false
}
}
请求参数
| 参数名称 | 是否必须 | 类型 | 描述 | 默认值 | 取值范围 |
|---|---|---|---|---|---|
| biz | y | string | 业务 | perpetual | |
| type | y | string | 类型 | position | |
| contractCode | y | string | 合约code | ||
| zip | N | boolean | 是否压缩 | false | |
| serialize | N | boolean | 是否序列化 | false |
Response
{
"biz": "perpetual",
"data": {
"result": true
},
"channel": "subscribe",
"type": "position"
}
订阅结果
- data对象说明
| 类型 | 字段名 | 说明 |
|---|---|---|
| boolean | result | 订阅结果(true:成功 false:失败) |
Request
{
"biz": "perpetual",
"data": {
"fee": "0",
"liqudatePrice": "0.00000000",
"realizedSurplus": "0.000000",
"type": 1,
"onlyPositionPartInLever": 20,
"quoteDisplayName": "USDT",
"score": 0,
"quote": "usdt",
"maintenanceMargin": "0",
"price": "0.00000000",
"indexBase": "band",
"id": 230393,
"entireLever": "20",
"modifyDate": 1668072633091,
"lever": "20",
"indexBaseDisplayName": "BAND",
"onlyPositionEntireLever": 20,
"size": "0",
"closingAmount": "0",
"unitAmount": "1",
"unRealizedSurplus": "0.000000",
"openMarginRate": "0",
"autoAddMargin": 0,
"marginDigit": 6,
"maxLever": "125",
"orderSize": "0",
"orderFee": "0",
"dualPosition": 0,
"feeRate": "0.00065",
"availableBalance": "1000156.633050",
"markPrice": "1.89923333",
"orderAmount": "0",
"baseDisplayName": "USDT",
"marketPriceDigit": 8,
"contractCodeDisplayName": "BANDUSDT",
"amount": "0",
"brokerId": 1,
"side": "long",
"openMargin": "0.000000",
"partInLever": "20",
"env": 0,
"userId": 10061,
"createdDate": 1668072633169,
"maintainRate": "0.025",
"brokerPrice": "0",
"orderMargin": "0",
"contractCode": "bandusdt",
"base": "usdt",
"lastPrice": "5.92100000"
},
"type": "position",
"env": 0
}
推送结果
- data对象说明
| 类型 | 字段名 | 说明 |
|---|---|---|
| string | closingProfitConditionAmount | 止盈中的数量 |
| string | closingLossConditionAmount | 止损中的数量 |
| string | closingConditionAmount | 止盈止损中的数量(取最大) |
| string | closingAmount | 正在平仓的数量 |
| string | amount | 持仓数量 |
| string | orderAmount | 订单数量 |
| string | orderSize | 挂单价值 |
| string | orderFee | 挂单手续费 |
| string | orderMargin | 订单保证金 |
| string | fee | 手续费 |
| string | liqudatePrice | 强平价 |
| string | realizedSurplus | 已实现盈余 |
| string | availableBalance | 可用余额(保证金) |
| string | maintenanceMargin | 维持保证金 |
| string | price | 持仓均价 |
| string | entireLever | 全仓杠杆(before) |
| string | openMargin | 开仓保证金 |
| string | lever | 杠杆 |
| string | partInLever | |
| string | size | 杠杆 |
| string | brokerPrice | 爆仓价 |
| string | unRealizedSurplus | 未实现盈亏 |
| int | createdDate | |
| string | unitAmount | 一张合约对应的面值,默认1 |
| int | marginDigit | 保证金精度 |
| string | openMarginRate | 开仓保证金率 |
| int | autoAddMargin | 是否开启自动追加保证金 |
| string | base | 基础货币名 |
| int | brokerId | 业务方ID |
| string | contractCode | 合约Code |
| int | env | 是否测试盘 0:线上盘,1:测试盘 |
| string | feeRate | 手续费率 |
| int | id | 主键id |
| string | maintainRate | 维持保证金率 |
| int | marketPriceDigit | 精度 |
| string | maxLever | 最大杠杆 |
| int | modifyDate | |
| string | preLiqudatePrice | 预强平价 |
| string | quote | 计价币 |
| int | score | 计算强减指示灯值 |
| string | side | 仓位类型,long多,short空 |
| int | type | 0全仓,1逐仓 |
| int | userId | 用户ID |
| string | indexBase | 指数币 |
| string | markPrice | 标记价 |
| string | lastPrice | 最新价 |
| string | baseDisplayName | 基础币显示名 |
| string | quoteDisplayName | 计价币显示名 |
| string | contractCodeDisplayName | 合约显示名 |
| string | indexBaseDisplayName | 指数币显示名 |
| int | dualPosition | //0-单向持仓/1-双向持仓 |
ws资金费率(需要登录)
Request
{
"event": "subscribe",
"params": {
"biz": "perpetual",
"type": "fund_rate",
"contractCode": "btcusdt",
"zip": false,
"serialize": false
}
}
请求参数
| 参数名称 | 是否必须 | 类型 | 描述 | 默认值 | 取值范围 |
|---|---|---|---|---|---|
| biz | y | string | 业务 | perpetual | |
| type | y | string | 类型 | fund_rate | |
| contractCode | y | string | 合约code | ||
| zip | N | boolean | 是否压缩 | false | |
| serialize | N | boolean | 是否序列化 | false |
Response
{
"biz": "perpetual",
"data": {
"result": true
},
"channel": "subscribe",
"type": "fund_rate",
"env": 0,
"contractCode": "btcusdt"
}
订阅结果
- data对象说明
| 类型 | 字段名 | 说明 |
|---|---|---|
| boolean | result | 订阅结果(true:成功 false:失败) |
Request
{
"biz": "perpetual",
"data": [
"btcusdt",
"67594.61",
"67592.90",
"0.0001",
"0.0001",
7294622,
"24054",
"436785.31",
"436796.42",
0,
"usdt",
"btc",
"usdt",
"USDT",
"BTC",
"USDT",
"0"
],
"type": "fund_rate",
"env": 0,
"contractCode": "btcusdt",
"timestamp": 1713016705540
}
推送结果
- data对象说明
| 类型 | 字段名 | 说明 |
|---|---|---|
| string | contractCode | 合约code |
| string | markPrice | 标记价 |
| string | indexPrice | 指数价 |
| string | feeRate | 手续费率 |
| string | estimateFeeRate | 预估资金费率 |
| string | nextLiquidationInterval | 下次清算时间 |
| string | totalPosition | 总持仓 |
| string | indexCny | 指数价cny |
| string | markCny | 最新价cny |
| string | env | 是否测试盘 0:线上盘,1:测试盘 |
| string | base | 基础货币名 |
| string | indexBase | 指数币 |
| string | quote | 计价币 |
| string | baseDisplayName | 基础币显示名 |
| string | indexBaseDisplayName | 指数币显示名 |
| string | quoteDisplayName | 计价币显示名 |
| string | preDeliveryPrice | 预交割价格 |
ws所有资金费率(需要登录)
Request
{
"event": "subscribe",
"params": {
"biz": "perpetual",
"type": "fund_rates",
"zip": false,
"serialize": false
}
}
请求参数
| 参数名称 | 是否必须 | 类型 | 描述 | 默认值 | 取值范围 |
|---|---|---|---|---|---|
| biz | y | string | 业务 | perpetual | |
| type | y | string | 类型 | fund_rates | |
| zip | N | boolean | 是否压缩 | false | |
| serialize | N | boolean | 是否序列化 | false |
Response
{
"biz": "perpetual",
"data": {
"result": true
},
"channel": "subscribe",
"type": "fund_rates",
"env": 0
}
订阅结果
- data对象说明
| 类型 | 字段名 | 说明 |
|---|---|---|
| boolean | result | 订阅结果(true:成功 false:失败) |
推送结果
Request
{
"biz": "perpetual",
"data": [
[
"movrusdt",
"13.783",
"13.782",
"0.0001",
"0.0001",
21859068,
"0",
"89.05",
"89.06",
0,
"",
"",
"",
"USDT",
"MOVR",
"USDT",
"0"
],
[
"1000xecusdt",
"0.06155",
"0.06155",
"0.0001",
"0.0001",
17359068,
"110",
"0.39",
"0.39",
0,
"",
"",
"",
"USDT",
"1000XEC",
"USDT",
"0"
]
],
"type": "fund_rates",
"env": 0,
"timestamp": 1713016540940
}
推送结果
- data对象说明
| 类型 | 字段名 | 说明 |
|---|---|---|
| string | contractCode | 合约code |
| string | markPrice | 标记价 |
| string | indexPrice | 指数价 |
| string | feeRate | 手续费率 |
| string | estimateFeeRate | 预估资金费率 |
| string | nextLiquidationInterval | 下次清算时间 |
| string | totalPosition | 总持仓 |
| string | indexCny | 指数价cny |
| string | markCny | 最新价cny |
| string | env | 是否测试盘 0:线上盘,1:测试盘 |
| string | base | 基础货币名 |
| string | indexBase | 指数币 |
| string | quote | 计价币 |
| string | baseDisplayName | 基础币显示名 |
| string | indexBaseDisplayName | 指数币显示名 |
| string | quoteDisplayName | 计价币显示名 |
| string | preDeliveryPrice | 预交割价格 |