English
javascript

币本位合约

这是币本位合约api文档。

1.签名接口请求方式

完整例子

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

let timestamp = Date.now(); // 1.当前时间戳

let param = { // 2.请求的参数
    "amount":"0.01",
    "symbol":"BTC",
    "type":0
};

let strParam = JSON.stringify(param); // 2.格式化参数

let strToSign = '' + timestamp + strParam; // 3.这就是需要签名的字符串

let apikey = "900625568558820892a8c833c33ebc8fd2701efe"; //your apikey
let secret = "c708ac3e70d115ec29efbee197330627d7edf842"; //你的 apikey 密码
let sign = CryptoJS.HmacMD5(strToSign, secret).toString();//4.签名后的结果

let url = "https://api.bibox.com/v3/assets/transfer/cbc";

request.post({
        url: url,//请求路径
        method: "POST",//请求方式
        headers: {//5.设置请求头
            'content-type': 'application/json',
            'bibox-api-key': apikey,
            'bibox-api-sign': sign,
            'bibox-timestamp': timestamp
        },
        body: strParam // 6.格式化参数
    },

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

    });

字段名 类型 描述 取值
content-type string 'application/json'
bibox-api-key string 你的apikey
bibox-timestamp long 当前时间戳,用毫秒表示 timestamp
bibox-api-sign string 签名结果 sign

2.资金划转

Request

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

let timestamp = Date.now(); // 1.当前时间戳

let param = { // 2.请求的参数
    "amount":"0.01",
    "symbol":"BTC",
    "type":0
};

let strParam = JSON.stringify(param); // 2.格式化参数

let strToSign = '' + timestamp + strParam; // 3.这就是需要签名的字符串

let apikey = "900625568558820892a8c833c33ebc8fd2701efe"; //your apikey
let secret = "c708ac3e70d115ec29efbee197330627d7edf842"; //你的 apikey 密码
let sign = CryptoJS.HmacMD5(strToSign, secret).toString();//4.签名后的结果

let url = "https://api.bibox.com/v3/assets/transfer/cbc";

request.post({
        url: url,//请求路径
        method: "POST",//请求方式
        headers: {//5.设置请求头
            'content-type': 'application/json',
            'bibox-api-key': apikey,
            'bibox-api-sign': sign,
            'bibox-timestamp': timestamp
        },
        body: strParam // 6.格式化参数
    },

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

    });

POST https://api.bibox.com/v3/assets/transfer/cbc

参数名称 是否必须 类型 描述 默认值 取值范围
amount true string 数量转字符串
symbol true string 币种 BTC,ETH, ...
type true integer 0转入,1转出 0,1

Response

{
    "state":0, // 成功
    "result":"352559634189422592"  // 忽略
}

名称 描述
state 0代表成功,否则代表失败
其它字段 忽略

3.下单

Request

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

let url = "https://api.bibox.com/v3/cbc/order/open";

let apikey = "900625568558820892a8c833c33ebc8fd2701efe"; //your apikey
let secret = "c708ac3e70d115ec29efbee197330627d7edf842"; //your apikey secret

let param = {
    "pair":"5BTC_USD",
    "order_side":1,
    "order_type":2,
    "price":"11500",
    "amount":1,
    "order_from":6,
    "client_oid": "1234567890",
};

let cmd = JSON.stringify(param); //format param
let timestamp = '' + (Date.now());
let sign = CryptoJS.HmacMD5(timestamp + cmd, secret).toString();//sign cmds

request.post({
        url: url,//请求路径
        method: "POST",//请求方式
        headers: {//设置请求头
            'content-type': 'application/json',
            'bibox-api-key': apikey,
            'bibox-api-sign': sign,
            'bibox-timestamp': timestamp
        },
        body: cmd//post参数字符串
    },

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

        console.log(body)

    });

POST https://api.bibox.com/v3/cbc/order/open

参数名称 是否必须 类型 描述 默认值 取值范围
pair true string 合约符号 5BTC_USD,5ETH_USD, ...
amount true string 数量转字符串
order_side true integer 下单类型,1开多,2开空,3平多,4平空 1,2,3,4
order_type true integer 下单方式,1市价单,2限价单 1,2
price true string 下单价格
order_from true integer 下单来源 6
client_oid false string 自定义id

Response

{
    "state":0,
    "order_id":"425510999949316", // 订单id
    "client_oid":"1234567890", // 自定义id
    "status":1, // 订单状态 1等待成交,2部分成交,3全部成交,4部分撤销,5全部撤销,100下单失败
    "cmd":"open" // 忽略
}

名称 描述
state 0代表成功,否则代表失败
order_id 订单id
client_oid 自定义id
status 订单状态 1等待成交,2部分成交,3全部成交,4部分撤销,5全部撤销,100下单失败
其它字段 忽略

4.撤单

Request

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

let url = "https://api.bibox.com/v3/cbc/order/close";

let apikey = "900625568558820892a8c833c33ebc8fd2701efe"; //your apikey
let secret = "c708ac3e70d115ec29efbee197330627d7edf842"; //your apikey secret

let param = {
    "order_id":"425510999949316"
};

let cmd = JSON.stringify(param); //format param
let timestamp = '' + (Date.now());
let sign = CryptoJS.HmacMD5(timestamp + cmd, secret).toString();//sign cmds

request.post({
        url: url,//请求路径
        method: "POST",//请求方式
        headers: {//设置请求头
            'content-type': 'application/json',
            'bibox-api-key': apikey,
            'bibox-api-sign': sign,
            'bibox-timestamp': timestamp
        },
        body: cmd//post参数字符串
    },

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

        console.log(body)

    });

POST https://api.bibox.com/v3/cbc/order/close

参数名称 是否必须 类型 描述 默认值 取值范围
order_id true string 订单id

Response

{
    "state":0, // 成功
    "result":"success", 
    "cmd":"close"
}

名称 描述
state 0代表成功,否则代表失败
其它字段 忽略

5.批量撤单

Request

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

let url = "https://api.bibox.com/v3/cbc/order/closeBatch";

let apikey = "900625568558820892a8c833c33ebc8fd2701efe"; //your apikey
let secret = "c708ac3e70d115ec29efbee197330627d7edf842"; //your apikey secret

let param = {
    "order_ids":["2234567890","2234567891"]
};

let cmd = JSON.stringify(param); //format param
let timestamp = '' + (Date.now());
let sign = CryptoJS.HmacMD5(timestamp + cmd, secret).toString();//sign cmds

request.post({
        url: url,//请求路径
        method: "POST",//请求方式
        headers: {//设置请求头
            'content-type': 'application/json',
            'bibox-api-key': apikey,
            'bibox-api-sign': sign,
            'bibox-timestamp': timestamp
        },
        body: cmd//post参数字符串
    },

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

        console.log(body)

    });

POST https://api.bibox.com/v3/cbc/order/closeBatch

参数名称 是否必须 类型 描述 默认值 取值范围
order_ids true 数组 订单id数组

Response

{
    "state":0,// 成功
    "result":"success",
    "cmd":"close"
}

名称 描述
state 0代表成功,否则代表失败
其它字段 忽略

6.全部撤单

Request

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

let url = "https://api.bibox.com/v3/cbc/order/closeAll";

let apikey = "900625568558820892a8c833c33ebc8fd2701efe"; //your apikey
let secret = "c708ac3e70d115ec29efbee197330627d7edf842"; //your apikey secret

let param = {
    "pair":"5BTC_USD"
};

let cmd = JSON.stringify(param); //format param
let timestamp = '' + (Date.now());
let sign = CryptoJS.HmacMD5(timestamp + cmd, secret).toString();//sign cmds

request.post({
        url: url,//请求路径
        method: "POST",//请求方式
        headers: {//设置请求头
            'content-type': 'application/json',
            'bibox-api-key': apikey,
            'bibox-api-sign': sign,
            'bibox-timestamp': timestamp
        },
        body: cmd//post参数字符串
    },

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

        console.log(body)

    });

POST https://api.bibox.com/v3/cbc/order/closeAll

参数名称 是否必须 类型 描述 默认值 取值范围
pair true string 合约符号 5BTC_USD,5ETH_USD, ...

Response

{
    "state":0,// 成功
    "result":"success",
    "cmd":"closeAll"
}

名称 描述
state 0代表成功,否则代表失败
其它字段 忽略

7.逐仓调整保证金

Request

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

let url = "https://api.bibox.com/v3/cbc/changeMargin";

let apikey = "900625568558820892a8c833c33ebc8fd2701efe"; //your apikey
let secret = "c708ac3e70d115ec29efbee197330627d7edf842"; //your apikey secret

