@@ -5,22 +5,21 @@ const blessedContrib = require('blessed-contrib')
5
5
const _isEmpty = require ( 'lodash/isEmpty' )
6
6
const _reverse = require ( 'lodash/reverse' )
7
7
const { preparePrice, prepareAmount } = require ( 'bfx-api-node-util' )
8
- const runExample = require ( '../util/run_example' )
8
+ const { args : { apiKey, apiSecret } , debug } = require ( '../util/setup' )
9
+ const WSv2 = require ( '../../lib/transports/ws2' )
9
10
10
- module . exports = runExample ( {
11
- name : 'ws2-order-book-viz' ,
12
- ws : {
13
- env : true ,
14
- connect : true ,
11
+ async function execute ( ) {
12
+ const ws = new WSv2 ( {
13
+ apiKey,
14
+ apiSecret,
15
15
transform : true ,
16
- manageOrderBooks : true , // tell the ws client to maintain full sorted OBs
17
- keepOpen : true
18
- } ,
19
- params : {
20
- market : 'tBTCUSD'
21
- }
22
- } , async ( { ws, params } ) => {
23
- const { market } = params
16
+ manageOrderBooks : true // tell the ws client to maintain full sorted OBs
17
+ } )
18
+ ws . on ( 'error' , e => debug ( 'WSv2 error: %s' , e . message | e ) )
19
+ await ws . open ( )
20
+ await ws . auth ( )
21
+
22
+ const market = 'tBTCUSD'
24
23
25
24
if ( _isEmpty ( market ) ) {
26
25
throw new Error ( 'market required' )
@@ -61,4 +60,6 @@ module.exports = runExample({
61
60
} )
62
61
63
62
await ws . subscribeOrderBook ( market , 'P0' , '25' )
64
- } )
63
+ }
64
+
65
+ execute ( )
0 commit comments