Skip to content

Commit 4aea70c

Browse files
author
Vitaliy Stoliarov
committed
update 'candles' example
1 parent 416b7b9 commit 4aea70c

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

examples/ws2/candles.js

+16-21
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
11
'use strict'
22

3-
const _isEmpty = require('lodash/isEmpty')
4-
const runExample = require('../util/run_example')
5-
6-
module.exports = runExample({
7-
name: 'ws2-candles',
8-
ws: {
9-
env: true,
10-
connect: true,
3+
const { args: { apiKey, apiSecret }, debug } = require('../util/setup')
4+
const WSv2 = require('../../lib/transports/ws2')
5+
6+
async function execute () {
7+
const ws = new WSv2({
8+
apiKey,
9+
apiSecret,
1110
manageCandles: true, // enable candle dataset persistence/management
12-
transform: true, // converts ws data arrays to Candle models (and others)
13-
keepOpen: true
14-
},
15-
params: {
16-
market: 'tBTCUSD',
17-
tf: '5m'
18-
}
19-
}, async ({ ws, debug, params }) => {
20-
const { market, tf } = params
21-
22-
if (_isEmpty(market)) throw new Error('market required')
23-
if (_isEmpty(tf)) throw new Error('time frame required')
11+
transform: true // converts ws data arrays to Candle models (and others)
12+
})
13+
ws.on('error', e => debug('WSv2 error: %s', e.message | e))
14+
await ws.open()
2415

16+
const market = 'tBTCUSD'
17+
const tf = '5m'
2518
const candleKey = `trade:${tf}:${market}`
2619
let prevTS = null
2720

@@ -41,4 +34,6 @@ module.exports = runExample({
4134
})
4235

4336
await ws.subscribeCandles(candleKey)
44-
})
37+
}
38+
39+
execute()

0 commit comments

Comments
 (0)