Skip to content

WS_API_Reference

Biboxcom edited this page Jul 18, 2019 · 6 revisions

目录

WebSocket API Reference

订阅 Kline 数据 bibox_sub_spot_$pair_kline_$period

成功建立和 WebSocket API 的连接之后,向 Server 发送如下格式的数据来订阅数据

{
  "event": "addChannel",
  "channel": "bibox_sub_spot_$pair_kline_$period"
}
参数名称 是否必须 类型 描述 默认值 取值范围
pair true string 交易对 BIX_BTC, BIX_ETH, BTC_USDT, ETH_USDT......
period true string K线周期 1min, 5min, 15min, 30min, 1hour, 2hour, 4hour, 6hour, 12hour, day, week

正确订阅的例子

正确订阅

{
  "event": "addChannel",
  "channel": "bibox_sub_spot_BIX_BTC_kline_1min"
}

订阅成功返回数据的例子

[{
  "channel": "bibox_sub_spot_BIX_BTC_kline_1min",
  "data_type": 0, //订阅成功返回一次全量数据,之后返回增量 
  "data": 
  [
      {
          "time":1536310020000,
          "open":"0.00006614",
          "high":"0.00006659",
          "low":"0.00006604",
          "close":"0.00006652",
          "vol":"74056.89597166"
      },
      {
          "time":1536310080000,
          "open":"0.00006652",
          "high":"0.00006652",
          "low":"0.00006652",
          "close":"0.00006652",
          "vol":"100"
      }
  ]
}]
  • "data_type" 标识返回的数据是全量还是增量,0-返回全量数据,1-返回增量数据

data 说明

  "data": {
    "time": k线某周期开始时间,
    "count": 成交笔数,
    "open": 开盘价,
    "high": 最高价,
    "low": 最低价,
    "close": 收盘价
    "vol": 成交量
  }

之后每当 KLine 有更新时,client 会收到数据,例子

[{
  "channel": "bibox_sub_spot_BIX_BTC_kline_1min",
  "data_type": 1, 
  "data": 
  [
      {
          "time":1536310020000,
          "open":"0.00006614",
          "high":"0.00006659",
          "low":"0.00006604",
          "close":"0.00006652",
          "vol":"74056.89597166"
      },
      {
          "time":1536310080000,
          "open":"0.00006652",
          "high":"0.00006652",
          "low":"0.00006652",
          "close":"0.00006652",
          "vol":"100"
      }
  ]
}]

注:返回增量k线时,每次都返回最新相邻两条kline

错误订阅的例子

错误订阅(错误的 pair,大小写敏感)

{
  "event": "addChannel",
  "channel": "bibox_sub_spot_bix_btc_kline_1min"
}

订阅失败返回数据的例子

{
  "channel": "bibox_sub_spot_bix_btc_kline_1min",
  "error": 
  {
       "code": "3009",
       "msg":"推送订阅channel不合法"
  }
}

订阅 Market 数据 bibox_sub_spot_ALL_ALL_market

成功建立和 WebSocket API 的连接之后,向 Server 发送如下格式的数据来订阅数据

{
  "event": "addChannel",
  "channel": "bibox_sub_spot_ALL_ALL_market"
}
参数名称 是否必须 类型 描述 默认值 取值范围

正确订阅

{
  "event": "addChannel",
  "channel": "bibox_sub_spot_ALL_ALL_market"
}

订阅成功返回数据的例子

[{
  "channel": "bibox_sub_spot_ALL_ALL_market",
  "data_type": 0, 
  "data":
    [
        {
            "id":1,
            "coin_symbol":"BIX",
            "currency_symbol":"BTC",
            "last":"0.00006604",
            "high":"0.00006712",
            "low":"0.00006421",
            "change":"+0.00000121",
            "percent":"+1.87%",
            "vol24H":"54475636",
            "amount":"3571.11",
            "last_cny":"2.91",
            "high_cny":"2.95",
            "low_cny":"2.83",
            "last_usd":"0.42",
            "high_usd":"0.43",
            "low_usd":"0.41"
        },
        {
            "id":2,
            "coin_symbol":"BIX",
            "currency_symbol":"ETH",
            "last":"0.00190235",
            "high":"0.00192190",
            "low":"0.00181724",
            "change":"+0.00008058",
            "percent":"+4.42%",
            "vol24H":"32059017",
            "amount":"59861.18",
            "last_cny":"2.90",
            "high_cny":"2.93",
            "low_cny":"2.77",
            "last_usd":"0.42",
            "high_usd":"0.42",
            "low_usd":"0.40"
        },
        ...  //其他交易对行情信息
    ]
}]

