English
javascript python csharp

Basic Information

Spot API

Using the Spot API to develop applications, you can accurately obtain market data of the Bibox spot market and conduct automated transactions quickly. The Spot API contains many interfaces, which are roughly divided into the following groups according to their functions:

Spot API usage is as followsBase URL:

List of alternate API domains

https://api.bibox.tel/v1/public/queryApiDomain

The REST interface of the Spot API uses the following HTTP methods:

Parameters required by the REST interface of the Spot API should be appended to the request according to the following rules:

Response

The response data of the Spot API is returned in JSON format. For the specific format, please refer to the description of each interface.

Error

Errors from the Spot API are returned in the following JSON format:

{
  "error": error code,
  "message": "error message"
}

Among them, error indicates the type of error, and message contains the cause of the error or a hint on how to avoid the error. For specific error types, please refer to the Error chapter.

Time or Timestamp

The time values involved in the interface parameters and response data of the Spot API are all UNIX time in milliseconds.


Traffic Restrictions

Bibox imposes the following access restrictions on requests from the same IP:

  1. Access Limits
  2. Usage Limits CPU usage limit

Authentication

Example

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

const endpoints = 'https://api.bibox.com/api'
const apikey = "9e03e8fda27b6e4fc6b29bb244747dcf64092996"; // your apikey
const secret = "b825a03636ca09c884ca11d71cfc4217a98cb8bf"; // your secret


const queryStr = 'asset=BTC';
const sign = CryptoJS.HmacSHA256(queryStr, secret).toString(); // POST or DELETE  replace queryStr with bodyStr
const url = `${endpoints}/v4/userdata/accounts?${queryStr}`;

request.get(url,{
          headers: {
            'Content-Type': 'application/json',
            'Bibox-Api-Key': apikey,
            'Bibox-Api-Sign': sign,
            'Bibox-Expire-Time':Date.now()+5000 // optional
          },
        },

        function optionalCallback(err, httpResponse, body) {
          if (err) {
            return console.error('upload failed:', err);
          }
          console.log(body) // 7.the result

        });
import hashlib
import hmac
import requests

END_POINT = 'https://api.bibox.com/api'
API_KEY = '9e03e8fda27b6e4fc6b29bb244747dcf64092996'
SECRET_KEY = 'b825a03636ca09c884ca11d71cfc4217a98cb8bf'


def do_request():
    path = '/v4/userdata/accounts'
    query_str = 'asset=BTC'
    # POST or DELETE replace query_str with body_str
    sign = hmac.new(SECRET_KEY.encode("utf-8"), query_str.encode("utf-8"), hashlib.sha256).hexdigest()

    headers = {
        'Content-Type': 'application/json',
        'Bibox-Api-Key': API_KEY,
        'Bibox-Api-Sign': sign,
    }
    resp = requests.get(END_POINT + path, query_str, headers=headers)
    print(resp.text)


if __name__ == '__main__':
    do_request()

Authentication

Generate API Key

HTTP Request Header

Requests to access private interfaces must append the following HTTP request headers:

The following HTTP request headers can also be appended if desired:

Create signature

Before sending the request, first determine the message body for signing. For GET type requests, Query String is the message body that needs to be signed. For POST and DELETE type requests, Body String is the message body that needs to be signed. The specific method of signing is as follows:

Api Key permission

Private interfaces require specific permissions to execute. Appropriate permissions can be granted to the Api Key. If the Api Key is not granted the permissions required by an interface, then requests submitted using that Api Key will be rejected.

The following permissions can be granted to Api Key:

The permissions required by the interfaces are given in the description of each interface.


Market Data Endpoints

Get Listed Pairs

Request

let request = require("request");
const endPoint = 'https://api.bibox.com/api';
const url = `${endPoint}/v4/marketdata/pairs?symbol=BTC_USDT`
request.get(url,
        function optionalCallback(err, httpResponse, body) {
          if (err) {
            return console.error('upload failed:', err);
          }

          console.log(body)

        });
import requests

END_POINT = 'https://api.bibox.com/api';

def do_request():
    path = '/v4/marketdata/pairs?symbol=BTC_USDT'
    resp = requests.get(END_POINT + path)
    print(resp.text)

if __name__ == '__main__':
    do_request()

Response

[
  {
    "symbol": "BTC_USDT", // trading pair code
    "base": "BTC", // underlying asset code
    "quote": "USDT", // denominated asset code
    "status": "tradable", // trading pair status
    "min_price": "100000000", // minimum price
    "max_price": "0.0001", // maximum price
    "price_increment": "0.0001", // price increment
    "price_scale": 4, // price decimal places
    "min_quantity": "0.0001", // minimum order amount
    "max_quantity": "1000000", // maximum order amount
    "quantity_increment": "0.0001", // Increment of order amount
    "quantity_scale": 4, // order amount decimal places
    "min_order_value": "10" // minimum order value
  }
]

Get a list of currencies

Parameter name Parameter type Required or not Description
symbol string No Trading pair codes, such as BTC_USDT, ETH_USDT, etc.
Multiple trading pair codes can be specified in the following two forms
1. /pairs?symbol=BTC_USDT,ETH_USDT
2. /pairs?symbol=BTC_USDT&symbol=ETH_USDT
If the symbol parameter is not specified, the information of all trading pairs will be returned

Cache

Get Order Book

Request

let request = require("request");
const endPoint = 'https://api.bibox.com/api';
const url = `${endPoint}/v4/marketdata/order_book?symbol=BTC_USDT`
request.get(url,
        function optionalCallback(err, httpResponse, body) {
          if (err) {
            return console.error('upload failed:', err);
          }

          console.log(body)

        });
import requests

END_POINT = 'https://api.bibox.com/api';

def do_request():
    path = '/v4/marketdata/order_book?symbol=BTC_USDT'
    resp = requests.get(END_POINT + path)
    print(resp.text)

if __name__ == '__main__':
    do_request()

Response

{
  "i": "1027024", // update id
          "t": "1644558642100", // update time
          "b": [ // buy order
    [
      "46125.7", // Order price
      "0.079045" // Order amount
    ],
    [
      "46125.7", // Order price
      "0.079045" // Order amount
    ],
    [
      "46125.7", // Order price
      "0.079045" // Order amount
    ]
    ...
  ],
          "a": [ // sell order
    [
      "46125.7", // Order price
      "0.079045" // Order amount
    ],
    [
      "46125.7", // Order price
      "0.079045" // Order amount
    ],
    [
      "46125.7", // Order price
      "0.079045" // Order amount
    ]
    ...
  ]
}

Get depth data

