From eca73aa92b20ffc5dbb7a871af2f2450d1b28822 Mon Sep 17 00:00:00 2001 From: JacobPlaster Date: Tue, 1 Oct 2019 12:15:39 +0100 Subject: [PATCH] standard --fix --- examples/rest2/positions.js | 2 - examples/rest2/submit_funding_offer.js | 8 +- examples/rest2/submit_order.js | 8 +- examples/rest2/wallet.js | 22 ++--- examples/ws2/candles.js | 2 +- test/lib/transports/ws2-unit.js | 116 +++++++++++++++---------- 6 files changed, 88 insertions(+), 70 deletions(-) diff --git a/examples/rest2/positions.js b/examples/rest2/positions.js index 5fe54eac..f33fdc0f 100644 --- a/examples/rest2/positions.js +++ b/examples/rest2/positions.js @@ -7,7 +7,6 @@ const debug = require('debug')('bfx:examples:rest2_positions') const bfx = require('../bfx') const rest = bfx.rest(2, { transform: true }) - const PL_ENABLED = process.argv[2] === 'pl' const tableColWidths = [20, 10, 20, 20, 20] const tableHeaders = [ @@ -82,5 +81,4 @@ const example = async () => { // }) } - example().catch(debug) diff --git a/examples/rest2/submit_funding_offer.js b/examples/rest2/submit_funding_offer.js index 60289994..32fc6965 100644 --- a/examples/rest2/submit_funding_offer.js +++ b/examples/rest2/submit_funding_offer.js @@ -9,8 +9,8 @@ const rest = bfx.rest(2, { transform: true }) debug('Submitting new order...') - // Build new order - const fo = new FundingOffer({ +// Build new order +const fo = new FundingOffer({ type: 'LIMIT', symbol: 'fUSD', rate: 0.0120000, @@ -19,9 +19,9 @@ debug('Submitting new order...') }, rest) fo.submit().then((fo) => { - debug("Submitted funding offer", fo.id) + debug('Submitted funding offer', fo.id) }) -.catch((err) => console.log(err)) + .catch((err) => console.log(err)) // cancel offer diff --git a/examples/rest2/submit_order.js b/examples/rest2/submit_order.js index 6000a863..4c64a4b1 100644 --- a/examples/rest2/submit_order.js +++ b/examples/rest2/submit_order.js @@ -9,8 +9,8 @@ const rest = bfx.rest(2) debug('Submitting new order...') - // Build new order - const o = new Order({ +// Build new order +const o = new Order({ cid: Date.now(), symbol: 'tBTCUSD', price: 18000, @@ -25,7 +25,7 @@ o.submit().then(() => { o.cid, o.id, o.mtsTIF ) }) -.catch((err) => console.log(err)) + .catch((err) => console.log(err)) // update order @@ -37,4 +37,4 @@ setTimeout(() => { setTimeout(() => { o.cancel() -},10000) +}, 10000) diff --git a/examples/rest2/wallet.js b/examples/rest2/wallet.js index 433df51d..638a251a 100644 --- a/examples/rest2/wallet.js +++ b/examples/rest2/wallet.js @@ -8,15 +8,15 @@ const rest = bfx.rest(2, { transform: true }) debug('Submitting new order...') - // get new deposit address - rest.getDepositAddress ({ +// get new deposit address +rest.getDepositAddress({ wallet: 'exchange', method: 'bitcoin', opRenew: 0 - }) -.then((address) => { - debug(`New wallet address ${address}`) }) + .then((address) => { + debug(`New wallet address ${address}`) + }) // transfer between accounts rest.transfer({ @@ -26,9 +26,9 @@ rest.transfer({ currency: 'BTC', currencyTo: 'BTC' }) -.then((res) => { - debug(`transfer confirmed: ${res}`) -}) + .then((res) => { + debug(`transfer confirmed: ${res}`) + }) // withdraw rest.withdraw({ @@ -37,6 +37,6 @@ rest.withdraw({ amount: 2, address: '1MUz4VMYui5qY1mxUiG8BQ1Luv6tqkvaiL' }) -.then((res) => { - debug(`withdraw confirmed: ${res}`) -}) + .then((res) => { + debug(`withdraw confirmed: ${res}`) + }) diff --git a/examples/ws2/candles.js b/examples/ws2/candles.js index 72203404..dc03322d 100644 --- a/examples/ws2/candles.js +++ b/examples/ws2/candles.js @@ -24,7 +24,7 @@ ws.onCandle({ key: CANDLE_KEY }, (candles) => { if (prevTS === null || candles[0].mts > prevTS) { const c = candles[1] // report previous candle - debug(`%s %s open: %f, high: %f, low: %f, close: %f, volume: %f`, + debug('%s %s open: %f, high: %f, low: %f, close: %f, volume: %f', CANDLE_KEY, new Date(c.mts).toLocaleTimeString(), c.open, c.high, c.low, c.close, c.volume ) diff --git a/test/lib/transports/ws2-unit.js b/test/lib/transports/ws2-unit.js index e56ddcc2..62b54669 100644 --- a/test/lib/transports/ws2-unit.js +++ b/test/lib/transports/ws2-unit.js @@ -38,7 +38,7 @@ describe('WSv2 utilities', () => { const listener = listenerSet.trade[0] assert.strictEqual(listener.modelClass, Map) - assert.deepStrictEqual(listener.filter, { '2': 'tBTCUSD' }) + assert.deepStrictEqual(listener.filter, { 2: 'tBTCUSD' }) assert.strictEqual(typeof listener.cb, 'function') }) @@ -349,7 +349,7 @@ describe('WSv2 auto reconnect', () => { ws.on('open', ws.auth.bind(ws)) ws.once('auth', () => { - let now = Date.now() + const now = Date.now() ws.reconnectAfterClose = () => { assert((Date.now() - now) >= 70) @@ -674,8 +674,8 @@ describe('WSv2 channel msg handling', () => { const lg = { '': [{ cb: func }], - 'test': [{ cb: func }], - 'nope': [{ cb: func }] + test: [{ cb: func }], + nope: [{ cb: func }] } WSv2._notifyListenerGroup(lg, [0, 'test', [0, 'tu']], false) @@ -683,7 +683,7 @@ describe('WSv2 channel msg handling', () => { it('_notifyListenerGroup: doesn\'t fail on missing data if filtering', (done) => { const lg = { - 'test': [{ + test: [{ filter: { 1: 'on' }, cb: () => { done(new Error('filter should not have matched')) @@ -726,14 +726,18 @@ describe('WSv2 channel msg handling', () => { transform: true }) - ws._channelMapA = { 42: { - channel: 'orderbook', - symbol: 'tBTCUSD' - } } - ws._channelMapB = { 43: { - channel: 'orderbook', - symbol: 'fUSD' - } } + ws._channelMapA = { + 42: { + channel: 'orderbook', + symbol: 'tBTCUSD' + } + } + ws._channelMapB = { + 43: { + channel: 'orderbook', + symbol: 'fUSD' + } + } ws._handleOBMessage([42, [ [100, 2, -4], @@ -778,10 +782,12 @@ describe('WSv2 channel msg handling', () => { transform: true }) - wsNoTransform._channelMap = { 42: { - channel: 'orderbook', - symbol: 'tBTCUSD' - } } + wsNoTransform._channelMap = { + 42: { + channel: 'orderbook', + symbol: 'tBTCUSD' + } + } wsTransform._channelMap = wsNoTransform._channelMap @@ -801,10 +807,12 @@ describe('WSv2 channel msg handling', () => { it('_handleOBMessage: forwards managed ob to listeners', (done) => { const ws = new WSv2({ manageOrderBooks: true }) - ws._channelMap = { 42: { - channel: 'orderbook', - symbol: 'tBTCUSD' - } } + ws._channelMap = { + 42: { + channel: 'orderbook', + symbol: 'tBTCUSD' + } + } let seen = 0 ws.onOrderBook({ symbol: 'tBTCUSD' }, (ob) => { @@ -861,10 +869,12 @@ describe('WSv2 channel msg handling', () => { it('_handleOBMessage: emits managed ob', (done) => { const ws = new WSv2({ manageOrderBooks: true }) - ws._channelMap = { 42: { - channel: 'orderbook', - symbol: 'tBTCUSD' - } } + ws._channelMap = { + 42: { + channel: 'orderbook', + symbol: 'tBTCUSD' + } + } ws.on('orderbook', (symbol, data) => { assert.strictEqual(symbol, 'tBTCUSD') @@ -877,11 +887,13 @@ describe('WSv2 channel msg handling', () => { it('_handleOBMessage: forwards transformed data if transform enabled', (done) => { const ws = new WSv2({ transform: true }) - ws._channelMap = { 42: { - chanId: 42, - channel: 'orderbook', - symbol: 'tBTCUSD' - } } + ws._channelMap = { + 42: { + chanId: 42, + channel: 'orderbook', + symbol: 'tBTCUSD' + } + } ws.onOrderBook({ symbol: 'tBTCUSD' }, (ob) => { assert(ob.asks) @@ -940,10 +952,12 @@ describe('WSv2 channel msg handling', () => { it('_handleCandleMessage: maintains internal candles if management is enabled', () => { const ws = new WSv2({ manageCandles: true }) - ws._channelMap = { 64: { - channel: 'candles', - key: 'trade:1m:tBTCUSD' - } } + ws._channelMap = { + 64: { + channel: 'candles', + key: 'trade:1m:tBTCUSD' + } + } ws._handleCandleMessage([64, [ [5, 100, 70, 150, 30, 1000], @@ -1014,11 +1028,13 @@ describe('WSv2 channel msg handling', () => { it('_handleCandleMessage: forwards managed candles to listeners', (done) => { const ws = new WSv2({ manageCandles: true }) - ws._channelMap = { 42: { - chanId: 42, - channel: 'candles', - key: 'trade:1m:tBTCUSD' - } } + ws._channelMap = { + 42: { + chanId: 42, + channel: 'candles', + key: 'trade:1m:tBTCUSD' + } + } let seen = 0 ws.onCandle({ key: 'trade:1m:tBTCUSD' }, (data) => { @@ -1039,10 +1055,12 @@ describe('WSv2 channel msg handling', () => { it('_handleCandleMessage: emits managed candles', (done) => { const ws = new WSv2({ manageCandles: true }) - ws._channelMap = { 42: { - channel: 'candles', - key: 'trade:1m:tBTCUSD' - } } + ws._channelMap = { + 42: { + channel: 'candles', + key: 'trade:1m:tBTCUSD' + } + } ws.on('candle', (data, key) => { assert.strictEqual(key, 'trade:1m:tBTCUSD') @@ -1058,11 +1076,13 @@ describe('WSv2 channel msg handling', () => { it('_handleCandleMessage: forwards transformed data if transform enabled', (done) => { const ws = new WSv2({ transform: true }) - ws._channelMap = { 42: { - chanId: 42, - channel: 'candles', - key: 'trade:1m:tBTCUSD' - } } + ws._channelMap = { + 42: { + chanId: 42, + channel: 'candles', + key: 'trade:1m:tBTCUSD' + } + } ws.onCandle({ key: 'trade:1m:tBTCUSD' }, (candles) => { assert.strictEqual(candles.length, 1)