English
javascript

U本位合约

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",
};

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.1/ctrade/transfer/in";

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.1/ctrade/transfer/in

参数名称 是否必须 类型 描述 默认值 取值范围
amount true integer USDT金额

Response

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

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

3.查询合约资产

Request

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

let url = "https://api.bibox.com/v3.1/cquery/query/assets";

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/query/assets

Response

{
    "result":{
        "balance":"97.2378", // 可用余额
        "freeze":"1.7326", // 冻结金额
        "profit":"-2.4327", 
        "margin":"1.7326",
        "imargin":"0.0000",
        "total_balance":"98.8397",
        "BTCValue":"0.02528321",
        "CNYValue":"664.61",
        "USDValue":"98.84",
        "floatProfitBTC":"-0.00003344",
        "floatProfit":"-0.1308",
        "profitBTC":"-0.00062226",
        "freezeBTC":"0.00044322"
    },
    "state":0,
}

名称 描述
state 0代表成功,否则代表失败
balance 可用余额
freeze 冻结金额
其它字段 忽略

3.1.查询合约账单

Request

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

let url = "https://api.bibox.com/v3.1/cquery/query/getMyBills";

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

let param = {
    page: 1, 
    size: 10, 
    type: 12, 
    begin_time: Date.now() - 1000 * 60 * 60, 
    end_time: Date.now()
};

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/query/getMyBills

参数名称 是否必须 类型 描述 默认值 取值范围
page true integer 第几页 1,2,...
size true integer 多少条 1,2,...
begin_time false integer 开始时间
end_time false integer 结束时间
type false integer 账单类型 1转入,2转出,3平仓,4手续费,6爆仓,7减仓,11资金费用调整,12资金费用

Response

{
     "result":{
        "count":11,
        "page":1,
        "items":[
            {
                "id":"1125899906850284004",
                "coin_symbol":"USDT",
                "bill_type":12,
                "comment":"4LTC_USDT|资金费用",
                "change_amount":"6.9553",
                "change_result":"182461.2621",
                "createdAt":"2020-11-23T00:00:00.000Z",
                "updatedAt":"2020-11-23T00:00:00.000Z"
            },
            ...
        ]
    },
    "state":0,
}

名称 描述
state 0代表成功,否则代表失败
id 账单id
coin_symbol 币种符号
bill_type 账单类型:1转入,2转出,3平仓,4手续费,6爆仓,7减仓,11资金费用调整,12资金费用
comment 账单描述
change_amount 资产改变量
change_result 资产改变结果
createdAt 账单时间
其它字段 忽略

3.2.查询合约资金划转记录

Request

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

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

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

let param = {
    page: 1, 
    size: 10, 
    begin_time: Date.now() - 1000 * 60 * 60, 
    end_time: Date.now()
};

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/query/transferLog

参数名称 是否必须 类型 描述 默认值 取值范围
page true integer 第几页 1,2,...
size true integer 多少条 1,2,...
begin_time false integer 开始时间
end_time false integer 结束时间

Response

{
     "result":{
        "count":11,
        "page":1,
        "items":[
            {
                "id":"1125899906850281534",
                "coin_symbol":"USDT",
                "bill_type":1,
                "comment":"转入",
                "change_amount":"1.0000",
                "change_result":"168599.4449",
                "createdAt":"2020-11-19T11:20:37.000Z",
                "updatedAt":"2020-11-19T11:20:37.000Z"

            },
            ...
        ]
    },
    "state":0,
}

名称 描述
state 0代表成功,否则代表失败
id 账单id
coin_symbol 币种符号
bill_type 账单类型:1转入,2转出
comment 账单描述
change_amount 资产改变量
change_result 资产改变结果
createdAt 账单时间
其它字段 忽略

4.查询单个持仓信息

Request

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

let url = "https://api.bibox.com/v3.1/cquery/query/order";

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

let param = {
    "pair":"4BTC_USDT"
};

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/query/order

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

Response

{
    "result":{
        "coin_symbol":"USDT",
        "pair":"4BTC_USDT", // 合约符号
        "contract":2, // 持仓张数
        "margin":"1.5612", // 持仓保证金
        "profit":"-2.4995",
        "price":"3903.0450", // 开仓均价
        "order_side":2, // 开仓方向:1开多,2开空
        "price_force":"3961.5907", // 强平价格
        "floatProfit":"-0.1376",
        "leverage":50, // 0:全仓,其它:逐仓杠杆倍数
        "icontract_up":2, // 开多未成交订单张数
        "icontract_down":0 // 开空未成交订单张数
    },
    "state":0, // 成功
}