let param = {
    "pair":"5BTC_USD",
    "margin":"0.01",
    "side":1
};

let cmd = JSON.stringify(param); //format param
let timestamp = '' + (Date.now());
let sign = CryptoJS.HmacMD5(timestamp + cmd, secret).toString();//sign cmds

request.post({
        url: url,//请求路径
        method: "POST",//请求方式
        headers: {//设置请求头
            'content-type': 'application/json',
            'bibox-api-key': apikey,
            'bibox-api-sign': sign,
            'bibox-timestamp': timestamp
        },
        body: cmd//post参数字符串
    },

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

        console.log(body)

    });

POST https://api.bibox.com/v3/cbc/changeMargin

参数名称 是否必须 类型 描述 默认值 取值范围
pair true string 合约符号 5BTC_USD,5ETH_USD, ...
margin true string 保证金数量
side true integer 仓位方向,1多仓, 2空仓 1,2

Response

{
    "state":3103, // 失败
    "msg":"没有持仓不支持该操作",
    "cmd":"changeMargin"
}

名称 描述
state 0代表成功,否则代表失败
其它字段 忽略

8.调整持仓模式及杠杆

Request

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

let url = "https://api.bibox.com/v3/cbc/changeMode";

let apikey = "900625568558820892a8c833c33ebc8fd2701efe"; //your apikey
let secret = "c708ac3e70d115ec29efbee197330627d7edf842"; //your apikey secret

let param = {
    "pair":"5BTC_USD",
    "mode":2,
    "leverage_long":10,
    "leverage_short":20
};

let cmd = JSON.stringify(param); //format param
let timestamp = '' + (Date.now());
let sign = CryptoJS.HmacMD5(timestamp + cmd, secret).toString();//sign cmds

request.post({
        url: url,//请求路径
        method: "POST",//请求方式
        headers: {//设置请求头
            'content-type': 'application/json',
            'bibox-api-key': apikey,
            'bibox-api-sign': sign,
            'bibox-timestamp': timestamp
        },
        body: cmd//post参数字符串
    },

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

        console.log(body)

    });

POST https://api.bibox.com/v3/cbc/changeMode

参数名称 是否必须 类型 描述 默认值 取值范围
pair true string 合约符号 5BTC_USD,5ETH_USD, ...
mode true integer 仓位模式,1全仓, 2逐仓 1,2
leverage_long true integer 多仓杠杆倍数 1~100
leverage_short true integer 空仓杠杆倍数 1~100

Response

{
    "state":0,
    "result":"success",
    "cmd":"changeMode"
}

名称 描述
state 0代表成功,否则代表失败
其它字段 忽略

9.查询资产

Request

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

let url = "https://api.bibox.com/v3/cbc/assets";

let apikey = "900625568558820892a8c833c33ebc8fd2701efe"; //your apikey
let secret = "c708ac3e70d115ec29efbee197330627d7edf842"; //your apikey secret

let param = {
    // "coin":"BTC",
};

let cmd = JSON.stringify(param); //format param
let timestamp = '' + (Date.now());
let sign = CryptoJS.HmacMD5(timestamp + cmd, secret).toString();//sign cmds

request.post({
        url: url,//请求路径
        method: "POST",//请求方式
        headers: {//设置请求头
            'content-type': 'application/json',
            'bibox-api-key': apikey,
            'bibox-api-sign': sign,
            'bibox-timestamp': timestamp
        },
        body: cmd//post参数字符串
    },

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

        console.log(body)

    });

POST https://api.bibox.com/v3/cbc/assets

参数名称 是否必须 类型 描述 默认值 取值范围
coin false string 币种符号 BTC,ETH,...

Response

{
    "state":0,
    "result":[
        {
            "b":"1", // 可用余额
            "c":"BTC", // 币种
            "u":100006, // 用户id
            "f":"0", // 冻结资金
            "m":"0" // 保证金资金
        },
        {
            "b":"1",
            "c":"ETH",
            "u":100006,
            "f":"0",
            "m":"0"
        }
    ],
    "cmd":"assets"
}

名称 描述
state 0代表成功,否则代表失败
b 可用余额
c 币种
u 用户id
f 冻结资金
m 保证金资金
其它字段 忽略

10.查询仓位

Request

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

let url = "https://api.bibox.com/v3/cbc/position";

let apikey = "900625568558820892a8c833c33ebc8fd2701efe"; //your apikey
let secret = "c708ac3e70d115ec29efbee197330627d7edf842"; //your apikey secret

let param = {
    // "pair":"5BTC_USD",
    // "side":1
};

let cmd = JSON.stringify(param); //format param
let timestamp = '' + (Date.now());
let sign = CryptoJS.HmacMD5(timestamp + cmd, secret).toString();//sign cmds

request.post({
        url: url,//请求路径
        method: "POST",//请求方式
        headers: {//设置请求头
            'content-type': 'application/json',
            'bibox-api-key': apikey,
            'bibox-api-sign': sign,
            'bibox-timestamp': timestamp
        },
        body: cmd//post参数字符串
    },

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

        console.log(body)

    });

POST https://api.bibox.com/v3/cbc/position

参数名称 是否必须 类型 描述 默认值 取值范围
pair false string 合约符号 5BTC_USD,5ETH_USD, ...
side false integer 仓位方向,1多仓, 2空仓 1,2

Response

{
    "state":0,
    "result":[
        {
            "pt":"0",//忽略
            "f":"0",//忽略
            "l":"10", // 杠杆
            "sd":1, // 仓位方向: 1, 多仓 2 , 空仓
            "pa":"0", //告警价格
            "ui":100006,//用户id
            "fb0":"0",//忽略
            "pf":"0",//爆仓价格
            "md":2,//仓位模式: 1, 全仓 2 , 逐仓
            "lc":"0",// 可平仓位价值
            "pi":"5BTC_USD", // 交易对
            "mg":"0", //保证金
            "hc":"0",// 仓位价值 = 合约张数X合约面值
            "fb":"0",//忽略
            "po":"0" //开仓价格
        },
        ...
    ],
    "cmd":"position"
}

名称 描述
state 0代表成功,否则代表失败
l 杠杆
sd 仓位方向: 1, 多仓 2 , 空仓
pa 告警价格
ui 用户id
pf 爆仓价格
md 仓位模式: 1全仓, 2逐仓
lc 可平仓位价值
pi 交易对
mg 保证金
hc 仓位价值 = 合约张数X合约面值
po 开仓价格
其它字段 忽略

11.查询订单列表

Request

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

let url = "https://api.bibox.com/v3/cbc/order/list";

let apikey = "900625568558820892a8c833c33ebc8fd2701efe"; //your apikey
let secret = "c708ac3e70d115ec29efbee197330627d7edf842"; //your apikey secret

let param = {
    // "pair":"5BTC_USD",
    // "order_side":1
};

let cmd = JSON.stringify(param); //format param
let timestamp = '' + (Date.now());
let sign = CryptoJS.HmacMD5(timestamp + cmd, secret).toString();//sign cmds

request.post({
        url: url,//请求路径
        method: "POST",//请求方式
        headers: {//设置请求头
            'content-type': 'application/json',
            'bibox-api-key': apikey,
            'bibox-api-sign': sign,
            'bibox-timestamp': timestamp
        },
        body: cmd//post参数字符串
    },

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

        console.log(body)

    });

POST https://api.bibox.com/v3/cbc/order/list

参数名称 是否必须 类型 描述 默认值 取值范围
pair false string 合约符号 5BTC_USD,5ETH_USD, ...
order_side true integer 下单类型,1开多,2开空,3平多,4平空 1,2,3,4

Response

{
    "state":0,
    "result":{
        "p":1,
        "t":1,
        "o":[
            {
                "f":"0", //手续费
                "dp":"0", //成交价格
                "eq":"0", //成交数量
                "p":"11092", //下单价格
                "tif":0, // 忽略
                "q":"1", //下单数量
                "sd":1, //下单方向
                "r":0, //reason
                "s":1, // status
                "t":1602679944815, //下单时间
                "ui":100006, //用户id
                "fz":"0.0000091417", //挂单冻结
                "fb0":"0", //优惠券抵扣
                "of":4, //order from
                "pi":"5BTC_USD", //交易对
                "oi":"426610511577093", // order id
                "coi":"1602679943911", //clientoid
                "fb":"0", //bix抵扣
                "po":false //忽略
            },
            ...
        ]
    },
    "cmd":"orderList"
}

