<commit_before>'use strict'

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

module.exports = runExample({
  name: 'ws2-auth',
  ws: { env: true } // manually open/auth to show usage
}, async ({ ws, debug }) => {
  // register a callback for any order snapshot that comes in (account orders)
  ws.onOrderSnapshot({}, (orders) => {
    debug(`order snapshot: ${JSON.stringify(orders, null, 2)}`)
  })

  await ws.open()
  debug('open')

  await ws.auth()
  debug('authenticated')

  // do something with authenticated ws stream
})<commit_msg>remove run_example in auth example<commit_after>'use strict'

const dotenv = require('dotenv')
const D = require('debug')
const WSv2 = require('../../lib/transports/ws2')
const debug = D('>')
debug.enabled = true

dotenv.config()
const { API_KEY, API_SECRET } = process.env

async function execute () {
  const ws = new WSv2({
    apiKey: API_KEY,
    apiSecret: API_SECRET
  })
  ws.on('error', e => debug('WSv2 error: %s', e.message | e))

  // register a callback for any order snapshot that comes in (account orders)
  ws.onOrderSnapshot({}, (orders) => {
    debug(`order snapshot: ${JSON.stringify(orders, null, 2)}`)
  })

  await ws.open()
  debug('open')

  await ws.auth()
  debug('authenticated')

  // do something with authenticated ws stream
}

execute()
{'fraction_non_alphanumeric': 0.15777439024390244, 'fraction_numerical': 0.005335365853658537, 'mean_word_length': 3.862962962962963, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3996359', 'n_tokens_mistral': 442, 'n_tokens_neox': 420, 'n_words': 126}