2
2
3
3
const Promise = require ( 'bluebird' )
4
4
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 ) )
15
15
await ws . open ( )
16
16
17
- const { filterByMarket } = params
17
+ const filterByMarket = null
18
18
19
19
debug ( 'awaiting order snapshot...' )
20
20
@@ -24,7 +24,10 @@ module.exports = runExample({
24
24
} )
25
25
26
26
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
28
31
}
29
32
30
33
const orders = _isEmpty ( filterByMarket )
@@ -53,4 +56,8 @@ module.exports = runExample({
53
56
'done! cancelled the following order IDs: %s' ,
54
57
confirmations . map ( o => o [ 0 ] ) . join ( ', ' )
55
58
)
56
- } )
59
+ await ws . close ( )
60
+ readline . close ( )
61
+ }
62
+
63
+ execute ( )
0 commit comments