Parameter name Parameter type Required or not Description
symbol string yes trading pair code, such as BTC_USDT, ETH_USDT, etc.
level int32 no Specifies the maximum level depth to return
Valid values 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000
Default value 100
price_scale integer No Specify the depth of consolidation by price. For example, the price of the specified trading pair has a maximum of 4 decimal places. When price_scale=0, the price returned includes a maximum of 4 decimal places, and when
price_scale=1, the returned price The price contains up to 3 decimal places, and the order quantity is the sum of all orders in the price range of 0.0010
The price returned when price_scale=2 contains up to 2 decimal places, and the order volume is the sum of all orders in the price range of 0.0100
br/>price_scale=3 The returned price contains at most 1 decimal place, and the order quantity is the sum of all orders in the price range of 0.1000.
price_scale=4 The returned price contains at most 0 decimal places, and the order volume is the price range Sum of all orders in 1.0000
Valid values 0, 1, 2, 3, 4, 5
Default value 0

Note: The data is sorted according to the best price, that is, the depth of the buy side is sorted by price from large to small, and the depth of the sell side is sorted by price from small to large

Cache

Get Candles

Request

let request = require("request");
const endPoint = 'https://api.bibox.com/api';
const url = `${endPoint}/v4/marketdata/candles?symbol=BTC_USDT&time_frame=1m`
request.get(url,
        function optionalCallback(err, httpResponse, body) {
          if (err) {
            return console.error('upload failed:', err);
          }

          console.log(body)

        });
import requests

END_POINT = 'https://api.bibox.com/api';

def do_request():
    path = '/v4/marketdata/candles?symbol=BTC_USDT&time_frame=1m'
    resp = requests.get(END_POINT + path)
    print(resp.text)

if __name__ == '__main__':
    do_request()

Response

[
  [
    "1644224940000", // start time
    "10190.53", // opening price
    "10192.5", // maximum price
    "9806.82", // minimum price
    "10127.37", // closing price
    "0.834", // transaction volume
    "8370.40506", // transaction value
    "1", // first transaction id
    278 // The total number of transactions in the range
  ],
  [
    "1644224940000", // start time
    "10190.53", // opening price
    "10192.5", // maximum price
    "9806.82", // minimum price
    "10127.37", // closing price
    "0.834", // transaction volume
    "8370.40506", // transaction value
    "1", // first transaction id
    278 // The total number of transactions in the range
  ],
  [
    "1644224940000", // start time
    "10190.53", // opening price
    "10192.5", // maximum price
    "9806.82", // minimum price
    "10127.37", // closing price
    "0.834", // transaction volume
    "8370.40506", // transaction value
    "1", // first transaction id
    278 // The total number of transactions in the range
  ]
  ...
]

Get K-line data

Parameter name Parameter type Required or not Description
symbol string yes trading pair code, such as BTC_USDT, ETH_USDT, etc.
time_frame string Yes K-line data time frame
Valid values 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 12h, 1d, 3d, 1W or 1M
before int64 No utc time
limited to return the latest time of the K-line record
after int64 No utc time
limited to return the earliest time of the K-line record
limit integer No Get the maximum number of K-line records
The default value is 100, the maximum value is 1000
  1. symbol + time_frame --> cache
  2. symbol + time_frame + limit --> cache
  3. symbol + time_frame + before --> database
  4. symbol + time_frame + before + limit --> database
  5. symbol + time_frame + after --> database
  6. symbol + time_frame + after + limit --> database

The returned results are sorted by time from earliest to latest

Get Trades

Request

let request = require("request");
const endPoint = 'https://api.bibox.com/api';
const url = `${endPoint}/v4/marketdata/trades?symbol=BTC_USDT`
request.get(url,
        function optionalCallback(err, httpResponse, body) {
          if (err) {
            return console.error('upload failed:', err);
          }

          console.log(body)

        });
import requests

END_POINT = 'https://api.bibox.com/api';

def do_request():
    path = '/v4/marketdata/trades?symbol=BTC_USDT'
    resp = requests.get(END_POINT + path)
    print(resp.text)

if __name__ == '__main__':
    do_request()

Response

[
  {
    "i": "17122255", // transaction id
    "p": "46125.7", // transaction price
    "q": "0.079045", // transaction amount
    "s": "buy", // Taker's transaction direction
    "t": "1628738748319" // transaction time
  },
  {
    "i": "17122255", // transaction id
    "p": "46125.7", // transaction price
    "q": "0.079045", // transaction amount
    "s": "buy", // Taker's transaction direction
    "t": "1628738748319" // transaction time
  },
  {
    "i": "17122255", //  transaction id
    "p": "46125.7", //  transaction price
    "q": "0.079045", // transaction amount
    "s": "buy", // Taker's transaction direction
    "t": "1628738748319" // transaction time
  }
  ...
]

Get transaction history

Parameter name Parameter type Required or not Description

| symbol | string | yes | trading pair code, such as BTC_USDT, ETH_USDT, etc. | | start_time | int64 | no | limited to return the earliest time of transaction records | | end_time | int64 | no | limited to return the latest time of transaction records | | before | int64 | no | transaction id
limited to return the maximum id of transaction records | | after | int64 | no | transaction id
limited to return the maximum id of transaction records | | limit | integer | no | Get the maximum number of trade records
The default value is 100, the maximum value is 1000 |

  1. symbol --> cache
  2. symbol + limit --> cache
  3. symbol + start_time --> database
  4. symbol + start_time + limit --> database
  5. symbol + end_time --> database
  6. symbol + end_time + limit --> database
  7. symbol + start_time + end_time --> database
  8. symbol + start_time + end_time + limit --> database
  9. symbol + before --> database
  10. symbol + before + limit --> database
  11. symbol + after --> database
  12. symbol + after + limit --> database

The parameter combination whose data source is cache is used to get the last 1000 transaction records

The parameter combination whose data source is database is used to obtain earlier transaction records

If the latest transaction record is obtained with the parameter combination whose data source is database, the result will be slightly delayed than the cache data source * Usage Usage example: Get all transaction records of a trading pair within three months

  1. First use the symbol + limit parameter combination to get the latest transaction record
  2. Use the tradeId of the first record obtained as the value of the before parameter, and repeatedly use the symbol + before + limit parameter combination to obtain more records, until all transaction records within three months are obtained and then stop

The returned results are sorted by transaction record id from small to large

Get Tickers

Request

let request = require("request");
const endPoint = 'https://api.bibox.com/api';
const url = `${endPoint}/v4/marketdata/ticker?symbol=BTC_USDT`
request.get(url,
        function optionalCallback(err, httpResponse, body) {
          if (err) {
            return console.error('upload failed:', err);
          }

          console.log(body)

        });
import requests

END_POINT = 'https://api.bibox.com/api';

def do_request():
    path = '/v4/marketdata/ticker?symbol=BTC_USDT'
    resp = requests.get(END_POINT + path)
    print(resp.text)

if __name__ == '__main__':
    do_request()

Response

