Skip to content

WS_API_Reference

Biboxcom edited this page Jul 18, 2019 · 5 revisions

Table of Contents

WebSocket API Reference

Subscribe Kline bibox_sub_spot_$pair_kline_$period

After buliding the connection with WebSocket API, sending the data with the following format to server to subscribe data

{
  "event": "addChannel",
  "channel": "bibox_sub_spot_$pair_kline_$period"
}
Name Necessary or not Type Description Default Value Range
pair true string Trading pair BIX_BTC, BIX_ETH, BTC_USDT, ETH_USDT......
period true string K line period 1min, 5min, 15min, 30min, 1hour, 2hour, 4hour, 6hour, 12hour, day, week

the example of subscribing correctly

subscribe correctly

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

The example of subscribing success return data

[{
  "channel": "bibox_sub_spot_BIX_BTC_kline_1min",
  "data_type": 0, //Subscribe one time of returning total value sucessfully, then return increment value
  "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" The type of data marked to be returned , 0-return total value, 1-return incremental value

data description

  "data": {
    "time": the starting time of K line period,
    "open": the openging price,
    "high": The highest price,
    "low": the lowest price,
    "close": the closing price
    "vol":  trading volume
  }

Client will receive the incremental data as long as Kline updates, for example

[{
  "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"
      }
  ]
}]

Note: 2 closest k lines will be returned every time, when incremental value k line be returned

example of subscribing wrongly

subscribe wrongly (wrong pair, capitalized sensitively)

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

The example of subscribing wrongly return data

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

Subscribe Market bibox_sub_spot_ALL_ALL_market

After buliding the connection with WebSocket API, sending the data with the following format to server to subscribe data

{
  "event": "addChannel",
  "channel": "bibox_sub_spot_ALL_ALL_market"
}
Name Necessary or not Type Description Default Value Range

subscribe correctly

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

The example of subscribing success return data

[{
  "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"
        },
        ...  //others
    ]
}]

data description

 {
     "id": pair id
     "coin_symbol": Trading Token
     "currency_symbol": Pricing Token
     "last": 24h the lastest price
     "high": 24h the highest price
     "low": 24h the lowest price
     "change": 24h price change
     "percent": 24h price change percentage
     "vol24H": 24h trading volume
     "amount": 24h trading amount
     "last_cny": The lastest price equivelant to CNY
     "high_cny": The highest price equivelant to CNY
     "low_cny": The lowest price equivelant to CNY
     "last_usd": The lastest price equivelant to USD
     "high_usd": The highest price equivelant to USD
     "low_usd": The lowest price equivelant to USD
 }

Client will receive the incremental data as long as Market updates, for example

[{
  "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"
        }
    ]
}]

Subscribe Depth bibox_sub_spot_$pair_depth

After buliding the connection with WebSocket API, sending the data with the following format to server to subscribe data

{
  "event": "addChannel",
  "channel": "bibox_sub_spot_$pair_depth"
}
Name Necessary or not Type Description Default Value Range
pair true string Trading pair BIX_BTC, BIX_ETH, BTC_USDT, ETH_USDT......

the example of subscribing correctly

subscribe correctly

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

The example of subscribing success return data

[{
    "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
        ]
    }
}]

datadescription

"bids": The depth list of buyers
"asks": The depth list of sellers 
{
    "price": order price,
    "volume": order amount
}

Client will receive the all measured data as long as Depth updates, for example

[{
    "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
        ]
    }
}]

Subscribe Deals bibox_sub_spot_$pair_deals

{
  "event": "addChannel",
  "channel": "bibox_sub_spot_$pair_deals"
}
Name Necessary or not Type Description Default Value Range
pair true string Trading pair BIX_BTC, BIX_ETH, BTC_USDT, ETH_USDT......

the example of subscribing correctly

subscribe correctly

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

The example of subscribing success return data

