Skip to content

Commit

Permalink
standard --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobPlaster authored and JacobPlaster committed Oct 2, 2019
1 parent 0e03396 commit eca73aa
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 70 deletions.
2 changes: 0 additions & 2 deletions examples/rest2/positions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -82,5 +81,4 @@ const example = async () => {
// })
}


example().catch(debug)
8 changes: 4 additions & 4 deletions examples/rest2/submit_funding_offer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down
8 changes: 4 additions & 4 deletions examples/rest2/submit_order.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand All @@ -37,4 +37,4 @@ setTimeout(() => {

setTimeout(() => {
o.cancel()
},10000)
}, 10000)
22 changes: 11 additions & 11 deletions examples/rest2/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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({
Expand All @@ -37,6 +37,6 @@ rest.withdraw({
amount: 2,
address: '1MUz4VMYui5qY1mxUiG8BQ1Luv6tqkvaiL'
})
.then((res) => {
debug(`withdraw confirmed: ${res}`)
})
.then((res) => {
debug(`withdraw confirmed: ${res}`)
})
2 changes: 1 addition & 1 deletion examples/ws2/candles.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
116 changes: 68 additions & 48 deletions test/lib/transports/ws2-unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -674,16 +674,16 @@ 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)
})

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'))
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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

Expand All @@ -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) => {
Expand Down Expand Up @@ -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')
Expand All @@ -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)
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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) => {
Expand All @@ -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')
Expand All @@ -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)
Expand Down

0 comments on commit eca73aa

Please sign in to comment.