[
  {
    "s": "BTC_USDT",  // trading pair code
    "o": "99.00000000",  // opening price
    "h": "100.00000000",  // highest price
    "l": "0.10000000",  // lowest price
    "p": "4.00000200",  // latest price
    "q": "0.002",  // latest volume
    "v": "8913.30000000",  // 24 hour volume
    "a": "15.30000000",  // 24 hour transaction value
    "c": "-94.99999800",  // 24 hour Change
    "t": 123456,  // 24 hour transaction count
    "f": 1234,  // 24 hour first transaction id
    "bp":9959.87,  // Best current bid price
    "bq":0.007,  // Best current bid quantity
    "ap":10022.77,  // Best current ask price
    "aq":0.006  // Best current ask quantity
  }
]

Get quote data

Parameter name Parameter type Required or not Description
symbol string Yes Trading pair code, such as BTC_USDT, ETH_USDT, etc.
Multiple trading pair codes can be specified in the following two forms
1. /pairs?symbol=BTC_USDT,ETH_USDT
2. /pairs?symbol=BTC_USDT&symbol=ETH_USDT

Cache

Market Data Streams

Overview

Example

const WebSocket = require('ws');
const biboxws = 'wss://market-wss.bibox360.com';

let wsClass = function () {
};

wsClass.prototype._initWs = async function () {
    let that = this;
    console.log(biboxws)
    let ws = new WebSocket(biboxws);
    that.ws = ws;

    ws.on('open', function open() {
        console.log(new Date(), 'open')
        ws.send(JSON.stringify({
            "id": 123,
            "method": "SUBSCRIBE",
            "params": [
                "BTC_USDT.order_book.20",
            ]
        }));
        setInterval(function () {
          ws.ping(Date.now())
        },30000)
    });

    ws.on('close', data => {
        console.log('close, ', data);
    });

    ws.on('error', data => {
        console.log('error', data);
    });

    ws.on('ping', data => {
        console.log('ping ', data.toString('utf8'));
    });

    ws.on('pong', data => {
        console.log('pong ', data.toString('utf8'));
    });

    ws.on('message', data => {
        console.log("rece message")
        console.log(data)
    });
};

let instance = new wsClass();

instance._initWs().catch(err => {
    console.log(err);
});

import websocket
import json

ws_url = 'wss://market-wss.bibox360.com'

def stringify(obj):
    return json.dumps(obj, sort_keys=True).replace("\'", "\"").replace(" ", "")


def get_sub_str():
    subdata = {
        "id": 123,
        "method": "SUBSCRIBE",
        "params": [
            "BTC_USDT.order_book.20",
        ]
    }
    return stringify(subdata)


def on_message(ws, message):
    print(message)


def on_error(ws, error):
    print(error)


def on_close(ws):
    print("### closed ###")


def on_open(ws):
    ws.send(get_sub_str())

def connect():
    # websocket.enableTrace(True)
    ws = websocket.WebSocketApp(ws_url,
                                on_message=on_message,
                                on_error=on_error,
                                on_close=on_close)
    ws.on_open = on_open
    ws.run_forever(ping_interval=30, ping_timeout=5)


if __name__ == "__main__":
    connect()

The market information can be obtained in time by using the Websocket push service.

After connecting, the client can send the following JSON-formatted request to the server

{
  "id": 123, // The request id given by the client
  "method": "..." // request type
  "params": [ // request parameter list
    "...",
    "...",
    ...
  ]
}

After receiving the request, the server will send the following JSON response to the client

{
  "id": 123, // request id
  "result": "..." // request result
}

If an error occurs, the server will send the following error message to the client

{
  "id": 123, // request id
  "error": -1000, // error code
  "message": "..." // error description
}

At the same time, the server will also send the following data stream in JSON format to the client, the data stream contains the change information of market conditions

{
  "stream": "BTC_USDT.trades", // data stream name
  "data": ..., // data
}

Request: Subscribe to a data stream

{
  "id": 1,
  "method": "SUBSCRIBE"
  "params": [
    "stream name",
    "stream name",
    ...
  ]
}

After connecting, please send the request to the server first, and then the server will send the corresponding data stream to the client when the market price changes.

"data stream name" is the data stream name, which is a string in the following format. symbol.data_type.param1.param2...

Among them, symbol is the name of the trading pair, such as BTC_USDT, ETH_USDT, etc. data_type is the data type, currently only the following data types are supported order_book: depth trades: list of trades candles: candlesticks ticker: latest transaction information

After data_type is the parameter list. Different data types have different parameter lists. These will be introduced later.

Request: Unsubscribe to a data stream

{
  "id": 1,
  "method": "UNSUBSCRIBE",
  "params": [
    "data stream name",
    "data stream name",
    ...
  ]
}

If the request is handled correctly by the server, the client receives the following response:

...

If an error occurs in the request, the client receives the following error response:

...

Request Methods

Request type and parameters

The client can send the following request to the server

{
  "id": 123, // request id given by client
  "method": "..." // request type
  "params": [ // request parameter list
    "...",
    "...",
    ...
  ]
}
optional value description
SUBSCRIBE 1. Subscribe to the data stream
2. The parameter is a list of data stream names
3. After successful subscription, the server will send the data stream to the client when the market price changes
UNSUBSCRIBE 1. Unsubscribe data stream
2. The parameter is a list of data stream names
3. After successfully unsubscribing, the client will no longer receive the corresponding data stream

Subscribe Order Book

Subscribe to depth information*

Send the following request to subscribe to depth information

{
  "id": 123,
  "method": "SUBSCRIBE"
  "params": [
    "BTC_USDT.order_book.20",
    "ETH_USDT.order_book.20",
    ...
  ]
}
  1. The parameter of the request is the depth stream name, in the following format:

data flow

  {
    "stream": "BTC_USDT.order_book.20",
    "data": {
      "i": "1027024", // update id
      "t": "1644558642100", // update time
      "b": [ // bid
        [
            "46125.7", // Order price
            "0.079045" // Order amount
          ],
        [
            "46125.7", // Order price
            "0.079045" // Order amount
          ],
        [
            "46125.7", // Order price
            "0.079045" // Order amount
          ],
        ...
      ],
      "a": [ // ask
        [
            "46125.7", // Order price
            "0.079045" // Order amount
          ],
        [
            "46125.7", // Order price
            "0.079045" // Order amount
          ],
        [
            "46125.7", // Order price
            "0.079045" // Order amount
          ],
       ...
      ]
    }
  }

After a successful subscription, the client will first receive a full-depth data stream, and then will receive an incremental change data stream. Please use the following methods to synthesize a full-depth data stream, or use the SDK.

  ...

Subscribe Trades

Subscribe to transaction list

Send the following request to subscribe to the transaction list