名称 描述
state 0代表成功,否则代表失败
pair 合约符号
contract 持仓张数
margin 持仓保证金
price 开仓均价
order_side 开仓方向:1开多,2开空
price_force 强平价格
leverage 0:全仓,其它:逐仓杠杆倍数
icontract_up 开多未成交订单张数
icontract_down 开空未成交订单张数
其它字段 忽略

5.查询所有持仓信息

Request

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

let url = "https://api.bibox.com/v3.1/cquery/query/orderAll";

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/query/orderAll

Response

{
    "result":[
        {
            "coin_symbol":"USDT",
            "pair":"4BTC_USDT", // 合约符号
            "contract":2, // 持仓张数
            "margin":"1.5612", // 持仓保证金
            "profit":"-2.4995",
            "price":"3903.0450", // 开仓均价
            "order_side":2, // 开仓方向:1开多,2开空
            "price_force":"3961.5907", // 强平价格
            "floatProfit":"-0.1376",
            "leverage":50, // 0:全仓,其它:逐仓杠杆倍数
            "icontract_up":2, // 开多未成交订单张数
            "icontract_down":0 // 开空未成交订单张数
        },
        ...
    ],
    "state":0,// 成功
}

名称 描述
state 0代表成功,否则代表失败
pair 合约符号
contract 持仓张数
margin 持仓保证金
price 开仓均价
order_side 开仓方向:1开多,2开空
price_force 强平价格
leverage 0:全仓,其它:逐仓杠杆倍数
icontract_up 开多未成交订单张数
icontract_down 开空未成交订单张数
其它字段 忽略

6.查询未成交订单

Request

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

let url = "https://api.bibox.com/v3.1/cquery/query/orderPending";

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

let param = {
    "page":1,
    "size":20,
    "pair":""
};

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/query/orderPending

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

Response

{
    "result":{
        "count":3,
        "page":1,
        "items":[
            {
                "id":491168, // 订单号
                "coin_symbol":"USDT",
                "pair":"4ETH_USDT", // 合约符号
                "order_side":1, // 挂单方向:1开多,2开空
                "order_type":2,
                "contract":3, // 委托合约张数
                "order_from":1,
                "status":1, // 0,1未成交 2部分成交  3完全成交 4部分取消 5完全取消 6,7 系统取消, >=100 下单失败
                "price":"136.0000", // 委托价格
                "price_deal":"0.0000", // 成交均价
                "deal_count":0, 
                "contract_deal":0, // 已成交合约张数
                "createdAt":"2019-02-20T02:01:46.000Z",
                "updatedAt":"2019-02-20T02:01:46.000Z"
            },
            {
                "id":489453,
                "coin_symbol":"USDT",
                "pair":"4BTC_USDT",
                "order_side":1,
                "order_type":2,
                "contract":2,
                "order_from":1,
                "status":1,
                "price":"3850.0000",
                "price_deal":"0.0000",
                "deal_count":0,
                "contract_deal":0,
                "createdAt":"2019-02-20T01:51:41.000Z",
                "updatedAt":"2019-02-20T01:51:42.000Z"
            }
        ]
    },
    "state":0,// 成功
}

名称 描述
state 0代表成功,否则代表失败
id 订单号
pair 合约符号
order_side 挂单方向:1开多,2开空
contract 委托合约张数
status 0,1未成交 2部分成交 3完全成交 4部分取消 5完全取消 6,7 系统取消, >=100 下单失败
price 委托价格
price_deal 成交均价
contract_deal 已成交合约张数
其它字段 忽略

6.1.查询近10天历史成交订单

Request

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

let url = "https://api.bibox.com/v3.1/cquery/query/getDealHistoryOrder";

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

let param = {
    "page":1,
    "size":20,
    "pair":"4BTC_USDT",
    "begin_time": new Date('2020-11-10T00:00:00.000Z').getTime(),
    "end_time": new Date('2020-11-11T00:00:00.000Z').getTime(),
};

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/query/getDealHistoryOrder

参数名称 是否必须 类型 描述 默认值 取值范围
page true integer 第几页 1,2, ...
size true integer 条数 10,20, ...
pair false string 合约符号 4BTC_USDT,4ETH_USDT, ...
begin_time false integer 开始时间 近10天
end_time false integer 结束时间 近10天

Response

