合约推送订阅

接入说明

WebSocket域名

wss://wss-ct.hotcoin.fit

       

订阅主题

成功建立与Websocket服务器的连接后,Websocket客户端发送请求以订阅特定主题:

{
    "event": "subscribe",   
    "params": {
        "biz": "perpetual",				//固定传参
        "type": "topic to subscribe",			//主题类型
        "contractCode": "contractCode",			//合约代号
        "zip": false,					//固定传参			
      	"serialize": false				//固定传参
    }
}

 

 

 

 

 

 

比如:

Request

{
    "event": "subscribe",
    "params": {
        "biz": "perpetual",
        "type": "fund_rate",
        "contractCode": "ethusdt",
        "zip": false,
      	"serialize": false
    }
}

 

 

 

 

 

 

成功订阅后,Websocket客户端将收到确认消息:

Response

{
    "biz": "perpetual",
    "data": {
        "result": true
    },
    "channel": "subscribe",
    "type": "fund_rate",
    "env": 0,
    "contractCode": "btcusdt"
}

之后, 一旦所订阅的主题有数据更新,热币服务器将向Websocket客户端推送更新消息。

 

 

 

 

 

 

维持

当用户的Websocket客户端连接到热币服务器后,用户需要定期向服务器发送心跳信息,否则5分钟之后将接收不到任何推送,如下:

{
    "event": "ping"
}

                                       

       

成功发送后,Websocket客户端将收到确认消息,如下:

{
    "event": "pong"
}

               

               

               

取消订阅

取消订阅的格式如下:

{
    "event": "unsubscribe",
    "params": {
        "biz": "perpetual",
        "type": "topic to subscribe",
        "contractCode": "contractCode",
        "zip": false,
      	"serialize": false
    }
}

                                                 

             

比如:

{
    "event": "unsubscribe",
    "params": {
        "biz": "perpetual",
        "type": "fund_rate",
        "contractCode": "ethusdt",
        "zip": false,
      	"serialize": false
    }
}

                                                     

         

取消订阅成功确认。

{
    "biz": "perpetual",
    "data": {
        "result": true
    },
    "channel": "unsubscribe",
    "type": "fund_rate",
    "contractCode": "ethusdt",
    "env": 0
}

                               

                               

                                                               

PING

请求参数

Request

{
    "event": "ping"
}

               

返回结果

{
    "event": "pong"
}

               

               

               

               

ws 登录

请求参数

参数名称 是否必须 类型 描述 默认值 取值范围
apiKey y string 访问key    
signature y string 签名,签名方式请看签名示列    
timestamp y string 时间戳    

Request

{
    "event": "signin",
    "params": {
        "apiKey": "xxx",
        "timestamp": "1593683685313",
        "signature": "xxx"
    }
}

返回结果

Response

{
    "data": {
        "result": true
    },
    "channel": "signin"
}

ws 深度

请求参数

参数名称 是否必须 类型 描述 默认值 取值范围
biz y string 业务   perpetual
type y string 类型   depth
contractCode y string 合约code    
zip y boolean 是否压缩    
serialize y boolean 是否序列化    

Request

{
    "event": "subscribe",
    "params": {
        "biz": "perpetual",
        "type": "depth",
        "contractCode": "ethusdt",
        "zip": false,
      	"serialize": false
    }
}

返回结果

Response

{
    "biz": "perpetual",
    "data": {
        "result": true
    },
    "channel": "subscribe",
    "type": "depth",
    "contractCode": "ethusdt"
}

推送结果

{
  "biz": "perpetual",
  "data": {
    "asks": [
      "0",//[0]价格
      "1",//[1]数量
      "2"//[2]深度
    ],
    "bids": [
      "0",//[0]价格
      "1",//[1]数量
      "2"//[2]深度
    ]
  },
  "type": "depth",
  "contractCode": "ethusdt"
}

ws K线

请求参数

参数名称 是否必须 类型 描述 默认值 取值范围
biz y string 业务   perpetual
type y string 类型   mark_candles-指数标记价格K线,candles-最新价K线
contractCode y string 合约code    
granularity   string K线类型   1min,3min,5min,15min,30min,1hour,2hour,4hour,6hour,12hour,day,week
           
zip y boolean 是否压缩    
serialize y boolean 是否序列化    

Request

{
    "event": "subscribe",
    "params": {
        "biz": "perpetual",
        "type": "candles",
        "contractCode": "ethusdt",
        "granularity": "1min",
        "zip": false,
      	"serialize": false
    }
}

返回结果

Response