{
  "id": 123,
  "method": "SUBSCRIBE"
  "params": [
    "BTC_USDT.trades",
    "ETH_USDT.trades",
    ...
  ]
}
  1. The parameter of the request is the name of the transaction flow, in the following format:

Data flow

{
  "stream": "BTC_USDT.trades",
  "data": [
    {
     "i": "17122255", // transaction id
      "p": "46125.7", // transaction price
      "q": "0.079045", // transaction volume
      "s": "buy", // Taker's transaction direction
      "t": "1628738748319" // transaction time
    },
    {
      "i": "17122255", // transaction id
      "p": "46125.7", // transaction price
      "q": "0.079045", // transaction volume
      "s": "buy", // Taker's transaction direction
      "t": "1628738748319" // transaction time
    },
    {
      "i": "17122255", // transaction id
      "p": "46125.7", // transaction price
      "q": "0.079045", // transaction volume
      "s": "buy", // Taker's transaction direction
      "t": "1628738748319" // transaction time
    },
    ...
  ]
}

Subscribe Candles

Subscribe to candles

Send the following request to subscribe to the candles

{
  "id": 123,
  "method": "SUBSCRIBE"
  "params": [
    "BTC_USDT.candles.1m",
    "ETH_USDT.candles.1h",
    ...
  ]
}
  1. The candles flow name format is as follows:

Data flow

{
  "stream": "BTC_USDT.candles.1m",
  "data": [
    [
      "1644224940000", // start time
      "10190.53", // opening price
      "10192.5", // maximum price
      "9806.82", // minimum price
      "10127.37", // closing price
      "0.834", // transaction volume
      "8370.40506", // transaction value
      "1", // first transaction id
      278 // The total number of transactions in the range
    ],
    [
      "1644224940000", // start time
      "10190.53", // opening price
      "10192.5", // maximum price
      "9806.82", // minimum price
      "10127.37", // closing price
      "0.834", // transaction volume
      "8370.40506", // transaction value
      "1", // first transaction id
      278 // The total number of transactions in the range
    ],
    [
      "1644224940000", // start time
      "10190.53", // opening price
      "10192.5", // maximum price
      "9806.82", // minimum price
      "10127.37", // closing price
      "0.834", // transaction volume
      "8370.40506", // transaction value
      "1", // first transaction id
      278 // The total number of transactions in the range
    ],
    ...
  ]
}

Subscribe Tickers

...


User Data Endpoints

Get Accounts

Request

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

const endpoints = 'https://api.bibox.com/api'
const apikey = "9e03e8fda27b6e4fc6b29bb244747dcf64092996"; // your apikey
const secret = "b825a03636ca09c884ca11d71cfc4217a98cb8bf"; // your secret


const queryStr = 'asset=BTC';
const sign = CryptoJS.HmacSHA256(queryStr, secret).toString();
const url = `${endpoints}/v4/userdata/accounts?${queryStr}`;

request.get(url,{
          headers: {
            'Content-Type': 'application/json',
            'Bibox-Api-Key': apikey,
            'Bibox-Api-Sign': sign,
            'Bibox-Expire-Time':Date.now()+5000 // optional
          },
        },

        function optionalCallback(err, httpResponse, body) {
          if (err) {
            return console.error('upload failed:', err);
          }
          console.log(body) // 7.the result

        });
import hashlib
import hmac
import requests

END_POINT = 'https://api.bibox.com/api'
API_KEY = '9e03e8fda27b6e4fc6b29bb244747dcf64092996'
SECRET_KEY = 'b825a03636ca09c884ca11d71cfc4217a98cb8bf'


def do_request():
    path = '/v4/userdata/accounts'
    query_str = 'asset=BTC'
    sign = hmac.new(SECRET_KEY.encode("utf-8"), query_str.encode("utf-8"), hashlib.sha256).hexdigest()

    headers = {
        'Content-Type': 'application/json',
        'Bibox-Api-Key': API_KEY,
        'Bibox-Api-Sign': sign,
    }
    resp = requests.get(END_POINT + path, query_str, headers=headers)
    print(resp.text)


if __name__ == '__main__':
    do_request()

Response

[
  {
    "s":"USDT",  // asset code
    "a":10000,  // Available amount
    "h":0  // frozen amount
  },
    {
    "s":"BTC",  // asset code
    "a":10000,  // Available amount
    "h":0  // frozen amount
  },
    {
    "s":"ETH",  // asset code
    "a":10000,  // Available amount
    "h":0  // frozen amount
  }
  ...
]

Get the balance, freezing and other information of various assets in the account corresponding to the API Key

Parameter name Parameter type Required or not Description
asset string No Asset code, such as BTC, ETH, etc.
Multiple asset codes can be specified in the following two forms
1. /v4/userdata/accounts?asset=BTC,ETH
2. /v4/userdata/accounts?asset=BTC&asset=ETH
If the asset parameter is not specified, it will return the information of all assets

Cache

Get an account's ledger

Request

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

const endpoints = 'https://api.bibox.com/api'
const apikey = "9e03e8fda27b6e4fc6b29bb244747dcf64092996"; // your apikey
const secret = "b825a03636ca09c884ca11d71cfc4217a98cb8bf"; // your secret


const queryStr = 'asset=BTC&end_time=1651895799668&limit=10';
const sign = CryptoJS.HmacSHA256(queryStr, secret).toString();
const url = `${endpoints}/v4/userdata/ledger?${queryStr}`;

request.get(url,{
        headers: {
            'Content-Type': 'application/json',
            'Bibox-Api-Key': apikey,
            'Bibox-Api-Sign': sign,
        },
    },

    function optionalCallback(err, httpResponse, body) {
        if (err) {
            return console.error('upload failed:', err);
        }
        console.log(body) // 7.the result

    });
import hashlib
import hmac
import requests

END_POINT = 'https://api.bibox.com/api'
API_KEY = '9e03e8fda27b6e4fc6b29bb244747dcf64092996'
SECRET_KEY = 'b825a03636ca09c884ca11d71cfc4217a98cb8bf'


def do_request():
    path = '/v4/userdata/ledger'
    query_str = 'asset=BTC&end_time=1651895799668&limit=10'
    sign = hmac.new(SECRET_KEY.encode("utf-8"), query_str.encode("utf-8"), hashlib.sha256).hexdigest()

    headers = {
        'Content-Type': 'application/json',
        'Bibox-Api-Key': API_KEY,
        'Bibox-Api-Sign': sign,
    }
    resp = requests.get(END_POINT + path, query_str, headers=headers)
    print(resp.text)


if __name__ == '__main__':
    do_request()

Response