名称 描述
state 0代表成功,否则代表失败
f 手续费
dp 成交价格
eq 成交数量
p 下单价格
q 下单数量
sd 下单方向
r 失败原因
s 订单状态
t 下单时间
ui 用户id
fz 挂单冻结
fb0 优惠券抵扣
of 订单来源
pi 交易对
oi 订单id
coi 用户自定义订单id
fb bix抵扣
其它字段 忽略

12.查询订单

Request

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

let url = "https://api.bibox.com/v3/cbc/order/detail";

let apikey = "900625568558820892a8c833c33ebc8fd2701efe"; //your apikey
let secret = "c708ac3e70d115ec29efbee197330627d7edf842"; //your apikey secret

let param = {
    "order_id":"426610511577093",
};

let cmd = JSON.stringify(param); //format param
let timestamp = '' + (Date.now());
let sign = CryptoJS.HmacMD5(timestamp + cmd, secret).toString();//sign cmds

request.post({
        url: url,//请求路径
        method: "POST",//请求方式
        headers: {//设置请求头
            'content-type': 'application/json',
            'bibox-api-key': apikey,
            'bibox-api-sign': sign,
            'bibox-timestamp': timestamp
        },
        body: cmd//post参数字符串
    },

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

        console.log(body)

    });

POST https://api.bibox.com/v3/cbc/order/detail

参数名称 是否必须 类型 描述 默认值 取值范围
order_id true string 订单id

Response

{
    "state":0,
    "result":{
        "f":"0", //手续费
        "dp":"0", //成交价格
        "eq":"0", //成交数量
        "p":"11092", //下单价格
        "tif":0, // 忽略
        "q":"1", //下单数量
        "sd":1, //下单方向
        "r":0, //reason
        "s":1, // status
        "t":1602679944815, //下单时间
        "ui":100006, //用户id
        "fz":"0.0000091417", //挂单冻结
        "fb0":"0", //优惠券抵扣
        "of":4, //order from
        "pi":"5BTC_USD", //交易对
        "oi":"426610511577093", // order id
        "coi":"1602679943911", //clientoid
        "fb":"0", //bix抵扣
        "po":false //忽略
    },
    "cmd":"orderDetail"
}

名称 描述
state 0代表成功,否则代表失败
f 手续费
dp 成交价格
eq 成交数量
p 下单价格
q 下单数量
sd 下单方向
r 失败原因
s 订单状态
t 下单时间
ui 用户id
fz 挂单冻结
fb0 优惠券抵扣
of 订单来源
pi 交易对
oi 订单id
coi 用户自定义订单id
fb bix抵扣
其它字段 忽略

13.批量查询订单列表

Request

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

let url = "https://api.bibox.com/v3/cbc/order/listBatch";

let apikey = "900625568558820892a8c833c33ebc8fd2701efe"; //your apikey
let secret = "c708ac3e70d115ec29efbee197330627d7edf842"; //your apikey secret

let param = {
    "order_ids":["426610511577093"],
};

let cmd = JSON.stringify(param); //format param
let timestamp = '' + (Date.now());
let sign = CryptoJS.HmacMD5(timestamp + cmd, secret).toString();//sign cmds

request.post({
        url: url,//请求路径
        method: "POST",//请求方式
        headers: {//设置请求头
            'content-type': 'application/json',
            'bibox-api-key': apikey,
            'bibox-api-sign': sign,
            'bibox-timestamp': timestamp
        },
        body: cmd//post参数字符串
    },

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

        console.log(body)

    });

POST https://api.bibox.com/v3/cbc/order/listBatch

参数名称 是否必须 类型 描述 默认值 取值范围
order_ids true 数组 订单id数组

Response

{
    "state":0,
    "result":[
        {
             "f":"0", //手续费
            "dp":"0", //成交价格
            "eq":"0", //成交数量
            "p":"11092", //下单价格
            "tif":0, // 忽略
            "q":"1", //下单数量
            "sd":1, //下单方向
            "r":0, //reason
            "s":1, // status
            "t":1602679944815, //下单时间
            "ui":100006, //用户id
            "fz":"0.0000091417", //挂单冻结
            "fb0":"0", //优惠券抵扣
            "of":4, //order from
            "pi":"5BTC_USD", //交易对
            "oi":"426610511577093", // order id
            "coi":"1602679943911", //clientoid
            "fb":"0", //bix抵扣
            "po":false //忽略
        }
    ],
    "cmd":"orderListBatch"
}

名称 描述
state 0代表成功,否则代表失败
f 手续费
dp 成交价格
eq 成交数量
p 下单价格
q 下单数量
sd 下单方向
r 失败原因
s 订单状态
t 下单时间
ui 用户id
fz 挂单冻结
fb0 优惠券抵扣
of 订单来源
pi 交易对
oi 订单id
coi 用户自定义订单id
fb bix抵扣
其它字段 忽略

14.根据clientoid批量查询订单列表

Request

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

let url = "https://api.bibox.com/v3/cbc/order/listBatchByClientOid";

let apikey = "900625568558820892a8c833c33ebc8fd2701efe"; //your apikey
let secret = "c708ac3e70d115ec29efbee197330627d7edf842"; //your apikey secret

let param = {
    "order_ids":["1602679943911"],
};

let cmd = JSON.stringify(param); //format param
let timestamp = '' + (Date.now());
let sign = CryptoJS.HmacMD5(timestamp + cmd, secret).toString();//sign cmds

request.post({
        url: url,//请求路径
        method: "POST",//请求方式
        headers: {//设置请求头
            'content-type': 'application/json',
            'bibox-api-key': apikey,
            'bibox-api-sign': sign,
            'bibox-timestamp': timestamp
        },
        body: cmd//post参数字符串
    },

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

        console.log(body)

    });

POST https://api.bibox.com/v3/cbc/order/listBatchByClientOid

参数名称 是否必须 类型 描述 默认值 取值范围
order_ids true 数组 自定义订单id数组

Response

{
    "state":0,
    "result":[
        {
             "f":"0", //手续费
            "dp":"0", //成交价格
            "eq":"0", //成交数量
            "p":"11092", //下单价格
            "tif":0, // 忽略
            "q":"1", //下单数量
            "sd":1, //下单方向
            "r":0, //reason
            "s":1, // status
            "t":1602679944815, //下单时间
            "ui":100006, //用户id
            "fz":"0.0000091417", //挂单冻结
            "fb0":"0", //优惠券抵扣
            "of":4, //order from
            "pi":"5BTC_USD", //交易对
            "oi":"426610511577093", // order id
            "coi":"1602679943911", //clientoid
            "fb":"0", //bix抵扣
            "po":false //忽略
        }
    ],
    "cmd":"orderListBatchByCLientOid"
}

名称 描述
state 0代表成功,否则代表失败
f 手续费
dp 成交价格
eq 成交数量
p 下单价格
q 下单数量
sd 下单方向
r 失败原因
s 订单状态
t 下单时间
ui 用户id
fz 挂单冻结
fb0 优惠券抵扣
of 订单来源
pi 交易对
oi 订单id
coi 用户自定义订单id
fb bix抵扣
其它字段 忽略

15.获取服务器时间

GET https://api.bibox.com/v3/cbc/timestamp

Response

{
    "time":"1602680518605"
}

名称 描述
time 服务器时间

16.查询持仓变化记录

Request

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

let url = "https://api.bibox.com/v3.1/cquery/base_coin/dealLog";

let apikey = "900625568558820892a8c833c33ebc8fd2701efe"; //your apikey
let secret = "c708ac3e70d115ec29efbee197330627d7edf842"; //your apikey secret

let param = {
    "pair": "5BTC_USD",
    "page": 1,
    "size": 10,
};

let cmd = JSON.stringify(param); //format param
let timestamp = '' + (Date.now());
let sign = CryptoJS.HmacMD5(timestamp + cmd, secret).toString();//sign cmds

request.post({
        url: url,//请求路径
        method: "POST",//请求方式
        headers: {//设置请求头
            'content-type': 'application/json',
            'bibox-api-key': apikey,
            'bibox-api-sign': sign,
            'bibox-timestamp': timestamp
        },
        body: cmd//post参数字符串
    },

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

        console.log(body)

    });

POST https://api.bibox.com/v3.1/cquery/base_coin/dealLog

参数名称 是否必须 类型 描述 默认值 取值范围
pair true string 合约符号 5BTC_USD,5ETH_USD, ...
page true integer 第几页 1,2, ...
size true integer 条数 10,20, ...

Response