{
    "result":{
        "count":3,
        "page":1,
        "items":[
            {
                "id":491168, // 订单号
                "coin_symbol":"USDT",
                "pair":"4ETH_USDT", // 合约符号
                "order_side":1, // 挂单方向:1开多,2开空
                "order_type":2,
                "contract":3, // 委托合约张数
                "order_from":1,
                "status":1, // 0,1未成交 2部分成交  3完全成交 4部分取消 5完全取消 6,7 系统取消, >=100 下单失败
                "price":"136.0000", // 委托价格
                "price_deal":"0.0000", // 成交均价
                "deal_count":0, 
                "contract_deal":0, // 已成交合约张数
                "createdAt":"2019-02-20T02:01:46.000Z",
                "updatedAt":"2019-02-20T02:01:46.000Z"
            },
            {
                "id":489453,
                "coin_symbol":"USDT",
                "pair":"4BTC_USDT",
                "order_side":1,
                "order_type":2,
                "contract":2,
                "order_from":1,
                "status":1,
                "price":"3850.0000",
                "price_deal":"0.0000",
                "deal_count":0,
                "contract_deal":0,
                "createdAt":"2019-02-20T01:51:41.000Z",
                "updatedAt":"2019-02-20T01:51:42.000Z"
            }
        ]
    },
    "state":0,// 成功
}

名称 描述
state 0代表成功,否则代表失败
id 订单号
pair 合约符号
order_side 挂单方向:1开多,2开空
contract 委托合约张数
status 0,1未成交 2部分成交 3完全成交 4部分取消 5完全取消 6,7 系统取消, >=100 下单失败
price 委托价格
price_deal 成交均价
contract_deal 已成交合约张数
其它字段 忽略

7.下单

Request

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

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

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

let param = {
    "pair":"4BTC_USDT",
    "order_type":2,
    "price":"3929.97",
    "contract":"1",
    "order_from":1,
    "leverage":50,
    "cross_leverage":25,
    "order_side":1,
    "client_oid": '123456789',
};

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/ctrade/order/open

参数名称 是否必须 类型 描述 默认值 取值范围
order_type true integer 订单类型 1:市价,2:限价
leverage true integer 杠杆倍数 全仓:0,逐仓:1,2,...
cross_leverage false integer 全仓杠杆 25 leverage=0时,且全仓:1,2,...50
order_side true integer 挂单方向 1:开多,2:开空
price true string 委托价格 大于0的数
contract true string 合约张数 1,2, ...
pair true string 合约符号 4BTC_USDT,4ETH_USDT, ...
order_from true integer 6 6
client_oid false Long 自定义标识 > 0

Response

{
    "result": '17592186044786', // 订单号
    "state":0, 
}

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

8.批量下单

Request

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

let url = "https://api.bibox.com/v3.1/ctrade/order/openBatch";

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

let param = {
    "pair":"4ETH_USDT",
    "leverage":50,
    "cross_leverage": 25,
    "arr":[
        {
            "order_side":1,
            "price":140,
            "contract":1,
            "client_oid": '123456787' 
        },
        {
            "order_side":1,
            "price":140.5,
            "contract":1,
            "client_oid": '123456788' 
        }
    ]
};

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/ctrade/order/openBatch

参数名称 是否必须 类型 描述 默认值 取值范围
leverage true integer 杠杆倍数 全仓:0,逐仓:1,2,...
cross_leverage false integer 全仓杠杆 25 leverage=0时全仓1,2,...50
order_side true integer 挂单方向 1:开多,2:开空
price true string 委托价格 大于0的数
contract true string 合约张数 1,2, ...
pair true string 合约符号 4BTC_USDT,4ETH_USDT, ...
client_oid false Long 自定义标识 > 0

Response

{
    "result":[
        { 
            code: 0, // 0代表成功;非0代表失败,code是错误码
            id: '17592186044787', // 挂单id号
            msg: '',
            client_oid: '123456787' 
         },
         { 
            code: 0,
            id: '17592186044790',
            msg: '',
            client_oid: '123456788'
         }
    ],
    "state":0,
}

名称 描述
state 0代表成功,否则代表失败
code 0代表成功;非0代表失败,code是错误码
id 挂单id号
其它字段 忽略

9.撤单

Request

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

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

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

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

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/ctrade/order/close

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

Response

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

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

10.撤多个单子

Request

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

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

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

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

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/ctrade/order/closeBatch

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

Response

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

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

11.撤1000个单子

Request

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

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

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/ctrade/order/closeAll

Response

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

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

12.通过client_oid撤单

Request

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

let url = "https://api.bibox.com/v3.1/ctrade/order/closeBatchClientOid";

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

let param = {
    "clientIds":[
        "1588819328619"
    ]
};

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/ctrade/order/closeBatchClientOid

参数名称 是否必须 类型 描述 默认值 取值范围
clientIds true string array 用户client_oid单号 最大长度限制50单

Response

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

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

13.调整杠杆倍数

Request

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

let url = "https://api.bibox.com/v3.1/ctrade/order/changeLeverage";

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

