Index Ticker

URL: https://api.bqi.com/api/public/ticker
Parameter: group, Required, Value 0, 20, 100, 500

Notes:
group: 0=all, 20=bqi20

  1. curl "https://api.bqi.com/api/public/ticker?group=0"
  2. response:
  3. {
  4. "Group": 0,
  5. "Data": {
  6. "Last": 101.61, //last index
  7. "High24H": 102.87, //24hour high index, Rolling granularity 5 minutes
  8. "Low24H": 100.68, //24hour low index, Rolling granularity 5 minutes
  9. "Change24H": -0.49, //24hour change index, Rolling granularity 5 minutes
  10. "ChangeRate24H": -0.48, //24hour change rate, Rolling granularity 5 minutes
  11. "Time": 1577322393 //timestamp (seconds)
  12. },
  13. "Code": 200, //200 on success
  14. "Message": "" //error cause
  15. }

Index Tickers

URL: https://api.bqi.com/api/public/tickers

  1. curl "https://api.bqi.com/api/public/tickers"
  2. response:
  3. {
  4. "Data": [{
  5. "Group": 0, //index group
  6. "Last": 101.57, //last index
  7. "High24H": 102.87, //24hour high index, Rolling granularity 5 minutes
  8. "Low24H": 100.68, //24hour low index, Rolling granularity 5 minutes
  9. "Change24H": -0.57, //24hour change index, Rolling granularity 5 minutes
  10. "ChangeRate24H": -0.55, //24hour change rate, Rolling granularity 5 minutes
  11. "Time": 1577322994 //timestamp (seconds)
  12. }, {
  13. "Group": 20,
  14. "Last": 101.21,
  15. "High24H": 102.4,
  16. "Low24H": 100.36,
  17. "Change24H": -0.47,
  18. "ChangeRate24H": -0.46,
  19. "Time": 1577322994
  20. }, {
  21. "Group": 100,
  22. "Last": 78.46,
  23. "High24H": 126.04,
  24. "Low24H": 77.54,
  25. "Change24H": -23.68,
  26. "ChangeRate24H": -23.18,
  27. "Time": 1577322994
  28. }, {
  29. "Group": 500,
  30. "Last": 104.1,
  31. "High24H": 104.82,
  32. "Low24H": 101.45,
  33. "Change24H": 2.3,
  34. "ChangeRate24H": 2.26,
  35. "Time": 1577322994
  36. }],
  37. "Code": 200, //200 on success
  38. "Message": "" //error cause
  39. }

Index Kline

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

  1. curl "https://api.bqi.com/api/public/kline?group=0&granularity=60"
  2. response:
  3. {
  4. "Group": 0,
  5. "Granularity": 60,
  6. "Data": [
  7. // Format [timestamp (seconds), open, high, low, close]
  8. [1577202900, 102.78, 102.79, 102.78, 102.79],
  9. [1577202960, 102.77, 102.77, 102.7, 102.7],
  10. [1577323680, 101.6, 101.6, 101.6, 101.6]
  11. ],
  12. "Code": 200, //200 on success
  13. "Message": "" //error cause
  14. }

Index Group Members

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

  1. curl "https://api.bqi.com/api/public/members?group=0"
  2. response:
  3. {
  4. "Group": 0,
  5. "Data": [{
  6. "CoinCode": "bitcoin", //coin code
  7. "CoinName": "Bitcoin", //coin name
  8. "CoinSymbol": "BTC", //coin symbol
  9. "NativeName": "Bitcoin", //coin native name
  10. "MaxSupply": 21000000, //max supply
  11. "TotalSupply": 17901187, //current total supply
  12. "CirculatingSupply": 17901187, //circulating supply
  13. "MarketCap": 128903549134, //market cap
  14. "Volume": 6449145269.4336, //volume
  15. "LastPrice": 7200.838086, //last price
  16. "HighPrice24H": 7269.954023, //24hour high price
  17. "LowPrice24H": 7142.958062, //24hour low price
  18. "ChangePrice24H": -36.675691, //24hour change price
  19. "ChangePriceRate24H": -0.51, //24hour change rate
  20. "Time": 1577324733 //timestamp (seconds)
  21. }, {
  22. "CoinCode": "ethereum",
  23. "CoinName": "Ethereum",
  24. "CoinSymbol": "ETH",
  25. "NativeName": "Ethereum",
  26. "MaxSupply": 107100935,
  27. "TotalSupply": 107100935,
  28. "CirculatingSupply": 107100935,
  29. "MarketCap": 13385208818,
  30. "Volume": 2313965685.4661,
  31. "LastPrice": 124.977516,
  32. "HighPrice24H": 126.500768,
  33. "LowPrice24H": 123.988757,
  34. "ChangePrice24H": -1.283036,
  35. "ChangePriceRate24H": -1.02,
  36. "Time": 1577324733
  37. }],
  38. "Code": 200,
  39. "Message": ""
  40. }