{
    "result":{
        "count":3,
        "page":1,
        "items":[
            {
                "id":"1125899906842635654", // 仓位变化id
                "user_id":100006, // 用户id
                "coin_symbol":"BTC",// 币种
                "pair":"5BTC_USD",// 交易对
                "side":1,// 仓位方向 1多仓,2空仓
                "model":1,// 仓位模式,1全仓,2逐仓
                "log_type":1,// 变化类型 1开仓,2平仓,3减仓降低风险等级, 4爆仓清空仓位, 5ADL
                "hold_coin_dx":"1.0000000000",// 仓位持仓变化量
                "hold_coin":"1.0000000000",// 仓位持仓
                "price_log":"11692.0000000000",// 参考价格
                "price_open":"11692.0000000000",// 开仓均价
                "profit":"0.0000000000",// 收益
                "fee":"0.0000000599",// 手续费
                "fee_bix":"0.0000000000",// bix抵扣
                "fee_bix0":"0.0000000000", // 优惠券抵扣
                "createdAt":"2020-10-14T03:00:08.000Z",// 变化时间
                "updatedAt":"2020-10-14T03:00:08.000Z"
            },
            ...
        ]
    },
    "state":0
}

名称 描述
state 0代表成功,否则代表失败
id 仓位变化id
user_id 用户id
coin_symbol 币种
pair 交易对
side 仓位方向 1多仓,2空仓
model 仓位模式,1全仓,2逐仓
log_type 变化类型 1开仓,2平仓,3减仓降低风险等级, 4爆仓清空仓位, 5ADL
hold_coin_dx 仓位持仓变化量
hold_coin 仓位持仓
price_log 参考价格
price_open 开仓均价
profit 收益
fee 手续费
fee_bix bix抵扣
fee_bix0 优惠券抵扣
createdAt 变化时间
其它字段 忽略

17.查询订单成交明细

Request

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

let url = "https://api.bibox.com/v3.1/cquery/base_coin/orderDetail";

let apikey = "900625568558820892a8c833c33ebc8fd2701efe"; //your apikey
let secret = "c708ac3e70d115ec29efbee197330627d7edf842"; //your apikey secret

let param = {
    "orderId":"421112953438213",
    "page":1,
    "size":10
};

let cmd = JSON.stringify(param); //format param
let timestamp = '' + (Date.now());
let sign = CryptoJS.HmacMD5(timestamp + cmd, secret).toString();//sign cmds

request.post({
        url: url,//请求路径
        method: "POST",//请求方式
        headers: {//设置请求头
            'content-type': 'application/json',
            'bibox-api-key': apikey,
            'bibox-api-sign': sign,
            'bibox-timestamp': timestamp
        },
        body: cmd//post参数字符串
    },

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

        console.log(body)

    });

POST https://api.bibox.com/v3.1/cquery/base_coin/orderDetail

参数名称 是否必须 类型 描述 默认值 取值范围
orderId true long 订单id
page true integer 第几页 1,2, ...
size true integer 条数 10,20, ...

Response

{
    "result":{
        "count":1,
        "page":1,
        "items":[
            {
                "id":"1125899906842635651",// 明细id
                "coin_symbol":"BTC",// 币种
                "pair":"5BTC_USD",// 交易对
                "side":2,// 挂单方向 1开多,2开空,3平多,4平空
                "order_from":4,// 订单来源
                "price":"10692.0000000000",// 挂单价格
                "deal_price":"11510.0000000000",// 成交价格
                "deal_coin":"1.0000000000",// 成交价值
                "fee":"0.0000000608",// 手续费
                "fee_bix":"0.0000000000",// bix抵扣
                "fee_bix0":"0.0000000000",// 优惠券抵扣
                "is_maker":0,// 是否是maker
                "createdAt":"2020-10-14T02:58:59.000Z"// 成交时间
            }
        ]
    }
    "state":0
}

名称 描述
state 0代表成功,否则代表失败
id 明细id
coin_symbol 币种
pair 交易对
side 挂单方向 1开多,2开空,3平多,4平空
order_from 订单来源
price 挂单价格
deal_price 成交价格
deal_coin 成交价值
fee 手续费
fee_bix bix抵扣
fee_bix0 优惠券抵扣
createdAt 变化时间
is_maker 是否是maker
其它字段 忽略

18.查询历史委托

Request

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

let url = "https://api.bibox.com/v3.1/cquery/base_coin/orderHistory";

let apikey = "900625568558820892a8c833c33ebc8fd2701efe"; //your apikey
let secret = "c708ac3e70d115ec29efbee197330627d7edf842"; //your apikey secret

let param = {
    "page": 1,
    "size": 10,
    "pair": "5BTC_USD",
    "side": 1,
    "status": [3, 4, 5, 100],
};

let cmd = JSON.stringify(param); //format param
let timestamp = '' + (Date.now());
let sign = CryptoJS.HmacMD5(timestamp + cmd, secret).toString();//sign cmds

request.post({
        url: url,//请求路径
        method: "POST",//请求方式
        headers: {//设置请求头
            'content-type': 'application/json',
            'bibox-api-key': apikey,
            'bibox-api-sign': sign,
            'bibox-timestamp': timestamp
        },
        body: cmd//post参数字符串
    },

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

        console.log(body)

    });

POST https://api.bibox.com/v3.1/cquery/base_coin/orderHistory

参数名称 是否必须 类型 描述 默认值 取值范围
pair false string 合约符号 5BTC_USD,5ETH_USD, ...
page true integer 第几页 1,2, ...
size true integer 条数 10,20, ...
side false integer 1开多 2开空 3平多 4平空
status false 数组 状态,3:全部成交,4:部分撤单, 5:全部撤单, 100:下单失败

Response

{
    "result":{
        "count":1,
        "page":1,
        "items":[
            {
                "id":421112953438215,// 订单id
                "user_id":100006,// 用户id
                "coin_symbol":"BTC",// 币种
                "pair":"5BTC_USD",// 交易对
                "side":1,// 挂单方向
                "order_type":2,// 挂单类型 1市价,2限价
                "price":"11692.0000000000",// 挂单价格
                "amount_coin":"1.0000000000",// 挂单数量
                "freeze":"0.0000000000",// 冻结资金
                "price_deal":"11692.0000000000",// 成交均价
                "deal_coin":"1.0000000000",// 成交价值
                "deal_num":1,// 成交笔数
                "fee":"0.0000000599",// 手续费
                "fee_bix":"0.0000000000",// bix抵扣
                "fee_bix0":"0.0000000000",// 优惠券抵扣
                "status":3,// 订单状态,1未成交,2部分成交,3完全成交,4部分撤销,5全部撤销,100下单失败
                "reason":0,// 失败原因
                "fee_rate_maker":"0.0007000000",// maker手续费费率
                "fee_rate_taker":"0.0007000000",// taker手续费费率
                "client_oid":1602644402806,// 自定义id
                "order_from":4, // 忽略
                "createdAt":"2020-10-14T03:00:08.000Z",// 挂单时间
                "updatedAt":"2020-10-14T03:00:08.000Z"// 最新变化时间
            }
        ]
    },
    "state":0
}

名称 描述
state 0代表成功,否则代表失败
id 订单id
user_id 用户id
coin_symbol 币种
pair 交易对
side 挂单方向 1开多,2开空,3平多,4平空
order_type 挂单类型 1市价,2限价
price 挂单价格
amount_coin 挂单数量
freeze 冻结资金
price_deal 成交均价
deal_coin 成交价值
deal_num 成交笔数
fee 手续费
fee_bix bix抵扣
fee_bix0 优惠券抵扣
status 订单状态,1未成交,2部分成交,3完全成交,4部分撤销,5全部撤销,100下单失败
reason 失败原因
fee_rate_maker maker手续费费率
fee_rate_taker taker手续费费率
client_oid 自定义id
order_from 订单来源
createdAt 挂单时间
其它字段 忽略

19.查询订单

Request

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

let url = "https://api.bibox.com/v3.1/cquery/base_coin/orderById";

let apikey = "900625568558820892a8c833c33ebc8fd2701efe"; //your apikey
let secret = "c708ac3e70d115ec29efbee197330627d7edf842"; //your apikey secret

let param = {
    "orderIds": ["421112953438213", "421112953438214"],
    "clientOids": ["1602644402806", "1602644402811"],
};

let cmd = JSON.stringify(param); //format param
let timestamp = '' + (Date.now());
let sign = CryptoJS.HmacMD5(timestamp + cmd, secret).toString();//sign cmds

request.post({
        url: url,//请求路径
        method: "POST",//请求方式
        headers: {//设置请求头
            'content-type': 'application/json',
            'bibox-api-key': apikey,
            'bibox-api-sign': sign,
            'bibox-timestamp': timestamp
        },
        body: cmd//post参数字符串
    },

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

        console.log(body)

    });

POST https://api.bibox.com/v3.1/cquery/base_coin/orderById