data 说明

 {
     "id": 交易对id
     "coin_symbol": 交易币种
     "currency_symbol": 定价币种
     "last": 24h最新价
     "high": 24h最高价
     "low": 24h最低价
     "change": 24h涨跌
     "percent": 24h涨跌幅
     "vol24H": 24h成交量
     "amount": 24h成交额
     "last_cny": 最新价折算cny
     "high_cny": 最高价折算cny
     "low_cny": 最低价折算cny
     "last_usd": 最新价折算usd
     "high_usd": 最高价折算usd
     "low_usd": 最低价折算usd
 }

之后每当 Market 有更新时,client 会收到数据,例子

[{
  "channel": "bibox_sub_spot_ALL_ALL_market",
  "data_type": 1, 
  "data":
    [
        {
            "id":1,
            "coin_symbol":"BIX",
            "currency_symbol":"BTC",
            "last":"0.00006604",
            "high":"0.00006712",
            "low":"0.00006421",
            "change":"+0.00000121",
            "percent":"+1.87%",
            "vol24H":"54475636",
            "amount":"3571.11",
            "last_cny":"2.91",
            "high_cny":"2.95",
            "low_cny":"2.83",
            "last_usd":"0.42",
            "high_usd":"0.43",
            "low_usd":"0.41"
        }
    ]
}]

请求 Depth 数据 bibox_sub_spot_$pair_depth

成功建立和 WebSocket API 的连接之后,向 Server 发送如下格式的数据来订阅数据

{
  "event": "addChannel",
  "channel": "bibox_sub_spot_$pair_depth"
}
参数名称 是否必须 类型 描述 默认值 取值范围
pair true string 交易对 BIX_BTC, BIX_ETH, BTC_USDT, ETH_USDT......

请求 Depth 数据的例子

正确订阅

{
  "event": "addChannel",
  "channel": "bibox_sub_spot_BIX_BTC_depth"
}

订阅成功返回数据的例子

[{
    "channel": "bibox_sub_spot_BIX_BTC_depth",
    "data_type": 0,
    "data": {
        "pair":"BIX_BTC",
        "update_time":1536648343927,
        "asks":[
            {
                "price":"0.0000683",
                "volume":"1048.8046"
            },
            {
                "price":"0.00006831",
                "volume":"1008.2509"
            },
            ... // other data
        ],
        "bids":[
            {
                "price":"0.00006801",
                "volume":"2.3472"
            },
            {
                "price":"0.00006793",
                "volume":"0.3458"
            },
            ... // other data
        ]
    }
}]

data说明

"bids": 买方深度列表
"asks": 卖方深度列表
{
    "price": 委托价格,
    "volume": 委托数量
}

之后每当 Depth 有更新时,client 都会收到全量数据,例子

[{
    "channel": "bibox_sub_spot_BIX_BTC_depth",
    "data_type": 1,
    "data": {
        "pair":"BIX_BTC",
        "update_time":1536648343927,
        "asks":[
            {
                "price":"0.0000683",
                "volume":"1048.8046"
            },
            {
                "price":"0.00006831",
                "volume":"1008.2509"
            },
            ... // other data
        ],
        "bids":[
            {
                "price":"0.00006801",
                "volume":"2.3472"
            },
            {
                "price":"0.00006793",
                "volume":"0.3458"
            },
            ... // other data
        ]
    }
}]

订阅 Deals 数据 bibox_sub_spot_$pair_deals

{
  "event": "addChannel",
  "channel": "bibox_sub_spot_$pair_deals"
}
参数名称 是否必须 类型 描述 默认值 取值范围
pair true string 交易对 BIX_BTC, BIX_ETH, BTC_USDT, ETH_USDT......

请求 Deals 数据的例子

正确订阅

{
  "event": "addChannel",
  "channel": "bibox_sub_spot_BIX_BTC_deals"
}

订阅成功返回数据的例子

[{
    "channel": "bibox_sub_spot_BIX_BTC_deals",
    "data_type": 0,
    "data":[
        {
            "id":71890943,
            "pair":"BIX_BTC",
            "price":"0.00006788",
            "amount":"9705.9732",
            "time":1536648308000,
            "side":2
        },
        {
            "id":71890942,
            "pair":"BIX_BTC",
            "price":"0.00006788",
            "amount":"11914.8712",
            "time":1536648308000,
            "side":2
        },
        ... // other data
    ]
}]

data说明

{
    "id": 成交历史id,
    "pair": 交易对,
    "price": 成交均价,
    "amount": 成交数量,
    "time": 成交时间戳,
    "side": taker(主动成交方)成交方向,1-买,2-卖
}

