File tree 1 file changed +16
-21
lines changed
1 file changed +16
-21
lines changed Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
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,
11
10
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 ( )
24
15
16
+ const market = 'tBTCUSD'
17
+ const tf = '5m'
25
18
const candleKey = `trade:${ tf } :${ market } `
26
19
let prevTS = null
27
20
@@ -41,4 +34,6 @@ module.exports = runExample({
41
34
} )
42
35
43
36
await ws . subscribeCandles ( candleKey )
44
- } )
37
+ }
38
+
39
+ execute ( )
You can’t perform that action at this time.
0 commit comments