参数名称 是否必须 类型 描述 默认值 取值范围
orderIds true 数组 订单id数组
clientOids true 数组 订单自定义di数组

Response

{
    "result":[
        {
            "id":421112953438214,// 订单id
            "user_id":100006,// 用户id
            "coin_symbol":"BTC",// 币种
            "pair":"5BTC_USD",// 交易对
            "side":1,// 挂单方向
            "order_type":2,// 挂单类型 1市价,2限价
            "price":"11692.0000000000",// 挂单价格
            "amount_coin":"1.0000000000",// 挂单数量
            "freeze":"0.0000000000",// 冻结资金
            "price_deal":"11692.0000000000",// 成交均价
            "deal_coin":"1.0000000000",// 成交价值
            "deal_num":1,// 成交笔数
            "fee":"0.0000000599",// 手续费
            "fee_bix":"0.0000000000",// bix抵扣
            "fee_bix0":"0.0000000000",// 优惠券抵扣
            "status":3,// 订单状态,1未成交,2部分成交,3完全成交,4部分撤销,5全部撤销,100下单失败
            "reason":0,// 失败原因
            "fee_rate_maker":"0.0007000000",// maker手续费费率
            "fee_rate_taker":"0.0007000000",// taker手续费费率
            "client_oid":1602644402806,// 自定义id
            "order_from":4, // 忽略
            "createdAt":"2020-10-14T03:00:08.000Z",// 挂单时间
            "updatedAt":"2020-10-14T03:00:08.000Z"// 最新变化时间
        },
        ...
    ],
    "state":0
}

名称 描述
state 0代表成功,否则代表失败
id 订单id
user_id 用户id
coin_symbol 币种
pair 交易对
side 挂单方向 1开多,2开空,3平多,4平空
order_type 挂单类型 1市价,2限价
price 挂单价格
amount_coin 挂单数量
freeze 冻结资金
price_deal 成交均价
deal_coin 成交价值
deal_num 成交笔数
fee 手续费
fee_bix bix抵扣
fee_bix0 优惠券抵扣
status 订单状态,1未成交,2部分成交,3完全成交,4部分撤销,5全部撤销,100下单失败
reason 失败原因
fee_rate_maker maker手续费费率
fee_rate_taker taker手续费费率
client_oid 自定义id
order_from 订单来源
createdAt 挂单时间
其它字段 忽略

19.1.查询划转记录

Request

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

let url = "https://api.bibox.com/v3.1/cquery/base_coin/transferLog";

let apikey = "900625568558820892a8c833c33ebc8fd2701efe"; //your apikey
let secret = "c708ac3e70d115ec29efbee197330627d7edf842"; //your apikey secret

let param = {
    coin_symbol: 'BTC', 
    from: Date.now() - 1000 * 60 * 60 * 24,
    to: Date.now() - 1000 * 60 * 60 * 24, 
    page: 1, 
    size: 10,
};

let cmd = JSON.stringify(param); //format param
let timestamp = '' + (Date.now());
let sign = CryptoJS.HmacMD5(timestamp + cmd, secret).toString();//sign cmds

request.post({
        url: url,//请求路径
        method: "POST",//请求方式
        headers: {//设置请求头
            'content-type': 'application/json',
            'bibox-api-key': apikey,
            'bibox-api-sign': sign,
            'bibox-timestamp': timestamp
        },
        body: cmd//post参数字符串
    },

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

        console.log(body)

    });

POST https://api.bibox.com/v3.1/cquery/base_coin/transferLog

参数名称 是否必须 类型 描述 默认值 取值范围
coin_symbol false string 币种符号 BTC,ETH, ...
page true integer 第几页 1,2, ...
size true integer 条数 10,20, ...
from false integer 起始时间
to false integer 结束时间

Response

{
    "result":{
        "count":5,
        "page":1,
        "items":[
            {
                "id":"1125899906862835742",
                "user_id":100006,
                "coin_symbol":"BTC",
                "pair":"",
                "change_amount":"0.0010000000",
                "change_result":"2.0230606258",
                "bill_type":1,
                "comment":"划转",
                "createdAt":"2020-11-26T03:59:09.000Z",
                "updatedAt":"2020-11-26T03:59:09.000Z"
            },
            ...
        ]
    },
    "state":0
}

名称 描述
state 0代表成功,否则代表失败
id 账单id
user_id 用户id
coin_symbol 币种
pair 交易对
change_amount 划转数量
createdAt 时间
其它字段 忽略

19.2.查询资产估值

Request

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

let url = "https://api.bibox.com/v3.1/cquery/base_coin/bassets";

let apikey = "900625568558820892a8c833c33ebc8fd2701efe"; //your apikey
let secret = "c708ac3e70d115ec29efbee197330627d7edf842"; //your apikey secret

let param = {

};

let cmd = JSON.stringify(param); //format param
let timestamp = '' + (Date.now());
let sign = CryptoJS.HmacMD5(timestamp + cmd, secret).toString();//sign cmds

request.post({
        url: url,//请求路径
        method: "POST",//请求方式
        headers: {//设置请求头
            'content-type': 'application/json',
            'bibox-api-key': apikey,
            'bibox-api-sign': sign,
            'bibox-timestamp': timestamp
        },
        body: cmd//post参数字符串
    },

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

        console.log(body)

    });

POST https://api.bibox.com/v3.1/cquery/base_coin/bassets

Response

{
    "result":{
        "coinAssets":[
            {
                "coin_symbol":"BTC",
                "balance":"2.0230867132",
                "freeze":"0.0000685393",
                "profit":"-0.0000004735",
                "unprofit":"-0.0008529014",
                "can_transfer":"2.0222338118",
                "total_balance":"2.0223023511",
                "total_balance_usd":"20223.0235110000",
                "total_balance_cny":"131550.6837466242",
                "total_balance_btc":"2.0223023511",
                "order_freeze":"0.0000035218",
                "margin":"0.0000650175"
            },
            ...
        ],
        "total_balance_btc":"11897.1202764313",
        "total_balance_cny":"773907178.6813000767",
        "total_balance_usd":"118971202.7643127656"
    },
    "state":0
}

名称 描述
state 0代表成功,否则代表失败
coin_symbol 币种
balance 可用余额
order_freeze 挂单冻结
margin 保证金冻结
unprofit 未实现盈亏
total_balance 账户权益
其它字段 忽略

20.查询资金费率

GET https://api.bibox.com/v3.1/cquery/bcFundRate

Response

{
    "result":{
        "5BTC_USD":{
            "pair":"5BTC_USD",
            "close":"0.0000000000",
            "fund_rate":"0.0001000000",
            "createdAt":"2020-10-14T00:00:00.000Z"
        },
        "5ETH_USD":{
            "pair":"5ETH_USD",
            "close":"0.0000000000",
            "fund_rate":"0.0001000000",
            "createdAt":"2020-10-14T00:00:00.000Z"
        }
    },
    "state":0
}

名称 描述
state 0代表成功,否则代表失败
pair 交易对
fund_rate 即将收取的资金费率
其它字段 忽略

21.查询标记价格

GET https://api.bibox.com/v3.1/cquery/bcTagPrice

Response

{
    "result":{
        "5BTC_USD":{//交易对
            "close":"11453.7224909000",// 指数价格
            "priceTag":"11454.2951770245",// 标记价格
            "createdAt":"2020-10-14T03:41:08.000Z" // 时间
        },
        "5ETH_USD":{
            "close":"383.1999999600",
            "priceTag":"383.2191599600",
            "createdAt":"2020-10-14T03:41:08.000Z"
        }
    },
    "state":0
}

名称 描述
state 0代表成功,否则代表失败
result 关键字是交易对
close 指数价格
priceTag 标记价格
createdAt 时间
其它字段 忽略

22.查询合约基本信息

GET https://api.bibox.com/v3.1/cquery/bcValue

Response

{
    "result":[
        {
            "id":465, // 忽略
            "pair":"5BTC_USD",//交易对
            "coin_symbol":"BTC", // 忽略
            "leverage_init":"10.0000000000", // 忽略
            "leverage_min":"0.0100000000",//最小杠杆倍数
            "leverage_max":"100.0000000000",//最大杠杆倍数
            "value":"1.0000000000",//合约面值
            "risk_level_base":"1000000.0000000000",//忽略
            "risk_level_dx":"50000.0000000000",//忽略
            "maker_fee":"0.0006000000",//默认maker手续费费率
            "taker_fee":"0.0006000000",//默认taker手续费费率
            "open_max_per":"10000000.0000000000",//单笔挂单最大数量
            "pending_max":100,//最大挂单个数
            "hold_max":"100000000.0000000000",//最大持仓价值
            "price_precision":1 // 忽略 
        },
        ...
    ],
    "state":0
}