之后每当 Deals 有更新时,client 都会收到增量数据,例子

[{
    "channel": "bibox_sub_spot_BIX_BTC_depth",
    "data_type": 1,
    "data":[
        {
            "price":"0.00006788",
            "amount":"9705.9732",
            "time":1536648308000,
            "side":2
        },
        {
            "price":"0.00006788",
            "amount":"11914.8712",
            "time":1536648308000,
            "side":2
        },
        ... // other data
    ]
}]

订阅 Ticker 数据 bibox_sub_spot_$pair_ticker

{
  "event": "addChannel",
  "channel": "bibox_sub_spot_$pair_ticker"
}
参数名称 是否必须 类型 描述 默认值 取值范围
pair true string 交易对 BIX_BTC, BIX_ETH, BTC_USDT, ETH_USDT......

请求 Ticker 数据的例子

正确订阅

{
  "event": "addChannel",
  "channel": "bibox_sub_spot_BIX_BTC_ticker"
}

订阅成功返回数据的例子

[{
    "channel": "bibox_sub_spot_BIX_BTC_ticker",
    "data_type": 0,
    "data":{
        "pair":"BIX_BTC",
        "last":"0.00006837",
        "last_usd":"0.43",
        "last_cny":"2.96",
        "high":"0.00007401",
        "low":"0.00006628",
        "buy":"0.00006814",
        "buy_amount":"2654.5376",
        "sell":"0.00006876",
        "sell_amount":"170.3094",
        "vol":"48027601",
        "percent":"-6.73%",
        "timestamp":1536650154258,
        "base_last_cny":"2.96838961"
    }
}]

data说明

"data":{
   "pair": 交易对
   "last": 最新成交价
   "last_cny": 最新成交价,cny计价
   "last_usd": 最新成交价,usd计价
   "high": 24h最高价
   "low": 24h最低价
   "buy": 最新买一价
   "buy_amount": 买一量
   "sell": 最新卖一价
   "sell_amount": 卖一量
   "vol": 24h成交量
   "percent": 24h涨跌幅
   "timestamp": 时间戳
   "base_last_cny": 最新成交价,cny计价(保留8位小数)
}

之后每当 Ticker 有更新时,client 都会收到数据,例子

[{
    "channel": "bibox_sub_spot_BIX_BTC_ticker",
    "data_type": 1,
    "data":{
        "pair":"BIX_BTC",
        "last":"0.00006837",
        "last_usd":"0.43",
        "last_cny":"2.96",
        "high":"0.00007401",
        "low":"0.00006628",
        "buy":"0.00006814",
        "buy_amount":"2654.5376",
        "sell":"0.00006876",
        "sell_amount":"170.3094",
        "vol":"48027601",
        "percent":"-6.73%",
        "timestamp":1536650154258,
        "base_last_cny":"2.96838961"
    }
}]

订阅 Login 数据 bibox_sub_spot_ALL_ALL_login

{
  "event": "addChannel",
  "channel": "bibox_sub_spot_ALL_ALL_login",
  "apikey": "thisisyourapikey",
  "sign": "thisissigneddata"
}
参数名称 是否必须 类型 描述 默认值 取值范围
apikey true string 您在Bibox交易所申请的apikey
sign true string 使用您在Bibox交易所申请的apisecret对整个请求数据进行签名

注:订阅Login会推送与用户有关的消息,包括:资产,委托单,成交历史

签名步骤

1.签名前数据

{
  "event": "addChannel",
  "channel": "bibox_sub_spot_ALL_ALL_login",
  "apikey": "thisisyourapikey"
}

2.根据key升序排列

{
  "apikey": "thisisyourapikey",
  "channel": "bibox_sub_spot_ALL_ALL_login",
  "event": "addChannel"
}

3.格式化待签名数据并签名

let data = {
             "apikey": "thisisyourapikey",
             "channel": "bibox_sub_spot_ALL_ALL_login",
             "event": "addChannel"
           };
let secret = "thisisyourapisecret";
let sign = CryptoJS.HmacMD5(JSON.stringify(data), secret).toString(); // 签名结果 thisissigneddata

4.添加签名结果到请求参数

{
  "event": "addChannel",
  "channel": "bibox_sub_spot_ALL_ALL_login",
  "apikey": "thisisyourapikey",
  "sign": "thisissigneddata"
}

完整签名例子 (nodejs实现)

let CryptoJS = require("crypto-js");

