Skip to content

Commit 416b7b9

Browse files
author
Vitaliy Stoliarov
committed
update 'cancel_all' example
1 parent e5dcad0 commit 416b7b9

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

examples/ws2/cancel_all.js

+20-13
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22

33
const Promise = require('bluebird')
44
const _isEmpty = require('lodash/isEmpty')
5-
const runExample = require('../util/run_example')
6-
7-
module.exports = runExample({
8-
name: 'cancel-all-orders',
9-
ws: { env: true, transform: true }, // no auto-auth so we can grab snapshot
10-
readline: true,
11-
params: {
12-
filterByMarket: null
13-
}
14-
}, async ({ ws, debug, readline, params }) => {
5+
const { args: { apiKey, apiSecret }, debug, readline } = require('../util/setup')
6+
const WSv2 = require('../../lib/transports/ws2')
7+
8+
async function execute () {
9+
const ws = new WSv2({
10+
apiKey,
11+
apiSecret,
12+
transform: true
13+
})
14+
ws.on('error', e => debug('WSv2 error: %s', e.message | e))
1515
await ws.open()
1616

17-
const { filterByMarket } = params
17+
const filterByMarket = null
1818

1919
debug('awaiting order snapshot...')
2020

@@ -24,7 +24,10 @@ module.exports = runExample({
2424
})
2525

2626
if (allOrders.length === 0) {
27-
return debug('no orders to cancel')
27+
debug('no orders to cancel')
28+
await ws.close()
29+
readline.close()
30+
return
2831
}
2932

3033
const orders = _isEmpty(filterByMarket)
@@ -53,4 +56,8 @@ module.exports = runExample({
5356
'done! cancelled the following order IDs: %s',
5457
confirmations.map(o => o[0]).join(', ')
5558
)
56-
})
59+
await ws.close()
60+
readline.close()
61+
}
62+
63+
execute()

0 commit comments

Comments
 (0)