WebSocket API

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

  1. <!DOCTYPE html>
  2. <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>WebSocket Demo</title>
  6. </head>
  7. <body>
  8. <script src="gzip.min.js"></script>
  9. <script src="gunzip.min.js"></script>
  10. <script>
  11. var WebSocketAPI = function (onopen) {
  12. var obj = {};
  13. var sock = null;
  14. var dispose_func = null;
  15. var timer = null;
  16. var kline_queue = new Array();
  17. var ticker_queue = new Array();
  18. var cointicker_queue = new Array();
  19. obj.onkline = function (data) { };
  20. obj.onticker = function (data) { };
  21. obj.oncointicker = function (data) { };
  22. var gzip_compress = function (data) {
  23. var plain = new TextEncoder().encode(data);
  24. var gzip = new Zlib.Gzip(plain);
  25. var compressed = gzip.compress();
  26. return compressed;
  27. };
  28. var gzip_decompress = function (data) {
  29. var gunzip = new Zlib.Gunzip(data);
  30. var plain = gunzip.decompress();
  31. return new TextDecoder().decode(plain);
  32. };
  33. var init = function () {
  34. var isclose = false;
  35. sock = new WebSocket('wss://api.bqi.com/ws/public');
  36. sock.onopen = function () {
  37. sock.onmessage = function (ev) {
  38. ev.data.arrayBuffer().then(function (buffer) {
  39. if (null === sock) {
  40. return;
  41. }
  42. try {
  43. var data = gzip_decompress(new Uint8Array(buffer));
  44. data = JSON.parse(data);
  45. if (data.Type === "response") {
  46. if (data.Action === 'ticker') {
  47. var item = ticker_queue.shift();
  48. item.Callback(null, data);
  49. }
  50. else if (data.Action === 'kline') {
  51. var item = kline_queue.shift();
  52. item.Callback(null, data);
  53. }
  54. else if (data.Action === 'coin-ticker') {
  55. var item = cointicker_queue.shift();
  56. item.Callback(null, data);
  57. }
  58. }
  59. else if (data.Type === "event") {
  60. if (data.Action === 'ticker') {
  61. obj.onticker(data);
  62. }
  63. else if (data.Action === 'kline') {
  64. obj.onkline(data);
  65. }
  66. else if (data.Action === 'coin-ticker') {
  67. obj.oncointicker(data);
  68. }
  69. }
  70. }
  71. catch (e) {
  72. sock.close();
  73. }
  74. });
  75. };
  76. var clear = function (ev) {
  77. while (kline_queue.length > 0) {
  78. var item = kline_queue.shift();
  79. item.Callback(new Error("code: " + ev.code + ", reason: " + ev.reason), null);
  80. }
  81. while (ticker_queue.length > 0) {
  82. var item = ticker_queue.shift();
  83. item.Callback(new Error("code: " + ev.code + ", reason: " + ev.reason), null);
  84. }
  85. while (cointicker_queue.length > 0) {
  86. var item = cointicker_queue.shift();
  87. item.Callback(new Error("code: " + ev.code + ", reason: " + ev.reason), null);
  88. }
  89. sock = null;
  90. };
  91. sock.onclose = function (ev) {
  92. if (false == isclose) {
  93. isclose = true;
  94. clear(ev);
  95. if (null === dispose_func) {
  96. if (null !== timer) clearTimeout(timer);
  97. timer = setTimeout(init, 1000);
  98. }
  99. else {
  100. dispose_func();
  101. }
  102. }
  103. };
  104. sock.onerror = function (ev) {
  105. if (false == isclose) {
  106. isclose = true;
  107. clear(ev);
  108. if (null === dispose_func) {
  109. if (null !== timer) clearTimeout(timer);
  110. timer = setTimeout(init, 1000);
  111. }
  112. else {
  113. dispose_func();
  114. }
  115. }
  116. };
  117. onopen();
  118. };
  119. };
  120. // Index Ticker
  121. // group = 0, 20, 100, 500
  122. // enable = true | false
  123. // func = (err,data) =>{}
  124. obj.ticker = function (group, enable, func) {
  125. ticker_queue.push({
  126. Action: 'ticker', Group: group, Enable: enable,
  127. Callback: func
  128. });
  129. sock.send(gzip_compress(JSON.stringify({
  130. Action: 'ticker', Group: group, Enable: enable
  131. })));
  132. };
  133. // Index Kline
  134. // group = 0, 20, 100, 500
  135. // granularity = 60, 180, 300, 900, 1800, 3600, 7200, 14400, 21600, 43200, 86400, 604800
  136. // enable = true | false
  137. // func = (err,data) =>{}
  138. obj.kline = function (group, granularity, enable, func) {
  139. kline_queue.push({
  140. Action: 'kline', Group: group, Granularity: granularity, Enable: enable,
  141. Callback: func
  142. });
  143. sock.send(gzip_compress(JSON.stringify({
  144. Action: 'kline', Group: group, Granularity: granularity, Enable: enable
  145. })));
  146. };
  147. // Coin Ticker
  148. // coincode = bitcoin,....
  149. // enable = true | false
  150. // func = (err,data) =>{}
  151. obj.cointicker = function (coincode, enable, func) {
  152. cointicker_queue.push({
  153. Action: 'coin-ticker', CoinCode: coincode, Enable: enable,
  154. Callback: func
  155. });
  156. sock.send(gzip_compress(JSON.stringify({
  157. Action: 'coin-ticker', CoinCode: coincode, Enable: enable
  158. })));
  159. };
  160. // dispose
  161. // func = () =>{}
  162. obj.dispose = function (func) {
  163. if (null !== sock) {
  164. if (WebSocket.CONNECTING === sock.readyState) {
  165. sock.close();
  166. sock = null;
  167. func();
  168. }
  169. else {
  170. dispose_func = func;
  171. sock.close();
  172. }
  173. }
  174. else if (null !== timer) {
  175. clearTimeout(timer);
  176. timer = null;
  177. func();
  178. }
  179. else {
  180. func();
  181. }
  182. };
  183. init();
  184. return obj;
  185. };
  186. </script>
  187. <script>
  188. // example
  189. // disconnection will automatically reconnect
  190. var api = new WebSocketAPI(function () {
  191. // Receive event
  192. api.onticker = function (data) {
  193. console.log(data);
  194. };
  195. api.onkline = function (data) {
  196. console.log(data);
  197. };
  198. api.oncointicker = function (data) {
  199. console.log(data);
  200. };
  201. // API
  202. api.ticker(20, true, function (err, data) {
  203. console.log(data);
  204. });
  205. api.ticker(100, true, function (err, data) {
  206. console.log(data);
  207. });
  208. api.kline(20, 300, true, function (err, data) {
  209. console.log(data);
  210. });
  211. api.kline(20, 900, true, function (err, data) {
  212. console.log(data);
  213. });
  214. api.cointicker('bitcoin', true, function (err, data) {
  215. console.log(data);
  216. });
  217. api.cointicker('ethereum', true, function (err, data) {
  218. console.log(data);
  219. });
  220. api.cointicker('eos', true, function (err, data) {
  221. console.log(data);
  222. });
  223. api.cointicker('eos', false, function (err, data) {
  224. console.log(data);
  225. });
  226. //dispose
  227. /*api.dispose(function () {
  228. console.log("close");
  229. });*/
  230. });
  231. </script>
  232. </body>
  233. </html>