let param = {
     "pair":"4BTC_USDT",
     "leverage":40,
     "cross": 0
};

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/ctrade/order/changeLeverage

参数名称 是否必须 类型 描述 默认值 取值范围
pair true string 合约符号 4BTC_USDT,4ETH_USDT, ...
leverage true integer 杠杆倍数 全仓:0,逐仓:1,2,...
cross true integer 是否全仓 0逐仓,1全仓

Response

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

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

14.调整保证金

Request

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

let url = "https://api.bibox.com/v3.1/ctrade/order/changeMargin";

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

let param = {
    "pair": "4ETH_USDT",
    "margin": 4
};

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/ctrade/order/changeMargin

参数名称 是否必须 类型 描述 默认值 取值范围
pair true string 合约符号 4BTC_USDT,4ETH_USDT, ...
margin true integer 增减保证金 增加margin>=0.5;减少margin<=-0.5

Response

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

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

15.查询市场成交记录

GET https://api.bibox.com/v3.1/cquery/deals?pair=4ETH_USDT&&size=10

参数名称 是否必须 类型 描述 默认值 取值范围
pair true String 合约符号 4BTC_USDT,4ETH_USDT,...
size true integer 返回数量 1,2,...

Response

{
    "result":[
        {
            "pair":"4ETH_USDT",      // 合约符号
            "order_side":1,          // 1看涨 2 看空
            "contract":75,           // 张数
            "price":"182.7500",      // 价格
            "createdAt":1565861520000 // 时间
        },
        ...
    ],
    "state": 0,
}

名称 描述
state 0代表成功,否则代表失败
pair 合约符号
order_side 1看涨 2 看空
contract 张数
price 价格
createdAt 时间
其它字段 忽略

16.通过订单号查询订单

Request

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

let url = "https://api.bibox.com/v3.1/cquery/query/orderPendingByIDs";

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

let param = {
    "ids":[
        "491168",
        "2"
    ]
};

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/query/orderPendingByIDs

参数名称 是否必须 类型 描述 默认值 取值范围
ids true string array 订单号 最大长度限制50单

Response

{
    "result":[
        {
            "id":491168, // 订单号
            "coin_symbol":"USDT",
            "pair":"4ETH_USDT", // 合约符号
            "order_side":1, // 挂单方向:1开多,2开空
            "order_type":2,
            "contract":3, // 委托合约张数
            "order_from":1,
            "status":1, // 0,1未成交 2部分成交  3完全成交 4部分取消 5完全取消 6,7 系统取消, >=100 下单失败
            "price":"136.0000", // 委托价格
            "price_deal":"0.0000", // 成交均价
            "deal_count":0, 
            "contract_deal":0, // 已成交合约张数
            "createdAt":"2019-02-20T02:01:46.000Z",
            "updatedAt":"2019-02-20T02:01:46.000Z"
        },
        {
            "id":2,
            "coin_symbol":"USDT",
            "pair":"4BTC_USDT",
            "order_side":1,
            "order_type":2,
            "contract":1,
            "order_from":1,
            "status":3,
            "price":"3622.0000",
            "price_deal":"3622.0000",
            "deal_count":1,
            "contract_deal":1,
            "createdAt":"2019-02-15T13:10:27.000Z",
            "updatedAt":"2019-02-15T13:10:45.000Z"
        }
    ],
    "state":0
}

名称 描述
state 0代表成功,否则代表失败
id 订单号
pair 合约符号
order_side 挂单方向:1开多,2开空
contract 委托合约张数
status 0,1未成交 2部分成交 3完全成交 4部分取消 5完全取消 6,7 系统取消, >=100 下单失败
price 委托价格
price_deal 成交均价
contract_deal 已成交合约张数
其它字段 忽略

17.通过client_oid查询未成交订单

Request

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

let url = "https://api.bibox.com/v3.1/cquery/query/ordersDetailByClientIds";

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

let param = {
    "clientIds":[
        "1588819328619"
    ]
};

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/query/ordersDetailByClientIds

参数名称 是否必须 类型 描述 默认值 取值范围
clientIds true string array 用户client_oid单号 最大长度限制50单

Response

{
    "result":[
        {
            "id": "71468256443234",
            "user_id": 101051,
            "client_oid": "1588819328619",
            "pair": "4BTC_USDT",
            "coin_symbol": "4BTC",
            "price": "9486.0000",
            "price_deal": "9485.9900",
            "contract": "15",
            "contract_deal": "4",
            "deal_count": "1",
            "order_side": 1,
            "order_type": 2,
            "order_from": 6,
            "status": 2,
            "reason": 0,
            "createdAt": 1588819336186,
            "updatedAt": 1588819336186
        },
    ],
    "state":0
}

