URL: https://api.bqi.com/api/public/ticker
Parameter: group, Required, Value 0, 20, 100, 500
Notes:
group: 0=all, 20=bqi20
curl "https://api.bqi.com/api/public/ticker?group=0"
response:
{
"Group": 0,
"Data": {
"Last": 101.61, //last index
"High24H": 102.87, //24hour high index, Rolling granularity 5 minutes
"Low24H": 100.68, //24hour low index, Rolling granularity 5 minutes
"Change24H": -0.49, //24hour change index, Rolling granularity 5 minutes
"ChangeRate24H": -0.48, //24hour change rate, Rolling granularity 5 minutes
"Time": 1577322393 //timestamp (seconds)
},
"Code": 200, //200 on success
"Message": "" //error cause
}
URL: https://api.bqi.com/api/public/tickers
curl "https://api.bqi.com/api/public/tickers"
response:
{
"Data": [{
"Group": 0, //index group
"Last": 101.57, //last index
"High24H": 102.87, //24hour high index, Rolling granularity 5 minutes
"Low24H": 100.68, //24hour low index, Rolling granularity 5 minutes
"Change24H": -0.57, //24hour change index, Rolling granularity 5 minutes
"ChangeRate24H": -0.55, //24hour change rate, Rolling granularity 5 minutes
"Time": 1577322994 //timestamp (seconds)
}, {
"Group": 20,
"Last": 101.21,
"High24H": 102.4,
"Low24H": 100.36,
"Change24H": -0.47,
"ChangeRate24H": -0.46,
"Time": 1577322994
}, {
"Group": 100,
"Last": 78.46,
"High24H": 126.04,
"Low24H": 77.54,
"Change24H": -23.68,
"ChangeRate24H": -23.18,
"Time": 1577322994
}, {
"Group": 500,
"Last": 104.1,
"High24H": 104.82,
"Low24H": 101.45,
"Change24H": 2.3,
"ChangeRate24H": 2.26,
"Time": 1577322994
}],
"Code": 200, //200 on success
"Message": "" //error cause
}
URL: https://api.bqi.com/api/public/kline
Parameter: group, Required, Value 0, 20, 100, 500
Parameter: granularity, Required, Value 60, 180, 300, 900, 1800, 3600, 7200, 14400, 21600, 43200, 86400, 604800
Parameter: begin, Optional, BeginTime(Timestamp seconds)
Parameter: end, Optional, EndTime(Timestamp seconds)
Parameter: size, Optional, Result size(Max 2000)
Notes:
group: 0=all, 20=bqi20
granularity: 1Minute, 3Minute, 5Minute, 15Minute, 30Minute, 1Hour, 2Hour, 4Hour, 6Hour, 12Hour, 1Day, 1Week
curl "https://api.bqi.com/api/public/kline?group=0&granularity=60"
response:
{
"Group": 0,
"Granularity": 60,
"Data": [
// Format [timestamp (seconds), open, high, low, close]
[1577202900, 102.78, 102.79, 102.78, 102.79],
[1577202960, 102.77, 102.77, 102.7, 102.7],
[1577323680, 101.6, 101.6, 101.6, 101.6]
],
"Code": 200, //200 on success
"Message": "" //error cause
}
URL: https://api.bqi.com/api/public/members
Parameter: group, Required, Value 0, 20, 100, 500
Parameter: lang, Optional, Value en-us, zh-cn
Parameter: size, Optional, Result size
Notes:
group: 0=all, 20=bqi20
Sort results by market cap
curl "https://api.bqi.com/api/public/members?group=0"
response:
{
"Group": 0,
"Data": [{
"CoinCode": "bitcoin", //coin code
"CoinName": "Bitcoin", //coin name
"CoinSymbol": "BTC", //coin symbol
"NativeName": "Bitcoin", //coin native name
"MaxSupply": 21000000, //max supply
"TotalSupply": 17901187, //current total supply
"CirculatingSupply": 17901187, //circulating supply
"MarketCap": 128903549134, //market cap
"Volume": 6449145269.4336, //volume
"LastPrice": 7200.838086, //last price
"HighPrice24H": 7269.954023, //24hour high price
"LowPrice24H": 7142.958062, //24hour low price
"ChangePrice24H": -36.675691, //24hour change price
"ChangePriceRate24H": -0.51, //24hour change rate
"Time": 1577324733 //timestamp (seconds)
}, {
"CoinCode": "ethereum",
"CoinName": "Ethereum",
"CoinSymbol": "ETH",
"NativeName": "Ethereum",
"MaxSupply": 107100935,
"TotalSupply": 107100935,
"CirculatingSupply": 107100935,
"MarketCap": 13385208818,
"Volume": 2313965685.4661,
"LastPrice": 124.977516,
"HighPrice24H": 126.500768,
"LowPrice24H": 123.988757,
"ChangePrice24H": -1.283036,
"ChangePriceRate24H": -1.02,
"Time": 1577324733
}],
"Code": 200,
"Message": ""
}
WebSocket Server URL:
wss://api.bqi.com/ws/public
Notes:
Sending and receiving data requires gzip library
gzip library: https://github.com/imaya/zlib.js.git
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>WebSocket Demo</title>
</head>
<body>
<script src="gzip.min.js"></script>
<script src="gunzip.min.js"></script>
<script>
var WebSocketAPI = function (onopen) {
var obj = {};
var sock = null;
var dispose_func = null;
var timer = null;
var kline_queue = new Array();
var ticker_queue = new Array();
var cointicker_queue = new Array();
obj.onkline = function (data) { };
obj.onticker = function (data) { };
obj.oncointicker = function (data) { };
var gzip_compress = function (data) {
var plain = new TextEncoder().encode(data);
var gzip = new Zlib.Gzip(plain);
var compressed = gzip.compress();
return compressed;
};
var gzip_decompress = function (data) {
var gunzip = new Zlib.Gunzip(data);
var plain = gunzip.decompress();
return new TextDecoder().decode(plain);
};
var init = function () {
var isclose = false;
sock = new WebSocket('wss://api.bqi.com/ws/public');
sock.onopen = function () {
sock.onmessage = function (ev) {
ev.data.arrayBuffer().then(function (buffer) {
if (null === sock) {
return;
}
try {
var data = gzip_decompress(new Uint8Array(buffer));
data = JSON.parse(data);
if (data.Type === "response") {
if (data.Action === 'ticker') {
var item = ticker_queue.shift();
item.Callback(null, data);
}
else if (data.Action === 'kline') {
var item = kline_queue.shift();
item.Callback(null, data);
}
else if (data.Action === 'coin-ticker') {
var item = cointicker_queue.shift();
item.Callback(null, data);
}
}
else if (data.Type === "event") {
if (data.Action === 'ticker') {
obj.onticker(data);
}
else if (data.Action === 'kline') {
obj.onkline(data);
}
else if (data.Action === 'coin-ticker') {
obj.oncointicker(data);
}
}
}
catch (e) {
sock.close();
}
});
};
var clear = function (ev) {
while (kline_queue.length > 0) {
var item = kline_queue.shift();
item.Callback(new Error("code: " + ev.code + ", reason: " + ev.reason), null);
}
while (ticker_queue.length > 0) {
var item = ticker_queue.shift();
item.Callback(new Error("code: " + ev.code + ", reason: " + ev.reason), null);
}
while (cointicker_queue.length > 0) {
var item = cointicker_queue.shift();
item.Callback(new Error("code: " + ev.code + ", reason: " + ev.reason), null);
}
sock = null;
};
sock.onclose = function (ev) {
if (false == isclose) {
isclose = true;
clear(ev);
if (null === dispose_func) {
if (null !== timer) clearTimeout(timer);
timer = setTimeout(init, 1000);
}
else {
dispose_func();
}
}
};
sock.onerror = function (ev) {
if (false == isclose) {
isclose = true;
clear(ev);
if (null === dispose_func) {
if (null !== timer) clearTimeout(timer);
timer = setTimeout(init, 1000);
}
else {
dispose_func();
}
}
};
onopen();
};
};
// Index Ticker
// group = 0, 20, 100, 500
// enable = true | false
// func = (err,data) =>{}
obj.ticker = function (group, enable, func) {
ticker_queue.push({
Action: 'ticker', Group: group, Enable: enable,
Callback: func
});
sock.send(gzip_compress(JSON.stringify({
Action: 'ticker', Group: group, Enable: enable
})));
};
// Index Kline
// group = 0, 20, 100, 500
// granularity = 60, 180, 300, 900, 1800, 3600, 7200, 14400, 21600, 43200, 86400, 604800
// enable = true | false
// func = (err,data) =>{}
obj.kline = function (group, granularity, enable, func) {
kline_queue.push({
Action: 'kline', Group: group, Granularity: granularity, Enable: enable,
Callback: func
});
sock.send(gzip_compress(JSON.stringify({
Action: 'kline', Group: group, Granularity: granularity, Enable: enable
})));
};
// Coin Ticker
// coincode = bitcoin,....
// enable = true | false
// func = (err,data) =>{}
obj.cointicker = function (coincode, enable, func) {
cointicker_queue.push({
Action: 'coin-ticker', CoinCode: coincode, Enable: enable,
Callback: func
});
sock.send(gzip_compress(JSON.stringify({
Action: 'coin-ticker', CoinCode: coincode, Enable: enable
})));
};
// dispose
// func = () =>{}
obj.dispose = function (func) {
if (null !== sock) {
if (WebSocket.CONNECTING === sock.readyState) {
sock.close();
sock = null;
func();
}
else {
dispose_func = func;
sock.close();
}
}
else if (null !== timer) {
clearTimeout(timer);
timer = null;
func();
}
else {
func();
}
};
init();
return obj;
};
</script>
<script>
// example
// disconnection will automatically reconnect
var api = new WebSocketAPI(function () {
// Receive event
api.onticker = function (data) {
console.log(data);
};
api.onkline = function (data) {
console.log(data);
};
api.oncointicker = function (data) {
console.log(data);
};
// API
api.ticker(20, true, function (err, data) {
console.log(data);
});
api.ticker(100, true, function (err, data) {
console.log(data);
});
api.kline(20, 300, true, function (err, data) {
console.log(data);
});
api.kline(20, 900, true, function (err, data) {
console.log(data);
});
api.cointicker('bitcoin', true, function (err, data) {
console.log(data);
});
api.cointicker('ethereum', true, function (err, data) {
console.log(data);
});
api.cointicker('eos', true, function (err, data) {
console.log(data);
});
api.cointicker('eos', false, function (err, data) {
console.log(data);
});
//dispose
/*api.dispose(function () {
console.log("close");
});*/
});
</script>
</body>
</html>