Skip to content

Commit de2d892

Browse files
author
Vitaliy Stoliarov
committed
uodate 'trades' example
1 parent 17d8808 commit de2d892

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

examples/ws2/trades.js

+13-18
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
11
'use strict'
22

3-
const _isEmpty = require('lodash/isEmpty')
4-
const runExample = require('../util/run_example')
3+
const { args: { apiKey, apiSecret }, debug } = require('../util/setup')
4+
const WSv2 = require('../../lib/transports/ws2')
55

6-
module.exports = runExample({
7-
name: 'ws2-trades',
8-
ws: {
9-
env: true,
10-
connect: true,
11-
keepOpen: true,
6+
async function execute () {
7+
const ws = new WSv2({
8+
apiKey,
9+
apiSecret,
1210
transform: true
13-
},
14-
params: {
15-
market: 'tBTCUSD'
16-
}
17-
}, async ({ ws, debug, params }) => {
18-
const { market } = params
11+
})
12+
ws.on('error', e => debug('WSv2 error: %s', e.message | e))
13+
await ws.open()
1914

20-
if (_isEmpty(market)) {
21-
throw new Error('market required')
22-
}
15+
const market = 'tBTCUSD'
2316

2417
if (market[0] === 't') {
2518
ws.onTradeEntry({ symbol: market }, (trade) => {
@@ -36,4 +29,6 @@ module.exports = runExample({
3629
})
3730

3831
await ws.subscribeTrades(market)
39-
})
32+
}
33+
34+
execute()

0 commit comments

Comments
 (0)