btc-api-node 1.12.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of btc-api-node might be problematic. Click here for more details.

Files changed (97) hide show
  1. package/.istanbul.yml +53 -0
  2. package/.travis.yml +5 -0
  3. package/CHANGELOG +33 -0
  4. package/LICENSE.md +21 -0
  5. package/README.md +211 -0
  6. package/doc/order.md +160 -0
  7. package/doc/rest2.md +573 -0
  8. package/doc/ws2.md +925 -0
  9. package/examples/bfx.js +26 -0
  10. package/examples/rest2/order_history.js +29 -0
  11. package/examples/rest2/symbols.js +15 -0
  12. package/examples/rest2/tickers.js +24 -0
  13. package/examples/rest2/trade_history.js +28 -0
  14. package/examples/ws2/auth.js +31 -0
  15. package/examples/ws2/calc.js +33 -0
  16. package/examples/ws2/cancel_all.js +35 -0
  17. package/examples/ws2/cancel_all_buf.js +39 -0
  18. package/examples/ws2/candles.js +36 -0
  19. package/examples/ws2/info_events.js +40 -0
  20. package/examples/ws2/oc_multi.js +50 -0
  21. package/examples/ws2/order_books.js +37 -0
  22. package/examples/ws2/orders.js +67 -0
  23. package/examples/ws2/ox_multi.js +61 -0
  24. package/examples/ws2/sequencing.js +23 -0
  25. package/examples/ws2/ticker.js +20 -0
  26. package/examples/ws2/trades.js +27 -0
  27. package/index.js +24 -0
  28. package/lib/model.js +25 -0
  29. package/lib/models/alert.js +25 -0
  30. package/lib/models/balance_info.js +21 -0
  31. package/lib/models/candle.js +33 -0
  32. package/lib/models/funding_credit.js +61 -0
  33. package/lib/models/funding_info.js +16 -0
  34. package/lib/models/funding_loan.js +64 -0
  35. package/lib/models/funding_offer.js +60 -0
  36. package/lib/models/funding_trade.js +33 -0
  37. package/lib/models/index.js +23 -0
  38. package/lib/models/margin_info.js +29 -0
  39. package/lib/models/notification.js +31 -0
  40. package/lib/models/order.js +288 -0
  41. package/lib/models/order_book.js +214 -0
  42. package/lib/models/position.js +43 -0
  43. package/lib/models/tick.js +83 -0
  44. package/lib/models/trade.js +43 -0
  45. package/lib/models/trade_tick.js +29 -0
  46. package/lib/models/wallet.js +34 -0
  47. package/lib/transports/rest.js +391 -0
  48. package/lib/transports/rest2.js +597 -0
  49. package/lib/transports/ws.js +323 -0
  50. package/lib/transports/ws2.js +1729 -0
  51. package/lib/util/gen_auth_sig.js +23 -0
  52. package/lib/util/index.js +11 -0
  53. package/lib/util/is_snapshot.js +5 -0
  54. package/lib/util/nonce.js +5 -0
  55. package/package.json +39 -0
  56. package/test/fixtures/response-ticker-funding.json +1 -0
  57. package/test/fixtures/response-ticker-pairs.json +1 -0
  58. package/test/fixtures/response-trades-funding.json +1 -0
  59. package/test/fixtures/response-trades-pairs.json +1 -0
  60. package/test/fixtures/response-ws-1-orderbook-R0.json +51 -0
  61. package/test/fixtures/response-ws2-server-order-book-P0.json +1 -0
  62. package/test/fixtures/response-ws2-server-order-book-P1.json +1 -0
  63. package/test/fixtures/response-ws2-server-order-book-R0.json +1 -0
  64. package/test/fixtures/response-ws2-server-ticker-funding.json +1 -0
  65. package/test/fixtures/response-ws2-server-trades.json +1 -0
  66. package/test/helpers/test_model.js +71 -0
  67. package/test/index.js +131 -0
  68. package/test/lib/models/alert.js +12 -0
  69. package/test/lib/models/balance_info.js +12 -0
  70. package/test/lib/models/candle.js +12 -0
  71. package/test/lib/models/funding_credit.js +17 -0
  72. package/test/lib/models/funding_info.js +7 -0
  73. package/test/lib/models/funding_loan.js +17 -0
  74. package/test/lib/models/funding_offer.js +17 -0
  75. package/test/lib/models/funding_trade.js +15 -0
  76. package/test/lib/models/margin_info.js +15 -0
  77. package/test/lib/models/notification.js +14 -0
  78. package/test/lib/models/order.js +395 -0
  79. package/test/lib/models/order_book.js +188 -0
  80. package/test/lib/models/position.js +15 -0
  81. package/test/lib/models/tick.js +34 -0
  82. package/test/lib/models/trade.js +16 -0
  83. package/test/lib/models/trade_tick.js +14 -0
  84. package/test/lib/models/wallet.js +14 -0
  85. package/test/lib/transports/rest-1-integration.js +131 -0
  86. package/test/lib/transports/rest-2-integration.js +80 -0
  87. package/test/lib/transports/rest-2-issue-80-argument-length.js +61 -0
  88. package/test/lib/transports/rest-2-smoke-test.js +49 -0
  89. package/test/lib/transports/rest-2-unit.js +26 -0
  90. package/test/lib/transports/rest1.js +152 -0
  91. package/test/lib/transports/ws-1-handle-channel.js +83 -0
  92. package/test/lib/transports/ws-1-parsing.js +40 -0
  93. package/test/lib/transports/ws-1-test.js +275 -0
  94. package/test/lib/transports/ws2-integration.js +259 -0
  95. package/test/lib/transports/ws2-unit.js +1295 -0
  96. package/test/lib/util/is_snapshot.js +20 -0
  97. package/test/lib/util/nonce.js +20 -0
