Skip to content

Commit 81c6739

Browse files
author
Vitaliy Stoliarov
committed
uodate 'order book viz' example
1 parent 100d487 commit 81c6739

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

examples/ws2/order_book_viz.js

+16-15
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,21 @@ const blessedContrib = require('blessed-contrib')
55
const _isEmpty = require('lodash/isEmpty')
66
const _reverse = require('lodash/reverse')
77
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')
910

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,
1515
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'
2423

2524
if (_isEmpty(market)) {
2625
throw new Error('market required')
@@ -61,4 +60,6 @@ module.exports = runExample({
6160
})
6261

6362
await ws.subscribeOrderBook(market, 'P0', '25')
64-
})
63+
}
64+
65+
execute()

0 commit comments

Comments
 (0)