[{
    "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 description

{
    "id": Trading history id,
    "pair": Trading pair,
    "price": The average price of trading,
    "amount": trading amount,
    "time": trading timestamp,
    "side": Taker trading side, 1-Buy, 2-Sell
}

Client will receive the incremental data as long as Deals updates, for example

[{
    "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
    ]
}]

Subscribe Ticker bibox_sub_spot_$pair_ticker

{
  "event": "addChannel",
  "channel": "bibox_sub_spot_$pair_ticker"
}
Name Necessary or not Type Description Default Value Range
pair true string Trading pair BIX_BTC, BIX_ETH, BTC_USDT, ETH_USDT......

the example of subscribing correctly

subscribe correctly

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

The example of subscribing success return data

[{
    "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 description

"data":{
   "pair": Trading pair
   "last": the lastest price
   "last_cny": The lastest price equivelant to CNY
   "last_usd": The lastest price equivelant to USD
   "high": 24h The highest price
   "low": 24h the lowest price
   "buy": The highest bid price
   "buy_amount": The highest bid amount
   "sell": The lowest ask price
   "sell_amount": The lowest ask amount
   "vol": 24h trading volume
   "percent": 24h price change percentage
   "timestamp": Timestamp
   "base_last_cny": The lastest trading price, equivalent to CNY (remains 8 decimals)
}

Client will receive the all measured data as long as Ticker updates, for example

[{
    "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"
    }
}]

Subscribe Login bibox_sub_spot_ALL_ALL_login

{
  "event": "addChannel",
  "channel": "bibox_sub_spot_ALL_ALL_login",
  "apikey": "thisisyourapikey",
  "sign": "thisissigneddata"
}
Name Necessary or not Type Description Default Value Range
apikey true string Your apikey
sign true string Use your apisecret to sign the whole request data

Note: Subscription Login channel will push user-related messages, including: assets, pending orders and history of orders

Sign Steps

1.Before sign

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

2.Sort in ascending with the key of Object

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

3.Format the data and sign

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(); // return thisissigneddata

4.Append the signed data to the request params

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

the example of completed signature (nodejs implements)

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;

the example of subscribing correctly

subscribe correctly

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

the successful response

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

Client will receive the incremental data as long as the user-related data(assets, pending orders and history of orders) updates, for example

Normal account assets

[{
     "channel":"bibox_sub_spot_ALL_ALL_login",
     "binary":"0",                              //push compressed data or not, 0-no, 1-yes
     "data_type":1,
     "data":{
         "assets":{                             //Type of Assets
             "normal":{                         //Normal assets
                 "BIX":{
                     "balance":"497.59601765",  //Available
                     "freeze":"0.00000000"      //Freeze   
                 },
                 "USDT":{
                     "balance":"20.52027574",
                     "freeze":"22.12000000"
                 }
             }
         }
     }
 }]

Credit account assets

[{
     "channel":"bibox_sub_spot_ALL_ALL_login",
     "binary":"0",
     "data_type":1,
     "data":{
         "assets":{                                 //Type of Assets
             "credit":{                             //Credit assets
                 "BIX_USDT":{                       //Pair
                     "BIX":{
                         "balance":"681.74441804",  //Available
                         "freeze":"0.00000000"      //Freeze
                     },
                     "USDT":{
                         "balance":"0.21698199",
                         "freeze":"0.00000000"
                     }
                 },
                 "BTC_USDT":{
                     "BTC":{
                         "balance":"100",
                         "freeze":"0.00000000"
                     },
                     "USDT":{
                         "balance":"10",
                         "freeze":"0.00000000"
                     }
                 }
             }
         }
     }
 }]

Note: Credit account assets are distinguished by Pair. The same currencies under different pairs (such as the USDT in BIX_USDT and BTC_USDT) are not related to each other.

Pending orders

[{
     "channel":"bibox_sub_spot_ALL_ALL_login",
     "binary":"0",
     "data_type":1,
     "data":{
         "orderpending":{                           //Type of Pending orders
             "id":159,
             "createdAt": 1512756997000,
             "account_type":0,  
             "coin_symbol":"LTC",                    //Trading Token
             "currency_symbol":"BTC",                //Pricing Token
             "order_side":2,                         //Trading side 1-Buy, 2-Sell
             "order_type":2,                         //2-limit order
             "price":"0.00900000",                   //order price
             "amount":"1.00000000",                  //order amount
             "money":"0.00900000",                   //currency amount (price * amount)
             "deal_amount":"0.00000000",             //deal amount
             "deal_percent":"0.00%",                 //deal percentage
             "unexecuted":"0.00000000",              //unexecuted amount
             "status":1                              //Status, 1-to be dealt, 2-dealt partly, 3-dealt totally, 4- cancelled partly, 5-cancelled totally, 6-to be cancelled
         }
     }
 }]

History of orders

[{
     "channel":"bibox_sub_spot_ALL_ALL_login",
     "binary":"0",
     "data_type":1,
     "data":{
         "history":{                                    //Type of History orders
             "id":"123432223346763",
             "createdAt": 1512756997000,
             "account_type":0,
             "coin_symbol":"LTC",
             "currency_symbol":"BTC", 
             "order_side":2, 
             "order_type":2,
             "price":"0.00886500", 
             "amount":"1.00000000",
             "money":"0.00886500",
             "relay_id":"11221615825364891",            // Order id
             "fee":0
         }
     }
}]