名称 描述
state 0代表成功,否则代表失败
id 订单号
pair 合约符号
order_side 挂单方向:1开多,2开空
contract 委托合约张数
status 0,1未成交 2部分成交 3完全成交 4部分取消 5完全取消 6,7 系统取消, >=100 下单失败
price 委托价格
price_deal 成交均价
contract_deal 已成交合约张数
其它字段 忽略

18.通过client_oid查询委托单

Request

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

let url = "https://api.bibox.com/v3.1/cquery/query/orderPendingByClientIds";

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

let param = {
    "clientIds":[
        "1588819328619"
    ]
};

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/query/orderPendingByClientIds

参数名称 是否必须 类型 描述 默认值 取值范围
clientIds true string array 用户client_oid单号 最大长度限制50单

Response

{
    "result":[
        {
            "id": 71468256443234,
            "client_oid": "1588819328619",
            "coin_symbol": "USDT",
            "pair": "4BTC_USDT",
            "order_side": 1,
            "order_type": 2,
            "contract": 15,
            "order_from": 6,
            "status": 3,
            "price": "9486.0000",
            "price_deal": "9485.9973",
            "deal_count": 2,
            "contract_deal": 15,
            "createdAt": "2020-05-07T02:42:16.000Z",
            "updatedAt": "2020-05-07T03:02:24.000Z"
        }
    ],
    "state":0
}

名称 描述
state 0代表成功,否则代表失败
id 订单号
pair 合约符号
order_side 挂单方向:1开多,2开空
contract 委托合约张数
status 0,1未成交 2部分成交 3完全成交 4部分取消 5完全取消 6,7 系统取消, >=100 下单失败
price 委托价格
price_deal 成交均价
contract_deal 已成交合约张数
其它字段 忽略

19.查询仓位变化记录

Request

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

let url = "https://api.bibox.com/v3.1/cquery/query/orderList";

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

let param = {
    "pair":"4BTC_USDT",
    "page":1,
    "size":100,
    "begin_time":1550971541000,
    "end_time":1550977541000,
    "type": 2,
};

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/query/orderList

参数名称 是否必须 类型 描述 默认值 取值范围
pair true String 合约符号 4BTC_USDT,4ETH_USDT,...
page true integer 第几页 1,2,...
size true integer 多少条 1,2,...
begin_time false integer 开始时间
end_time false integer 结束时间
type false integer 成交类型 1开仓, 2平仓, 3爆仓, 4减仓

Response

{
    "result":{
        "count":101,
        "page":1,
        "items":[
            {
                "id":236343,
                "coin_symbol":"USDT", 
                "pair":"4BTC_USDT", // 合约符号
                "type":2, // 1开仓, 2平仓, 3爆仓, 4减仓
                "order_side":2, // 1开多,2开空
                "price_open":"3999.0000", // 委托价格
                "price":"3964.5800", // 开仓均价
                "price_deal":"3999.0000", // 成交价格
                "contract":2, // 合约张数
                "profit":"0.6884", // 盈亏
                "fee":"0.0000", // 手续费
                "createdAt":"2019-02-23T17:07:31.000Z"
            },
            ...
        ]
    },
    "state":0
}

名称 描述
state 0代表成功,否则代表失败
pair 合约符号
type 1开仓, 2平仓, 3爆仓, 4减仓
order_side 1开多,2开空
price_open 委托价格
price 开仓均价
price_deal 成交价格
contract 合约张数
profit 盈亏
fee 手续费
其它字段 忽略

20.查询订单详情

Request

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

let url = "https://api.bibox.com/v3.1/cquery/query/orderDetailByID";

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

let param = {
    "id":"58", // 订单号
};

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)

    });

GET https://api.bibox.com/v3.1/cquery/query/orderDetailByID

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

Response

{
    "result":{
        "items":[
            {
                 "id":42,                  // 成交记录ID
                "coin_symbol":"USDT",      //计价单位
                "pair":"4BTC_USDT",        // 合约符号
                "order_side":1,            // 1 买,看涨; 2 卖,看空;
                "contract":1,              // 合约张数
                "order_from":1,            // 1网页,2安卓,3ios, 6 apikey,
                "createdAt":"2019-08-13T08:22:25.000Z", // 创建时间
                "updatedAt":"2019-08-13T08:22:26.000Z", 
                "price":"7029.9700",       // 价格
                "price_deal":"0.0000",     // 成交价
                "fee":"0.0000",            // 手续费
                "is_cancel":1,             // 0 正常单; 1: 已撤销
                "is_maker":1,              // 0: taker; 1: maker; 
                "order_type":2             // 1 市价单; 2 限价单
            }
        ],
        "count":9,
        "page":1
    },
    "state":0
}