function getSign(data) {
    let secret = "your apisecret";
    let sdic = Object.keys(data).sort();//sort in ascending
    let dataTmp = {};
    for(let ki in sdic){
        dataTmp[sdic[ki]] = data[sdic[ki]];
    }
    return CryptoJS.HmacMD5(JSON.stringify(dataTmp), secret).toString();
}

let data = {
   "event": "addChannel",
   "channel": 'bibox_sub_spot_ALL_ALL_login',
   "apikey": "your apikey"
};
let sign = getSign(data);//return the signed data
data.sign = sign;

请求 Login 数据的例子

正确订阅

{
  "event": "addChannel",
  "channel": "bibox_sub_spot_ALL_ALL_login",
  "apikey": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "sign": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}

订阅成功返回

[{
    "channel": "bibox_sub_spot_ALL_ALL_login",
    "data_type": 0,
    "data":{ result: '订阅成功' }
}]

之后每当 用户资产、委托单、成交历史 有更新时,client 都会收到数据,例子

现货账户资产

[{
     "channel":"bibox_sub_spot_ALL_ALL_login",
     "binary":"0",                              //是否推送压缩数据,0-不压缩,1-压缩
     "data_type":1,
     "data":{
         "assets":{                             //资产类型
             "normal":{                         //现货账户资产
                 "BIX":{
                     "balance":"497.59601765",  //可用资产
                     "freeze":"0.00000000"      //冻结资产   
                 },
                 "USDT":{
                     "balance":"20.52027574",
                     "freeze":"22.12000000"
                 }
             }
         }
     }
 }]

信用账户资产

[{
     "channel":"bibox_sub_spot_ALL_ALL_login",
     "binary":"0",
     "data_type":1,
     "data":{
         "assets":{                                 //资产类型
             "credit":{                             //信用账户资产
                 "BIX_USDT":{                       //交易对
                     "BIX":{
                         "balance":"681.74441804",  //可用资产
                         "freeze":"0.00000000"      //冻结资产
                     },
                     "USDT":{
                         "balance":"0.21698199",
                         "freeze":"0.00000000"
                     }
                 },
                 "BTC_USDT":{
                     "BTC":{
                         "balance":"100",
                         "freeze":"0.00000000"
                     },
                     "USDT":{
                         "balance":"10",
                         "freeze":"0.00000000"
                     }
                 }
             }
         }
     }
 }]

注:信用账户资产以交易对区分,不同交易对下的相同币种(比如BIX_USDT与BTC_USDT的相同币种USDT)互不相关。

委托单

[{
     "channel":"bibox_sub_spot_ALL_ALL_login",
     "binary":"0",
     "data_type":1,
     "data":{
         "orderpending":{                           //委托单类型
             "id":159,
             "createdAt": 1512756997000,
             "account_type":0,                       //账户类型 0-普通账户
             "coin_symbol":"LTC",                    //交易币种
             "currency_symbol":"BTC",                //定价币种
             "order_side":2,                         //交易方向,1-买,2-卖
             "order_type":2,                         //订单类型,2-限价单
             "price":"0.00900000",                   //委托价格,市价单是0
             "amount":"1.00000000",                  //委托数量,市价买单是0
             "money":"0.00900000",                   //委托金额,市价卖单是0
             "deal_amount":"0.00000000",             //已成交数量
             "deal_percent":"0.00%",                 //成交百分比
             "unexecuted":"0.00000000",              //未成交数量
             "status":1                              //状态,1-待成交,2-部分成交,3-完全成交,4-部分撤销,5-完全撤销,6-待撤销
         }
     }
 }]

成交历史

[{
     "channel":"bibox_sub_spot_ALL_ALL_login",
     "binary":"0",
     "data_type":1,
     "data":{
         "history":{                                    //成交历史
             "id":"128345653242332",
             "createdAt": 1512756997000,
             "account_type":0,                           //账户类型 0-普通账户
             "coin_symbol":"LTC",                        //交易币种
             "currency_symbol":"BTC",                    //定价币种
             "order_side":2,                             //交易方向,1-买,2-卖
             "order_type":2,                             //订单类型,2-限价单
             "price":"0.00886500",                       //成交价格
             "amount":"1.00000000",                      //成交量
             "money":"0.00886500",                       //成交额,单位是定价币种
             "relay_id":"123345677775423",               //关联订单id
             "fee":0                                     //手续费
         }
     }
}]

Bibox交易所提供REST API 和 WebSocket API,便于投资者查看行情、快速交易。

Bibox交易所

https://www.bibox.com

REST API

WebSocket API

合约

REST API

WebSocket API

Clone this wiki locally