[
  {
    "i":1125899906842648350,  // entry id
    "s":"BTC",  // asset symbol
    "T":"trade",  // entry type: transfer, trade, fee
    "a":0.003,  // amount
    "b":10.009,  // balance
    "t":1643289492985  // time
  },
  {
    "i":1125899906842648350,  // entry id
    "s":"USDT",  // asset symbol
    "T":"trade",  // entry type: transfer, trade, fee
    "a":0.003,  // amount
    "b":10.009,  // balance
    "t":1643289492985  // time
  },
  {
    "i":1125899906842648350,  // entry id
    "s":"ETH",  // asset symbol
    "T":"trade",  // entry type: transfer, trade, fee
    "a":0.003,  // amount
    "b":10.009,  // balance
    "t":1643289492985  // time
  }
  ...
]

Get the bill of the account corresponding to the API Key, including all records of changing the account balance, such as fund transfer, transaction, handling fee collection, etc.

Parameter name Parameter type Required or not Description
asset string No Asset code, such as BTC, ETH, etc.
Multiple asset codes can be specified in the following two forms
1. /v4/userdata/ledger?asset=BTC,ETH
2. /v4/userdata/ledger?asset=BTC&asset=ETH
If the asset parameter is not specified, it will return the bill records of all assets
start_time int64 No Limited to return the earliest time of the bill records
end_time int64 no Limited to return the latest time of the bill records
before int64 No Bill record id
Limited to return the maximum id value of the bill records
after int64 No Bill record id
Limited to return the minimum id value of the bill records
limit int32 No Limited to return the maximum number of the bill records
default 100
start_time int64 No Limited to return the earliest time of the bill records
start_time int64 No Limited to return the earliest time of the bill records

DB

Create an order

Request

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

const endpoints = 'https://api.bibox.com/api'
const apikey = "9e03e8fda27b6e4fc6b29bb244747dcf64092996"; // your apikey
const secret = "b825a03636ca09c884ca11d71cfc4217a98cb8bf"; // your secret

const param = {
    symbol:'BTC_USDT',
    side:'sell',
    type:'limit',
    quantity:'0.0001',
    price:'50000'
}

let bodyStr = JSON.stringify(param);
const sign = CryptoJS.HmacSHA256(bodyStr, secret).toString();
const url = `${endpoints}/v4/userdata/order`;

request.post({
        url:url,
        body:param,
        json:true,
        headers: {
            'Content-Type': 'application/json',
            'Bibox-Api-Key': apikey,
            'Bibox-Api-Sign': sign,
            'Bibox-Expire-Time':Date.now()+5000  // optional

        },
    },

    function optionalCallback(err, httpResponse, body) {
        if (err) {
            return console.error('upload failed:', err);
        }
        console.log(body) // 7.the result

    });

import hashlib
import hmac
import requests
import json
import time

END_POINT = 'https://api.bibox.com/api'
API_KEY = '9e03e8fda27b6e4fc6b29bb244747dcf64092996'
SECRET_KEY = 'b825a03636ca09c884ca11d71cfc4217a98cb8bf'
t = time.time()

def do_request():

    param = {
        'symbol': 'BTC_USDT',
        'side': 'sell',
        'type': 'limit',
        'quantity': '0.0001',
        'price': '50000'
    }
    body_str = json.dumps(param)
    sign = hmac.new(SECRET_KEY.encode("utf-8"), body_str.encode("utf-8"), hashlib.sha256).hexdigest()
    path = '/v4/userdata/order'
    headers = {
        'Content-Type': 'application/json',
        'Bibox-Api-Key': API_KEY,
        'Bibox-Api-Sign': sign,
        'Bibox-Expire-Time':str(round(t * 1000 +5000)) # optional
    }
    resp = requests.post(END_POINT + path, json=param, headers=headers)
    print(resp.text)


if __name__ == '__main__':
    do_request()

Response

{
  "i": 4611688217450643477,  // The order id assigned by the exchange
  "I": "",  // User specified order id
  "m": "BTC_USDT",  // trading pair code
  "T": "limit",  // order type
  "s": "sell",  // order direction
  "Q": -0.0100,  // order amount
  "P": 10043.8500,  // order price
  "t": "gtc",  // Time In Force
  "o": false,  // Post Only
  "S": "filled",  // order status
  "E": -0.0100,  // transaction volume
  "e": -100.43850000,  // transaction value
  "C": 1643193746043,  // creation time
  "U": 1643193746464,  // update time
  "n": 2,  // Number of transactions
  "F": [{
    "i": 13,  // transaction id
    "t": 1643193746464,  // Transaction time
    "p": 10043.85,  // transaction price
    "q": -0.009,  // transaction volume
    "l": "maker",  // Maker / Taker transaction 
    "f": {
      "a": "USDT",  // The asset used for the transaction to pay the handling fee
      "m": 0.09039465000  // The transaction fee
    }
  }, {
    "i": 12,
    "t": 1643193746266,
    "p": 10043.85,
    "q": -0.001,
    "l": "maker",
    "f": {
      "a": "USDT",
      "m": 0.01004385000
    }
  }],
  "f": [{
    "a": "USDT",  // Assets used to pay fees
    "m": 0.10043850000  // Total handling fee
  }]
}

Submit an order

Parameter name Parameter type Required or not Description
symbol string yes trading pair code, such as BTC_USDT, ETH_USDT, etc.
side string yes order direction, valid value buy, sell, case insensitive
type string yes order type, valid value limit
client_order_id string No Order id, a string with a valid value of an int64 integer, it is recommended to use the Unix timestamp when the order was submitted
quantity decimal No Order Quantity
price decimal No Order Limit
time_in_force string No Order Timeliness
Valid value gtc, ioc
gtc means that the order that is not fully filled will remain valid until the user cancels the order
ioc means that the order matching will immediately cancel the order that cannot be fully filled at the time of placing the order,
Any transaction will be retained
The default value gtc
post_only bool no ...

Order object Up to 20 transactions of the order If the order has more than 20 transactions, the object only contains the last 20 transactions, and other transactions can be obtained through the fills interface

Get an order

Request

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

const endpoints = 'https://api.bibox.com/api'
const apikey = "9e03e8fda27b6e4fc6b29bb244747dcf64092996"; // your apikey
const secret = "b825a03636ca09c884ca11d71cfc4217a98cb8bf"; // your secret


const queryStr = 'id=1118621391231';
const sign = CryptoJS.HmacSHA256(queryStr, secret).toString();
const url = `${endpoints}/v4/userdata/order?${queryStr}`;

request.get(url,{
        headers: {
            'Content-Type': 'application/json',
            'Bibox-Api-Key': apikey,
            'Bibox-Api-Sign': sign,
        },
    },

    function optionalCallback(err, httpResponse, body) {
        if (err) {
            return console.error('upload failed:', err);
        }
        console.log(body) // 7.the result

    });
import hashlib
import hmac
import requests

END_POINT = 'https://api.bibox.com/api'
API_KEY = '9e03e8fda27b6e4fc6b29bb244747dcf64092996'
SECRET_KEY = 'b825a03636ca09c884ca11d71cfc4217a98cb8bf'