{
    "biz": "perpetual",
    "data": {
        "result": true
    },
    "granularity": "1min",
    "channel": "subscribe",
    "type": "candles",
    "contractCode": "ethusdt"
}

推送结果

最新价K线
{
  "biz": "perpetual",
  "data": [],//[0]毫秒时间戳,[1],[2],[3],[4],[5]成交量
  "type": "candles",
  "contractCode": "ethusdt",
  "granularity": "1min"
}
指数标记价格K线
  "biz": "perpetual",
  "data": [],//[0]毫秒时间戳,[1]指数价低,[2]指数价高,[3]指数价开,[4]指数价收,[5]标记价低,[6]标记价高,[7]标记价开,[8]标记价收
  "type": "mark_candles",
  "contractCode": "ethusdt",
  "granularity": "1min"
}

ws行情所有币对

请求参数

参数名称 是否必须 类型 描述 默认值 取值范围
biz y string 业务   perpetual
type y string 类型   tickers
zip y boolean 是否压缩    
serialize y boolean 是否序列化    

Request

{
    "event": "subscribe",
    "params": {
        "biz": "perpetual",
        "type": "tickers",
        "zip": false,
      	"serialize": false
    }
}

返回结果

Response

{
    "biz": "perpetual",
    "data": {
        "result": true
    },
    "channel": "subscribe",
    "type": "tickers",
}

推送结果

{
    "biz": "perpetual",
    "data": [
        [
            1597801773851,//时间戳
            "432.50",//最高价
            "415.00",//最低价
            "75250152",//成交张数
            "3200391170.386",//成交价值
            "430.30",//原始成交价
            "424.50",//最新成交价
            "-5.85",//24小时价格涨跌幅
            "-1.35",//24小时价格涨跌幅比例
            "424.4",//盘口买一
            "424.55",//盘口卖一
            "ethusdt",//币对
            "2954.17"//最新成交价(cny)
        ]
    ],
    "type": "tickers",
  	"contractCode":"ethusdt"
  
}

ws 资金费率和合理价格单个币对

请求参数

参数名称 是否必须 类型 描述 默认值 取值范围
biz y string 业务   perpetual
type y string 类型   fund_rate
contractCode y string 合约code    
zip y boolean 是否压缩    
serialize y boolean 是否序列化    

Request

{
    "event": "subscribe",
    "params": {
        "biz": "perpetual",
        "type": "fund_rate",
        "zip": false,
        "contractCode": "ethusdt",
        "serialize": true
    }
}

返回结果

Response

{
    "biz": "perpetual",
    "data": {
        "result": true
    },
    "channel": "subscribe",
    "type": "fund_rate",
  	"contractCode": "btcusdt",
}

推送结果

{
    "biz": "perpetual",
    "data": [],//[0]合约编码,[1]标记价格,[2]指数价格,[3]费率,[4]估算费率,[5]下次结算时间,[6]当前持仓量,[7]指数价折合人民币,[8]标记价折合人民币,[9]env,[10]基础币,[11]指数币,[12]计价币,[13]基础币显示名,[14]指数币显示名,[15]计价币显示名
    "type": "fund_rate",
    "env": 0,
    "contractCode": "btcusdt"
}

ws 资金费率和合理价格所有币对

请求参数

参数名称 是否必须 类型 描述 默认值 取值范围
biz y string 业务   perpetual
type y string 类型   fund_rates
zip y boolean 是否压缩    
serialize y boolean 是否序列化    

Request

{
    "event": "subscribe",
    "params": {
        "biz": "perpetual",
        "type": "fund_rates",
        "zip": false,
        "serialize": true
    }
}

返回结果

Response

{
    "biz": "perpetual",
    "data": {
        "result": true
    },
    "channel": "subscribe",
    "type": "fund_rates",
}

推送结果

{
    "biz": "perpetual",
    "data": [
        []//[0]合约编码,[1]标记价格,[2]指数价格,[3]费率,[4]估算费率,[5]下次结算时间,[6]当前持仓量,[7]指数价折合人民币,[8]标记价折合人民币,[9]env,[10]基础币,[11]指数币,[12]计价币,[13]基础币显示名,[14]指数币显示名,[15]计价币显示名
    ],
    "type": "fund_rates",
    "env": 1
}

ws 最新成交

请求参数

参数名称 是否必须 类型 描述 默认值 取值范围
biz y string 业务   perpetual
type y string 类型   fills
contractCode y string 合约code    
zip y boolean 是否压缩    
serialize y boolean 是否序列化    

Request

