'use strict'

const runExample = require('../util/run_example')

module.exports = runExample({
  name: 'ws2-cancel-all-buffered',
  ws: {
    env: true,
    connect: true,
    auth: true,
    transform: true,
    orderOpBufferDelay: 250
  }
}, async ({ ws, debug }) => {
  ws.onOrderSnapshot({}, async (snapshot) => {
    if (snapshot.length === 0) {
      debug('no orders to cancel')
      return
    }

    debug('canceling %d orders', snapshot.length)

    await ws.cancelOrders(snapshot)
    debug('cancelled all orders')
  })
})

@@ -17,258 +17,355 @@
 nst 
-runExample = require('../util/run_example')%0A%0Amodule.exports = runExample(%7B%0A  name: 'ws2-cancel-all-buffered',%0A  ws: %7B%0A    env: true,%0A    connect: true,%0A    auth: true,%0A    transform: true,%0A    orderOpBufferDelay: 250%0A  %7D%0A%7D, async (%7B ws, debug %7D) =%3E %7B
+%7B args: %7B apiKey, apiSecret %7D, debug %7D = require('../util/setup')%0Aconst WSv2 = require('../../lib/transports/ws2')%0A%0Aasync function execute () %7B%0A  const ws = new WSv2(%7B%0A    apiKey,%0A    apiSecret,%0A    transform: true,%0A    orderOpBufferDelay: 250%0A  %7D)%0A  ws.on('error', e =%3E debug('WSv2 error: %25s', e.message %7C e))%0A  await ws.open()%0A  await ws.auth()%0A
 %0A  w
@@ -484,24 +484,19 @@
     
-  return%0A    %7D%0A%0A
+%7D else %7B%0A  
     
@@ -542,16 +542,18 @@
 ength)%0A%0A
+  
     awai
@@ -580,24 +580,26 @@
 apshot)%0A    
+  
 debug('cance
@@ -622,10 +622,47 @@
 )%0A  
-%7D)%0A%7D
+  %7D%0A    await ws.close()%0A  %7D)%0A%7D%0A%0Aexecute(
 )%0A

update cancel_all_buf example