def do_request():
    path = '/v4/userdata/order'
    query_str = 'id=14118828812271651'
    sign = hmac.new(SECRET_KEY.encode("utf-8"), query_str.encode("utf-8"), hashlib.sha256).hexdigest()

    headers = {
        'Content-Type': 'application/json',
        'Bibox-Api-Key': API_KEY,
        'Bibox-Api-Sign': sign,
    }
    resp = requests.get(END_POINT + path, query_str, headers=headers)
    print(resp.text)


if __name__ == '__main__':
    do_request()

Response

{
  "i": 4611688217450643477,  // The order id assigned by the exchange
  "I": "",  // User specified order id
  "m": "BTC_USDT",  // trading pair code
  "T": "limit",  // order type
  "s": "sell",  // order direction
  "Q": -0.0100,  // order amount
  "P": 10043.8500,  // order price
  "t": "gtc",  // Time In Force
  "o": false,  // Post Only
  "S": "filled",  // order status
  "E": -0.0100,  // transaction volume
  "e": -100.43850000,  // transaction value
  "C": 1643193746043,  // creation time
  "U": 1643193746464,  // update time
  "n": 2,  // Number of transactions
  "F": [{
    "i": 13,  // transaction id
    "t": 1643193746464,  // Transaction time
    "p": 10043.85,  // transaction price
    "q": -0.009,  // transaction volume
    "l": "maker",  // Maker / Taker transaction 
    "f": {
      "a": "USDT",  // The asset used for the transaction to pay the handling fee
      "m": 0.09039465000  // The transaction fee
    }
  }, {
    "i": 12,
    "t": 1643193746266,
    "p": 10043.85,
    "q": -0.001,
    "l": "maker",
    "f": {
      "a": "USDT",
      "m": 0.01004385000
    }
  }],
  "f": [{
    "a": "USDT",  // Assets used to pay fees
    "m": 0.10043850000  // Total handling fee
  }]
}

Get the order with the specified id

Parameter name Parameter type Required or not Description
id string yes order id
The order id can be assigned by the exchange, or
can be defined by the user (use the client_order_id parameter when submitting the order).
When using a custom id, you need to add the "c:" prefix before the id.
For example: when submitting an order, a custom id "123" is used, and when obtaining an order you need to use "c:123".

Get Orders

Request

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

const endpoints = 'https://api.bibox.com/api'
const apikey = "9e03e8fda27b6e4fc6b29bb244747dcf64092996"; // your apikey
const secret = "b825a03636ca09c884ca11d71cfc4217a98cb8bf"; // your secret


const queryStr = 'limit=2&status=settled&symbol=BTC_USDT';
const sign = CryptoJS.HmacSHA256(queryStr, secret).toString();
const url = `${endpoints}/v4/userdata/orders?${queryStr}`;

request.get(url,{
        headers: {
            'Content-Type': 'application/json',
            'Bibox-Api-Key': apikey,
            'Bibox-Api-Sign': sign,
        },
    },

    function optionalCallback(err, httpResponse, body) {
        if (err) {
            return console.error('upload failed:', err);
        }
        console.log(body) // 7.the result

    });
import hashlib
import hmac
import requests

END_POINT = 'https://api.bibox.com/api'
API_KEY = '9e03e8fda27b6e4fc6b29bb244747dcf64092996'
SECRET_KEY = 'b825a03636ca09c884ca11d71cfc4217a98cb8bf'


def do_request():
    path = '/v4/userdata/orders'
    query_str = 'limit=2&status=settled&symbol=BTC_USDT'
    sign = hmac.new(SECRET_KEY.encode("utf-8"), query_str.encode("utf-8"), hashlib.sha256).hexdigest()

    headers = {
        'Content-Type': 'application/json',
        'Bibox-Api-Key': API_KEY,
        'Bibox-Api-Sign': sign,
    }
    resp = requests.get(END_POINT + path, query_str, headers=headers)
    print(resp.text)


if __name__ == '__main__':
    do_request()

Response

[
  {
    "i": 4611688217450643477, // The order id assigned by the exchange
    "I": "", // User specified order id
    "m": "BTC_USDT", // trading pair code
    "T": "limit", // order type
    "s": "sell", // order direction
    "Q": -0.0100, // Order amount
    "P": 10043.8500, // order price
    "t": "gtc", // Time In Force
    "o": false, // Post Only
    "S": "filled", // order status
    "E": -0.0100, // transaction volume 
    "e": -100.43850000, // transaction value
    "C": 1643193746043, // creation time
    "U": 1643193746464, // update time
    "n": 2, // number of transactions
    "F": [{
      "i": 13, // transaction id
      "t": 1643193746464, // transaction time
      "p": 10043.85, // transaction price
      "q": -0.009, // transaction volume
      "l": "maker", // Maker / Taker transaction 
      "f": {
        "a": "USDT", // This transaction is used to pay the transaction fee
        "m": 0.09039465000 // The handling fee for this transaction
      }
    }, {
      "i": 12,
      "t": 1643193746266,
      "p": 10043.85,
      "q": -0.001,
      "l": "maker",
      "f": {
        "a": "USDT",
        "m": 0.01004385000
      }
    }],
    "f": [{
      "a": "USDT",  // Assets used to pay fees
      "m": 0.10043850000  // Total handling fee
    }]
  }
  ...
]

Obtain the order that meets the following conditions in the account corresponding to ApiKey

  1. All unsettled orders
  2. Settled orders within three months, including rejected, cancelled and filled orders
  3. All completed orders
  4. All cancelled partial transaction orders
Parameter name Parameter type Required or not Description
status string No Valid values unsettled, settled
unsettled means get unsettled orders, the returned results are sorted in reverse order by order creation time
settled means settled orders are acquired, and the returned results are sorted in reverse order by order settlement time
Default unsettled
symbol string No Trading pair code, such as BTC_USDT, ETH_USDT, etc.
When status=unsettled, if symbol is not specified, it will return unsettled orders for all trading pairs
When status=settled, symbol parameters must be given
start_time long no limited to return the last creation time of the order
end_time long no limited to return the last creation time of the order
before int64 no order update id
limited to return the maximum update id of the order
after int64 no delegate update id
limited to return the minimum update id of the order
limit long No Specify the maximum number of orders to return

The returned unsettled orders are sorted by creation time from earliest to latest The returned settled orders are sorted by settlement time from earliest to latest

Cancel an Order

Request

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

const endpoints = 'https://api.bibox.com/api'
const apikey = "9e03e8fda27b6e4fc6b29bb244747dcf64092996"; // your apikey
const secret = "b825a03636ca09c884ca11d71cfc4217a98cb8bf"; // your secret