名称 描述
state 0代表成功,否则代表失败
id 成交记录ID
coin_symbol 计价单位
pair 合约符号
order_side 1 买,看涨; 2 卖,看空;
contract 合约张数
order_from 1网页,2安卓,3ios, 6 apikey,
createdAt 创建时间
price 价格
price_deal 成交价
fee 手续费
is_cancel 0 正常单; 1: 已撤销
is_maker 0: taker; 1: maker;
order_type 1 市价单; 2 限价单
其它字段 忽略

21.查询合约面值

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

Response

{
    "result":[
        {
            "pair":"4BTC_USDT",  
            "value":"0.0100000000", 
            "coin_symbol":"BTC"
        },
       ...
    ],
    "state":0
}

名称 描述
state 0代表成功,否则代表失败
pair 交易对
value 合约面值
其它字段 忽略

22.查询合约杠杆信息

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

Response

{
    "result":{
        "cross_leverage":25,   // 全仓默认杠杆数
        "leverage_max":50,    // 最大杠杆数
        "margin_rate_force":"0.01", // 爆仓率
        "night_fee_rate":"0.0006",  // 隔夜费
        "hold_limit":{           // 最大持仓数量
            "BTC":5000,
            "ETH":150000,
            "EOS":50000,
            "LTC":35000,
            "BCH":100000
        }
    },
    "state":0
}

名称 描述
state 0代表成功,否则代表失败
cross_leverage 全仓默认杠杆数
leverage_max 最大杠杆数
margin_rate_force 爆仓率
night_fee_rate 隔夜费
hold_limit 最大持仓数量
其它字段 忽略

23.查询合约单笔下单限制

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

Response

{
    "result":{
        "BTC":5000,
        "ETH":75000,
        "EOS":75000,
        "LTC":15000,
        "BCH":15000
    },
    "state":0
}

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

24.查询当期资金费率

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

Response

{
    "result":{
        "4BTC_USDT":{
            "id":164391,
            "pair":"4BTC_USDT", 
            "close":"0.0007000000",
            "fund_rate_up":"0.0005000000", 
            "fund_rate_down":"-0.0005000000",
            "createdAt":"2020-02-27T00:00:00.000Z",
            "updatedAt":"2020-02-27T00:00:00.000Z"
        },
        ...
    },
    "state":0
}

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

25.查询k线

参数名称 是否必须 类型 描述 默认值 取值范围
pair true string 交易对 4BTC_USDT, 4ETH_USDT, ...
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 成交量
其它字段 忽略

26.查询市场深度

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

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

Response

