How to use bfx-api-mock-srv - 6 common examples

To help you get started, we’ve selected a few bfx-api-mock-srv examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bitfinexcom / bitfinex-api-node / test / lib / transports / ws2-unit.js View on Github external
it('automatically enables sequencing if seqAudit is true in constructor', (done) => {
    const wss = new MockWSv2Server()
    const ws = createTestWSv2Instance({
      seqAudit: true
    })

    wss._onClientMessage = (ws, msgJSON) => {
      const msg = JSON.parse(msgJSON)

      if (msg.event === 'conf' && msg.flags === 65536) {
        wss.close()
        done()
      }
    }

    ws.open()
  })
github bitfinexcom / bitfinex-api-node / test / lib / transports / ws2-integration.js View on Github external
it('keeps orders up to date', (done) => {
    const wss = new MockWSv2Server({ listen: true })
    const ws = createTestWSv2Instance()
    ws.on('open', ws.auth.bind(ws))

    ws.once('auth', () => {
      const o = new Order({
        gid: null,
        cid: 0,
        type: 'EXCHANGE LIMIT',
        price: 100,
        amount: 1,
        symbol: 'tBTCUSD'
      }, ws)

      o.registerListeners()

      o.submit().then(() => {
github bitfinexcom / bitfinex-api-node / test / lib / transports / ws2-unit.js View on Github external
it('_handleInfoEvent: closes & emits error if not on api v2', (done) => {
    const wss = new MockWSv2Server()
    const ws = createTestWSv2Instance()
    let seen = 0

    const d = () => {
      wss.close()
      done()
    }

    ws.once('open', () => {
      ws.on('error', () => { if (++seen === 2) { d() } })
      ws.on('close', () => { if (++seen === 2) { d() } })

      ws._handleInfoEvent({ version: 3 })
    })

    ws.open()
github bitfinexcom / bitfinex-api-node / test / lib / transports / ws2-integration.js View on Github external
it('tracks channel refs to auto sub/unsub', (done) => {
    const ws = createTestWSv2Instance()
    const wss = new MockWSv2Server()
    let subs = 0
    let unsubs = 0

    wss.on('message', (ws, msg) => {
      if (msg.event === 'subscribe' && msg.channel === 'trades') {
        subs++
        ws.send(JSON.stringify({
          event: 'subscribed',
          chanId: 42,
          channel: 'trades',
          symbol: msg.symbol
        }))
      } else if (msg.event === 'unsubscribe' && msg.chanId === 42) {
        unsubs++
        ws.send(JSON.stringify({
          event: 'unsubscribed',
github bitfinexcom / bitfinex-api-node / test / lib / transports / ws2-integration.js View on Github external
it('updateOrder: sends order changeset packet through', (done) => {
    const wss = new MockWSv2Server()
    const wsSingle = createTestWSv2Instance()
    wsSingle.open()
    wsSingle.on('open', wsSingle.auth.bind(wsSingle))
    wsSingle.once('auth', () => {
      const o = new Order({
        id: Date.now(),
        type: 'EXCHANGE LIMIT',
        price: 100,
        amount: 1,
        symbol: 'tBTCUSD'
      }, wsSingle)

      wsSingle._ws.send = (msgJSON) => {
        const msg = JSON.parse(msgJSON)

        assert.strictEqual(msg[0], 0)
github bitfinexcom / bitfinex-api-node / test / lib / transports / rest-2-integration.js View on Github external
it(`${name}: fetches expected data`, (done) => {
      const srv = new MockRESTv2Server({ listen: true })
      const r = getTestREST2()
      const nn = n++

      srv.setResponse(dataKey, [nn])

      args.push((err, res) => {
        if (err) {
          return srv.close().then(() => done(err)).catch(done)
        }

        assert.deepEqual(res, [nn])
        srv.close().then(done).catch(done)
      })

      r[name].apply(r, args)
    })

bfx-api-mock-srv

Bitfinex API server mock library

Apache-2.0
Latest version published 9 months ago

Package Health Score

56 / 100
Full package analysis