名称 描述
state 0代表成功,否则代表失败
pair 交易对
leverage_min 最小杠杆倍数
leverage_max 最大杠杆倍数
value 合约面值
maker_fee 默认maker手续费费率
taker_fee 默认taker手续费费率
open_max_per 单笔挂单最大数量
pending_max 最大挂单个数
hold_max 最大持仓价值
其它字段 忽略

23.查询精度配置

GET https://api.bibox.com/v3.1/cquery/bcUnit

Response

{
    "result":[
        {
            "pair":"5BTC_USD",//交易对
            "price_unit":1,//下单小数点数
            "vol_unit":6, // 忽略
            "value_unit":0 // 忽略
        },
        ...
    ],
    "state":0
}

名称 描述
state 0代表成功,否则代表失败
pair 交易对
price_unit 下单小数点数
其它字段 忽略

24.查询k线

参数名称 是否必须 类型 描述 默认值 取值范围
pair true string 交易对 5BTC_USD, 5ETH_USD, ...
period true string k线周期 '1min', '3min', '5min', '15min', '30min', '1hour', '2hour', '4hour', '6hour', '12hour', 'day', 'week'
size false integer 数量 1000 1-1000

Response

{
    "result":[
        {
            "time":1602680580000,// 时间戳
            "open":"10666.00000000",// 开盘价
            "high":"10666.00000000",// 最高价
            "low":"10666.00000000", // 最低价
            "close":"10666.00000000",// 收盘价
            "vol":"0.00000000"// 成交量
        },
        ...
    ],
    "cmd":"kline",
    "ver":"2.0"
}

名称 描述
result 有数据代表成功,否则代表失败
time 时间戳
open 开盘价
high 最高价
low 最低价
close 收盘价
vol 成交量
其它字段 忽略

25.查询合约市场深度

GET https://api.bibox.com/v2/mdata/depth?pair=5BTC_USD&size=10

参数名称 是否必须 类型 描述 默认值 取值范围
pair true string 交易对 4BTC_USDT, 4ETH_USDT, ...
size false integer 数量 200 1-200

Response

{
    "result":{
        "pair":"5BTC_USD",
        "update_time":1602669350668,
        "asks":[//卖方深度

        ],
        "bids":[//买方深度
            {
                "volume":"54054",//挂单数量
                "price":"10666"//挂单价格
            },
            ...
        ]
    },
    "cmd":"depth",
    "ver":"2.0"
}

名称 描述
result 有数据代表成功,否则代表失败
pair 交易对
update_time 时间
asks 卖方深度
bids 买方深度
volume 挂单数量
price 挂单价格
其它字段 忽略

26.订阅 Kline 数据

完整例子


const WebSocket = require('ws');
const zlib = require('zlib');

const biboxws = 'wss://push.bibox.me/cbc';

let wsClass = function () {

};

wsClass.prototype._decodeMsg = async function (data) {
    let that = this;
    return new Promise((resolve, reject) => {
        // console.log(Buffer.from(data, 'base64'))
        zlib.unzip(Buffer.from(data, 'base64'), (err, buffer) => {
            if (err) {
                return reject(err);
            }
            try {
                console.log('_decodeMsg', buffer.toString())
                let data = JSON.parse(buffer.toString());
                resolve(data);
            } catch (e) {
                console.log('_decodeMsg catch', buffer.toString())
                reject(e);
            }
        });
    }).catch(err => {
        console.warn(err);
    });
};

wsClass.prototype._consumerMsg = function (msg) {
    let that = this;
    Promise.resolve().then(async () => {
        let data = msg.data;
        if (msg.binary == 1) {
            data = await that._decodeMsg(data);
        }
    }).catch(err => {

    });
};

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

    ws.on('open', function open() {
        console.log(new Date(), 'open')
        {
            ws.send(JSON.stringify({
                event: 'addChannel',
                channel: 'bibox_sub_spot_5BTC_USD_kline_1min',
                binary: 0,
                ver: 8,
            }));
        }
    });

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

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

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

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

    ws.on('message', data => {
        console.log('message', data)
        let jdata = JSON.parse(data); // 获得数据
        for (let i = 0; i < jdata.length; i++) {
            let item = jdata[i];
            if (!item.data) {
                continue;
            }
            that._consumerMsg(item);
        }
    });
};

let instance = new wsClass();

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

wss://push.bibox.me/cbc

参数名称 是否必须 类型 描述 默认值 取值范围
pair true string 交易对 5BTC_USD, 5ETH_USD
period true string K线周期 1min, 5min, 15min, 30min, 1hour, 2hour, 4hour, 6hour, 12hour, day, week
event true string 行为 'addChannel'
channel true string 'bibox_sub_spot_' + ${pair} + '_kline_' + ${period}
binary true int 0
ver true int 8

Response

[
    {
        "channel":"bibox_sub_spot_5BTC_USD_kline_1min",
        "binary":0,
        "data_type":1,
        "data":[
            {
                "time":1603969980000,
                "open":"13131.80000000",
                "high":"13136.40000000",
                "low":"13131.80000000",
                "close":"13136.40000000",
                "vol":"43045.00000000"
            },
            {
                "time":1603970040000,
                "open":"13136.30000000",
                "high":"13136.80000000",
                "low":"13136.30000000",
                "close":"13136.70000000",
                "vol":"5561.00000000"
            }
        ]
    }
]

名称 描述
time k线某周期开始时间
count 成交笔数
open 开盘价
high 最高价
low 最低价
close 收盘价
vol 成交量(合约价值)
binary 0代表数据没有压缩,1代表数据压缩了
其它字段 忽略

27.订阅标记价格

完整例子


const WebSocket = require('ws');
const zlib = require('zlib');

const biboxws = 'wss://push.bibox.me/cbc';

let wsClass = function () {

};

wsClass.prototype._decodeMsg = async function (data) {
    let that = this;
    return new Promise((resolve, reject) => {
        // console.log(Buffer.from(data, 'base64'))
        zlib.unzip(Buffer.from(data, 'base64'), (err, buffer) => {
            if (err) {
                return reject(err);
            }
            try {
                console.log('_decodeMsg', buffer.toString())
                let data = JSON.parse(buffer.toString());
                resolve(data);
            } catch (e) {
                console.log('_decodeMsg catch', buffer.toString())
                reject(e);
            }
        });
    }).catch(err => {
        console.warn(err);
    });
};

wsClass.prototype._consumerMsg = function (msg) {
    let that = this;
    Promise.resolve().then(async () => {
        let data = msg.data;
        if (msg.binary == 1) {
            data = await that._decodeMsg(data);
        }
    }).catch(err => {

    });
};

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

    ws.on('open', function open() {
        console.log(new Date(), 'open')
        {
            ws.send(JSON.stringify({
                event: 'addChannel',
                channel: 'bibox_sub_spot_5BTC_USDTAGPRICE_kline_1min',
                binary: 0,
                ver: 8,
            }));
        }
    });

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

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

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

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

    ws.on('message', data => {
        console.log('message', data)
        let jdata = JSON.parse(data); // 获得数据
        for (let i = 0; i < jdata.length; i++) {
            let item = jdata[i];
            if (!item.data) {
                continue;
            }
            that._consumerMsg(item);
        }
    });
};

let instance = new wsClass();

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

wss://push.bibox.me/cbc

参数名称 是否必须 类型 描述 默认值 取值范围
pair true string 交易对 5BTC_USD, 5ETH_USD
event true string 行为 'addChannel'
channel true string 'bibox_sub_spot_' + ${pair} + 'TAGPRICE_kline_1min'
binary true int 0
ver true int 8

Response

[
    {
        "channel":"bibox_sub_spot_5BTC_USDTAGPRICE_kline_1min",
        "binary":0,
        "data_type":1,
        "data":[
            {
                "time":1603970520000,
                "open":"13153.34453367",
                "high":"13153.34453367",
                "low":"13151.07785535",
                "close":"13151.13533507",
                "vol":"30.00000000"
            },
            {
                "time":1603970580000,
                "open":"13150.75301752",
                "high":"13150.75301752",
                "low":"13149.51581987",
                "close":"13149.51581987",
                "vol":"5.00000000"
            }
        ]
    }
]

名称 描述
time k线某周期开始时间
count 成交笔数
open 开盘价
high 最高价
low 最低价
close 最新价
binary 0代表数据没有压缩,1代表数据压缩了
其它字段 忽略

28.订阅深度

完整例子


const WebSocket = require('ws');
const zlib = require('zlib');

const biboxws = 'wss://push.bibox.me/cbc';