const param = {
    id:'14244173146202090'
}

let bodyStr = JSON.stringify(param);
const sign = CryptoJS.HmacSHA256(bodyStr, secret).toString();
const url = `${endpoints}/v4/userdata/order`;

request.delete({
        url:url,
        body:param,
        json:true,
        headers: {
            'Content-Type': 'application/json',
            'Bibox-Api-Key': apikey,
            'Bibox-Api-Sign': sign,
            'Bibox-Expire-Time':Date.now()+5000 // optional
        },
    },

    function optionalCallback(err, httpResponse, body) {
        if (err) {
            return console.error('upload failed:', err);
        }
        console.log(body) // 7.the result

    });
import hashlib
import hmac
import requests
import json
import time

END_POINT = 'https://api.bibox.com/api'
API_KEY = '9e03e8fda27b6e4fc6b29bb244747dcf64092996'
SECRET_KEY = 'b825a03636ca09c884ca11d71cfc4217a98cb8bf'
t = time.time()

def do_request():

    param = {
        'id': '14245272657638034'
    }
    body_str = json.dumps(param)
    sign = hmac.new(SECRET_KEY.encode("utf-8"), body_str.encode("utf-8"), hashlib.sha256).hexdigest()
    path = '/v4/userdata/order'
    headers = {
        'Content-Type': 'application/json',
        'Bibox-Api-Key': API_KEY,
        'Bibox-Api-Sign': sign,
        'Bibox-Expire-Time':str(round(t * 1000 +5000)) #optional
    }
    resp = requests.delete(END_POINT + path, json=param, headers=headers)
    print(resp.text)


if __name__ == '__main__':
    do_request()

Response

{
  "i": 4611688217450643477, // The order id assigned by the exchange
  "I": "", // User specified order id
  "m": "BTC_USDT", // trading pair code
  "T": "limit", // order type
  "s": "sell", // order direction
  "Q": -0.0100, // Order amount
  "P": 10043.8500, // order price
  "t": "gtc", // Time In Force
  "o": false, // Post Only
  "S": "filled", // order status
  "E": -0.0100, // transaction volume 
  "e": -100.43850000, // transaction value
  "C": 1643193746043, // creation time
  "U": 1643193746464, // update time
  "n": 2, // number of transactions
  "F": [{
    "i": 13, // deal id
    "t": 1643193746464, // transaction time
    "p": 10043.85, // transaction price
    "q": -0.009, // transaction volume
    "l": "maker", // Maker / Taker transaction 
    "f": {
      "a": "USDT", // This transaction is used to pay the transaction fee
      "m": 0.09039465000 // The handling fee for this transaction
    }
  }, {
    "i": 12,
    "t": 1643193746266,
    "p": 10043.85,
    "q": -0.001,
    "l": "maker",
    "f": {
      "a": "USDT",
      "m": 0.01004385000
    }
  }],
  "f": [{
    "a": "USDT",  // Assets used to pay fees
    "m": 0.10043850000  // Total handling fee
  }]
}

Revoke the order with the specified id

Parameter name Parameter type Required or not Description
id string yes order id
The order id can be assigned by the exchange,
or user-defined (use the client_order_id parameter when submitting the order).
When using a custom id, you need to add a "c:" prefix before the id.
For example: the custom id "123" is used when submitting the order, and "c:123" must be used when canceling the order.

If the order with the specified id has been settled, or if there is no order with the specified id, you will receive a -3004 error.

Cancel all Orders

Request

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

const endpoints = 'https://api.bibox.com/api'
const apikey = "9e03e8fda27b6e4fc6b29bb244747dcf64092996"; // your apikey
const secret = "b825a03636ca09c884ca11d71cfc4217a98cb8bf"; // your secret

const param = {
    symbol:'BTC_USDT'
}

let bodyStr = JSON.stringify(param);
const sign = CryptoJS.HmacSHA256(bodyStr, secret).toString();
const url = `${endpoints}/v4/userdata/orders`;

request.delete({
        url:url,
        body:param,
        json:true,
        headers: {
            'Content-Type': 'application/json',
            'Bibox-Api-Key': apikey,
            'Bibox-Api-Sign': sign,
            'Bibox-Expire-Time':Date.now()+5000 // optional
        },
    },

    function optionalCallback(err, httpResponse, body) {
        if (err) {
            return console.error('upload failed:', err);
        }
        console.log(body) // 7.the result

    });
import hashlib
import hmac
import requests
import json
import time

END_POINT = 'https://api.bibox.com/api'
API_KEY = '9e03e8fda27b6e4fc6b29bb244747dcf64092996'
SECRET_KEY = 'b825a03636ca09c884ca11d71cfc4217a98cb8bf'
t = time.time()

def do_request():

    param = {
        'symbol': 'BTC_USDT'
    }
    body_str = json.dumps(param)
    sign = hmac.new(SECRET_KEY.encode("utf-8"), body_str.encode("utf-8"), hashlib.sha256).hexdigest()
    path = '/v4/userdata/orders'
    headers = {
        'Content-Type': 'application/json',
        'Bibox-Api-Key': API_KEY,
        'Bibox-Api-Sign': sign,
        'Bibox-Expire-Time':str(round(t * 1000 +5000)) # optional
    }
    resp = requests.delete(END_POINT + path, json=param, headers=headers)
    print(resp.text)


if __name__ == '__main__':
    do_request()

Response

[]

Cancel all orders

Parameter name Parameter type Required or not Description
symbol string yes trading pair code
such as BTC_USDT, ETH_USDT, etc.

Returns an empty array if the request was executed correctly, otherwise returns an error message

Get fills

Request

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

const endpoints = 'https://api.bibox.com/api'
const apikey = "9e03e8fda27b6e4fc6b29bb244747dcf64092996"; // your apikey
const secret = "b825a03636ca09c884ca11d71cfc4217a98cb8bf"; // your secret


const queryStr = 'limit=2&symbol=BTC_USDT';
const sign = CryptoJS.HmacSHA256(queryStr, secret).toString();
const url = `${endpoints}/v4/userdata/fills?${queryStr}`;

request.get(url,{
        headers: {
            'Content-Type': 'application/json',
            'Bibox-Api-Key': apikey,
            'Bibox-Api-Sign': sign,
        },
    },

    function optionalCallback(err, httpResponse, body) {
        if (err) {
            return console.error('upload failed:', err);
        }
        console.log(body) // 7.the result

    });
import hashlib
import hmac
import requests

END_POINT = 'https://api.bibox.com/api'
API_KEY = '9e03e8fda27b6e4fc6b29bb244747dcf64092996'
SECRET_KEY = 'b825a03636ca09c884ca11d71cfc4217a98cb8bf'