{
    "result":{
        "pair":"4BTC_USDT",
        "update_time":1602669350668,
        "asks":[//卖方深度

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

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

27.订阅 Kline 数据

完整例子


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

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

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_4BTC_USDT_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

参数名称 是否必须 类型 描述 默认值 取值范围
pair true string 交易对 4BTC_USDT, 4ETH_USDT, ...
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_4BTC_USDT_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代表数据压缩了
其它字段 忽略

28.订阅Market数据

完整例子


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

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

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_ALL_ALL_market',
                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

参数名称 是否必须 类型 描述 默认值 取值范围
event true string 行为 'addChannel'
channel true string 'bibox_sub_spot_ALL_ALL_market'
binary true int 0

Response

{
    "id":36,
    "is_hide":0,
    "pair_type":0,
    "area_id":15,
    "coin_symbol":"4BTC",
    "currency_symbol":"USDT",
    "last":"13669.5900",
    "high":"13860.2500",
    "low":"13626.4000",
    "change":"-90.6300",
    "percent":"-0.65%",
    "vol24H":"21492",
    "amount":"295494126.56",
    "last_cny":"90971.0974",
    "base_last_cny":"90971.09739152",
    "high_cny":"92239.9394",
    "low_cny":"90683.6680",
    "last_usd":"13669.5900",
    "high_usd":"13860.2500",
    "low_usd":"13626.4000",
    "time":0
}

名称 描述
id 交易对id
coin_symbol 交易币种 如:4BTC、4ETH...
currency_symbol 定价币种
last 24h最新价
high 24h最高价
low 24h最低价
change 24h涨跌
percent 24h涨跌幅
vol24H 24h成交量(张数)
amount 24h成交额(USDT)
last_cny 最新价折算cny
high_cny 最高价折算cny
low_cny 最低价折算cny
last_usd 最新价折算usd
high_usd 最高价折算usd
low_usd 最低价折算usd
binary 0代表数据没有压缩,1代表数据压缩了
其它字段 忽略

29.订阅深度

完整例子


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

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

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_4BTC_USDT_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

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

Response

{
    "pair":"4BTC_USDT",
    "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代表数据压缩了
其它字段 忽略

30.订阅成交记录

完整例子


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

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

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_4BTC_USDT_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

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

Response

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

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

31.订阅最新成交价

完整例子


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

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

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_4BTC_USDT_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

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

Response

[
    {
        "channel":"bibox_sub_spot_4BTC_USDT_ticker",
        "binary":0,
        "data_type":1,
        "data":{
            "pair":"4BTC_USDT",
            "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代表数据压缩了
其它字段 忽略

32.订阅用户数据方法

实际例子


'use strict'

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

const biboxws = 'wss://push.bibox.me'; // 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

参数名称 是否必须 类型 描述 默认值 取值范围
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 "订阅成功" 代表订阅成功
其它字段 忽略

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

contract_assets

Response

[
    {
        "channel":"bibox_sub_spot_ALL_ALL_login",
        "binary":"0",
        "data_type":1,
        "data":{
            "contract_assets":{
                "user_id":10101010,
                "coin_symbol":"USDT",
                "balance":"99.1823", // 可用余额
                "freeze":"0.7899", // 冻结金额
                "profit":"-3.6816",
                "margin":"0.7899", // 冻结保证金
                "imargin":"0.0000" // 挂单冻结资金
            }
        }
    }
]

名称 描述
balance 可用余额
freeze 冻结金额
margin 冻结保证金
imargin 挂单冻结资金
其它字段 忽略

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

contract_order

Response

[
    {
        "channel":"bibox_sub_spot_ALL_ALL_login",
        "binary":"0",
        "data_type":1,
        "data":{
            "contract_order":{
                "user_id":10101010,
                "coin_symbol":"USDT",
                "pair":"4BTC_USDT", // 合约符号
                "order_side":2, // 持仓方向,1开多,2开空
                "price":"3949.7850", // 开仓均价
                "price_up":"4009.0200", // 挂单开多均价
                "price_down":"3946.0300", // 挂单开空均价
                "fee_rate":"0.0000",
                "contract":2, // 持仓张数
                "margin":"1.5799", // 保证金
                "imargin":"0.0000", // 挂单占用资金
                "icontract_up":1, // 委托开多未成交张数
                "icontract_down":0, // 委托开空未成交张数
                "leverage":"50", // 杠杆倍数,0代表全仓
                "price_force":"4009.0318", // 爆仓价格
                "price_alert":"3989.2829", // 爆仓告警价格
                "profit":"-3.5492" 
            }
        }
    }
]

名称 描述
pair 合约符号
order_side 持仓方向,1开多,2开空
price 开仓均价
price_up 挂单开多均价
price_down 挂单开空均价
contract 持仓张数
margin 保证金
imargin 挂单占用资金
icontract_up 委托开多未成交张数
icontract_down 委托开空未成交张数
leverage 杠杆倍数,0代表全仓
price_force 爆仓价格
price_alert 爆仓告警价格
其它字段 忽略

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

contract_pending

Response

[
    {
        "channel":"bibox_sub_spot_ALL_ALL_login",
        "binary":"0",
        "data_type":1,
        "data":{
            "contract_pending":{
                "id":"628754", // 委托订单号
                "user_id":10101010,
                "client_oid": "1589868279533",
                "coin_symbol":"USDT",
                "pair":"4BTC_USDT", // 合约符号
                "order_side":1, // 1开多,2开空
                "order_type":1,
                "price":"4009.0200", // 挂单价格
                "contract":1, // 挂单张数
                "order_from":1,
                "status":3, // 0,1未成交 2部分成交  3完全成交 4部分取消 5完全取消 6,7 系统取消, >=100 下单失败
                "price_deal":"3952.5600", // 成交均价
                "contract_deal":1, // 已成交张数
                "deal_count":1,
                "createdAt":1550671734000, // 下单时间
                "updatedAt":1550671734000
            }
        }
    }
]

名称 描述
id 委托订单号
pair 合约符号
order_side 1开多,2开空
price 挂单价格
contract 挂单张数
status 0,1未成交 2部分成交 3完全成交 4部分取消 5完全取消 6,7 系统取消, >=100 下单失败
price_deal 成交均价
contract_deal 已成交张数
createdAt 下单时间
其它字段 忽略

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

contract_detail

Response

[
    {
        "channel":"bibox_sub_spot_ALL_ALL_login",
        "binary":"0",
        "data_type":1,
        "data":{
            "contract_detail":{
                "order_id":"628754", // 委托订单号
                "user_id":10101010,
                "coin_symbol":"USDT",
                "pair":"4BTC_USDT", // 合约符号
                "order_side":1, // 1开多,2开空
                "order_type":1, // 1市价,2限价
                "order_from":1,
                "contract":1, // 成交张数
                "price":"4009.0200", // 开仓价
                "price_deal":"3952.5600", // 成交价
                "fee":"0.0000", // 手续费
                "is_maker":0, // 是否是maker
                "is_cancel":0, // 是否是撤销单
                "is_persist":0,
                "force_sub":0,
                "createdAt":1550671735000, // 生成时间
                "updatedAt":1550671735000
            }
        }
    }
]

名称 描述
order_id 委托订单号
pair 合约符号
order_side 1开多,2开空
order_type 1市价,2限价
contract 成交张数
price 开仓价
price_deal 成交价
fee 手续费
is_maker 是否是maker
is_cancel 是否是撤销单
createdAt 生成时间
其它字段 忽略

37.订阅用户数据解析持仓变化信息

contract_deal_log

Response

{
    "channel":"bibox_sub_spot_ALL_ALL_login",
    "binary":"0",
    "data_type":1,
    "data":{
        "contract_deal_log":{
            "id":"1125899906842966183", 
            "user_id":10040000,
            "type":"1", // 1开仓,2平仓,3爆仓,4减仓
            "pair":"4ETH_USDT",
            "coin_symbol":"USDT",
            "price_open":"182.2091272149", // 开仓均价
            "price":"181.1900", // 挂单价格
            "price_deal":"181.1900", // 成交价格
            "contract":"1", // 成交张数,可能为负
            "profit":"0", // 收益
            "fee":"0.0011", // 手续费
            "order_side":1, // 方向
            "createdAt":1572855008209,
            "updatedAt":1572855008209
        }
    }
}

名称 描述
type 1开仓,2平仓,3爆仓,4减仓
price_open 开仓均价
price 挂单价格
price_deal 成交价格
contract 成交张数,可能为负
profit 收益
fee 手续费
order_side 方向,1开多,2开空
其它字段 忽略

38.订阅指数

完整例子


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

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

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_ALL_ALL_indexMarket',
                binary: 1,
            }));
        }
    });

    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

参数名称 是否必须 类型 描述 默认值 取值范围
event true string 行为 'addChannel'
channel true string 'bibox_sub_spot_ALL_ALL_indexMarket'
binary true int 1

Response

[
    {
        "id":146,
        "is_hide":0,
        "pair_type":0,
        "area_id":15,
        "coin_symbol":"BTC",
        "currency_symbol":"USDT",
        "last":"3955.1652",
        "high":"3993.1069",
        "low":"3880.6072",
        "change":"+6.1701",
        "percent":"+0.16%",
        "vol24H":"43109",
        "amount":"169654088.16",
        "last_cny":"26588.2733",
        "base_last_cny":"",
        "high_cny":"26843.3333",
        "low_cny":"26087.0635",
        "last_usd":"3955.1651",
        "high_usd":"3993.1068",
        "low_usd":"3880.6072"
    },
    ...
]

名称 描述
coin_symbol 币种
currency_symbol 计价货币
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代表数据压缩了
其它字段 忽略

39.订阅下单价格限制

完整例子


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

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

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_ALL_ALL_contractPriceLimit',
                binary: 1,
            }));
        }
    });

    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

参数名称 是否必须 类型 描述 默认值 取值范围
event true string 行为 'addChannel'
channel true string 'bibox_sub_spot_ALL_ALL_contractPriceLimit'
binary true int 1

Response

{
    "4BTC_USDT":{
        "min_up":"2964.4562",
        "max_up":"4090.9496",
        "min_down":"3814.2670",
        "max_down":"4940.7603",
        "market_up":"4090.9496",
        "market_down":"3814.2670"
    },
    "4ETH_USDT":{
        "min_up":"110.3038",
        "max_up":"155.1606",
        "min_down":"138.9828",
        "max_down":"183.8396",
        "market_up":"155.1606",
        "market_down":"138.9828"
    }
}

名称 描述
min_up 开多最小价格
max_up 开多最大价格
min_down 开空最小价格
max_down 开空最大价格
market_up 市价开多最大价格
market_down 市价开空最小价格
binary 0代表数据没有压缩,1代表数据压缩了
其它字段 忽略

40.资金转出

Request

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

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

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

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.1/ctrade/transfer/out";

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.1/ctrade/transfer/out

参数名称 是否必须 类型 描述 默认值 取值范围
amount true integer USDT金额

Response

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

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

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