diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 00000000..0d3c698f --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,36 @@ +version: 2.0 + +shared: &shared + steps: + - run: + name: "Show Node Environment" + command: 'echo "node: $(node -v)" && echo "npm: v$(npm -v)"' + - checkout + - run: npm install + - run: npm run lint + - run: npm run prettier + - run: npm test + +jobs: + "node-6": + <<: *shared + docker: + - image: circleci/node:6 + + "node-8": + <<: *shared + docker: + - image: circleci/node:8 + + "node-10": + <<: *shared + docker: + - image: circleci/node:10 + +workflows: + version: 2 + build: + jobs: + - "node-6" + - "node-8" + - "node-10" diff --git a/circle.yml b/circle.yml deleted file mode 100644 index 30e5ecc7..00000000 --- a/circle.yml +++ /dev/null @@ -1,3 +0,0 @@ -machine: - node: - version: 6.12.2 diff --git a/lib/orderbook.js b/lib/orderbook.js index 57feb06e..e7cdb298 100644 --- a/lib/orderbook.js +++ b/lib/orderbook.js @@ -15,21 +15,23 @@ class Orderbook { state(book) { if (book) { - book.bids - .forEach(order => this.add({ + book.bids.forEach(order => + this.add({ id: order[2], side: 'buy', price: BigNumber(order[0]), size: BigNumber(order[1]), - })); + }) + ); - book.asks - .forEach(order => this.add({ + book.asks.forEach(order => + this.add({ id: order[2], side: 'sell', price: BigNumber(order[0]), size: BigNumber(order[1]), - })); + }) + ); } else { book = { asks: [], bids: [] }; diff --git a/lib/orderbook_sync.js b/lib/orderbook_sync.js index 0cd278e2..0c411358 100644 --- a/lib/orderbook_sync.js +++ b/lib/orderbook_sync.js @@ -76,9 +76,10 @@ class OrderbookSync extends WebsocketClient { // subscriptions changed -- possible new products _newSubscription(data) { const channel = data.channels.find(c => c.name === 'full'); - channel && channel.product_ids - .filter(productID => !(productID in this.books)) - .forEach(this._newProduct, this); + channel && + channel.product_ids + .filter(productID => !(productID in this.books)) + .forEach(this._newProduct, this); } processMessage(data) { diff --git a/package-lock.json b/package-lock.json index fec4de47..7457b6b1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -219,9 +219,9 @@ } }, "bignumber.js": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-5.0.0.tgz", - "integrity": "sha512-KWTu6ZMVk9sxlDJQh2YH1UOnfDP8O8TpxUxgQG/vKASoSnEjK9aVuOueFaPcQEYQ5fyNXNTOYwYw3099RYebWg==" + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-6.0.0.tgz", + "integrity": "sha512-x247jIuy60/+FtMRvscqfxtVHQf8AGx2hm9c6btkgC0x/hp9yt+teISNhvF8WlwRkCc5yF2fDECH8SIMe8j+GA==" }, "bintrees": { "version": "1.0.2", diff --git a/package.json b/package.json index 4170d3d8..c0586521 100644 --- a/package.json +++ b/package.json @@ -62,6 +62,9 @@ "url": "git://github.com/coinbase/gdax-node.git" }, "scripts": { + "lint": "eslint --ext .js ./", + "prettier": "prettier -l README.md *.js **/*.js", + "prettier-write": "npm run prettier -- --write", "test": "mocha --full-trace --ui tdd --bail --reporter spec tests/*.js", "precommit": "lint-staged" }, diff --git a/tests/authenticated.spec.js b/tests/authenticated.spec.js index cd5a5a91..c2a0f545 100644 --- a/tests/authenticated.spec.js +++ b/tests/authenticated.spec.js @@ -175,7 +175,7 @@ suite('AuthenticatedClient', () => { .then(() => done()) .catch(err => assert.ifError(err) || assert.fail()); }); - + test('.getAccountTransfers()', done => { const expectedResponse = [ { @@ -741,7 +741,7 @@ suite('AuthenticatedClient', () => { test('.depositCrypto()', done => { const params = { - currency: 'BTC' + currency: 'BTC', }; const expectedAccountsRespons = [ { @@ -751,8 +751,8 @@ suite('AuthenticatedClient', () => { currency: 'BTC', type: 'wallet', primary: true, - active: true - } + active: true, + }, ]; const expectedAddressResponse = { id: 'test-id', @@ -765,9 +765,10 @@ suite('AuthenticatedClient', () => { resource: 'address', resource_path: '/v2/accounts/test-account-id/addresses/test-id', warning_title: 'Only send Bitcoin (BTC) to this address', - warning_details: 'Sending any other digital asset, including Bitcoin Cash (BCH), will result in permanent loss.', + warning_details: + 'Sending any other digital asset, including Bitcoin Cash (BCH), will result in permanent loss.', callback_url: null, - exchange_deposit_address: true + exchange_deposit_address: true, }; nock(EXCHANGE_API_URL) diff --git a/tests/orderbook_sync.spec.js b/tests/orderbook_sync.spec.js index 3a6457df..ba0ac349 100644 --- a/tests/orderbook_sync.spec.js +++ b/tests/orderbook_sync.spec.js @@ -98,13 +98,15 @@ suite('OrderbookSync', () => { test: true, product_id: 'BTC-USD', }); - server.close(); - done(); }); }); server.on('connection', socket => { socket.send(JSON.stringify({ test: true, product_id: 'BTC-USD' })); + socket.on('message', () => { + server.close(); + done(); + }); }); }); @@ -128,13 +130,15 @@ suite('OrderbookSync', () => { test: true, product_id: 'BTC-USD', }); - server.close(); - done(); }); }); server.on('connection', socket => { socket.send(JSON.stringify({ test: true, product_id: 'BTC-USD' })); + socket.on('message', () => { + server.close(); + done(); + }); }); }); @@ -152,13 +156,15 @@ suite('OrderbookSync', () => { orderbookSync.on('error', err => { assert.equal(err.message, 'Failed to load orderbook: whoops'); - server.close(); - done(); }); }); server.on('connection', socket => { socket.send(JSON.stringify({ product_id: 'BTC-USD' })); + socket.on('message', () => { + server.close(); + done(); + }); }); }); @@ -177,13 +183,15 @@ suite('OrderbookSync', () => { orderbookSync.on('error', err => { assert.equal(err.message, 'Failed to load orderbook: whoops'); - server.close(); - done(); }); }); server.on('connection', socket => { socket.send(JSON.stringify({ product_id: 'BTC-USD' })); + socket.on('message', () => { + server.close(); + done(); + }); }); }); @@ -202,7 +210,6 @@ suite('OrderbookSync', () => { bids: [], }); - let count = 0; const server = testserver(port, () => { const orderbookSync = new Gdax.OrderbookSync( ['BTC-USD', 'ETH-USD'], @@ -212,20 +219,18 @@ suite('OrderbookSync', () => { orderbookSync.on('message', data => { const state = orderbookSync.books[data.product_id].state(); - assert.deepEqual(state, { asks: [], bids: [] }); assert.equal(orderbookSync.books['ETH-BTC'], undefined); - - if (++count >= 2) { - server.close(); - done(); - } }); }); server.on('connection', socket => { socket.send(JSON.stringify({ product_id: 'BTC-USD' })); socket.send(JSON.stringify({ product_id: 'ETH-USD' })); + socket.on('message', () => { + server.close(); + done(); + }); }); }); @@ -245,14 +250,16 @@ suite('OrderbookSync', () => { ); orderbookSync.on('sync', productID => { - assert.equal(productID, 'BTC-USD'); - server.close(); - done(); + assert.equal(productID, 'BTC-USD'); }); }); server.on('connection', socket => { socket.send(JSON.stringify({ product_id: 'BTC-USD' })); + socket.on('message', () => { + server.close(); + done(); + }); }); }); @@ -272,14 +279,16 @@ suite('OrderbookSync', () => { ); orderbookSync.on('synced', productID => { - assert.equal(productID, 'BTC-USD'); - server.close(); - done(); + assert.equal(productID, 'BTC-USD'); }); }); server.on('connection', socket => { socket.send(JSON.stringify({ product_id: 'BTC-USD' })); + socket.on('message', () => { + server.close(); + done(); + }); }); }); }); diff --git a/tests/websocket.spec.js b/tests/websocket.spec.js index 3da62dbc..fa8c7faf 100644 --- a/tests/websocket.spec.js +++ b/tests/websocket.spec.js @@ -269,9 +269,6 @@ suite('WebsocketClient', () => { client.once('error', err => { assert.equal(err.message, 'test error'); assert.equal(err.reason, 'because error'); - - server.close(); - done(); }); }); @@ -283,6 +280,10 @@ suite('WebsocketClient', () => { reason: 'because error', }) ); + socket.on('message', () => { + server.close(); + done(); + }); }); }); });