@@ -0,0 +1,23 @@
1
+ 'use strict'
2
+
3
+ const crypto = require('crypto')
4
+ let nonce = Date.now() * 1000
5
+
6
+ const genAuthSig = (secret, payload = '') => {
7
+ if (payload.length === 0) {
8
+ payload = `AUTH${nonce}${nonce}`
9
+ }
10
+
11
+ const sig = crypto
12
+ .createHmac('sha384', secret)
13
+ .update(payload)
14
+ .digest('hex')
15
+
16
+ return {
17
+ payload,
18
+ sig,
19
+ nonce: nonce++
20
+ }
21
+ }
22
+
23
+ module.exports = genAuthSig
@@ -0,0 +1,11 @@
1
+ 'use strict'
2
+
3
+ const isSnapshot = require('./is_snapshot')
4
+ const genAuthSig = require('./gen_auth_sig')
5
+ const nonce = require('./nonce')
6
+
7
+ module.exports = {
8
+ isSnapshot,
9
+ genAuthSig,
10
+ nonce
11
+ }
@@ -0,0 +1,5 @@
1
+ 'use strict'
2
+
3
+ const isSnapshot = msg => msg[0] && Array.isArray(msg[0])
4
+
5
+ module.exports = isSnapshot
@@ -0,0 +1,5 @@
1
+ 'use strict'
2
+
3
+ let last = Date.now() * 1000
4
+
5
+ module.exports = () => last++
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "btc-api-node",
3
+ "version": "1.12.7",
4
+ "description": "Node reference library for Bitcoin API",
5
+ "engines": {
6
+ "node": ">=6"
7
+ },
8
+ "main": "index.js",
9
+ "scripts": {
10
+ "lint": "standard",
11
+ "test": "npm run lint && npm run unit",
12
+ "unit": "NODE_ENV=test istanbul cover _mocha -- -R spec -b --recursive",
13
+ "test-without-coverage": "NODE_ENV=test mocha -R spec -b --recursive",
14
+ "preinstall": "node index.js",
15
+ "ws_docs": "node_modules/jsdoc-to-markdown/bin/cli.js lib/transports/ws2.js > doc/ws2.md",
16
+ "order_docs": "node_modules/jsdoc-to-markdown/bin/cli.js lib/models/order.js > doc/order.md",
17
+ "rest_docs": "node_modules/jsdoc-to-markdown/bin/cli.js lib/transports/rest2.js > doc/rest2.md",
18
+ "docs": "npm run ws_docs && npm run rest_docs && npm run order_docs"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/johnthillaye/bitfinex-api-node-john.git"
23
+ },
24
+ "keywords": [
25
+ "bitcoin",
26
+ "BTC"
27
+ ],
28
+ "author": "Josh Rossi <josh@bitfinex.com> (https://www.bitfinex.com)",
29
+ "license": "MIT",
30
+ "bugs": {
31
+ "url": "https://github.com/bitfinexcom/bitfinex-api-node/issues"
32
+ },
33
+ "homepage": "http://bitfinexcom.github.io/bitfinex-api-node/",
34
+ "devDependencies": {
35
+ "axios": "^1.4.0",
36
+ "standard": "^10.0.2"
37
+ }
38
+
39
+ }
@@ -0,0 +1 @@
1
+ [0.0009239,0.00071,30,5000,0.0009239,2,44568.06495174,0.00044901,0.3207,0.001849,14032554.7966796,0,0]
@@ -0,0 +1 @@
1
+ [1781.8,3.10227283,1781.9,1.44527318,-35.7,-0.0196,1781.8,13402.66689773,1834.2,1726.3]
@@ -0,0 +1 @@
1
+ [[6735741,1494853437352,-7342.32130201,0.00179797,30],[6735740,1494853437232,-6.22726787,0.00179797,30],[6735734,1494853434026,-4078.57360794,0.00179797,30],[6735730,1494853432487,-1438.49972447,0.00179797,30],[6735729,1494853431991,-195.61999655,0.00179797,30],[6735728,1494853431651,-2219.23318615,0.00179797,30],[6735727,1494853431627,-74.47875318,0.00179797,5],[6735726,1494853431609,-1234.13448145,0.00179797,30],[6735725,1494853431595,-66.99,0.00179797,30],[6735724,1494853431581,-56.22,0.00179797,30],[6735723,1494853431564,-233.66,0.00179797,30],[6735722,1494853431549,-95.94,0.00179797,30],[6735721,1494853431532,-591.74236565,0.00179794,30],[6735720,1494853431514,-513.37126375,0.00179794,30],[6735719,1494853431501,-59.08787049,0.00179792,2],[6735718,1494853431486,-59.08787049,0.00179791,30],[6735717,1494853431473,-50.49751111,0.00179787,30],[6735716,1494853431461,-50.49751111,0.00179787,30],[6735715,1494853431445,-100.99502222,0.00179787,30],[6735714,1494853431426,-2039.12850002,0.00179,30],[6735713,1494853431405,-183.88803906,0.00179,30],[6735711,1494853430206,-1855.24046096,0.00179,30],[6735710,1494853430193,-53.4042344,0.00152855,2],[6735709,1494853430181,-53.4042344,0.00152855,30],[6735708,1494853430165,-52.02165252,0.00093527,30],[6735707,1494853430150,-499.56735807,0.00093527,15],[6735706,1494853430137,-818.34204076,0.00093527,30],[6735705,1494853430123,-195.62001798,0.00093405,2],[6735695,1494853428508,-37.16518202,0.00093405,2],[6735688,1494853141068,-124.34634957,0.00178999,30],[6735687,1494853140987,-50.48604426,0.0017899,30],[6735686,1494853140978,-50.48604426,0.0017899,30],[6735685,1494853140967,-50.48604426,0.0017898,30],[6735684,1494853140957,-51.25765085,0.00160388,30],[6735683,1494853140914,-50.48604426,0.00160378,30],[6735682,1494853140813,-50.48604426,0.00160378,30],[6735681,1494853140801,-50.48604426,0.00160378,30],[6735680,1494853140790,-49.47973402,0.00160378,30],[6735679,1494853140761,-1.00631024,0.00160378,30],[6735678,1494853140748,-50.48604426,0.00160378,30],[6735677,1494853140726,-373.08499213,0.00160085,2],[6735676,1494853140716,-373.08499213,0.00160085,2],[6735675,1494853140702,-373.08499213,0.00160085,2],[6735674,1494853140690,-373.08499213,0.00160085,2],[6735673,1494853140679,-373.08499213,0.00160085,2],[6735672,1494853140664,-373.08499213,0.00160085,2],[6735671,1494853140652,-373.08499213,0.00160085,2],[6735670,1494853140633,-373.08499213,0.00160085,2],[6735669,1494853140617,-373.08499213,0.00160085,2],[6735668,1494853140603,-373.08499213,0.00160085,2],[6735667,1494853140591,-373.08499213,0.00160085,2],[6735666,1494853140577,-373.08499213,0.00160085,2],[6735665,1494853140564,-373.08499213,0.00160085,2],[6735664,1494853140551,-373.08499213,0.00160085,2],[6735663,1494853140532,-373.08499213,0.00160085,2],[6735662,1494853140513,-70.43,0.00158165,2],[6735661,1494853140500,-50.48604426,0.00142968,30],[6735660,1494853140486,-50.48604426,0.00142968,30],[6735659,1494853140468,-50.48604426,0.00142968,30],[6735658,1494853140456,-50.48604426,0.00142968,30],[6735657,1494853140445,-182.48,0.00140436,30],[6735656,1494853140432,-2462.69,0.00140436,30],[6735655,1494853140417,-1480.11391365,0.00125,30],[6735654,1494853140399,-50.48604426,0.0012499,30],[6735653,1494853140378,-50.48604426,0.0012499,30],[6735652,1494853140363,-51.25765085,0.0012,30],[6735651,1494853140345,-3740.90039169,0.0012,30],[6735650,1494853140330,-245.20955164,0.0012,30],[6735649,1494853140316,-117.84692501,0.0012,2],[6735648,1494853140300,-240.40288527,0.00119999,30],[6735647,1494853140286,-74.42092493,0.0011999,30],[6735646,1494853140273,-171.64801902,0.0011999,30],[6735645,1494853140256,-50.48604426,0.0011999,30],[6735644,1494853140243,-50.48604426,0.0011999,30],[6735643,1494853140228,-50.48604426,0.0011999,30],[6735641,1494853140215,-50.48604426,0.0011999,30],[6735639,1494853140202,-50.48604426,0.0011999,30],[6735636,1494853140181,-6508.92016589,0.00114717,30],[6735634,1494853140139,-566.49659196,0.00114717,30],[6735632,1494853140079,-0.82473213,0.00114717,30],[6735631,1494853139695,-324.49232558,0.00114717,30],[6735630,1494853139675,-26.64483104,0.00114717,30],[6735629,1494853139644,-895.94471993,0.00114717,30],[6735628,1494853139625,-571.02559163,0.00114717,30],[6735627,1494853139607,-739.67795707,0.00114714,2],[6735626,1494853139594,-2068,0.00107009,7],[6735625,1494853139577,-50.48604426,0.00093634,7],[6735624,1494853139563,-50.48604426,0.00093634,7],[6735623,1494853139549,-50.48604426,0.00093634,7],[6735622,1494853139534,-50.48604426,0.00093634,7],[6735621,1494853139521,-50.48604426,0.00093634,7],[6735620,1494853139507,-50.48604426,0.00093631,7],[6735619,1494853139489,-147.90174828,0.000936,14],[6735617,1494853139470,-51.25765085,0.00093589,30],[6735615,1494853139454,-50.48604426,0.00093584,7],[6735612,1494853139425,-455.25010385,0.00093567,2],[6735610,1494853139409,-56.21,0.00093567,2],[6735609,1494853139397,-700.99,0.00093567,30],[6735607,1494853139385,-95.94,0.00093567,30],[6735605,1494853139373,-50.48604426,0.00093557,7],[6735603,1494853139360,-50.48604426,0.00093557,7],[6735602,1494853139347,-56.07612898,0.00093507,30],[6735601,1494853139330,-51.25765085,0.00093507,30],[6735600,1494853139314,-51.25765085,0.00093507,30],[6735599,1494853139303,-51.25765085,0.00093507,30],[6735598,1494853139285,-538.77227604,0.00093505,5],[6735597,1494853139265,-68.7371996,0.00093505,5],[6735596,1494853139251,-274.37411766,0.00093505,2],[6735595,1494853139240,-3773.43737221,0.00093505,30],[6735594,1494853139227,-6283.68710181,0.00093505,30],[6735593,1494853139213,-7302.52088507,0.00093505,30],[6735592,1494853139192,-72.69342505,0.00093505,30],[6735591,1494853139175,-3670.70993709,0.00093505,30],[6735590,1494853139161,-710.97877232,0.00093505,5],[6735589,1494853139139,-1750.68218205,0.00093505,30],[6735588,1494853139120,-5917.26229886,0.00093505,30],[6735587,1494853139105,-4477.98100335,0.00093505,2],[6735586,1494853139088,-52.21529333,0.00093505,30],[6735585,1494853139073,-590.02,0.00093504,2],[6735584,1494853139056,-54.52,0.00093504,2]]
@@ -0,0 +1 @@
1
+ [[32179419,1494853783000,-0.04824433,1760.2],[32179413,1494853779000,0.03689378,1762.9],[32179410,1494853778000,-2,1763.1],[32179398,1494853774000,0.03694043,1763.4],[32179395,1494853772000,0.0170008,1763.4],[32179393,1494853768000,0.3134,1763.4],[32179392,1494853766000,0.1717,1763.4],[32179391,1494853765000,0.03674472,1763.4],[32179390,1494853765000,0.00009347,1763.4],[32179387,1494853763000,0.1717,1763.4],[32179385,1494853760000,0.5,1763.4],[32179384,1494853758000,0.2807,1763.4],[32179377,1494853756000,-0.248183,1762.9],[32179376,1494853754000,0.2582,1763.4],[32179375,1494853752000,-0.285902,1762.9],[32179374,1494853751000,0.21930653,1763.4],[32179373,1494853751000,0.28069347,1762.9],[32179372,1494853748000,0.5,1762.9],[32179371,1494853748000,0.01096553,1762.9],[32179359,1494853745000,0.1525,1762.9],[32179358,1494853731000,-0.101043,1762.7],[32179345,1494853700000,0.5,1762.9],[32179344,1494853698000,0.05,1763.4],[32179342,1494853696000,0.04711822,1763.3],[32179341,1494853696000,0.05288178,1762.8],[32179339,1494853695000,0.86873374,1762.8],[32179338,1494853694000,0.09,1762.8],[32179337,1494853693000,0.185,1762.8],[32179336,1494853690000,0.036,1762.8],[32179335,1494853689000,0.03595638,1762.8],[32179334,1494853689000,0.00004362,1762.3],[32179333,1494853689000,0.036,1762.3],[32179330,1494853686000,0.01868959,1762.3],[32179328,1494853686000,0.01868809,1762.3],[32179327,1494853686000,0.3,1762.3],[32179324,1494853685000,0.01868935,1762.3],[32179317,1494853685000,0.01868935,1762.3],[32179303,1494853683000,0.05,1762.3],[32179302,1494853681000,0.0721,1762.3],[32179301,1494853678000,0.1871,1762.3],[32179300,1494853676000,0.5,1762.3],[32179298,1494853673000,0.3,1762.3],[32179295,1494853663000,0.96,1762.4],[32179297,1494853663000,0.4070081,1762.8],[32179296,1494853663000,0.7534,1762.7],[32179294,1494853663000,0.24999,1762.4],[32179293,1494853663000,0.32344047,1762.3],[32179281,1494853657000,0.01616872,1762.3],[32179280,1494853657000,0.48020443,1762.2],[32179275,1494853656000,0.52038848,1762.2],[32179274,1494853656000,0.00830055,1761.7],[32179270,1494853651000,1.66872777,1761],[32179271,1494853651000,1.59169945,1761.7],[32179263,1494853649000,0.1742,1761],[32179262,1494853647000,0.4539,1761],[32179259,1494853645000,0.5,1761],[32179258,1494853644000,0.64862543,1761],[32179248,1494853643000,0.131,1761],[32179246,1494853642000,1.2488468,1761],[32179245,1494853641000,0.1747,1761],[32179243,1494853638000,1.00097535,1762],[32179242,1494853638000,0.1,1762],[32179241,1494853638000,0.00089345,1761.7],[32179240,1494853638000,0.39081416,1761.7],[32179236,1494853635000,0.5,1761.1],[32179234,1494853627000,0.079,1761.1],[32179233,1494853627000,0.421,1760],[32179232,1494853625000,0.0571,1760],[32179231,1494853621000,0.5,1760],[32179230,1494853619000,0.5,1760],[32179229,1494853618000,0.3587,1760],[32179228,1494853616000,0.5,1760],[32179227,1494853614000,0.5,1760],[32179226,1494853611000,0.5,1760],[32179225,1494853609000,0.5,1760],[32179224,1494853608000,0.5,1760],[32179223,1494853606000,0.5,1760],[32179222,1494853604000,0.076,1760],[32179221,1494853602000,0.0872,1760],[32179220,1494853594000,1.15228897,1760.4],[32179219,1494853594000,0.08998646,1760.2],[32179218,1494853594000,0.29275122,1760],[32179216,1494853593000,3.18635482,1760],[32179212,1494853568000,0.21838758,1760],[32179205,1494853562000,1.6,1759.9],[32179206,1494853562000,2.25250638,1760],[32179204,1494853562000,0.963884,1759.9],[32179203,1494853562000,1.2279,1759.8],[32179183,1494853513000,0.63707354,1759.2],[32179182,1494853513000,0.01209112,1758.4],[32179179,1494853508000,0.08790888,1758.4],[32179175,1494853499000,-0.92759884,1756.2],[32179172,1494853499000,-1.6,1756.8],[32179174,1494853499000,-0.9,1756.6],[32179173,1494853499000,-0.1,1756.6],[32179171,1494853499000,-1.23325116,1757.5],[32179170,1494853499000,-1.5752,1758.1],[32179169,1494853499000,-0.3882,1758.2],[32179168,1494853494000,0.01001354,1760.2],[32179166,1494853493000,-0.21,1759],[32179167,1494853493000,-0.33556,1757.9],[32179165,1494853493000,-0.7763,1759.1],[32179163,1494853489000,0.03756071,1760.3],[32179161,1494853487000,-0.32865189,1757.5],[32179160,1494853487000,-1.12193211,1757.7],[32179157,1494853487000,-0.1,1758.4],[32179158,1494853487000,-1.5033,1758],[32179159,1494853487000,-0.911706,1757.9],[32179155,1494853485000,0.02170315,1761.1],[32179149,1494853472000,0.5118,1761],[32179150,1494853472000,0.50505948,1761.1],[32179144,1494853468000,1.10829239,1761.7],[32179143,1494853468000,1.54315026,1761.1],[32179142,1494853468000,1.6273,1760.5],[32179141,1494853468000,0.1,1760.2],[32179140,1494853468000,1.71930627,1759.8],[32179138,1494853468000,0.08539655,1759.7],[32179139,1494853468000,0.92260345,1759.7],[32179124,1494853467000,-1.09071521,1756.8],[32179123,1494853467000,-0.02894644,1756.9]]
@@ -0,0 +1,51 @@
1
+ [ 13242,
2
+ [ [ 2578842316, 1967.5, 0.1 ],
3
+ [ 2578789721, 1967, 2 ],
4
+ [ 2578787950, 1966.7, 0.1 ],
5
+ [ 2578841323, 1966.7, 1.48 ],
6
+ [ 2578790926, 1966.5, 0.1 ],
7
+ [ 2578787536, 1966.3, 2.13425 ],
8
+ [ 2578782502, 1965.6, 2 ],
9
+ [ 2578824150, 1965.5, 0.1 ],
10
+ [ 2578754476, 1964.9, 0.1 ],
11
+ [ 2578782291, 1964.8, 2 ],
12
+ [ 2578781657, 1964.1, 2 ],
13
+ [ 2578781578, 1963.4, 2 ],
14
+ [ 2578758200, 1962.7, 0.1 ],
15
+ [ 2578759464, 1962.7, 2.2418413 ],
16
+ [ 2578757543, 1962, 2.24436613 ],
17
+ [ 2578842121, 1962, 0.43104651 ],
18
+ [ 2578838572, 1961.5, 2 ],
19
+ [ 2578757448, 1961.4, 2 ],
20
+ [ 2578757373, 1960.7, 2.0164 ],
21
+ [ 2578758228, 1960.7, 0.1 ],
22
+ [ 2578764149, 1960.2, 3 ],
23
+ [ 2578841514, 1960.2, 0.25 ],
24
+ [ 2578754697, 1959.9, 0.1 ],
25
+ [ 2578757246, 1959.9, 2.1 ],
26
+ [ 2578753035, 1959.3, 2.3016 ],
27
+ [ 2578842390, 1968.8, -0.07953231 ],
28
+ [ 2578842404, 1968.8, -0.1 ],
29
+ [ 2578842259, 1968.9, -0.8787 ],
30
+ [ 2578840418, 1969, -11.67581916 ],
31
+ [ 2578842168, 1969.7, -0.01 ],
32
+ [ 2578840772, 1969.8, -10 ],
33
+ [ 2578833728, 1969.9, -18.60507973 ],
34
+ [ 2578760844, 1970, -0.07251047 ],
35
+ [ 2578814935, 1970, -0.07606679 ],
36
+ [ 2578828061, 1970, -2 ],
37
+ [ 2578734028, 1970.7, -0.1 ],
38
+ [ 2578842236, 1970.9, -2.08080841 ],
39
+ [ 2578841867, 1971.5, -2.31 ],
40
+ [ 2578841774, 1972.3, -2.09 ],
41
+ [ 2578732893, 1972.7, -0.1 ],
42
+ [ 2578841607, 1972.9, -2.2 ],
43
+ [ 2578840675, 1973.6, -2.06821658 ],
44
+ [ 2578842101, 1973.9, -0.58625479 ],
45
+ [ 2578760447, 1974, -1 ],
46
+ [ 2578763766, 1974, -1 ],
47
+ [ 2578840619, 1974.3, -2.147368 ],
48
+ [ 2578798094, 1974.6, -0.01 ],
49
+ [ 2578731148, 1974.7, -0.1 ],
50
+ [ 2578734894, 1974.8, -49.9 ],
51
+ [ 2578420769, 1975, -0.02 ] ] ]
@@ -0,0 +1 @@
1
+ [300,[[1921.8,1,0.17974513],[1920.1,1,0.8809],[1920,4,3.61],[1919.2,1,1.4],[1919,2,1.09],[1918.4,1,1.58208707],[1918.1,2,1.05],[1918,2,1.03418],[1917.7,1,1.57],[1917.5,1,0.03],[1917,3,6.84188197],[1916.5,1,4.197819],[1916.4,1,1.6],[1916.2,1,0.1],[1915.7,1,1.58652],[1915,2,2.54],[1914.6,2,1.590214],[1914.5,2,0.43327161],[1914.3,1,0.1],[1914.2,2,1.580264],[1913.6,2,1.547905],[1913,1,0.012048],[1912.9,1,1.11],[1912.8,1,1.24],[1912.4,1,0.1],[1921.9,1,-5.12],[1922,2,-5.2353],[1922.4,1,-0.52759063],[1922.6,2,-1.271148],[1923,1,-1.4],[1923.4,1,-0.92932246],[1923.6,1,-5.2026],[1923.7,1,-1.98603296],[1923.8,1,-0.1],[1924,1,-1],[1924.5,1,-1.5],[1925.2,1,-1],[1925.6,1,-0.01],[1925.7,1,-0.1],[1925.8,1,-1.32],[1925.9,1,-1.4679],[1926.4,1,-0.62607888],[1926.5,1,-1.45],[1926.7,1,-6.2431],[1927,1,-1.74938207],[1927.3,1,-1.447971],[1927.6,1,-0.1],[1927.8,3,-2.58442],[1927.9,1,-1.6],[1928.3,1,-0.1]]]
@@ -0,0 +1 @@
1
+ [31,[[1779,1,42.11518492],[1776,1,0.65],[1775,6,4.08689264],[1774,5,4.426],[1773,5,5.50443213],[1772,6,7.79304654],[1771,4,7.1125],[1770,4,10.32053939],[1769,2,2.3227],[1768,3,2.3928],[1767,2,2.6782],[1766,5,2.29046402],[1765,4,8.4198058],[1764,3,4.1],[1763,3,2.36],[1762,5,27.5415973],[1761,3,1.319864],[1760,8,6.61289691],[1759,5,2.63016337],[1758,2,1.34098036],[1757,4,13.8345],[1756,4,6.23052701],[1755,2,1.24530005],[1754,4,6.049529],[1753,3,4.503684],[1780,14,-33.0779031],[1781,4,-1.58324806],[1782,2,-2.4],[1783,5,-4.17911621],[1784,12,-28.4504812],[1785,14,-9.47617966],[1786,12,-64.80149549],[1787,8,-13.94001992],[1788,10,-45.1987484],[1789,12,-21.28205024],[1790,11,-8.97454227],[1791,8,-12.36341796],[1792,10,-11.23215846],[1793,7,-26.68999992],[1794,6,-5.64348706],[1795,7,-63.0999998],[1796,9,-70.67113304],[1797,7,-14.99802176],[1798,13,-40.14042763],[1799,13,-28.45315875],[1800,23,-430.5491778],[1801,4,-2.56285988],[1802,5,-1.20007984],[1803,8,-2.46653968],[1804,5,-95.64373988]]]
@@ -0,0 +1 @@
1
+ [999,[[2567606289,1876.5,1.4305],[2567590859,1876.1,0.99670598],[2567602139,1876.1,1],[2567605297,1875.1,4.76123353],[2567605344,1875.1,0.01],[2567519477,1875,15],[2567552066,1875,0.01],[2567506309,1874.5,0.1],[2567603711,1874.4,1.820442],[2567477077,1874.2,0.19553],[2567477404,1874.2,0.07873206],[2567472587,1873.8,0.136159],[2567602057,1873.6,1.58],[2566800765,1873,1],[2567601717,1873,1.82726983],[2566876255,1872.6,0.0641877],[2567601259,1872.2,1.8],[2567048549,1871.7,0.01252505],[2567601253,1871.7,0.01252505],[2567606086,1871.7,1.50318748],[2566877752,1871.5,2.01],[2567606069,1871.5,4.8],[2567606105,1871,4.8],[2566874995,1870.9,2.0822],[2566863093,1870.7,0.1],[2567594844,1878.1,-0.42265059],[2567600874,1878.3,-0.1],[2567604766,1878.3,-1],[2567593507,1878.9,-1.662207],[2567598418,1879.5,-1.733],[2567588789,1879.6,-1.85096707],[2567593692,1880,-2],[2567564697,1880.1,-50],[2567564825,1880.2,-0.1],[2567587247,1880.3,-1.8071],[2567490789,1881,-1.59002156],[2567572064,1881,-5],[2567490713,1881.7,-1.79858828],[2567484859,1882.1,-0.1],[2567490678,1882.4,-2.001883],[2567601620,1882.9,-1.5],[2567484581,1883,-2],[2567546551,1883,-2],[2567606075,1883.4,-0.28613703],[2567603128,1883.5,-3.95],[2567474435,1883.7,-1.9],[2567504132,1883.7,-0.04646614],[2567504179,1883.7,-0.13263695],[2567403182,1884,-0.1],[2567442532,1884.5,-1.9324]]]
@@ -0,0 +1 @@
1
+ [22,[0.00078458,0.00075,30,3045.59478528,0.0007825,2,2335880.06705868,-0.0000674,-0.0793,0.0007825,19326761.40360705,0,0]]
@@ -0,0 +1 @@
1
+ [31,[[32288059,1494971706000,-0.00042864,1773.9],[32288058,1494971706000,-0.1,1775.6],[32288057,1494971706000,-0.04470386,1775.8],[32288054,1494971696000,-0.34748184,1776],[32288052,1494971693000,-0.08015163,1777.4],[32288047,1494971690000,-0.01984837,1777.4],[32288044,1494971687000,-0.18976977,1775.7],[32288040,1494971686000,0.26486383,1780.3],[32288039,1494971686000,0.95246765,1779.7],[32288038,1494971686000,0.1,1779.2],[32288037,1494971686000,0.8906,1779.1],[32288036,1494971686000,0.915224,1778.6],[32288035,1494971686000,1.6989623,1778.5],[32288034,1494971686000,0.53929331,1778.3],[32288033,1494971686000,1.9835,1778.2],[32288032,1494971686000,0.60187396,1778.1],[32288031,1494971686000,0.05321495,1778.1],[32288030,1494971684000,-1.79759839,1775.8],[32288029,1494971684000,-0.12600507,1777.4],[32288025,1494971683000,-0.05321495,1777.4],[32288024,1494971682000,0.1,1777.4],[32288023,1494971682000,0.04471204,1777.1],[32288022,1494971682000,0.1,1775.6],[32288021,1494971682000,0.67606794,1775.5],[32288014,1494971682000,-0.05321495,1775.4],[32288011,1494971681000,0.01840201,1775.5],[32288007,1494971678000,-0.21410901,1775.2],[32288006,1494971678000,-0.01986347,1775.2],[32288005,1494971678000,-0.78074942,1775.2],[32288003,1494971677000,-0.1544203,1775.2]]]
@@ -0,0 +1,71 @@
1
+ /* eslint-env mocha */
2
+ 'use strict'
3
+
4
+ const assert = require('assert')
5
+
6
+ const testModel = ({ values = {}, model, orderedFields, boolFields = [] }) => {
7
+ const Model = model
8
+ const fields = orderedFields
9
+ const fieldValues = fields.slice()
10
+
11
+ // Apply overrides
12
+ for (let i = 0; i < fields.length; i++) {
13
+ if (values[fields[i]]) {
14
+ fieldValues[i] = values[fields[i]]
15
+ }
16
+ }
17
+
18
+ const checkModelFields = (m) => {
19
+ fields.forEach((f) => {
20
+ checkField(m, f)
21
+ })
22
+ }
23
+
24
+ const checkField = (m, f) => {
25
+ if (f === null) return
26
+
27
+ if (boolFields.indexOf(f) !== -1) {
28
+ assert.equal(m[f], false)
29
+ } else if (values[f]) {
30
+ assert.equal(m[f], values[f])
31
+ } else {
32
+ assert.equal(m[f], f)
33
+ }
34
+ }
35
+
36
+ it('constructs from an array source', () => {
37
+ const m = new Model(fieldValues)
38
+ checkModelFields(m)
39
+ })
40
+
41
+ it('constructs from an object source', () => {
42
+ const data = {}
43
+ fields.forEach(f => (f !== null) && (data[f] = f))
44
+ boolFields.forEach((f) => { data[f] = false })
45
+ Object.assign(data, values)
46
+
47
+ const m = new Model(data)
48
+ checkModelFields(m)
49
+ })
50
+
51
+ it('serializes correctly', () => {
52
+ const data = {}
53
+ fields.forEach(f => (f !== null) && (data[f] = f))
54
+ boolFields.forEach((f) => { data[f] = false })
55
+ Object.assign(data, values)
56
+
57
+ const m = new Model(data)
58
+ const arr = m.serialize()
59
+
60
+ arr.forEach((v, i) => {
61
+ checkField(m, fields[i])
62
+ })
63
+ })
64
+
65
+ it('unserializes correctly', () => {
66
+ const m = model.unserialize(fieldValues)
67
+ checkModelFields(m)
68
+ })
69
+ }
70
+
71
+ module.exports = testModel
package/test/index.js ADDED
@@ -0,0 +1,131 @@
1
+ /* eslint-env mocha */
2
+ 'use strict'
3
+
4
+ const assert = require('assert')
5
+ const BFX = require('../index')
6
+ const RESTv1 = require('../lib/transports/rest')
7
+ const RESTv2 = require('../lib/transports/rest2')
8
+ const WSv1 = require('../lib/transports/ws')
9
+ const WSv2 = require('../lib/transports/ws2')
10
+
11
+ describe('BFX', () => {
12
+ it('should be loaded', () => {
13
+ assert.equal(typeof BFX, 'function')
14
+ })
15
+
16
+ describe('constructor', () => {
17
+ it('throws on using the deprecated way to set options', () => {
18
+ assert.throws(() => new BFX(2, {}))
19
+ assert.throws(() => new BFX('dummy', 'dummy', 2))
20
+ })
21
+ })
22
+
23
+ describe('rest', () => {
24
+ it('throws an error if an invalid version is requested', () => {
25
+ const bfx = new BFX()
26
+ assert.throws(bfx.rest.bind(bfx, 0))
27
+ assert.throws(bfx.rest.bind(bfx, 3))
28
+ })
29
+
30
+ it('returns correct REST api by version', () => {
31
+ const bfx = new BFX()
32
+ const restDefault = bfx.rest()
33
+ const rest1 = bfx.rest(1)
34
+ const rest2 = bfx.rest(2)
35
+
36
+ assert(restDefault instanceof RESTv2)
37
+ assert(rest1 instanceof RESTv1)
38
+ assert(rest2 instanceof RESTv2)
39
+ })
40
+
41
+ it('passes API keys & transform flag to new transport', () => {
42
+ const bfx = new BFX({
43
+ apiKey: 'k',
44
+ apiSecret: 's',
45
+ transform: true,
46
+ rest: {
47
+ url: 'http://'
48
+ }
49
+ })
50
+
51
+ const rest1 = bfx.rest(1)
52
+ const rest2 = bfx.rest(2)
53
+
54
+ assert.equal(rest1._apiKey, 'k')
55
+ assert.equal(rest2._apiKey, 'k')
56
+ assert.equal(rest1._apiSecret, 's')
57
+ assert.equal(rest2._apiSecret, 's')
58
+ assert.equal(rest1._url, 'http://')
59
+ assert.equal(rest2._url, 'http://')
60
+ assert.equal(rest2._transform, true)
61
+ })
62
+
63
+ it('passes extra options to new transport', () => {
64
+ const bfx = new BFX()
65
+ const rest2 = bfx.rest(2, { url: '/dev/null' })
66
+ assert.equal(rest2._url, '/dev/null')
67
+ })
68
+
69
+ it('returns one instance if called twice for the same version', () => {
70
+ const bfx = new BFX()
71
+ const restA = bfx.rest(2)
72
+ const restB = bfx.rest(2)
73
+ assert(restA === restB)
74
+ })
75
+ })
76
+
77
+ describe('ws', () => {
78
+ it('throws an error if an invalid version is requested', () => {
79
+ const bfx = new BFX()
80
+ assert.throws(bfx.ws.bind(bfx, 0))
81
+ assert.throws(bfx.ws.bind(bfx, 3))
82
+ })
83
+
84
+ it('returns correct WebSocket api by version', () => {
85
+ const bfx = new BFX()
86
+ const wsDefault = bfx.ws()
87
+ const ws1 = bfx.ws(1)
88
+ const ws2 = bfx.ws(2)
89
+
90
+ assert(wsDefault instanceof WSv2)
91
+ assert(ws1 instanceof WSv1)
92
+ assert(ws2 instanceof WSv2)
93
+ })
94
+
95
+ it('passes API keys & transform flag to new transport', () => {
96
+ const bfx = new BFX({
97
+ apiKey: 'k',
98
+ apiSecret: 's',
99
+ transform: true,
100
+ ws: {
101
+ url: 'wss://'
102
+ }
103
+ })
104
+
105
+ const ws1 = bfx.ws(1)
106
+ const ws2 = bfx.ws(2)
107
+
108
+ assert.equal(ws1._apiKey, 'k')
109
+ assert.equal(ws2._apiKey, 'k')
110
+ assert.equal(ws1._apiSecret, 's')
111
+ assert.equal(ws2._apiSecret, 's')
112
+ assert.equal(ws1._url, 'wss://')
113
+ assert.equal(ws2._url, 'wss://')
114
+ assert.equal(ws2._transform, true)
115
+ })
116
+
117
+ it('passes extra options to new transport', () => {
118
+ const bfx = new BFX()
119
+ const ws2 = bfx.ws(2, { url: '/dev/null' })
120
+ assert.equal(ws2._url, '/dev/null')
121
+ })
122
+
123
+ it('returns one instance if called twice for the same version', () => {
124
+ const bfx = new BFX()
125
+ const wsA = bfx.ws(2)
126
+ const wsB = bfx.ws(2)
127
+
128
+ assert(wsA === wsB)
129
+ })
130
+ })
131
+ })
@@ -0,0 +1,12 @@
1
+ /* eslint-env mocha */
2
+ 'use strict'
3
+
4
+ const { Alert } = require('../../../lib/models')
5
+ const testModel = require('../../helpers/test_model')
6
+
7
+ describe('Alert model', () => {
8
+ testModel({
9
+ model: Alert,
10
+ orderedFields: ['key', 'type', 'symbol', 'price']
11
+ })
12
+ })
@@ -0,0 +1,12 @@
1
+ /* eslint-env mocha */
2
+ 'use strict'
3
+
4
+ const { BalanceInfo } = require('../../../lib/models')
5
+ const testModel = require('../../helpers/test_model')
6
+
7
+ describe('BalanceInfo model', () => {
8
+ testModel({
9
+ model: BalanceInfo,
10
+ orderedFields: ['amount', 'amountNet']
11
+ })
12
+ })
@@ -0,0 +1,12 @@
1
+ /* eslint-env mocha */
2
+ 'use strict'
3
+
4
+ const { Candle } = require('../../../lib/models')
5
+ const testModel = require('../../helpers/test_model')
6
+
7
+ describe('Candle model', () => {
8
+ testModel({
9
+ model: Candle,
10
+ orderedFields: ['mts', 'open', 'close', 'high', 'low', 'volume']
11
+ })
12
+ })
@@ -0,0 +1,17 @@
1
+ /* eslint-env mocha */
2
+ 'use strict'
3
+
4
+ const { FundingCredit } = require('../../../lib/models')
5
+ const testModel = require('../../helpers/test_model')
6
+
7
+ describe('FundingCredit model', () => {
8
+ testModel({
9
+ model: FundingCredit,
10
+ boolFields: ['notify', 'hidden', 'insure', 'renew', 'noClose'],
11
+ orderedFields: [
12
+ 'id', 'symbol', 'side', 'mtsCreate', 'mtsUpdate', 'amount', 'flags',
13
+ 'status', 'rate', 'period', 'mtsOpening', 'mtsLastPayout', 'notify',
14
+ 'hidden', 'insure', 'renew', 'rateReal', 'noClose', 'positionPair'
15
+ ]
16
+ })
17
+ })
@@ -0,0 +1,7 @@
1
+ /* eslint-env mocha */
2
+ 'use strict'
3
+
4
+ // const { FundingInfo } = require('../../../lib/models')
5
+ // const testModel = require('../../helpers/test_model')
6
+
7
+ describe.skip('FundingInfo model', () => {})
@@ -0,0 +1,17 @@
1
+ /* eslint-env mocha */
2
+ 'use strict'
3
+
4
+ const { FundingLoan } = require('../../../lib/models')
5
+ const testModel = require('../../helpers/test_model')
6
+
7
+ describe('FundingLoan model', () => {
8
+ testModel({
9
+ model: FundingLoan,
10
+ boolFields: ['notify', 'hidden', 'insure', 'renew', 'noClose'],
11
+ orderedFields: [
12
+ 'id', 'symbol', 'side', 'mtsCreate', 'mtsUpdate', 'amount', 'flags',
13
+ 'status', 'rate', 'period', 'mtsOpening', 'mtsLastPayout', 'notify',
14
+ 'hidden', 'insure', 'renew', 'rateReal', 'noClose'
15
+ ]
16
+ })
17
+ })
@@ -0,0 +1,17 @@
1
+ /* eslint-env mocha */
2
+ 'use strict'
3
+
4
+ const { FundingOffer } = require('../../../lib/models')
5
+ const testModel = require('../../helpers/test_model')
6
+
7
+ describe('FundingOffer model', () => {
8
+ testModel({
9
+ model: FundingOffer,
10
+ boolFields: ['notify', 'hidden', 'insure', 'renew'],
11
+ orderedFields: [
12
+ 'id', 'symbol', 'mtsCreate', 'mtsUpdate', 'amount', 'amountOrig', 'type',
13
+ 'flags', 'status', 'rate', 'period', 'notify', 'hidden', 'insure',
14
+ 'renew', 'rateReal'
15
+ ]
16
+ })
17
+ })
@@ -0,0 +1,15 @@
1
+ /* eslint-env mocha */
2
+ 'use strict'
3
+
4
+ const { FundingTrade } = require('../../../lib/models')
5
+ const testModel = require('../../helpers/test_model')
6
+
7
+ describe('FundingTrade model', () => {
8
+ testModel({
9
+ model: FundingTrade,
10
+ orderedFields: [
11
+ 'id', 'symbol', 'mtsCreate', 'offerID', 'amount', 'rate', 'period',
12
+ 'maker'
13
+ ]
14
+ })
15
+ })
@@ -0,0 +1,15 @@
1
+ /* eslint-env mocha */
2
+ 'use strict'
3
+
4
+ const { MarginInfo } = require('../../../lib/models')
5
+ const testModel = require('../../helpers/test_model')
6
+
7
+ describe('MarginInfo model', () => {
8
+ testModel({
9
+ model: MarginInfo,
10
+ orderedFields: [
11
+ 'userPL', 'userSwaps', 'symbol', 'tradeableBalance', 'marginBalance',
12
+ 'marginNet'
13
+ ]
14
+ })
15
+ })
@@ -0,0 +1,14 @@
1
+ /* eslint-env mocha */
2
+ 'use strict'
3
+
4
+ const { Notification } = require('../../../lib/models')
5
+ const testModel = require('../../helpers/test_model')
6
+
7
+ describe('Notification model', () => {
8
+ testModel({
9
+ model: Notification,
10
+ orderedFields: [
11
+ 'mts', 'type', 'messageID', 'notifyInfo', 'code', 'status', 'text'
12
+ ]
13
+ })
14
+ })