{
    "event": "subscribe",
    "params": {
        "biz": "perpetual",
        "type": "fills",
        "contractCode": "btcusdt",
        "zip": false,
        "serialize": true
    }
}

返回结果

Response

{
    "biz": "perpetual",
    "data": {
        "result": true
    },
    "channel": "subscribe",
    "type": "fills",
  	"contractCode": "btcusdt"
}

推送结果

{
    "biz": "perpetual",
    "data": [
        []//[0]价格,[1]数量,[2]方向,[3]时间戳毫秒
    ],
    "type": "fills",
    "env": 0,
    "contractCode": "btcusdt"
}

ws用户资产(需要登录)

请求参数

参数名称 是否必须 类型 描述 默认值 取值范围
biz y string 业务   perpetual
type y string 类型   assets
zip y boolean 是否压缩    
serialize y boolean 是否序列化    

Request

{
    "event": "subscribe",
    "params": {
        "biz": "perpetual",
        "type": "assets",
        "zip": false,
        "serialize": false
    }
}

返回结果

Response

{
    "biz": "perpetual",
    "data": {
        "result": true
    },
    "channel": "subscribe",
    "type": "assets"
}

推送结果

{
    "biz": "perpetual",
    "data": {
        "totalCnyAccountRights": "3283806187.35",//总的账户权益CNY
        "totalBtcUnRealizedSurplus": "0",//总的为实现盈亏BTC
        "data": [
            {
                "cnPrice": "7451165.96",//人民币价格
                "appLogo": "https://hotcoin-hk-static.oss-accelerate.aliyuncs.com/hotcoin/upload/coin/a417aec2fc85428aafed802649e227caUSDT.png",//app logo
                "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",//持仓账户权益(取AvailableBalance)
                "currencyCodeDisplayName": "USDT",//币种显示名
                "unRealizedSurplusBtcValue": "0.000000",//未实现盈亏(btc)
                "unRealizedSurplusValue": "0.000000",//未实现盈亏USDT
                "accountRightsValue": "1000156.635250",//总账户权益(USDT)
                "openMargin": "0.000000",//开仓保证金
                "frozenBalance": "0.000000",//冻结
                "sort": 1,//排序
                "env": 0,//是否测试币 0:线上币,1:测试币
                "accountRightsBtcValue": "47.215127",//总账户权益(btc)
                "accountRightsCnValue": "7451166.93",//总账户权益(RNB)
                "decimalPlaces": 6,//精度
                "currentOrderMargin": "0.130460",//当前委托保证金
                "webLogo": "https://hotcoin-hk-static.oss-accelerate.aliyuncs.com/hotcoin/upload/coin/a417aec2fc85428aafed802649e227caUSDT.png",//web logo
                "unRealizedSurplus": "0.000000",//未实现盈亏
                "orderMargin": "0.130460",//挂单保证金
                "positionMargin": "0.000000",//开仓保证金
                "currencyCode": "USDT",//币种
                "availableMargin": "0.000000",//可用保证金
                "btcValue": "47.21512161"//btc估值
            }
        ],
        "totalBtcAccountRights": "20808.19422358",//总的账户权益BTC
        "totalBtcAvaliableMargins": "20808.19421819",//总的可用保证金BTC
        "userId": 10061//用户ID
    },
    "type": "assets",
    "env": 0
}

ws用户订单(需要登录)

请求参数

参数名称 是否必须 类型 描述 默认值 取值范围
biz y string 业务   perpetual
type y string 类型   orders-普通单,condition_orders-条件单
zip y boolean 是否压缩    
serialize y boolean 是否序列化    

Request

{
    "event": "subscribe",
    "params": {
        "biz": "perpetual",
        "type": "orders",
        "zip": false,
      	"serialize": false
    }
}

返回结果

Response

{
    "biz": "perpetual",
    "data": {
        "result": true
    },
    "channel": "subscribe",
    "type": "orders"
}

推送数据

类型 字段名 说明
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:计划委托
{
    "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
}

ws用户仓位(需要登录)

请求参数

参数名称 是否必须 类型 描述 默认值 取值范围
biz y string 业务   perpetual
type y string 类型   position
contractCode y string 合约code    
zip y boolean 是否压缩    
serialize y boolean 是否序列化    

Request

{
    "event": "subscribe",
    "params": {
        "biz": "perpetual",
        "type": "position",
        "zip": false,
        "serialize": false
    }
}

返回结果

Response

{
    "biz": "perpetual",
    "data": {
        "result": true
    },
    "channel": "subscribe",
    "type": "position"
}

推送结果

类型 字段名 说明
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-双向持仓
{
    "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
}