let wsClass = function () {

};

wsClass.prototype._decodeMsg = async function (data) {
    let that = this;
    return new Promise((resolve, reject) => {
        // console.log(Buffer.from(data, 'base64'))
        zlib.unzip(Buffer.from(data, 'base64'), (err, buffer) => {
            if (err) {
                return reject(err);
            }
            try {
                console.log('_decodeMsg', buffer.toString())
                let data = JSON.parse(buffer.toString());
                resolve(data);
            } catch (e) {
                console.log('_decodeMsg catch', buffer.toString())
                reject(e);
            }
        });
    }).catch(err => {
        console.warn(err);
    });
};

wsClass.prototype._consumerMsg = function (msg) {
    let that = this;
    Promise.resolve().then(async () => {
        let data = msg.data;
        if (msg.binary == 1) {
            data = await that._decodeMsg(data);
        }
    }).catch(err => {

    });
};

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

    ws.on('open', function open() {
        console.log(new Date(), 'open')
        {
            ws.send(JSON.stringify({
                event: 'addChannel',
                channel: 'bibox_sub_spot_5BTC_USD_depth', // depth
                binary: 0,
                ver: 3,
            }));
        }
    });

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

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

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

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

    ws.on('message', data => {
        console.log('message', data)
        let jdata = JSON.parse(data); // 获得数据
        for (let i = 0; i < jdata.length; i++) {
            let item = jdata[i];
            if (!item.data) {
                continue;
            }
            that._consumerMsg(item);
        }
    });
};

let instance = new wsClass();

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

wss://push.bibox.me/cbc

参数名称 是否必须 类型 描述 默认值 取值范围
pair true string 交易对 5BTC_USD, 5ETH_USD
event true string 行为 'addChannel'
channel true string 'bibox_sub_spot_' + ${pair} + '_depth_'
binary true int 0
ver true int 3

Response

{
    "pair":"5BTC_USD",
    "update_time":1604021669643,
    "seq":4544162,
    "add":{
        "asks":null,
        "bids":null
    },
    "del":{
        "asks":null,
        "bids":null
    },
    "mod":{
        "asks":[
            {
                "volume":"54000",
                "price":"13574.4"
            }
        ],
        "bids":[
            {
                "volume":"17012",
                "price":"13574.3"
            }
        ]
    }
}

名称 描述
pair 交易对
update_time 时间
seq 交易对
add 新增的深度
del 删除的深度
mod 修改的深度
asks 卖单
bids 买单
volume 挂单数量
price 深度价格
binary 0代表数据没有压缩,1代表数据压缩了
其它字段 忽略

29.订阅成交记录

完整例子


const WebSocket = require('ws');
const zlib = require('zlib');

const biboxws = 'wss://push.bibox.me/cbc';

let wsClass = function () {

};

wsClass.prototype._decodeMsg = async function (data) {
    let that = this;
    return new Promise((resolve, reject) => {
        // console.log(Buffer.from(data, 'base64'))
        zlib.unzip(Buffer.from(data, 'base64'), (err, buffer) => {
            if (err) {
                return reject(err);
            }
            try {
                console.log('_decodeMsg', buffer.toString())
                let data = JSON.parse(buffer.toString());
                resolve(data);
            } catch (e) {
                console.log('_decodeMsg catch', buffer.toString())
                reject(e);
            }
        });
    }).catch(err => {
        console.warn(err);
    });
};

wsClass.prototype._consumerMsg = function (msg) {
    let that = this;
    Promise.resolve().then(async () => {
        let data = msg.data;
        if (msg.binary == 1) {
            data = await that._decodeMsg(data);
        }
    }).catch(err => {

    });
};

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

    ws.on('open', function open() {
        console.log(new Date(), 'open')
        {
            ws.send(JSON.stringify({
                event: 'addChannel',
                channel: 'bibox_sub_spot_5BTC_USD_deals', 
                binary: 0,
            }));
        }
    });

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

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

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

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

    ws.on('message', data => {
        console.log('message', data)
        let jdata = JSON.parse(data); // 获得数据
        for (let i = 0; i < jdata.length; i++) {
            let item = jdata[i];
            if (!item.data) {
                continue;
            }
            that._consumerMsg(item);
        }
    });
};

let instance = new wsClass();

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

wss://push.bibox.me/cbc

参数名称 是否必须 类型 描述 默认值 取值范围
pair true string 交易对 5BTC_USD, 5ETH_USD
event true string 行为 'addChannel'
channel true string 'bibox_sub_spot_' + ${pair} + '_deals'
binary true int 0

Response

[
    {
        "pair":"5BTC_USD",
        "price":"13570.600000",
        "amount":"800.00",
        "time":1604022129044,
        "side":2,
        "id":0
    }
]

名称 描述
pair 交易对
price 成交价格
amount 成交价值
time 成交时间戳
side 成交方向,1-开多,2-开空
binary 0代表数据没有压缩,1代表数据压缩了
其它字段 忽略

30.订阅最新成交价

完整例子


const WebSocket = require('ws');
const zlib = require('zlib');

const biboxws = 'wss://push.bibox.me/cbc';

let wsClass = function () {

};

wsClass.prototype._decodeMsg = async function (data) {
    let that = this;
    return new Promise((resolve, reject) => {
        // console.log(Buffer.from(data, 'base64'))
        zlib.unzip(Buffer.from(data, 'base64'), (err, buffer) => {
            if (err) {
                return reject(err);
            }
            try {
                console.log('_decodeMsg', buffer.toString())
                let data = JSON.parse(buffer.toString());
                resolve(data);
            } catch (e) {
                console.log('_decodeMsg catch', buffer.toString())
                reject(e);
            }
        });
    }).catch(err => {
        console.warn(err);
    });
};

wsClass.prototype._consumerMsg = function (msg) {
    let that = this;
    Promise.resolve().then(async () => {
        let data = msg.data;
        if (msg.binary == 1) {
            data = await that._decodeMsg(data);
        }
    }).catch(err => {

    });
};

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

    ws.on('open', function open() {
        console.log(new Date(), 'open')
        {
            ws.send(JSON.stringify({
                event: 'addChannel',
                channel: 'bibox_sub_spot_5BTC_USD_ticker', 
                binary: 0,
            }));
        }
    });

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

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

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

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

    ws.on('message', data => {
        console.log('message', data)
        let jdata = JSON.parse(data); // 获得数据
        for (let i = 0; i < jdata.length; i++) {
            let item = jdata[i];
            if (!item.data) {
                continue;
            }
            that._consumerMsg(item);
        }
    });
};

let instance = new wsClass();

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

wss://push.bibox.me/cbc

参数名称 是否必须 类型 描述 默认值 取值范围
pair true string 交易对 5BTC_USD, 5ETH_USD
event true string 行为 'addChannel'
channel true string 'bibox_sub_spot_' + ${pair} + '_ticker'
binary true int 0

Response

[
    {
        "channel":"bibox_sub_spot_5BTC_USD_ticker",
        "binary":0,
        "data_type":1,
        "data":{
            "pair":"5BTC_USD",
            "last":"13593.5",
            "last_usd":"13593.50",
            "last_cny":"91076.20",
            "high":"13700.300000",
            "low":"12986.000000",
            "buy":"13593.5",
            "buy_amount":"48375",
            "sell":"13593.6",
            "sell_amount":"56625",
            "vol":"155811681.00",
            "percent":"+2.44%",
            "timestamp":1604022393028,
            "base_last_cny":"91076.20000000"
        }
    }
]

名称 描述
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位小数)
binary 0代表数据没有压缩,1代表数据压缩了
其它字段 忽略

31.订阅用户数据方法

实际例子


'use strict'

const WebSocket = require('ws');
let CryptoJS = require("crypto-js");

const biboxws = 'wss://push.bibox.me/cbc'; // 1.请求路径

let apikey = '900625568558820892a8c833c33ebc8fd2701efe'; // 你的apikey
let param = {  // 定义参数对象param,需要用到apikey
    "apikey": apikey,
    "channel": "bibox_sub_spot_ALL_ALL_login",
    "event": "addChannel"
};
let strParam = JSON.stringify(param); // 格式化参数对象param,得到strParam
let secret = 'c708ac3e70d115ec29efbee197330627d7edf842'; // apikey的密码
let sign = CryptoJS.HmacMD5(strParam, secret).toString(); // 用apikey的密码secret对strParam进行HmacMD5签名,得到签名结果sign
let wsparam = {  // 2.请求参数
    "apikey": apikey,
    "channel": "bibox_sub_spot_ALL_ALL_login",
    "event": "addChannel",
    "sign": sign,
};