def do_request():
    path = '/v4/userdata/fills'
    query_str = 'limit=2&symbol=BTC_USDT'
    # POST or DELETE replace query_str with body_str
    sign = hmac.new(SECRET_KEY.encode("utf-8"), query_str.encode("utf-8"), hashlib.sha256).hexdigest()

    headers = {
        'Content-Type': 'application/json',
        'Bibox-Api-Key': API_KEY,
        'Bibox-Api-Sign': sign,
    }
    resp = requests.get(END_POINT + path, query_str, headers=headers)
    print(resp.text)


if __name__ == '__main__':
    do_request()

Response

[
  {
    "i": 13,  // transaction id
    "t": 1643193746464,  // transaction time
    "p": 10043.85,  // transaction price
    "q": -0.009,  // transaction volume
    "l": "maker",  // Maker / Taker transaction 
    "f": {
      "a": "USDT",  // The asset used for the transaction to pay the handling fee
      "m": 0.09039465000  // The transaction fee
    }
  },
    {
    "i": 13,  // transaction id
    "t": 1643193746464,  // transaction time
    "p": 10043.85,  // transaction price
    "q": -0.009,  // transaction volume
    "l": "maker",  // Maker / Taker transaction 
    "f": {
      "a": "USDT",  // The asset used for the transaction to pay the handling fee
      "m": 0.09039465000  // The transaction fee
    }
  },
    {
    "i": 13,  // transaction id
    "t": 1643193746464,  // transaction time
    "p": 10043.85,  // transaction price
    "q": -0.009,  // transaction volume
    "l": "maker",  // Maker / Taker transaction 
    "f": {
      "a": "USDT",  // The asset used for the transaction to pay the handling fee
      "m": 0.09039465000  // The transaction fee
    }
  },
  ...
]

Get transaction records

Parameter name Parameter type Required or not Description
order_id string No The order id assigned by the exchange
Only return the transaction records of the specified order
If this parameter is not specified, please specify symbol
symbol string No Trading pair code
Such as BTC_USDT, ETH_USDT, etc.
Only return the transaction records of the specified trading pair
If this parameter is not specified, please specify order_id
start_time int64 No Limited to return the earliest time of transaction records
end_time int64 No Limited to return the latest time of transaction records
before int64 No Transaction record id
Limited to return the maximum id of transaction records
after int64 No Transaction record id
Limited to return the minimum id of transaction records
limit int32 No Limit the maximum number of returned results
default 100

The returned results are sorted by transaction record id from small to large

User Data Streams

Overview

Example

const CryptoJS = require("crypto-js");
const WebSocket = require('ws');
const biboxws = 'wss://user-wss.bibox360.com';
const apikey = "9e2bd17ff73e8531c0f3c26f93e48bfa402a3b13"; // your apikey
const secret = "ca55beb9e45d4f30b3959b464402319b9e12bac7"; // your secret
const sign = CryptoJS.HmacSHA256("", secret).toString();

let wsClass = function () {
};


wsClass.prototype._initWs = async function () {
  let that = this;
  console.log(biboxws);

  let ws = new WebSocket(biboxws,"",{headers:{
      'BIBOX-API-KEY': apikey,
      'BIBOX-API-SIGN': sign,
    }});
  that.ws = ws;

  ws.on('open', function open() {
    console.log(new Date(), 'open')
    setInterval(function () {
      ws.ping(Date.now())
    },30000)
  });

  ws.on('close', data => {
    console.log('close, ', data);
  });

  ws.on('error',  data => {
    console.log('error ',data);
  });

  ws.on('ping', data => {
    console.log('ping ', data.toString('utf8'));
  });

  ws.on('pong', data => {
    console.log('pong ', data.toString('utf8'));
  });

  ws.on('message', data => {
    console.log(data.toString()) // the data may be is error message,check the data's stream is order or account
  });
};

let instance = new wsClass();

instance._initWs().catch(err => {
  console.log(err);
});

import websocket
import hashlib
import hmac

ws_url = 'wss://user-wss.bibox360.com'
API_KEY = '9e2bd17ff73e8531c0f3c26f93e48bfa402a3b13'
SECRET_KEY = 'ca55beb9e45d4f30b3959b464402319b9e12bac7'

def on_message(ws, message):
    print(message)


def on_error(ws, error):
    print(error)


def on_close(ws):
    print("### closed ###")


def on_open(ws):
    print("### opened ###")


def connect():
    # websocket.enableTrace(True)

    sign = hmac.new(SECRET_KEY.encode("utf-8"), "".encode('utf-8'), hashlib.sha256).hexdigest()
    header = {
        'BIBOX-API-KEY': API_KEY,
        'BIBOX-API-SIGN': sign,
    }
    ws = websocket.WebSocketApp(ws_url,
                                header=header,
                                on_message=on_message,
                                on_error=on_error,
                                on_close=on_close)
    ws.on_open = on_open
    ws.run_forever(ping_interval=30, ping_timeout=5)


if __name__ == "__main__":
    connect()

Using the Websocket push service, you can obtain the account balance and order change information in time.

Connect to Websocket server

Please use the following URL to connect to the Websocket server:

wss://user-wss.bibox360.com

When connecting, please append the following HTTP request headers

Please refer to the Authentication chapter for specific methods

Data flow After the connection is successfully established, the client will receive the balance change information and order change information of the account corresponding to the ApiKey. The format is as follows:

{
  "stream": "account",
  "stream": { Account }
}

{
  "stream": "order",
  "data": { Order }
}

Account

When the account balance changes, the account event is received

{
  "stream": "account",
  "data": {
    "s":"USDT",  // asset code
    "a":10000,  // available amount
    "h":0  // frozen amount
  }
}

Orders

When the order changes, the order event will be received

{
  "stream": "order",
  "data": {
     "i": 4611688217450643477,  // The order id assigned by the exchange
     "I": "",  // User specified order id
     "m": "BTC_USDT",  // trading pair code
     "T": "limit",  // order type
     "s": "sell",  // order direction
     "Q": -0.0100,  // order amount
     "P": 10043.8500,  // Order price
     "t": "gtc",  // Time In Force
     "o": false,  // Post Only
     "S": "filled",  // Order status
     "E": -0.0100,  // transaction volume
     "e": -100.43850000,  // transaction value
     "C": 1643193746043,  // creation time
     "U": 1643193746464,  // update time
     "n": 2,  // Number of transactions
  }
}

Errors

error code

Code Description
-1000 Unknown
-2001 No request header given
-2002 Invalid value for request header
-2003 No parameter given
-2004 Invalid value for parameter
-2005 Body contains invalid Json format
-2006 Invalid signature
-2101 Specified API access limit exceeded
-2102 Specified API usage limit exceeded
-2103 ApiKey has not been granted the relevant permission
-2104 Request expired
-3001 Specified asset does not exist
-3002 Specified trading pair does not exist
-3003 Specified order does not exist