let init = function () {

    let ws = new WebSocket(biboxws);

    setInterval(function () {
        if (ws && ws.readyState == WebSocket.OPEN) {
            console.log('manu ping');
            ws.ping(Date.now());
        }
    }, 1000 * 10);

    ws.on('open', function open() {

        console.log('open')
        ws.send(JSON.stringify(wsparam));

    });

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

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

    ws.on('ping', err => {
        console.log('ping', err)
    });

    ws.on('pong', err => {
        console.log('pong', err)
    });

    ws.on('message', function incoming(data) {
        let jdata = JSON.parse(data); // 返回结果
        if (!jdata.ping) {
            console.log('message', data)
        }

    });
};

module.exports = {};

init();


wss://push.bibox.me/cbc

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

1.定义参数对象param,需要用到apikey

let apikey = 'thisisyourapikey';

let param = { "apikey": apikey, "channel": "bibox_sub_spot_ALL_ALL_login", "event": "addChannel" };

2.格式化参数对象param,得到strParam

let strParam = JSON.stringify(param);

3.用apikey的密码secret对strParam进行HmacMD5签名,得到签名结果sign

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

let secret = 'c708ac3e70d115ec29efbee197330627d7edf842';

let sign = CryptoJS.HmacMD5(strParam, secret).toString();

4.生成订阅参数 wsparam

let wsparam = { "apikey": apikey, "channel": "bibox_sub_spot_ALL_ALL_login", "event": "addChannel", "sign": sign, };

Response

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

名称 描述
result "订阅成功" 代表订阅成功
其它字段 忽略

32.订阅用户数据解析资产

cbc_assets

Response

[
    {
        "channel":"bibox_sub_spot_ALL_ALL_login",
        "binary":"0",
        "data_type":1,
        "data":{
            "cbc_assets":{
                "b":"2.9403466391",
                "c":"BTC",
                "u":100006,
                "f":"0.0005725599",
                "m":"0.062609658"
            }
        }
    }
]

名称 描述
b 可用余额
c 币种符号
u 用户id
f 冻结资金
m 冻结保证金
其它字段 忽略

33.订阅用户数据解析仓位

cbc_order

Response

[
    {
        "channel":"bibox_sub_spot_ALL_ALL_login",
        "binary":"0",
        "data_type":1,
        "data":{
            "cbc_order":{
                "pt":"0",
                "f":"0",
                "l":"10",
                "sd":2,
                "pa":"1.0006153088",
                "ui":100006,
                "fb0":"0",
                "pf":"1.0006148393",
                "md":1,
                "lc":"0",
                "pi":"5BTC_USD",
                "mg":"0",
                "hc":"0",
                "fb":"0",
                "po":"0"
            }
        }
    }
]

名称 描述
l 杠杆
sd 仓位方向: 1, 多仓 2 , 空仓
pa 告警价格
ui 用户id
pf 爆仓价格
md 仓位模式: 1全仓, 2逐仓
lc 可平仓位价值
pi 交易对
mg 保证金
hc 仓位价值 = 合约张数X合约面值
po 开仓价格
其它字段 忽略

34.订阅用户数据解析挂单

cbc_pending

Response

[
    {
        "channel":"bibox_sub_spot_ALL_ALL_login",
        "binary":"0",
        "data_type":1,
        "data":{
            "cbc_pending":{
                "f":"0",
                "dp":"0",
                "eq":"0",
                "p":"11692",
                "tif":0,
                "q":"1",
                "sd":2,
                "r":0,
                "s":1,
                "t":1602750121093,
                "ui":100006,
                "fz":"0.0000086786",
                "fb0":"0",
                "of":4,
                "pi":"5BTC_USD",
                "oi":"432108069716000",
                "coi":"1602750117690",
                "fb":"0",
                "po":false
            }
        }
    }
]

名称 描述
f 手续费
dp 成交价格
eq 成交数量
p 下单价格
q 下单数量
sd 下单方向
r 失败原因
s 订单状态
t 下单时间
ui 用户id
fz 挂单冻结
fb0 优惠券抵扣
of 订单来源
pi 交易对
oi 订单id
coi 用户自定义订单id
fb bix抵扣
其它字段 忽略

35.订阅用户数据解析成交明细

cbc_detail

Response

[
    {
        "channel":"bibox_sub_spot_ALL_ALL_login",
        "binary":"0",
        "data_type":1,
        "data":{
            "cbc_detail":{
                "oi":"432108069715999",//挂单id
                "ui":"100006",//用户id
                "id":"1125899906842648855",//成交id
                "coi":"1602750117684",//自定义id
                "pi":"5BTC_USD",//交易对
                "sd":1,//
                "s":3,//
                "ot":2,
                "of":4,// 挂单来源
                "q":"1",
                "p":"11692",//挂单价格
                "dp":"10655",//成交价格
                "ep":"1",
                "f":"0.0000000657",//手续费
                "fb":"0",//bix抵扣
                "fb0":"0",//优惠券抵扣
                "im":0,//是否是maker
                "t":1602750121093, //成交时间
            }
        }
    }
]

名称 描述
oi 订单id
ui 用户id
id 明细id
coi 用户自定义订单id
pi 交易对
sd 下单方向
of 订单来源
p 下单价格
dp 成交价格
f 手续费
fb0 优惠券抵扣
fb bix抵扣
im 是否是maker
t 下单时间
其它字段 忽略

36.订阅用户数据解析持仓被动变化信息

cbc_deal_log

Response

[
    {
        "channel":"bibox_sub_spot_ALL_ALL_login",
        "binary":"0",
        "data_type":1,
        "data":{
            "cbc_deal_log":{
                "id":"1125899906842654296",// 变化id
                "user_id":100006,//用户id
                "type":5,//变化类型,1开仓,2平仓,3减仓降低风险等级, 4爆仓清空仓位, 5ADL
                "mode":2,//仓位模式 1全仓,2逐仓
                "pair":"5BTC_USD",//交易对
                "price":"11247.6",//参考价格
                "hold_dx":"1",//持仓变化量
                "order_side":2,// 仓位方向,1多仓,2空仓
                "time":1602755131000, //变化时间
            }
        }
    }
]

名称 描述
id 变化id
user_id 用户id
type 变化类型,1开仓,2平仓,3减仓降低风险等级, 4爆仓清空仓位, 5ADL
mode 仓位模式 1全仓,2逐仓
pair 交易对
price 参考价格
hold_dx 持仓变化量
order_side 仓位方向,1多仓,2空仓
time 变化时间
其它字段 忽略

Errors

错误码

Code 描述 Msg
2003 Cookie 失效 Cookie expired
2033 操作失败!订单已完成或已撤销 Operation failed! Order completed or canceled
2034 操作失败!请检查参数是否正确 Operation failed! Please check parameter
2040 操作失败!没有该订单 Operation failed! No record
2064 订单撤销中,不能再次撤销 Canceling. Unable to cancel again
2065 委托价格设置过高,请重新设置价格 Precatory price is exorbitant, please reset
2066 委托价格设置过低,请重新设置价格 Precatory price is low , please reset
2067 暂不支持市价单 Limit Order Only
2068 下单数量不能低于0.0001 Min Amount:0.0001
2069 市价单无法撤销 Market order can not be canceled
2078 下单价格非法 unvalid order price
2085 币种最小下单数量限制 the trade amount is low
2086 账户资产异常,限制下单 Abnormal account assets, trade is forbiden
2091 请求过于频繁,请稍后再试 request is too frequency, please try again later
2092 币种最小下单金额限制 Minimum amount not met
3000 请求参数错误 Requested parameter incorrect
3002 参数不能为空 Parameter cannot be null
3009 推送订阅channel不合法 Illegal subscription channel
3010 websocket连接异常 websocket connection error
3011 接口不支持apikey请求方式 Illegal subscribe event
3012 apikey无效 Interface does not support apikey request method
3016 交易对错误 Invalid apikey
3017 推送订阅event不合法 Trading pair error
3024 apikey权限不足 apikey authorization insufficient
3025 apikey签名验证失败 apikey signature verification failed
3026 apikey ip受限制 apikey ip is restricted
3027 账户没有apikey No apikey in your account
3028 账户apikey数量超过了限制数量 Account apikey has exceeded the limit amount
3029 apikey允许ip数量超过了限制数量 apikey ip has exceeded the limit amount
3033 查询类请求限制一个cmd query allow only one cmd
3034 最大cmd个数限制 maxinum cmds
3035 cmd请求个数限制 too many cmds
4000 当前网络连接不稳定,请稍候重试 the network is unstable now, please try again later
4003 服务器繁忙,请稍后再试 The server is busy, please try again later