diff --git a/.babelrc b/.babelrc index 10266dd0..6a13c6a5 100644 --- a/.babelrc +++ b/.babelrc @@ -1,9 +1,13 @@ { "presets": [ - "env" + ["@babel/preset-env", { + "targets": { + "node": "8.3.0" + } + }] ], "plugins": [ - "transform-regenerator", - "transform-object-rest-spread" + "@babel/plugin-transform-regenerator", + "@babel/plugin-proposal-object-rest-spread" ] } diff --git a/.eslintrc.json b/.eslintrc.json index 04d5ccb6..71c4cbcb 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,6 +1,9 @@ { + "root": true, + "plugins": [ - "jsdoc" + "jsdoc", + "mocha" ], "env": { @@ -17,6 +20,7 @@ "plugin:import/errors", "plugin:import/warnings", "plugin:lodash/recommended", + "plugin:mocha/recommended", "plugin:jsdoc/recommended" ], @@ -25,11 +29,16 @@ }, "rules": { + "jsdoc/check-tag-names": 0, + "jsdoc/no-undefined-types": 0, "no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 1 }], "promise/no-callback-in-promise": 0, "lodash/prefer-lodash-method": 0, "lodash/prefer-noop": 0, "lodash/prefer-constant": 0, - "node/no-unpublished-require": 0 + "node/no-unpublished-require": 0, + "mocha/no-mocha-arrows": 0, + "mocha/no-setup-in-describe": 0, + "mocha/no-skipped-tests": 0 } } diff --git a/.gitignore b/.gitignore index c0a7bdb0..53dae3fb 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ coverage/ tags .undodir Session.vim +!./docs/jsdoc/.keep +./docs/jsdoc/ diff --git a/.istanbul.yml b/.istanbul.yml deleted file mode 100644 index 021978c6..00000000 --- a/.istanbul.yml +++ /dev/null @@ -1,53 +0,0 @@ -verbose: false -instrumentation: - root: . - extensions: - - .js - default-excludes: true - excludes: [] - embed-source: false - variable: __coverage__ - compact: true - preserve-comments: false - complete-copy: false - save-baseline: false - baseline-file: ./coverage/coverage-baseline.json - include-all-sources: false - include-pid: false -reporting: - print: summary - reports: - - lcov - dir: ./source/images/coverage - watermarks: - statements: [50, 80] - lines: [50, 80] - functions: [50, 80] - branches: [50, 80] - report-config: - clover: {file: clover.xml} - cobertura: {file: cobertura-coverage.xml} - json: {file: coverage-final.json} - json-summary: {file: coverage-summary.json} - lcovonly: {file: lcov.info} - teamcity: {file: null, blockName: Code Coverage Summary} - text: {file: null, maxCols: 0} - text-lcov: {file: lcov.info} - text-summary: {file: null} -hooks: - hook-run-in-context: false - post-require-hook: null - handle-sigint: false -check: - global: - statements: 0 - lines: 0 - branches: 0 - functions: 0 - excludes: [] - each: - statements: 0 - lines: 0 - branches: 0 - functions: 0 - excludes: [] diff --git a/.jsdoc.json b/.jsdoc.json deleted file mode 100644 index 44805c70..00000000 --- a/.jsdoc.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "tags": { - "allowUnknownTags": false, - "dictionaries": ["jsdoc"] - }, - "source": { - "include": ["lib", "LICENSE.md", "README.md"], - "includePattern": ".js$", - "excludePattern": "(node_modules/|docs)" - }, - "plugins": [ - "plugins/markdown" - ], - "templates": { - "cleverLinks": false, - "monospaceLinks": true, - "useLongnameInNav": false, - "showInheritedInNav": true - }, - "opts": { - "destination": "./docs/", - "encoding": "utf8", - "recurse": true, - "template": "./node_modules/docdash" - }, - "package": "" -} diff --git a/CHANGELOG b/CHANGELOG index edfb5d4d..db1ac21f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,8 @@ +4.0.15 +- meta: bump deps +- meta: normalize eslint config +- refactor: improve doclets + 4.0.14 - fix: README docs reference diff --git a/README.md b/README.md index 8ba72aac..5a1c1265 100644 --- a/README.md +++ b/README.md @@ -28,11 +28,11 @@ const ws = new WSv2({ transform: true }) ### Docs -Refer to the [`docs/`](https://cdn.statically.io/gh/bitfinexcom/bitfinex-api-node/master/docs/index.html) -folder for JSDoc-generated HTML documentation, and the [`examples/`](/examples) -folder for executable examples covering common use cases. +API documentation can be found in [`docs/reference.md`](docs/reference.md), and +examples in the [`examples`](examples) folder. -Official API documentation at [https://docs.bitfinex.com/v2/reference](https://docs.bitfinex.com/v2/reference) +Complete API documentation can be found at +[docs.bitfinex.com/v2/reference](https://docs.bitfinex.com/v2/reference) ### Examples diff --git a/docs/.keep b/docs/.keep new file mode 100644 index 00000000..e69de29b diff --git a/docs/WS2Manager.html b/docs/WS2Manager.html deleted file mode 100644 index a996742b..00000000 --- a/docs/WS2Manager.html +++ /dev/null @@ -1,5095 +0,0 @@ - - - - - - WS2Manager - Documentation - - - - - - - - - - - - - - - - - - - -
- -

WS2Manager

- - - - - - - -
- -
- -

- WS2Manager -

- -

Provides a wrapper around the WSv2 class, opening new sockets when a -subscription would push a single socket over the data channel limit.

-

For more complex operations, grab a socket reference with getSocket() or -getFreeDataSocket(), or create a new WSv2 instance manually

- - -
- -
- -
- - - - -

Constructor

- - -

new WS2Manager(socketArgs, authArgsopt)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - -
Example
- -
const rest = new RESTv2()
-const details = await rest.symbolDetails()
-const symbols = details.map(d => `t${d.pair.toUpperCase()}`)
-const timeFrames = ['1m', '5m', '30m', '1h', '6h']
-const keys = _flatten(symbols.map(s => {
-  return timeFrames.map(tf => `trade:${tf}:${s}`)
-}))
-
-const m = new Manager()
-
-m.on('error', (err) => {
-  debug('error: %s', err)
-})
-
-m.once('open', () => {
-  debug('open')
-
-  keys.forEach(key => {
-    m.subscribeCandles(key)
-    m.onCandle({ key }, (candles) => {
-      debug('recv %d candles on channel %s', candles.length, key)
-    })
-  })
-
-  symbols.forEach(symbol => {
-    m.subscribeTrades(symbol)
-    m.onTrades({ symbol }, (trades) => {
-      debug('recv %d trades on channel %s', trades.length, symbol)
-    })
-  })
-
-  symbols.forEach(symbol => {
-    m.subscribeTicker(symbol)
-    m.onTicker({ symbol }, (ticker) => {
-      debug('recv ticker on channel %s: %j', symbol, ticker)
-    })
-  })
-
-  symbols.forEach(symbol => {
-    m.subscribeOrderBook(symbol)
-    m.onOrderBook({ symbol }, (update) => {
-      debug('recv book update on channel %s: %j', symbol, update)
-    })
-  })
-
-  setInterval(() => {
-    debug('num keys: %d', keys.length)
-    debug('num sockets: %d', m.getNumSockets())
-    debug('socket info: %j', m.getSocketInfo())
-  }, 5000)
-})
-
-m.openSocket()
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
socketArgs - - -object - - - - - - - - - -

passed to WSv2 constructors

authArgs - - -object - - - - - - <optional>
- - - - - -

cached for all internal socket auth() calls

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
calc - - -object - - - - - - <optional>
- - - - - -

default 0

dms - - -object - - - - - - <optional>
- - - - - -

default 0

- -
- - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -

Methods

- - - - - - -

(static) getDataChannelCount(s) → {number}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
s - - -object - - - -

socket state

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

count - # of subscribed/pending data channels

-
- - - -
-
- Type -
-
- -number - - -
-
- - - - - - - - - - -

auth(args)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Authenticates all existing & future sockets with the provided credentials. -Does nothing if an apiKey/apiSecret pair are already known.

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
args - - -object - - - -

arguments

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
apiKey - - -object - - - - - - - - - -

saved if not already provided

apiSecret - - -object - - - - - - - - - -

saved if not already provided

calc - - -object - - - - - - <optional>
- - - - - -

default 0

dms - - -object - - - - - - <optional>
- - - - - -

dead man switch, active 4

- -
- - - - - - - - - - - - - - - - - - - - - - - - -

(async) close() → {Promise}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Closes all open sockets

-
- - - - - - - - - - - - - - - - - - - - - - - - - -
Returns:
- - -
-

p

-
- - - -
-
- Type -
-
- -Promise - - -
-
- - - - - - - - - - -

getAuthArgs() → {object}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Retrieve internal authentication arguments

-
- - - - - - - - - - - - - - - - - - - - - - - - - -
Returns:
- - -
-

args

-
- - - -
-
- Type -
-
- -object - - -
-
- - - - - - - - - - -

getAuthenticatedSocket() → {object}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Returns:
- - -
-

state

-
- - - -
-
- Type -
-
- -object - - -
-
- - - - - - - - - - -

getFreeDataSocket() → {object}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Returns the first socket that has less active/pending channels than the -DATA_CHANNEL_LIMIT

-
- - - - - - - - - - - - - - - - - - - - - - - - - -
Returns:
- - -
-

state - undefined if none found

-
- - - -
-
- Type -
-
- -object - - -
-
- - - - - - - - - - -

getNumSockets() → {number}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Returns:
- - -
-

n

-
- - - -
-
- Type -
-
- -number - - -
-
- - - - - - - - - - -

getSocket(i) → {object}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
i - - -number - - - -

index into pool

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

state

-
- - - -
-
- Type -
-
- -object - - -
-
- - - - - - - - - - -

getSocketInfo() → {Array.<object>}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Returns an object which can be logged to inspect the socket pool

-
- - - - - - - - - - - - - - - - - - - - - - - - - -
Returns:
- - -
-

socketInfo

-
- - - -
-
- Type -
-
- -Array.<object> - - -
-
- - - - - - - - - - -

getSocketWithChannel(chanId) → {object}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

NOTE: Cannot filter against pending subscriptions, due to unknown chanId

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
chanId - - -number - - - -

channel ID

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

wsState - undefined if not found

-
- - - -
-
- Type -
-
- -object - - -
-
- - - - - - - - - - -

getSocketWithDataChannel(type, filter) → {object}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Returns the first socket that is subscribed/pending sub to the specified -channel.

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
type - - -string - - - -

i.e. 'book'

filter - - -object - - - -

i.e. { symbol: 'tBTCUSD', prec: 'R0' }

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

wsState - undefined if not found

-
- - - -
-
- Type -
-
- -object - - -
-
- - - - - - - - - - -

getSocketWithSubRef(channel, identifier) → {object}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
channel - - -string - - - -

channel type

identifier - - -string - - - -

unique channel identifier

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

wsState - undefined if not found

-
- - - -
-
- Type -
-
- -object - - -
-
- - - - - - - - - - -

managedUnsubscribe(channel, identifier)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
channel - - -string - - - -

channel type

identifier - - -string - - - -

unique channel identifier

- - - - - - - - - - - - - - - - - - - - - - - - -

onCandle(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
key - - -string - - - - - - - - - -

candle set key, i.e. trade:30m:tBTCUSD

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - -
Throws:
- - - -
- -

an error if no data socket is available

- -
- - - - - - - - - - - - - -

onOrderBook(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - - - - -

order book symbol

prec - - -string - - - - - - <optional>
- - - - - -

precision, i.e. 'R0', default 'P0'

len - - -string - - - - - - <optional>
- - - - - -

length, default '25'

freq - - -string - - - - - - <optional>
- - - - - -

default 'F0'

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - -
Throws:
- - - -
- -

an error if no data socket is available

- -
- - - - - - - - - - - - - -

onTicker(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol for ticker

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - -
Throws:
- - - -
- -

an error if no data socket is available

- -
- - - - - - - - - - - - - -

onTrades(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol for trades

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - -
Throws:
- - - -
- -

an error if no data socket is available

- -
- - - - - - - - - - - - - -

openSocket() → {object}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Creates a new socket/state instance and adds it to the internal pool. Binds -event listeners to forward via our own event emitter, and to manage pending -subs/unsubs.

-
- - - - - - - - - - - - - - - - - - - - - - - - - -
Returns:
- - -
-

state

-
- - - -
-
- Type -
-
- -object - - -
-
- - - - - - - - - - -

(async) reconnect() → {Promise}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Reconnects all open sockets

-
- - - - - - - - - - - - - - - - - - - - - - - - - -
Returns:
- - -
-

p

-
- - - -
-
- Type -
-
- -Promise - - -
-
- - - - - - - - - - -

setAuthArgs(args)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Update authentication arguments on all sockets

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
args - - -object - - - -

arguments

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
calc - - -object - - - - - - <optional>
- - - - - -

calc value

dms - - -object - - - - - - <optional>
- - - - - -

active 4

- -
- - - - - - - - - - - - - - - - - - - - - - - - -

subscribe(type, ident, filter)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Subscribes a free data socket if available to the specified channel, or -opens a new socket & subs if needed.

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
type - - -string - - - -

i.e. 'book'

ident - - -string - - - -

i.e. 'tBTCUSD'

filter - - -object - - - -

i.e. { symbol: 'tBTCUSD', prec: 'R0' }

- - - - - - - - - - - - - - - - - - - - - - - - -

subscribeCandles(key)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
key - - -string - - - -

candle channel key

- - - - - - - - - - - - - - - - - - - - - - - - -

subscribeOrderBook(symbol, precopt, lenopt, freqopt)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDefaultDescription
symbol - - -string - - - - - - - - - - - -

symbol for order book

prec - - -string - - - - - - <optional>
- - - - - -
- - P0 - -

precision, i.e. 'R0', default 'P0'

len - - -string - - - - - - <optional>
- - - - - -
- - 25 - -

length, default '25'

freq - - -string - - - - - - <optional>
- - - - - -
- - F0 - -

default 'F0'

- - - - - - - - - - - - - - - - - - - - - - - - -

subscribeTicker(symbol)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
symbol - - -string - - - -

symbol for ticker

- - - - - - - - - - - - - - - - - - - - - - - - -

subscribeTrades(symbol)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
symbol - - -string - - - -

symbol for trades

- - - - - - - - - - - - - - - - - - - - - - - - -

unsubscribe(chanId)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Unsubscribes the first socket w/ the specified channel. Does nothing if no -such socket is found.

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
chanId - - -number - - - -

channel ID

- - - - - - - - - - - - - - - - - - - - - - - - -

withAllSockets(cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Calls the provided cb with all internal socket instances

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - - - - - -
- -
- - - - - - - - - - - \ No newline at end of file diff --git a/docs/WSv2.html b/docs/WSv2.html deleted file mode 100644 index a2af9c3a..00000000 --- a/docs/WSv2.html +++ /dev/null @@ -1,40069 +0,0 @@ - - - - - - WSv2 - Documentation - - - - - - - - - - - - - - - - - - - -
- -

WSv2

- - - - - - - -
- -
- -

- WSv2 -

- - -
- -
- -
- - - - - -

new WSv2(optsopt)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Instantiate a new ws2 transport. Does not auto-open

-
- - - - - - - - - -
Example
- -
const ws = new WSv2()
-
-  ws.on('open', async () => {
-    ws.onTrades({ symbol: 'tBTCUSD' }, (trades) => {
-      console.log('recv trades: %j', trades)
-    })
-
-    await ws.subscribeTrades('tBTCUSD')
-  })
-
-  await ws.open()
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
opts - - -object - - - - - - <optional>
- - - - - -

instance options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
affCode - - -string - - - - - - <optional>
- - - - - -

affiliate code to be applied to all orders

apiKey - - -string - - - - - - <optional>
- - - - - -

API key

apiSecret - - -string - - - - - - <optional>
- - - - - -

API secret

url - - -string - - - - - - <optional>
- - - - - -

ws connection url, defaults to WSv2#url

orderOpBufferDelay - - -number - - - - - - <optional>
- - - - - -

multi-order op batching timeout

transform - - -boolean - - - - - - <optional>
- - - - - -

if true, packets are converted to models

agent - - -object - - - - - - <optional>
- - - - - -

optional node agent for ws connection (proxy)

manageOrderBooks - - -boolean - - - - - - <optional>
- - - - - -

enable local OB persistence

manageCandles - - -boolean - - - - - - <optional>
- - - - - -

enable local candle persistence

seqAudit - - -boolean - - - - - - <optional>
- - - - - -

enable sequence numbers & verification

autoReconnect - - -boolean - - - - - - <optional>
- - - - - -

if true, we will reconnect on close

reconnectDelay - - -number - - - - - - <optional>
- - - - - -

optional, defaults to 1000 (ms)

reconnectThrottler - - -PromiseThrottle - - - - - - <optional>
- - - - - -

optional pt to limit reconnect freq

packetWDDelay - - -number - - - - - - <optional>
- - - - - -

watch-dog forced reconnection delay

- -
- - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -

Members

- - - -

(constant) WSv2.flags

- - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
Properties:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
DEC_S - - -number - - - -

flag to request all decimals as strings

TIME_S - - -number - - - -

flag to request all timestamps as strings

TIMESTAMP - - -number - - - -

flag to request timestamp in milliseconds

SEQ_ALL - - -number - - - -

flag to enable sequence numbers & verification

CHECKSUM - - -number - - - -

flag to enable order book checksums

- - - - - - -
-

Map of flag names and numeric values for usage with the API

-
- - - - - - - - - - -

(constant) WSv2.info

- - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
Properties:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
SERVER_RESTART - - -number - - - -

server restart event

MAINTENANCE_START - - -number - - - -

maintenance start event

MAINTENANCE_END - - -number - - - -

maintenance end event

- - - - - - -
-

Map of info event names and their respective codes for usage with the API

-
- - - - - - - - - - -

(constant) WSv2.url :string

- - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - -
Default Value:
-
    -
  • wss://api.bitfinex.com/ws/2
  • -
- - - - - - - -
- - - - - -
-

Default connection URL

-
- - - -
Type:
-
    -
  • - -string - - -
  • -
- - - - - - - - - - -

Methods

- - - - - - -

(async) auth(calcnullable, dmsnullable) → {Promise}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Generates & sends an authentication packet to the server; if already -authenticated, rejects with an error, resolves on success.

-

If a DMS flag of 4 is provided, all open orders are cancelled when the -connection terminates.

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
calc - - -number - - - - - - - - <nullable>
- - - -

optional, default is 0

dms - - -number - - - - - - - - <nullable>
- - - -

optional dead man switch flag, active 4

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

p

-
- - - -
-
- Type -
-
- -Promise - - -
-
- - - - - - - - - - -

(async) cancelOrder(order) → {Promise}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Cancels an order by ID and resolves the returned promise once the cancel is -confirmed. Emits an error if not authenticated. The ID can be passed as a -number, or taken from an order array/object.

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
order - - -object -| - -Array -| - -number - - - -

order model, array, or ID to be cancelled

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

p

-
- - - -
-
- Type -
-
- -Promise - - -
-
- - - - - - - - - - -

(async) cancelOrders(orders) → {Promise}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Cancels multiple orders, returns a promise that resolves once all -operations are confirmed.

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
orders - - -Array.<object> -| - -Array.<Array> -| - -Array.<number> - - - -

array of order models, arrays -or IDs to be cancelled

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

p

-
- - - -
-
- Type -
-
- -Promise - - -
-
- - - - - - - - - - -

(async) close(code, reason) → {Promise}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Closes the active connection. If there is none, rejects with a promise. -Resolves on success

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
code - - -number - - - -

passed to ws

reason - - -string - - - -

passed to ws

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

p

-
- - - -
-
- Type -
-
- -Promise - - -
-
- - - - - - - - - - -

(async) enableFlag(flag) → {Promise}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
-
    -
  • WSv2#flags
  • -
-
- - - -
- - - - - -
-

Enables a configuration flag.

-
- - - - - - - - - -
Example
- -
const ws = new WSv2()
-
-ws.on('open', async () => {
-  await ws.enableFlag(WSv2.flags.CHECKSUM)
-  console.log('ob checkums enabled')
-})
-
-await ws.open()
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
flag - - -number - - - -

flag to update, as numeric value

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

p

-
- - - -
-
- Type -
-
- -Promise - - -
-
- - - - - - - - - - -

(async) enableSequencing(args) → {Promise}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
-
    -
  • WSv2#flags
  • -
-
- - - -
- - - - - -
-

Configures the seq flag to enable sequencing (packet number) for this -connection. When enabled, the seq number will be the last value of -channel packet arrays.

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
args - - -object - - - -

params

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
audit - - -boolean - - - - - - <optional>
- - - - - -

if true, an error is emitted on invalid seq

- -
- - - - - - - - - - - - - - - - -
Returns:
- - -
-

p

-
- - - -
-
- Type -
-
- -Promise - - -
-
- - - - - - - - - - -

getAuthArgs() → {object}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Fetch the current default auth parameters

-
- - - - - - - - - - - - - - - - - - - - - - - - - -
Returns:
- - -
-

authArgs

-
- - - -
-
- Type -
-
- -object - - -
-
- - - - - - - - - - -

getCandles(key) → {Array}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Fetch a reference to the full set of synced candles for the specified key. -Set managedCandles: true in the constructor to use.

-
- - - - - - - - - -
Example
- -
const ws = new WSv2({ managedCandles: true })
-
-  ws.on('open', async () => {
-      ws.onCandles({ key: 'trade:1m:tBTCUSD' }, () => {
-        const candles = ws.getCandles('trade:1m:tBTCUSD')
-
-        if (!candles) return
-
-        console.log('%d candles in dataset', candles.length)
-      })
-
-      ws.subscribeCandles({ key: 'trade:1m:tBTCUSD' })
-  })
-
-  await ws.open()
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
key - - -string - - - -

key for candle set

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

candles - empty array if none exist

-
- - - -
-
- Type -
-
- -Array - - -
-
- - - - - - - - - - -

getChannelData(opts) → {object}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Fetch a channel definition

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
chanId - - -number - - - - - - - - - -

channel ID

channel - - -string - - - - - - - - - -

channel name

symbol - - -string - - - - - - <optional>
- - - - - -

match by symbol

key - - -string - - - - - - <optional>
- - - - - -

match by key (for candle channels)

- -
- - - - - - - - - - - - - - - - -
Returns:
- - -
-

chanData - null if not found

-
- - - -
-
- Type -
-
- -object - - -
-
- - - - - - - - - - -

getDataChannelCount() → {number}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Get the total number of data channels this instance is currently -subscribed too.

-
- - - - - - - - - - - - - - - - - - - - - - - - - -
Returns:
- - -
-

count

-
- - - -
-
- Type -
-
- -number - - -
-
- - - - - - - - - - -

getDataChannelId(type, filter) → {number}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Fetch the ID of a channel matched by type and channel data filter

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
type - - -string - - - -

channel type

filter - - -object - - - -

to be matched against channel data

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

channelID

-
- - - -
-
- Type -
-
- -number - - -
-
- - - - - - - - - - -

getLosslessOB(symbol) → {OrderBook}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Returns an up-to-date lossless copy of the order book for the specified symbol, or -null if no OB is managed for that symbol. All amounts and prices are in original -string format.

-

Set manageOrderBooks: true in the constructor to use.

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
symbol - - -string - - - -

symbol for order book

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

ob - null if not found

-
- - - -
-
- Type -
-
- -OrderBook - - -
-
- - - - - - - - - - -

getOB(symbol) → {OrderBook}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Returns an up-to-date copy of the order book for the specified symbol, or -null if no OB is managed for that symbol.

-

Set managedOrderBooks: true in the constructor to use.

-
- - - - - - - - - -
Example
- -
const ws = new WSv2({ managedOrderBooks: true })
-
-  ws.on('open', async () => {
-      ws.onOrderBook({ symbol: 'tBTCUSD' }, () => {
-        const book = ws.getOB('tBTCUSD')
-
-        if (!book) return
-
-        const spread = book.midPrice()
-        console.log('spread for tBTCUSD: %f', spread)
-      })
-
-      ws.subscribeOrderBook({ symbol: 'tBTCUSD' })
-  })
-
-  await ws.open()
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
symbol - - -string - - - -

symbol for order book

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

ob - null if not found

-
- - - -
-
- Type -
-
- -OrderBook - - -
-
- - - - - - - - - - -

getURL() → {string}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Returns:
- - -
-

url

-
- - - -
-
- Type -
-
- -string - - -
-
- - - - - - - - - - -

hasChannel(chanId) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Check if the instance is subscribed to the specified channel ID

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
chanId - - -number - - - -

ID of channel to query

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

isSubscribed

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

hasDataChannel(type, filter) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Check if the instance is subscribed to a data channel matching the -specified type and filter.

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
type - - -string - - - -

channel type

filter - - -object - - - -

to be matched against channel data

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

hasChannel

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

hasSubscriptionRef(channel, identifier) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Check if a channel/identifier pair has been subscribed too

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
channel - - -string - - - -

channel type

identifier - - -string - - - -

unique identifier for the reference

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

hasRef

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

isAuthenticated() → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Returns:
- - -
-

authenticated

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

isFlagEnabled(flag) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
-
    -
  • enableFlag
  • -
-
- - - -
- - - - - -
-

Checks local state, relies on successful server config responses

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
flag - - -number - - - -

flag to check for

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

enabled

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

isOpen() → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Returns:
- - -
-

open

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

isReconnecting() → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Returns:
- - -
-

reconnecting

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

managedSubscribe(channel, identifier, payload) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
To Do:
-
-
    -
  • will be refactored to return promise from subscribe() call instead - of sub action taken flag
  • -
-
- -
- - - - - -
-

Subscribes and tracks subscriptions per channel/identifier pair. If -already subscribed to the specified pair, nothing happens.

-
- - - - - - - - - -
Example
- -
const ws = new WSv2()
-
-ws.on('open', async () => {
-  ws.onTrades({ symbol: 'tBTCUSD' }, (trades) => {
-    console.log('recv trades: %j', trades)
- })
-
-  ws.managedSubscribe('trades', 'tBTCUSD', { symbol: 'tBTCUSD' })
-})
-
-await ws.open()
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
channel - - -string - - - -

channel name

identifier - - -string - - - -

for uniquely identifying the ref count

payload - - -object - - - -

merged with sub packet

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

subSent

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

managedUnsubscribe(channel, identifier) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Decreases the subscription ref count for the channel/identifier pair, and -unsubscribes from the channel if it reaches 0.

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
channel - - -string - - - -

channel name

identifier - - -string - - - -

for uniquely identifying the ref count

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

unsubSent

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

notifyUI(opts)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Sends a broadcast notification, which will be received by any active UI -websocket connections (at bitfinex.com), triggering a desktop notification.

-

In the future our mobile app will also support spawning native push -notifications in response to incoming ucm-notify-ui packets.

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
message - - -string - - - - - - <optional>
- - - - - -

message to display

type - - -string - - - - - - <optional>
- - - - - -

notification type, 'ucm-*' for broadcasts

level - - -string - - - - - - <optional>
- - - - - -

'info', 'error', or 'success'

image - - -string - - - - - - <optional>
- - - - - -

link to an image to be shown

link - - -string - - - - - - <optional>
- - - - - -

URL the notification should forward too

sound - - -string - - - - - - <optional>
- - - - - -

URL of sound to play

- -
- - - - - - - - - - - - - - -
Throws:
- - - -
- -

an error if given no type or message, or the instance is not open -and authenticated

- -
- - - - - - - - - - - - - -

onAccountTradeEntry(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each personal trade 'te' event

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
pair - - -string - - - - - - <optional>
- - - - - -

required if no symbol specified

symbol - - -string - - - - - - <optional>
- - - - - -

required if no pair specified

cbGID - - -string -| - -number - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onAccountTradeUpdate(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each personal trade 'tu' event

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
pair - - -string - - - - - - <optional>
- - - - - -

required if no symbol specified

symbol - - -string - - - - - - <optional>
- - - - - -

required if no pair specified

cbGID - - -string -| - -number - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onBalanceInfoUpdate(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each balance info update

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onCandle(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called with each received candle

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
key - - -string - - - - - - - - - -

candle set key, i.e. trade:30m:tBTCUSD

cbGID - - -string -| - -number - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onFundingCreditClose(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called when a funding credit is closed

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onFundingCreditNew(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called when a funding credit is created

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onFundingCreditSnapshot(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each funding credit snapshot (sent on -auth)

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onFundingCreditUpdate(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called when a funding credit is updated

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onFundingInfoUpdate(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each funding info update

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onFundingLoanClose(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called when a funding loan is closed

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onFundingLoanNew(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called when a funding loan is created

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onFundingLoanSnapshot(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each funding loan snapshot (sent on -auth)

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onFundingLoanUpdate(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called when a funding loan is updated

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onFundingOfferClose(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called when a funding offer is closed

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onFundingOfferNew(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called when a funding offer is created

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onFundingOfferSnapshot(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each fundign offer snapshot (sent on -auth)

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onFundingOfferUpdate(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called when a funding offer is updated

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onFundingTradeEntry(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each funding trade 'te' event

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onFundingTradeUpdate(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each funding trade 'tu' event

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onInfoMessage(code, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Registers a new callback to be called when a matching info message is -received.

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
code - - -number - - - -

from #WSv2.info

cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onMaintenanceEnd(cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Register a callback to be notified of a maintenance period ending

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
cb - - -function - - - -

called on event trigger

- - - - - - - - - - - - - - - - - - - - - - - - -

onMaintenanceStart(cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Register a callback in case of a 'maintenance started' message from the -server. This is a good time to pause server packets until maintenance ends

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
cb - - -function - - - -

called on event trigger

- - - - - - - - - - - - - - - - - - - - - - - - -

onMarginInfoUpdate(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each margin info update

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onMessage(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Register a generic handler to be called with each received message

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
cbGID - - -string -| - -number - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onNotification(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each notification

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
type - - -string - - - - - - <optional>
- - - - - -

type to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onOrderBook(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called with each received candle

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - - - - -

book symbol

prec - - -string - - - - - - - - - -

book precision, i.e. 'R0'

len - - -string - - - - - - - - - -

book length, i.e. '25'

cbGID - - -string -| - -number - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onOrderBookChecksum(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called with each received order book checksum

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - - - - -

book symbol

prec - - -string - - - - - - - - - -

book precision, i.e. 'R0'

len - - -string - - - - - - - - - -

book length, i.e. '25'

cbGID - - -string -| - -number - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onOrderClose(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each order close packet

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

id - - -number - - - - - - <optional>
- - - - - -

order ID to match

cid - - -number - - - - - - <optional>
- - - - - -

order client ID to match

gid - - -number - - - - - - <optional>
- - - - - -

order group ID to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onOrderNew(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each new order packet

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

id - - -number - - - - - - <optional>
- - - - - -

order ID to match

cid - - -number - - - - - - <optional>
- - - - - -

order client ID to match

gid - - -number - - - - - - <optional>
- - - - - -

order group ID to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onOrderSnapshot(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each full order snapshot (sent on auth)

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

id - - -number - - - - - - <optional>
- - - - - -

order ID to match

cid - - -number - - - - - - <optional>
- - - - - -

order client ID to match

gid - - -number - - - - - - <optional>
- - - - - -

order group ID to match

cbGID - - -string -| - -number - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onOrderUpdate(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each order update packet

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

id - - -number - - - - - - <optional>
- - - - - -

order ID to match

cid - - -number - - - - - - <optional>
- - - - - -

order client ID to match

gid - - -number - - - - - - <optional>
- - - - - -

order group ID to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onPositionClose(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called when a position is closed

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onPositionNew(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called when a position is opened

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onPositionSnapshot(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each position snapshot (sent on auth)

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onPositionUpdate(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called when a position is updated

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onServerRestart(cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Register a callback in case of a ws server restart message; Use this to -call reconnect() if needed. (code 20051)

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
cb - - -function - - - -

called on event trigger

- - - - - - - - - - - - - - - - - - - - - - - - -

onStatus(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each message for the desired status -feed.

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
key - - -string - - - - - - - - - -

key of feed to listen on

cbGID - - -string -| - -number - - - - - - <optional>
- - - - - -

callback group ID

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onTicker(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each received ticker

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - - - - -

symbol for tickers

cbGID - - -string -| - -number - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onTradeEntry(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each trade 'te' event

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
pair - - -string - - - - - - <optional>
- - - - - -

required if no symbol specified

symbol - - -string - - - - - - <optional>
- - - - - -

required if no pair specified

cbGID - - -string -| - -number - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onTrades(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called with each received trade (pair or symbol -required)

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
pair - - -string - - - - - - <optional>
- - - - - -

required if no symbol specified

symbol - - -string - - - - - - <optional>
- - - - - -

required if no pair specified

cbGID - - -string -| - -number - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onWalletSnapshot(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each wallet snapshot (sent on auth)

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onWalletUpdate(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each wallet update

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

(async) open() → {Promise}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Opens a connection to the API server. Rejects with an error if a -connection is already open. Resolves on success.

-
- - - - - - - - - - - - - - - - - - - - - - - - - -
Returns:
- - -
-

p

-
- - - -
-
- Type -
-
- -Promise - - -
-
- - - - - - - - - - -

(async) reconnect() → {Promise}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Utility method to close & re-open the ws connection. Re-authenticates if -previously authenticated

-
- - - - - - - - - - - - - - - - - - - - - - - - - -
Returns:
- - -
-

p - resolves on completion

-
- - - -
-
- Type -
-
- -Promise - - -
-
- - - - - - - - - - -

removeListeners(cbGID)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Remove all listeners by callback group ID

-
- - - - - - - - - -
Example
- -
await ws.subscribeTrades({ symbol: 'tBTCUSD', cbGID: 42 })
-await ws.subscribeTrades({ symbol: 'tLEOUSD', cbGID: 42 })
-await ws.subscribeTrades({ symbol: 'tETHUSD', cbGID: 42 })
-
-// ...
-
-ws.removeListeners(42)
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
cbGID - - -string - - - -

callback group to remove

- - - - - - - - - - - - - - - - - - - - - - - - -

requestCalc(prefixes)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Request a calc operation to be performed on the specified indexes

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
prefixes - - -Array.<string> - - - -

desired prefixes to be calculated

- - - - - - - - - - - - - - - - - - - - - - - - -

send(msg)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Send a packet to the WS server

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
msg - - -* - - - -

packet, gets stringified

- - - - - - - - - - - - - - - - - - - - - - - - -

sequencingEnabled() → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Returns:
- - -
-

sequencingEnabled

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

setAPICredentials(apiKey, apiSecret)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Update the internal API credentials, used on subsequent WSv2#auth -calls

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
apiKey - - -string - - - -

API key

apiSecret - - -string - - - -

API secret

- - - - - - - - - - - - - - - - - - - - - - - - -

(async) submitOrder(order) → {Promise}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Sends a new order to the server and resolves the returned promise once the -order submit is confirmed. Emits an error if not authenticated. The order -can be either an array, key/value map, or Order object instance.

-
- - - - - - - - - -
Example
- -
const o = new Order({
-  type: Order.type.EXCHANGE_LIMIT,
-  amount: 18,
-  price: 0.75,
-  symbol: 'tBTCUSD',
-  hidden: true
-}, ws)
-
-await ws.submitOrder(o)
-
-console.log('order confirmed! status: %s', o.status)
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
order - - -object -| - -Array - - - -

order object model or array

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

p - resolves on submit notification

-
- - - -
-
- Type -
-
- -Promise - - -
-
- - - - - - - - - - -

(async) submitOrderMultiOp(opPayloads) → {Promise}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Sends the op payloads to the server as an 'ox_multi' command. A promise is -returned and resolves immediately if authenticated, as no confirmation is -available for this message type.

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opPayloads - - -Array.<object> - - - -

order operations

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

p - rejects if not authenticated

-
- - - -
-
- Type -
-
- -Promise - - -
-
- - - - - - - - - - -

subscribe(channel, payload)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Subscribe to a channel with the given filter payload

-
- - - - - - - - - -
Example
- -
const ws = new WSv2()
-
-ws.on('open', () => {
-  ws.onTrades({ symbol: 'tBTCUSD' }, (trades) => {
-    // ...
-  })
-
-  ws.subscribe('trades', { symbol: 'tBTCUSD' })
-})
-
-await ws.open()
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
channel - - -string - - - -

channel payload/data

payload - - -object - - - -

optional extra packet data

- - - - - - - - - - - - - - - - - - - - - - - - -

(async) subscribeCandles(key) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Subscribe to a candle data channel

-
- - - - - - - - - -
Example
- -
await ws.subscribeCandles('trade:5m:tBTCUSD')
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
key - - -string - - - -

'trade:5m:tBTCUSD'

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

subscribed

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

(async) subscribeOrderBook(symbol, prec, len) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Subscribe to an order book data channel

-
- - - - - - - - - -
Example
- -
await ws.subscribeOrderBook('tBTCUSD', 'R0', '25')
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDefaultDescription
symbol - - -string - - - - - -

symbol of order book

prec - - -string - - - - - - P0 - -

P0, P1, P2, or P3 (default P0)

len - - -string - - - - - - 25 - -

25 or 100 (default 25)

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

subscribed

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

(async) subscribeStatus(key) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Subscribe to a status data channel

-
- - - - - - - - - -
Example
- -
await ws.subscribeStatus('liq:global')
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
key - - -string - - - -

i.e. 'liq:global'

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

subscribed

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

(async) subscribeTicker(symbol) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Subscribe to a ticker data channel

-
- - - - - - - - - -
Example
- -
await ws.subscribeTicker('tBTCUSD')
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
symbol - - -string - - - -

symbol of ticker

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

subscribed

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

(async) subscribeTrades(symbol) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Subscribe to a trades data channel

-
- - - - - - - - - -
Example
- -
await ws.subscribeTrades('tBTCUSD')
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
symbol - - -string - - - -

symbol of market to monitor

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

subscribed

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

unsubscribe(chanId)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Unsubscribe from a channel by ID

-
- - - - - - - - - -
Example
- -
const id = ws.getDataChannelId('ticker', { symbol: 'tBTCUSD' })
-
-if (id) {
-  ws.unsubscribe(id)
-}
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
chanId - - -number - - - -

ID of channel to unsubscribe from

- - - - - - - - - - - - - - - - - - - - - - - - -

(async) unsubscribeCandles(symbol, frame) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - - - - - - - - - -
Example
- -
await ws.unsubscribeCandles('tBTCUSD', '1m')
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
symbol - - -string - - - -

symbol of candles

frame - - -string - - - -

time frame

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

unsubscribed

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

(async) unsubscribeOrderBook(symbol) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Unsubscribe from an order book data channel

-
- - - - - - - - - -
Example
- -
await ws.unsubcribeOrderBook('tBTCUSD')
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
symbol - - -string - - - -

symbol of order book

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

unsubscribed

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

(async) unsubscribeStatus(key) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
key - - -string - - - -

key that was used in initial WSv2#subscribeStatus call

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

unsubscribed

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

(async) unsubscribeTicker(symbol) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Unsubscribe from a ticker data channel

-
- - - - - - - - - -
Example
- -
await ws.unsubscribeTicker('tBTCUSD')
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
symbol - - -string - - - -

symbol of ticker

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

unsubscribed

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

(async) unsubscribeTrades(symbol) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Unsubscribe from a trades data channel

-
- - - - - - - - - -
Example
- -
await ws.unsubcribeTrades('tBTCUSD')
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
symbol - - -string - - - -

symbol of market to unsubscribe from

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

unsubscribed

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

updateAuthArgs(args)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Set calc and dms values to be used on the next WSv2#auth call

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
args - - -object - - - -

arguments

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
calc - - -number - - - - - - <optional>
- - - - - -

calc value

dms - - -number - - - - - - <optional>
- - - - - -

dms value, active 4

- -
- - - - - - - - - - - - - - - - - - - - - - - - -

(async) updateOrder(changes) → {Promise}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Send a changeset to update an order in-place while maintaining position in -the price queue. The changeset must contain the order ID, and supports a -'delta' key to increase/decrease the total amount.

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
changes - - -object - - - -

requires at least an 'id'

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

p - resolves on receiving an confirmation notification

-
- - - -
-
- Type -
-
- -Promise - - -
-
- - - - - - - - - - -

usesAgent() → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Returns:
- - -
-

usesAgent

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - - -
- -
- - - - - - - -
- -
- -

- WSv2 -

- -

Communicates with v2 of the Bitfinex WebSocket API

- - -
- -
- -
- - - - -

Constructor

- - -

new WSv2()

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -

Members

- - - -

(constant) WSv2.flags

- - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
Properties:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
DEC_S - - -number - - - -

flag to request all decimals as strings

TIME_S - - -number - - - -

flag to request all timestamps as strings

TIMESTAMP - - -number - - - -

flag to request timestamp in milliseconds

SEQ_ALL - - -number - - - -

flag to enable sequence numbers & verification

CHECKSUM - - -number - - - -

flag to enable order book checksums

- - - - - - -
-

Map of flag names and numeric values for usage with the API

-
- - - - - - - - - - -

(constant) WSv2.info

- - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
Properties:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
SERVER_RESTART - - -number - - - -

server restart event

MAINTENANCE_START - - -number - - - -

maintenance start event

MAINTENANCE_END - - -number - - - -

maintenance end event

- - - - - - -
-

Map of info event names and their respective codes for usage with the API

-
- - - - - - - - - - -

(constant) WSv2.url :string

- - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - -
Default Value:
-
    -
  • wss://api.bitfinex.com/ws/2
  • -
- - - - - - - -
- - - - - -
-

Default connection URL

-
- - - -
Type:
-
    -
  • - -string - - -
  • -
- - - - - - - - - - -

Methods

- - - - - - -

(async) auth(calcnullable, dmsnullable) → {Promise}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Generates & sends an authentication packet to the server; if already -authenticated, rejects with an error, resolves on success.

-

If a DMS flag of 4 is provided, all open orders are cancelled when the -connection terminates.

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
calc - - -number - - - - - - - - <nullable>
- - - -

optional, default is 0

dms - - -number - - - - - - - - <nullable>
- - - -

optional dead man switch flag, active 4

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

p

-
- - - -
-
- Type -
-
- -Promise - - -
-
- - - - - - - - - - -

(async) cancelOrder(order) → {Promise}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Cancels an order by ID and resolves the returned promise once the cancel is -confirmed. Emits an error if not authenticated. The ID can be passed as a -number, or taken from an order array/object.

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
order - - -object -| - -Array -| - -number - - - -

order model, array, or ID to be cancelled

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

p

-
- - - -
-
- Type -
-
- -Promise - - -
-
- - - - - - - - - - -

(async) cancelOrders(orders) → {Promise}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Cancels multiple orders, returns a promise that resolves once all -operations are confirmed.

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
orders - - -Array.<object> -| - -Array.<Array> -| - -Array.<number> - - - -

array of order models, arrays -or IDs to be cancelled

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

p

-
- - - -
-
- Type -
-
- -Promise - - -
-
- - - - - - - - - - -

(async) close(code, reason) → {Promise}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Closes the active connection. If there is none, rejects with a promise. -Resolves on success

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
code - - -number - - - -

passed to ws

reason - - -string - - - -

passed to ws

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

p

-
- - - -
-
- Type -
-
- -Promise - - -
-
- - - - - - - - - - -

(async) enableFlag(flag) → {Promise}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
-
    -
  • WSv2#flags
  • -
-
- - - -
- - - - - -
-

Enables a configuration flag.

-
- - - - - - - - - -
Example
- -
const ws = new WSv2()
-
-ws.on('open', async () => {
-  await ws.enableFlag(WSv2.flags.CHECKSUM)
-  console.log('ob checkums enabled')
-})
-
-await ws.open()
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
flag - - -number - - - -

flag to update, as numeric value

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

p

-
- - - -
-
- Type -
-
- -Promise - - -
-
- - - - - - - - - - -

(async) enableSequencing(args) → {Promise}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
-
    -
  • WSv2#flags
  • -
-
- - - -
- - - - - -
-

Configures the seq flag to enable sequencing (packet number) for this -connection. When enabled, the seq number will be the last value of -channel packet arrays.

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
args - - -object - - - -

params

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
audit - - -boolean - - - - - - <optional>
- - - - - -

if true, an error is emitted on invalid seq

- -
- - - - - - - - - - - - - - - - -
Returns:
- - -
-

p

-
- - - -
-
- Type -
-
- -Promise - - -
-
- - - - - - - - - - -

getAuthArgs() → {object}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Fetch the current default auth parameters

-
- - - - - - - - - - - - - - - - - - - - - - - - - -
Returns:
- - -
-

authArgs

-
- - - -
-
- Type -
-
- -object - - -
-
- - - - - - - - - - -

getCandles(key) → {Array}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Fetch a reference to the full set of synced candles for the specified key. -Set managedCandles: true in the constructor to use.

-
- - - - - - - - - -
Example
- -
const ws = new WSv2({ managedCandles: true })
-
-  ws.on('open', async () => {
-      ws.onCandles({ key: 'trade:1m:tBTCUSD' }, () => {
-        const candles = ws.getCandles('trade:1m:tBTCUSD')
-
-        if (!candles) return
-
-        console.log('%d candles in dataset', candles.length)
-      })
-
-      ws.subscribeCandles({ key: 'trade:1m:tBTCUSD' })
-  })
-
-  await ws.open()
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
key - - -string - - - -

key for candle set

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

candles - empty array if none exist

-
- - - -
-
- Type -
-
- -Array - - -
-
- - - - - - - - - - -

getChannelData(opts) → {object}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Fetch a channel definition

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
chanId - - -number - - - - - - - - - -

channel ID

channel - - -string - - - - - - - - - -

channel name

symbol - - -string - - - - - - <optional>
- - - - - -

match by symbol

key - - -string - - - - - - <optional>
- - - - - -

match by key (for candle channels)

- -
- - - - - - - - - - - - - - - - -
Returns:
- - -
-

chanData - null if not found

-
- - - -
-
- Type -
-
- -object - - -
-
- - - - - - - - - - -

getDataChannelCount() → {number}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Get the total number of data channels this instance is currently -subscribed too.

-
- - - - - - - - - - - - - - - - - - - - - - - - - -
Returns:
- - -
-

count

-
- - - -
-
- Type -
-
- -number - - -
-
- - - - - - - - - - -

getDataChannelId(type, filter) → {number}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Fetch the ID of a channel matched by type and channel data filter

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
type - - -string - - - -

channel type

filter - - -object - - - -

to be matched against channel data

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

channelID

-
- - - -
-
- Type -
-
- -number - - -
-
- - - - - - - - - - -

getLosslessOB(symbol) → {OrderBook}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Returns an up-to-date lossless copy of the order book for the specified symbol, or -null if no OB is managed for that symbol. All amounts and prices are in original -string format.

-

Set manageOrderBooks: true in the constructor to use.

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
symbol - - -string - - - -

symbol for order book

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

ob - null if not found

-
- - - -
-
- Type -
-
- -OrderBook - - -
-
- - - - - - - - - - -

getOB(symbol) → {OrderBook}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Returns an up-to-date copy of the order book for the specified symbol, or -null if no OB is managed for that symbol.

-

Set managedOrderBooks: true in the constructor to use.

-
- - - - - - - - - -
Example
- -
const ws = new WSv2({ managedOrderBooks: true })
-
-  ws.on('open', async () => {
-      ws.onOrderBook({ symbol: 'tBTCUSD' }, () => {
-        const book = ws.getOB('tBTCUSD')
-
-        if (!book) return
-
-        const spread = book.midPrice()
-        console.log('spread for tBTCUSD: %f', spread)
-      })
-
-      ws.subscribeOrderBook({ symbol: 'tBTCUSD' })
-  })
-
-  await ws.open()
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
symbol - - -string - - - -

symbol for order book

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

ob - null if not found

-
- - - -
-
- Type -
-
- -OrderBook - - -
-
- - - - - - - - - - -

getURL() → {string}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Returns:
- - -
-

url

-
- - - -
-
- Type -
-
- -string - - -
-
- - - - - - - - - - -

hasChannel(chanId) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Check if the instance is subscribed to the specified channel ID

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
chanId - - -number - - - -

ID of channel to query

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

isSubscribed

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

hasDataChannel(type, filter) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Check if the instance is subscribed to a data channel matching the -specified type and filter.

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
type - - -string - - - -

channel type

filter - - -object - - - -

to be matched against channel data

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

hasChannel

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

hasSubscriptionRef(channel, identifier) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Check if a channel/identifier pair has been subscribed too

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
channel - - -string - - - -

channel type

identifier - - -string - - - -

unique identifier for the reference

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

hasRef

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

isAuthenticated() → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Returns:
- - -
-

authenticated

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

isFlagEnabled(flag) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
-
    -
  • enableFlag
  • -
-
- - - -
- - - - - -
-

Checks local state, relies on successful server config responses

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
flag - - -number - - - -

flag to check for

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

enabled

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

isOpen() → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Returns:
- - -
-

open

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

isReconnecting() → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Returns:
- - -
-

reconnecting

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

managedSubscribe(channel, identifier, payload) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
To Do:
-
-
    -
  • will be refactored to return promise from subscribe() call instead - of sub action taken flag
  • -
-
- -
- - - - - -
-

Subscribes and tracks subscriptions per channel/identifier pair. If -already subscribed to the specified pair, nothing happens.

-
- - - - - - - - - -
Example
- -
const ws = new WSv2()
-
-ws.on('open', async () => {
-  ws.onTrades({ symbol: 'tBTCUSD' }, (trades) => {
-    console.log('recv trades: %j', trades)
- })
-
-  ws.managedSubscribe('trades', 'tBTCUSD', { symbol: 'tBTCUSD' })
-})
-
-await ws.open()
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
channel - - -string - - - -

channel name

identifier - - -string - - - -

for uniquely identifying the ref count

payload - - -object - - - -

merged with sub packet

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

subSent

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

managedUnsubscribe(channel, identifier) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Decreases the subscription ref count for the channel/identifier pair, and -unsubscribes from the channel if it reaches 0.

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
channel - - -string - - - -

channel name

identifier - - -string - - - -

for uniquely identifying the ref count

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

unsubSent

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

notifyUI(opts)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Sends a broadcast notification, which will be received by any active UI -websocket connections (at bitfinex.com), triggering a desktop notification.

-

In the future our mobile app will also support spawning native push -notifications in response to incoming ucm-notify-ui packets.

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
message - - -string - - - - - - <optional>
- - - - - -

message to display

type - - -string - - - - - - <optional>
- - - - - -

notification type, 'ucm-*' for broadcasts

level - - -string - - - - - - <optional>
- - - - - -

'info', 'error', or 'success'

image - - -string - - - - - - <optional>
- - - - - -

link to an image to be shown

link - - -string - - - - - - <optional>
- - - - - -

URL the notification should forward too

sound - - -string - - - - - - <optional>
- - - - - -

URL of sound to play

- -
- - - - - - - - - - - - - - -
Throws:
- - - -
- -

an error if given no type or message, or the instance is not open -and authenticated

- -
- - - - - - - - - - - - - -

onAccountTradeEntry(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each personal trade 'te' event

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
pair - - -string - - - - - - <optional>
- - - - - -

required if no symbol specified

symbol - - -string - - - - - - <optional>
- - - - - -

required if no pair specified

cbGID - - -string -| - -number - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onAccountTradeUpdate(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each personal trade 'tu' event

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
pair - - -string - - - - - - <optional>
- - - - - -

required if no symbol specified

symbol - - -string - - - - - - <optional>
- - - - - -

required if no pair specified

cbGID - - -string -| - -number - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onBalanceInfoUpdate(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each balance info update

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onCandle(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called with each received candle

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
key - - -string - - - - - - - - - -

candle set key, i.e. trade:30m:tBTCUSD

cbGID - - -string -| - -number - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onFundingCreditClose(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called when a funding credit is closed

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onFundingCreditNew(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called when a funding credit is created

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onFundingCreditSnapshot(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each funding credit snapshot (sent on -auth)

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onFundingCreditUpdate(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called when a funding credit is updated

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onFundingInfoUpdate(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each funding info update

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onFundingLoanClose(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called when a funding loan is closed

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onFundingLoanNew(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called when a funding loan is created

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onFundingLoanSnapshot(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each funding loan snapshot (sent on -auth)

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onFundingLoanUpdate(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called when a funding loan is updated

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onFundingOfferClose(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called when a funding offer is closed

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onFundingOfferNew(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called when a funding offer is created

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onFundingOfferSnapshot(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each fundign offer snapshot (sent on -auth)

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onFundingOfferUpdate(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called when a funding offer is updated

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onFundingTradeEntry(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each funding trade 'te' event

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onFundingTradeUpdate(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each funding trade 'tu' event

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onInfoMessage(code, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Registers a new callback to be called when a matching info message is -received.

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
code - - -number - - - -

from #WSv2.info

cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onMaintenanceEnd(cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Register a callback to be notified of a maintenance period ending

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
cb - - -function - - - -

called on event trigger

- - - - - - - - - - - - - - - - - - - - - - - - -

onMaintenanceStart(cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Register a callback in case of a 'maintenance started' message from the -server. This is a good time to pause server packets until maintenance ends

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
cb - - -function - - - -

called on event trigger

- - - - - - - - - - - - - - - - - - - - - - - - -

onMarginInfoUpdate(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each margin info update

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onMessage(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Register a generic handler to be called with each received message

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
cbGID - - -string -| - -number - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onNotification(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each notification

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
type - - -string - - - - - - <optional>
- - - - - -

type to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onOrderBook(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called with each received candle

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - - - - -

book symbol

prec - - -string - - - - - - - - - -

book precision, i.e. 'R0'

len - - -string - - - - - - - - - -

book length, i.e. '25'

cbGID - - -string -| - -number - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onOrderBookChecksum(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called with each received order book checksum

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - - - - -

book symbol

prec - - -string - - - - - - - - - -

book precision, i.e. 'R0'

len - - -string - - - - - - - - - -

book length, i.e. '25'

cbGID - - -string -| - -number - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onOrderClose(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each order close packet

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

id - - -number - - - - - - <optional>
- - - - - -

order ID to match

cid - - -number - - - - - - <optional>
- - - - - -

order client ID to match

gid - - -number - - - - - - <optional>
- - - - - -

order group ID to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onOrderNew(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each new order packet

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

id - - -number - - - - - - <optional>
- - - - - -

order ID to match

cid - - -number - - - - - - <optional>
- - - - - -

order client ID to match

gid - - -number - - - - - - <optional>
- - - - - -

order group ID to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onOrderSnapshot(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each full order snapshot (sent on auth)

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

id - - -number - - - - - - <optional>
- - - - - -

order ID to match

cid - - -number - - - - - - <optional>
- - - - - -

order client ID to match

gid - - -number - - - - - - <optional>
- - - - - -

order group ID to match

cbGID - - -string -| - -number - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onOrderUpdate(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each order update packet

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

id - - -number - - - - - - <optional>
- - - - - -

order ID to match

cid - - -number - - - - - - <optional>
- - - - - -

order client ID to match

gid - - -number - - - - - - <optional>
- - - - - -

order group ID to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onPositionClose(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called when a position is closed

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onPositionNew(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called when a position is opened

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onPositionSnapshot(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each position snapshot (sent on auth)

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onPositionUpdate(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called when a position is updated

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - <optional>
- - - - - -

symbol to match

cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onServerRestart(cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Register a callback in case of a ws server restart message; Use this to -call reconnect() if needed. (code 20051)

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
cb - - -function - - - -

called on event trigger

- - - - - - - - - - - - - - - - - - - - - - - - -

onStatus(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each message for the desired status -feed.

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
key - - -string - - - - - - - - - -

key of feed to listen on

cbGID - - -string -| - -number - - - - - - <optional>
- - - - - -

callback group ID

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onTicker(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each received ticker

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
symbol - - -string - - - - - - - - - -

symbol for tickers

cbGID - - -string -| - -number - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onTradeEntry(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each trade 'te' event

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
pair - - -string - - - - - - <optional>
- - - - - -

required if no symbol specified

symbol - - -string - - - - - - <optional>
- - - - - -

required if no pair specified

cbGID - - -string -| - -number - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onTrades(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called with each received trade (pair or symbol -required)

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
pair - - -string - - - - - - <optional>
- - - - - -

required if no symbol specified

symbol - - -string - - - - - - <optional>
- - - - - -

required if no pair specified

cbGID - - -string -| - -number - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onWalletSnapshot(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each wallet snapshot (sent on auth)

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

onWalletUpdate(opts, cb)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Register a handler to be called on each wallet update

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opts - - -object - - - -

options

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
cbGID - - -string - - - - - - <optional>
- - - - - -

callback group id

- -
cb - - -function - - - -

callback

- - - - - - - - - - - - - - - - - - - - - - - - -

(async) open() → {Promise}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Opens a connection to the API server. Rejects with an error if a -connection is already open. Resolves on success.

-
- - - - - - - - - - - - - - - - - - - - - - - - - -
Returns:
- - -
-

p

-
- - - -
-
- Type -
-
- -Promise - - -
-
- - - - - - - - - - -

(async) reconnect() → {Promise}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Utility method to close & re-open the ws connection. Re-authenticates if -previously authenticated

-
- - - - - - - - - - - - - - - - - - - - - - - - - -
Returns:
- - -
-

p - resolves on completion

-
- - - -
-
- Type -
-
- -Promise - - -
-
- - - - - - - - - - -

removeListeners(cbGID)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Remove all listeners by callback group ID

-
- - - - - - - - - -
Example
- -
await ws.subscribeTrades({ symbol: 'tBTCUSD', cbGID: 42 })
-await ws.subscribeTrades({ symbol: 'tLEOUSD', cbGID: 42 })
-await ws.subscribeTrades({ symbol: 'tETHUSD', cbGID: 42 })
-
-// ...
-
-ws.removeListeners(42)
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
cbGID - - -string - - - -

callback group to remove

- - - - - - - - - - - - - - - - - - - - - - - - -

requestCalc(prefixes)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Request a calc operation to be performed on the specified indexes

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
prefixes - - -Array.<string> - - - -

desired prefixes to be calculated

- - - - - - - - - - - - - - - - - - - - - - - - -

send(msg)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Send a packet to the WS server

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
msg - - -* - - - -

packet, gets stringified

- - - - - - - - - - - - - - - - - - - - - - - - -

sequencingEnabled() → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Returns:
- - -
-

sequencingEnabled

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

setAPICredentials(apiKey, apiSecret)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Update the internal API credentials, used on subsequent WSv2#auth -calls

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
apiKey - - -string - - - -

API key

apiSecret - - -string - - - -

API secret

- - - - - - - - - - - - - - - - - - - - - - - - -

(async) submitOrder(order) → {Promise}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Sends a new order to the server and resolves the returned promise once the -order submit is confirmed. Emits an error if not authenticated. The order -can be either an array, key/value map, or Order object instance.

-
- - - - - - - - - -
Example
- -
const o = new Order({
-  type: Order.type.EXCHANGE_LIMIT,
-  amount: 18,
-  price: 0.75,
-  symbol: 'tBTCUSD',
-  hidden: true
-}, ws)
-
-await ws.submitOrder(o)
-
-console.log('order confirmed! status: %s', o.status)
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
order - - -object -| - -Array - - - -

order object model or array

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

p - resolves on submit notification

-
- - - -
-
- Type -
-
- -Promise - - -
-
- - - - - - - - - - -

(async) submitOrderMultiOp(opPayloads) → {Promise}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Sends the op payloads to the server as an 'ox_multi' command. A promise is -returned and resolves immediately if authenticated, as no confirmation is -available for this message type.

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
opPayloads - - -Array.<object> - - - -

order operations

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

p - rejects if not authenticated

-
- - - -
-
- Type -
-
- -Promise - - -
-
- - - - - - - - - - -

subscribe(channel, payload)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Subscribe to a channel with the given filter payload

-
- - - - - - - - - -
Example
- -
const ws = new WSv2()
-
-ws.on('open', () => {
-  ws.onTrades({ symbol: 'tBTCUSD' }, (trades) => {
-    // ...
-  })
-
-  ws.subscribe('trades', { symbol: 'tBTCUSD' })
-})
-
-await ws.open()
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
channel - - -string - - - -

channel payload/data

payload - - -object - - - -

optional extra packet data

- - - - - - - - - - - - - - - - - - - - - - - - -

(async) subscribeCandles(key) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Subscribe to a candle data channel

-
- - - - - - - - - -
Example
- -
await ws.subscribeCandles('trade:5m:tBTCUSD')
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
key - - -string - - - -

'trade:5m:tBTCUSD'

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

subscribed

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

(async) subscribeOrderBook(symbol, prec, len) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Subscribe to an order book data channel

-
- - - - - - - - - -
Example
- -
await ws.subscribeOrderBook('tBTCUSD', 'R0', '25')
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDefaultDescription
symbol - - -string - - - - - -

symbol of order book

prec - - -string - - - - - - P0 - -

P0, P1, P2, or P3 (default P0)

len - - -string - - - - - - 25 - -

25 or 100 (default 25)

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

subscribed

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

(async) subscribeStatus(key) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Subscribe to a status data channel

-
- - - - - - - - - -
Example
- -
await ws.subscribeStatus('liq:global')
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
key - - -string - - - -

i.e. 'liq:global'

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

subscribed

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

(async) subscribeTicker(symbol) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Subscribe to a ticker data channel

-
- - - - - - - - - -
Example
- -
await ws.subscribeTicker('tBTCUSD')
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
symbol - - -string - - - -

symbol of ticker

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

subscribed

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

(async) subscribeTrades(symbol) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Subscribe to a trades data channel

-
- - - - - - - - - -
Example
- -
await ws.subscribeTrades('tBTCUSD')
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
symbol - - -string - - - -

symbol of market to monitor

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

subscribed

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

unsubscribe(chanId)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Unsubscribe from a channel by ID

-
- - - - - - - - - -
Example
- -
const id = ws.getDataChannelId('ticker', { symbol: 'tBTCUSD' })
-
-if (id) {
-  ws.unsubscribe(id)
-}
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
chanId - - -number - - - -

ID of channel to unsubscribe from

- - - - - - - - - - - - - - - - - - - - - - - - -

(async) unsubscribeCandles(symbol, frame) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - - - - - - - - - -
Example
- -
await ws.unsubscribeCandles('tBTCUSD', '1m')
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
symbol - - -string - - - -

symbol of candles

frame - - -string - - - -

time frame

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

unsubscribed

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

(async) unsubscribeOrderBook(symbol) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Unsubscribe from an order book data channel

-
- - - - - - - - - -
Example
- -
await ws.unsubcribeOrderBook('tBTCUSD')
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
symbol - - -string - - - -

symbol of order book

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

unsubscribed

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

(async) unsubscribeStatus(key) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
key - - -string - - - -

key that was used in initial WSv2#subscribeStatus call

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

unsubscribed

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

(async) unsubscribeTicker(symbol) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Unsubscribe from a ticker data channel

-
- - - - - - - - - -
Example
- -
await ws.unsubscribeTicker('tBTCUSD')
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
symbol - - -string - - - -

symbol of ticker

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

unsubscribed

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

(async) unsubscribeTrades(symbol) → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Unsubscribe from a trades data channel

-
- - - - - - - - - -
Example
- -
await ws.unsubcribeTrades('tBTCUSD')
- - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
symbol - - -string - - - -

symbol of market to unsubscribe from

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

unsubscribed

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - -

updateAuthArgs(args)

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Set calc and dms values to be used on the next WSv2#auth call

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
args - - -object - - - -

arguments

-
Properties
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
calc - - -number - - - - - - <optional>
- - - - - -

calc value

dms - - -number - - - - - - <optional>
- - - - - -

dms value, active 4

- -
- - - - - - - - - - - - - - - - - - - - - - - - -

(async) updateOrder(changes) → {Promise}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See:
-
- -
- - - -
- - - - - -
-

Send a changeset to update an order in-place while maintaining position in -the price queue. The changeset must contain the order ID, and supports a -'delta' key to increase/decrease the total amount.

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
changes - - -object - - - -

requires at least an 'id'

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

p - resolves on receiving an confirmation notification

-
- - - -
-
- Type -
-
- -Promise - - -
-
- - - - - - - - - - -

usesAgent() → {boolean}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Returns:
- - -
-

usesAgent

-
- - - -
-
- Type -
-
- -boolean - - -
-
- - - - - - - - - - - -
- -
- - - - - - -
- -
- - - - - - - - - - - \ No newline at end of file diff --git a/docs/fonts/Montserrat/Montserrat-Bold.eot b/docs/fonts/Montserrat/Montserrat-Bold.eot deleted file mode 100644 index f2970bbd..00000000 Binary files a/docs/fonts/Montserrat/Montserrat-Bold.eot and /dev/null differ diff --git a/docs/fonts/Montserrat/Montserrat-Bold.ttf b/docs/fonts/Montserrat/Montserrat-Bold.ttf deleted file mode 100644 index 3bfd79b6..00000000 Binary files a/docs/fonts/Montserrat/Montserrat-Bold.ttf and /dev/null differ diff --git a/docs/fonts/Montserrat/Montserrat-Bold.woff b/docs/fonts/Montserrat/Montserrat-Bold.woff deleted file mode 100644 index 92607654..00000000 Binary files a/docs/fonts/Montserrat/Montserrat-Bold.woff and /dev/null differ diff --git a/docs/fonts/Montserrat/Montserrat-Bold.woff2 b/docs/fonts/Montserrat/Montserrat-Bold.woff2 deleted file mode 100644 index d9940cd1..00000000 Binary files a/docs/fonts/Montserrat/Montserrat-Bold.woff2 and /dev/null differ diff --git a/docs/fonts/Montserrat/Montserrat-Regular.eot b/docs/fonts/Montserrat/Montserrat-Regular.eot deleted file mode 100644 index 735d12b5..00000000 Binary files a/docs/fonts/Montserrat/Montserrat-Regular.eot and /dev/null differ diff --git a/docs/fonts/Montserrat/Montserrat-Regular.ttf b/docs/fonts/Montserrat/Montserrat-Regular.ttf deleted file mode 100644 index 5da852a3..00000000 Binary files a/docs/fonts/Montserrat/Montserrat-Regular.ttf and /dev/null differ diff --git a/docs/fonts/Montserrat/Montserrat-Regular.woff b/docs/fonts/Montserrat/Montserrat-Regular.woff deleted file mode 100644 index bf918327..00000000 Binary files a/docs/fonts/Montserrat/Montserrat-Regular.woff and /dev/null differ diff --git a/docs/fonts/Montserrat/Montserrat-Regular.woff2 b/docs/fonts/Montserrat/Montserrat-Regular.woff2 deleted file mode 100644 index 72d13c60..00000000 Binary files a/docs/fonts/Montserrat/Montserrat-Regular.woff2 and /dev/null differ diff --git a/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot b/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot deleted file mode 100644 index 0f24510b..00000000 Binary files a/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot and /dev/null differ diff --git a/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg b/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg deleted file mode 100644 index 5384f985..00000000 --- a/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +++ /dev/null @@ -1,978 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf b/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf deleted file mode 100644 index e6c158c2..00000000 Binary files a/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf and /dev/null differ diff --git a/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff b/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff deleted file mode 100644 index d0a1c292..00000000 Binary files a/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff and /dev/null differ diff --git a/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 b/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 deleted file mode 100644 index d2869749..00000000 Binary files a/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 and /dev/null differ diff --git a/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot b/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot deleted file mode 100644 index b4204488..00000000 Binary files a/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot and /dev/null differ diff --git a/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg b/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg deleted file mode 100644 index dee0949f..00000000 --- a/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +++ /dev/null @@ -1,1049 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf b/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf deleted file mode 100644 index 4d56c337..00000000 Binary files a/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf and /dev/null differ diff --git a/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff b/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff deleted file mode 100644 index 4681019d..00000000 Binary files a/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff and /dev/null differ diff --git a/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 b/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 deleted file mode 100644 index 8ddcae37..00000000 Binary files a/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 and /dev/null differ diff --git a/docs/global.html b/docs/global.html deleted file mode 100644 index fe35a918..00000000 --- a/docs/global.html +++ /dev/null @@ -1,497 +0,0 @@ - - - - - - Global - Documentation - - - - - - - - - - - - - - - - - - - -
- -

Global

- - - - - - - -
- -
- -

- -

- - -
- -
- -
- - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - -
- - - - - - - - - - - - - - - - - -

Methods

- - - - - - -

setSigFig(number, maxSigsopt) → {string}

- - - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-

Smartly set the precision (decimal) on a value based off of the significant -digit maximum. For example, calling with 3.34 when the max sig figs allowed -is 5 would return '3.3400', the representation number of decimals IF they -weren't zeros.

-
- - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDefaultDescription
number - - -number - - - - - - - - - - - - 0 - -

number to manipulate

maxSigs - - -number - - - - - - <optional>
- - - - - -
- -

default 5

- - - - - - - - - - - - - - - - -
Returns:
- - -
-

str

-
- - - -
-
- Type -
-
- -string - - -
-
- - - - - - - - - -

Type Definitions

- - - -

PromiseThrottle

- - - - - -
- - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
Properties:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
add - - -function - - - -

add a promise to be throttled

- - - - - - -
-

A Promise Throttle instance

-
- - - -
Type:
-
    -
  • - -object - - -
  • -
- - - - - - - - - - -
- -
- - - - - - -
- -
- - - - - - - - - - - \ No newline at end of file diff --git a/docs/index.html b/docs/index.html deleted file mode 100644 index 37ca0cff..00000000 --- a/docs/index.html +++ /dev/null @@ -1,249 +0,0 @@ - - - - - - Home - Documentation - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - -
-

-
- - - - - - - - - - - - - -
-

Bitfinex WSv2 Trading API for Node.JS - Bitcoin, Ethereum, Ripple and more

-

Build Status

-

A Node.JS reference implementation of the Bitfinex API

-

Features

-
    -
  • Official implementation
  • -
  • REST v2 API
  • -
  • WebSockets v2 API
  • -
  • WebSockets v1 API
  • -
-

Installation

-
  npm i --save bitfinex-api-node
-
-

Quickstart

-
const { WSv2 } = require('bitfinex-api-node')
-const ws = new WSv2({ transform: true })
-
-// do something with ws client
-
-

Docs

-

See docs/ws2.md for WS2 API methods, -and docs/usage.md for a basic usage guide. For executable -examples, refer to the examples/ folder.

-

Official API documentation at https://docs.bitfinex.com/v2/reference

-

Examples

-

Sending an order & tracking status:

-
const ws = bfx.ws()
-
-ws.on('error', (err) => console.log(err))
-ws.on('open', ws.auth.bind(ws))
-
-ws.once('auth', () => {
-  const o = new Order({
-    cid: Date.now(),
-    symbol: 'tETHUSD',
-    amount: 0.1,
-    type: Order.type.MARKET
-  }, ws)
-
-  // Enable automatic updates
-  o.registerListeners()
-
-  o.on('update', () => {
-    console.log(`order updated: ${o.serialize()}`)
-  })
-
-  o.on('close', () => {
-    console.log(`order closed: ${o.status}`)
-    ws.close()
-  })
-
-  o.submit().then(() => {
-    console.log(`submitted order ${o.id}`)
-  }).catch((err) => {
-    console.error(err)
-    ws.close()
-  })
-})
-
-ws.open()
-
-

Cancel all open orders

-
const ws = bfx.ws(2)
-
-ws.on('error', (err) => console.log(err))
-ws.on('open', ws.auth.bind(ws))
-
-ws.onOrderSnapshot({}, (orders) => {
-  if (orders.length === 0) {
-    console.log('no open orders')
-    return
-  }
-
-  console.log(`recv ${orders.length} open orders`)
-
-  ws.cancelOrders(orders).then(() => {
-    console.log('cancelled orders')
-  })
-})
-
-ws.open()
-
-

Subscribe to trades by pair

-
const ws = bfx.ws(2)
-
-ws.on('error', (err) => console.log(err))
-ws.on('open', () => {
-  ws.subscribeTrades('BTCUSD')
-})
-
-ws.onTrades({ symbol: 'tBTCUSD' }, (trades) => {
-  console.log(`trades: ${JSON.stringify(trades)}`)
-})
-ws.onTradeEntry({ symbol: 'tBTCUSD' }, (trades) => {
-  console.log(`te: ${JSON.stringify(trades)}`)
-})
-
-ws.open()
-
-

Version 2.0.0 Breaking changes

-

constructor takes only an options object now, including the API keys

-

Old:

-
new BFX(API_KEY, API_SECRET, { version: 2 })
-
-

since 2.0.0:

-
new BFX({ apiKey: '', apiSecret: '' })
-
-

trade and orderbook snapshots are emitted as nested lists

-

To make dealing with snapshots better predictable, snapshots are emitted as an array.

-

normalized orderbooks for R0

-

Lists of raw orderbooks (R0) are ordered in the same order as P0, P1, -P2, P3

-

Testing

-
npm test
-
-

FAQ

-

Order Creation Limits

-

The base limit per-user is 1,000 orders per 5 minute interval, and is shared -between all account API connections. It increases proportionally to your trade -volume based on the following formula:

-

1000 + (TOTAL_PAIRS_PLATFORM * 60 * 5) / (250000000 / USER_VOL_LAST_30d)

-

Where TOTAL_PAIRS_PLATFORM is the number of pairs shared between -Ethfinex/Bitfinex (currently ~101) and USER_VOL_LAST_30d is in USD.

-

'on' Packet Guarantees

-

No; if your order fills immediately, the first packet referencing the order -will be an oc signaling the order has closed. If the order fills partially -immediately after creation, an on packet will arrive with a status of -PARTIALLY FILLED...

-

For example, if you submit a LIMIT buy for 0.2 BTC and it is added to the -order book, an on packet will arrive via ws2. After a partial fill of 0.1 -BTC, an ou packet will arrive, followed by a final oc after the remaining -0.1 BTC fills.

-

On the other hand, if the order fills immediately for 0.2 BTC, you will only -receive an oc packet.

-

Nonce too small

-

I make multiple parallel request and I receive an error that the nonce is too -small. What does it mean?

-

Nonces are used to guard against replay attacks. When multiple HTTP requests -arrive at the API with the wrong nonce, e.g. because of an async timing issue, -the API will reject the request.

-

If you need to go parallel, you have to use multiple API keys right now.

-

te vs tu Messages

-

A te packet is sent first to the client immediately after a trade has been -matched & executed, followed by a tu message once it has completed processing. -During times of high load, the tu message may be noticably delayed, and as -such only the te message should be used for a realtime feed.

-

Sequencing

-

If you enable sequencing on v2 of the WS API, each incoming packet will have a -public sequence number at the end, along with an auth sequence number in the -case of channel 0 packets. The public seq numbers increment on each packet, -and the auth seq numbers increment on each authenticated action (new orders, -etc). These values allow you to verify that no packets have been missed/dropped, -since they always increase monotonically.

-

Differences Between R* and P* Order Books

-

Order books with precision R0 are considered 'raw' and contain entries for -each order submitted to the book, whereas P* books contain entries for each -price level (which aggregate orders).

-

Contributing

-
    -
  1. Fork it
  2. -
  3. Create your feature branch (git checkout -b my-new-feature)
  4. -
  5. Commit your changes (git commit -am 'Add some feature')
  6. -
  7. Push to the branch (git push origin my-new-feature)
  8. -
  9. Create a new Pull Request
  10. -
-
- - - - - - - - -
- -
- - - - - - - - - - - \ No newline at end of file diff --git a/docs/reference.md b/docs/reference.md new file mode 100644 index 00000000..281bc6e6 --- /dev/null +++ b/docs/reference.md @@ -0,0 +1,2312 @@ +## Modules + +
+
bitfinex-api-node
+

A Node.JS reference implementation of the Bitfinex API

+
+
+ +## Classes + +
+
ClientManager
+

Provides access to versions 1 & 2 of the HTTP & WebSocket Bitfinex APIs.

+
+
WS2Managerevents.EventEmitter
+

Provides a wrapper around the WSv2 class, opening new sockets when a +subscription would push a single socket over the data channel limit.

+

For more complex operations, grab a socket reference with getSocket() or +getFreeDataSocket(), or create a new WSv2 instance manually

+
+
WSv2events.EventEmitter
+

Communicates with v2 of the Bitfinex WebSocket API

+
+
+ +## Typedefs + +
+
CandleChannel : object
+

An object describing a trade data channel on a WSv2 data stream.

+
+
OrderBookChannel : object
+

An object describing an order book data channel on a WSv2 data stream.

+
+
TickerChannel : object
+

An object describing a ticker data channel on a WSv2 data stream.

+
+
TradeChannel : object
+

An object describing a trade data channel on a WSv2 data stream.

+
+
+ + + +## bitfinex-api-node +A Node.JS reference implementation of the Bitfinex API + +**License**: MIT +**Example** *(sending an order & tracking status)* +```js +const ws = bfx.ws() + +ws.on('error', (err) => console.log(err)) +ws.on('open', ws.auth.bind(ws)) + +ws.once('auth', () => { + const o = new Order({ + cid: Date.now(), + symbol: 'tETHUSD', + amount: 0.1, + type: Order.type.MARKET + }, ws) + + // Enable automatic updates + o.registerListeners() + + o.on('update', () => { + console.log(`order updated: ${o.serialize()}`) + }) + + o.on('close', () => { + console.log(`order closed: ${o.status}`) + ws.close() + }) + + o.submit().then(() => { + console.log(`submitted order ${o.id}`) + }).catch((err) => { + console.error(err) + ws.close() + }) +}) + +ws.open() +``` +**Example** *(cancel all open orders)* +```js +const ws = bfx.ws(2) + +ws.on('error', (err) => console.log(err)) +ws.on('open', ws.auth.bind(ws)) + +ws.onOrderSnapshot({}, (orders) => { + if (orders.length === 0) { + console.log('no open orders') + return + } + + console.log(`recv ${orders.length} open orders`) + + ws.cancelOrders(orders).then(() => { + console.log('cancelled orders') + }) +}) + +ws.open() +``` +**Example** *(subscribe to trades by pair)* +```js +const ws = bfx.ws(2) + +ws.on('error', (err) => console.log(err)) +ws.on('open', () => { + ws.subscribeTrades('BTCUSD') +}) + +ws.onTrades({ symbol: 'tBTCUSD' }, (trades) => { + console.log(`trades: ${JSON.stringify(trades)}`) +}) +ws.onTradeEntry({ symbol: 'tBTCUSD' }, (trades) => { + console.log(`te: ${JSON.stringify(trades)}`) +}) + +ws.open() +``` + + +## ClientManager +Provides access to versions 1 & 2 of the HTTP & WebSocket Bitfinex APIs. + +**Kind**: global class +**See**: [WSv2](#WSv2) + +* [ClientManager](#ClientManager) + * [new ClientManager(opts)](#new_ClientManager_new) + * [.rest([version], [extraOpts])](#ClientManager+rest) ⇒ bfx-api-node-rest.RESTv1 \| bfx-api-node-rest.RESTv2 + * [.ws([version], [extraOpts])](#ClientManager+ws) ⇒ [WSv2](#WSv2) \| bfx-api-node-ws1.WSv1 + + + +### new ClientManager(opts) + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| opts.apiKey | string | API key | +| opts.apiSecret | string | API secret | +| opts.authToken | string | optional auth option | +| opts.transform | string | if true, packets are converted to models | +| opts.nonceGenerator | string | optional | +| opts.ws | [Configuration](#WSv2..Configuration) | ws transport options | +| opts.rest | string | rest transport options | + + + +### clientManager.rest([version], [extraOpts]) ⇒ bfx-api-node-rest.RESTv1 \| bfx-api-node-rest.RESTv2 +Returns a new REST API class instance (cached by version) + +**Kind**: instance method of [ClientManager](#ClientManager) +**Returns**: bfx-api-node-rest.RESTv1 \| bfx-api-node-rest.RESTv2 - transport + +| Param | Type | Default | Description | +| --- | --- | --- | --- | +| [version] | number | 2 | 1 or 2 | +| [extraOpts] | object | {} | passed to transport constructor | + + + +### clientManager.ws([version], [extraOpts]) ⇒ [WSv2](#WSv2) \| bfx-api-node-ws1.WSv1 +Returns a new WebSocket API class instance (cached by version) + +**Kind**: instance method of [ClientManager](#ClientManager) +**Returns**: [WSv2](#WSv2) \| bfx-api-node-ws1.WSv1 - transport + +| Param | Type | Default | Description | +| --- | --- | --- | --- | +| [version] | number | 2 | 1 or 2 | +| [extraOpts] | [Configuration](#WSv2..Configuration) | {} | passed to transport constructor | + + + +## WS2Manager ⇐ events.EventEmitter +Provides a wrapper around the WSv2 class, opening new sockets when a +subscription would push a single socket over the data channel limit. + +For more complex operations, grab a socket reference with getSocket() or +getFreeDataSocket(), or create a new WSv2 instance manually + +**Kind**: global class +**Extends**: events.EventEmitter + +* [WS2Manager](#WS2Manager) ⇐ events.EventEmitter + * [new WS2Manager(socketArgs, [authArgs])](#new_WS2Manager_new) + * _instance_ + * [.setAuthArgs(args)](#WS2Manager+setAuthArgs) + * [.getAuthArgs()](#WS2Manager+getAuthArgs) ⇒ object + * [.reconnect()](#WS2Manager+reconnect) ⇒ Promise + * [.close()](#WS2Manager+close) ⇒ Promise + * [.getNumSockets()](#WS2Manager+getNumSockets) ⇒ number + * [.getSocket(i)](#WS2Manager+getSocket) ⇒ [SocketState](#WS2Manager..SocketState) + * [.getSocketInfo()](#WS2Manager+getSocketInfo) ⇒ Array.<object> + * [.auth(args)](#WS2Manager+auth) + * [.openSocket()](#WS2Manager+openSocket) ⇒ [SocketState](#WS2Manager..SocketState) + * [.getAuthenticatedSocket()](#WS2Manager+getAuthenticatedSocket) ⇒ [SocketState](#WS2Manager..SocketState) + * [.getFreeDataSocket()](#WS2Manager+getFreeDataSocket) ⇒ [SocketState](#WS2Manager..SocketState) + * [.getSocketWithDataChannel(type, filter)](#WS2Manager+getSocketWithDataChannel) ⇒ [SocketState](#WS2Manager..SocketState) + * [.getSocketWithChannel(chanId)](#WS2Manager+getSocketWithChannel) ⇒ [SocketState](#WS2Manager..SocketState) + * [.getSocketWithSubRef(channel, identifier)](#WS2Manager+getSocketWithSubRef) ⇒ [SocketState](#WS2Manager..SocketState) + * [.withAllSockets(cb)](#WS2Manager+withAllSockets) + * [.subscribe(type, ident, filter)](#WS2Manager+subscribe) + * [.managedUnsubscribe(channel, identifier)](#WS2Manager+managedUnsubscribe) + * [.unsubscribe(chanId)](#WS2Manager+unsubscribe) + * [.subscribeTicker(symbol)](#WS2Manager+subscribeTicker) + * [.subscribeTrades(symbol)](#WS2Manager+subscribeTrades) + * [.subscribeOrderBook(symbol, [prec], [len], [freq])](#WS2Manager+subscribeOrderBook) + * [.subscribeCandles(key)](#WS2Manager+subscribeCandles) + * [.onCandle(opts, cb)](#WS2Manager+onCandle) + * [.onOrderBook(opts, cb)](#WS2Manager+onOrderBook) + * [.onTrades(opts, cb)](#WS2Manager+onTrades) + * [.onTicker(opts, cb)](#WS2Manager+onTicker) + * _static_ + * [.getDataChannelCount(s)](#WS2Manager.getDataChannelCount) ⇒ number + * _inner_ + * [~SocketState](#WS2Manager..SocketState) : object + + + +### new WS2Manager(socketArgs, [authArgs]) + +| Param | Type | Description | +| --- | --- | --- | +| socketArgs | [Configuration](#WSv2..Configuration) | passed to [WSv2](#WSv2) constructor | +| [authArgs] | object | cached for all internal socket auth() calls | +| [authArgs.calc] | object | default 0 | +| [authArgs.dms] | object | default 0 | + +**Example** +```js +const rest = new RESTv2() +const details = await rest.symbolDetails() +const symbols = details.map(d => `t${d.pair.toUpperCase()}`) +const timeFrames = ['1m', '5m', '30m', '1h', '6h'] +const keys = _flatten(symbols.map(s => { + return timeFrames.map(tf => `trade:${tf}:${s}`) +})) + +const m = new Manager() + +m.on('error', (err) => { + debug('error: %s', err) +}) + +m.once('open', () => { + debug('open') + + keys.forEach(key => { + m.subscribeCandles(key) + m.onCandle({ key }, (candles) => { + debug('recv %d candles on channel %s', candles.length, key) + }) + }) + + symbols.forEach(symbol => { + m.subscribeTrades(symbol) + m.onTrades({ symbol }, (trades) => { + debug('recv %d trades on channel %s', trades.length, symbol) + }) + }) + + symbols.forEach(symbol => { + m.subscribeTicker(symbol) + m.onTicker({ symbol }, (ticker) => { + debug('recv ticker on channel %s: %j', symbol, ticker) + }) + }) + + symbols.forEach(symbol => { + m.subscribeOrderBook(symbol) + m.onOrderBook({ symbol }, (update) => { + debug('recv book update on channel %s: %j', symbol, update) + }) + }) + + setInterval(() => { + debug('num keys: %d', keys.length) + debug('num sockets: %d', m.getNumSockets()) + debug('socket info: %j', m.getSocketInfo()) + }, 5000) +}) + +m.openSocket() +``` + + +### wS2Manager.setAuthArgs(args) +Update authentication arguments on all sockets + +**Kind**: instance method of [WS2Manager](#WS2Manager) + +| Param | Type | Description | +| --- | --- | --- | +| args | object | arguments | +| [args.calc] | object | calc value | +| [args.dms] | object | active 4 | + + + +### wS2Manager.getAuthArgs() ⇒ object +Retrieve internal authentication arguments + +**Kind**: instance method of [WS2Manager](#WS2Manager) +**Returns**: object - args + + +### wS2Manager.reconnect() ⇒ Promise +Reconnects all open sockets + +**Kind**: instance method of [WS2Manager](#WS2Manager) +**Returns**: Promise - p + + +### wS2Manager.close() ⇒ Promise +Closes all open sockets + +**Kind**: instance method of [WS2Manager](#WS2Manager) +**Returns**: Promise - p + + +### wS2Manager.getNumSockets() ⇒ number +**Kind**: instance method of [WS2Manager](#WS2Manager) +**Returns**: number - n + + +### wS2Manager.getSocket(i) ⇒ [SocketState](#WS2Manager..SocketState) +**Kind**: instance method of [WS2Manager](#WS2Manager) +**Returns**: [SocketState](#WS2Manager..SocketState) - state + +| Param | Type | Description | +| --- | --- | --- | +| i | number | index into pool | + + + +### wS2Manager.getSocketInfo() ⇒ Array.<object> +Returns an object which can be logged to inspect the socket pool + +**Kind**: instance method of [WS2Manager](#WS2Manager) +**Returns**: Array.<object> - socketInfo + + +### wS2Manager.auth(args) +Authenticates all existing & future sockets with the provided credentials. +Does nothing if an apiKey/apiSecret pair are already known. + +**Kind**: instance method of [WS2Manager](#WS2Manager) + +| Param | Type | Description | +| --- | --- | --- | +| args | object | arguments | +| args.apiKey | object | saved if not already provided | +| args.apiSecret | object | saved if not already provided | +| [args.calc] | object | default 0 | +| [args.dms] | object | dead man switch, active 4 | + + + +### wS2Manager.openSocket() ⇒ [SocketState](#WS2Manager..SocketState) +Creates a new socket/state instance and adds it to the internal pool. Binds +event listeners to forward via our own event emitter, and to manage pending +subs/unsubs. + +**Kind**: instance method of [WS2Manager](#WS2Manager) +**Returns**: [SocketState](#WS2Manager..SocketState) - state + + +### wS2Manager.getAuthenticatedSocket() ⇒ [SocketState](#WS2Manager..SocketState) +**Kind**: instance method of [WS2Manager](#WS2Manager) +**Returns**: [SocketState](#WS2Manager..SocketState) - state + + +### wS2Manager.getFreeDataSocket() ⇒ [SocketState](#WS2Manager..SocketState) +Returns the first socket that has less active/pending channels than the +DATA_CHANNEL_LIMIT + +**Kind**: instance method of [WS2Manager](#WS2Manager) +**Returns**: [SocketState](#WS2Manager..SocketState) - state - undefined if none found + + +### wS2Manager.getSocketWithDataChannel(type, filter) ⇒ [SocketState](#WS2Manager..SocketState) +Returns the first socket that is subscribed/pending sub to the specified +channel. + +**Kind**: instance method of [WS2Manager](#WS2Manager) +**Returns**: [SocketState](#WS2Manager..SocketState) - wsState - + undefined if not found + +| Param | Type | Description | +| --- | --- | --- | +| type | string | i.e. 'book' | +| filter | object | i.e. { symbol: 'tBTCUSD', prec: 'R0' } | + + + +### wS2Manager.getSocketWithChannel(chanId) ⇒ [SocketState](#WS2Manager..SocketState) +NOTE: Cannot filter against pending subscriptions, due to unknown chanId + +**Kind**: instance method of [WS2Manager](#WS2Manager) +**Returns**: [SocketState](#WS2Manager..SocketState) - wsState - + undefined if not found + +| Param | Type | Description | +| --- | --- | --- | +| chanId | number | channel ID | + + + +### wS2Manager.getSocketWithSubRef(channel, identifier) ⇒ [SocketState](#WS2Manager..SocketState) +**Kind**: instance method of [WS2Manager](#WS2Manager) +**Returns**: [SocketState](#WS2Manager..SocketState) - wsState - + undefined if not found + +| Param | Type | Description | +| --- | --- | --- | +| channel | string | channel type | +| identifier | string | unique channel identifier | + + + +### wS2Manager.withAllSockets(cb) +Calls the provided cb with all internal socket instances + +**Kind**: instance method of [WS2Manager](#WS2Manager) + +| Param | Type | Description | +| --- | --- | --- | +| cb | function | callback | + + + +### wS2Manager.subscribe(type, ident, filter) +Subscribes a free data socket if available to the specified channel, or +opens a new socket & subs if needed. + +**Kind**: instance method of [WS2Manager](#WS2Manager) + +| Param | Type | Description | +| --- | --- | --- | +| type | string | i.e. 'book' | +| ident | string | i.e. 'tBTCUSD' | +| filter | object | i.e. { symbol: 'tBTCUSD', prec: 'R0' } | + + + +### wS2Manager.managedUnsubscribe(channel, identifier) +**Kind**: instance method of [WS2Manager](#WS2Manager) + +| Param | Type | Description | +| --- | --- | --- | +| channel | string | channel type | +| identifier | string | unique channel identifier | + + + +### wS2Manager.unsubscribe(chanId) +Unsubscribes the first socket w/ the specified channel. Does nothing if no +such socket is found. + +**Kind**: instance method of [WS2Manager](#WS2Manager) + +| Param | Type | Description | +| --- | --- | --- | +| chanId | number | channel ID | + + + +### wS2Manager.subscribeTicker(symbol) +**Kind**: instance method of [WS2Manager](#WS2Manager) + +| Param | Type | Description | +| --- | --- | --- | +| symbol | string | symbol for ticker | + + + +### wS2Manager.subscribeTrades(symbol) +**Kind**: instance method of [WS2Manager](#WS2Manager) + +| Param | Type | Description | +| --- | --- | --- | +| symbol | string | symbol for trades | + + + +### wS2Manager.subscribeOrderBook(symbol, [prec], [len], [freq]) +**Kind**: instance method of [WS2Manager](#WS2Manager) + +| Param | Type | Default | Description | +| --- | --- | --- | --- | +| symbol | string | | symbol for order book | +| [prec] | string | "P0" | precision, i.e. 'R0', default 'P0' | +| [len] | string | "25" | length, default '25' | +| [freq] | string | "F0" | default 'F0' | + + + +### wS2Manager.subscribeCandles(key) +**Kind**: instance method of [WS2Manager](#WS2Manager) + +| Param | Type | Description | +| --- | --- | --- | +| key | string | candle channel key | + + + +### wS2Manager.onCandle(opts, cb) +**Kind**: instance method of [WS2Manager](#WS2Manager) +**Throws**: + +- an error if no data socket is available + +**See**: https://docs.bitfinex.com/v2/reference#ws-public-candle + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| opts.key | string | candle set key, i.e. trade:30m:tBTCUSD | +| [opts.cbGID] | string | callback group id | +| cb | function | callback | + + + +### wS2Manager.onOrderBook(opts, cb) +**Kind**: instance method of [WS2Manager](#WS2Manager) +**Throws**: + +- an error if no data socket is available + +**See**: https://docs.bitfinex.com/v2/reference#ws-public-order-books + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| opts.symbol | string | order book symbol | +| [opts.prec] | string | precision, i.e. 'R0', default 'P0' | +| [opts.len] | string | length, default '25' | +| [opts.freq] | string | default 'F0' | +| [opts.cbGID] | string | callback group id | +| cb | function | callback | + + + +### wS2Manager.onTrades(opts, cb) +**Kind**: instance method of [WS2Manager](#WS2Manager) +**Throws**: + +- an error if no data socket is available + +**See**: https://docs.bitfinex.com/v2/reference#ws-public-trades + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.symbol] | string | symbol for trades | +| [opts.cbGID] | string | callback group id | +| cb | function | callback | + + + +### wS2Manager.onTicker(opts, cb) +**Kind**: instance method of [WS2Manager](#WS2Manager) +**Throws**: + +- an error if no data socket is available + +**See**: https://docs.bitfinex.com/v2/reference#ws-public-ticker + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.symbol] | string | symbol for ticker | +| [opts.cbGID] | string | callback group id | +| cb | function | callback | + + + +### WS2Manager.getDataChannelCount(s) ⇒ number +**Kind**: static method of [WS2Manager](#WS2Manager) +**Returns**: number - count - # of subscribed/pending data channels + +| Param | Type | Description | +| --- | --- | --- | +| s | [SocketState](#WS2Manager..SocketState) | socket state | + + + +### WS2Manager~SocketState : object +Object containing socket state for [WS2Manager](#WS2Manager). + +**Kind**: inner typedef of [WS2Manager](#WS2Manager) +**Properties** + +| Name | Type | Description | +| --- | --- | --- | +| ws | [WSv2](#WSv2) | client instance | +| pendingSubscriptions | Array.<Array> | array of sent but unconfirmed channel subscriptions | +| pendingUnsubscriptions | Array.<Array> | array of sent but unconfirmed channel unsubscribe packets | + + + +## WSv2 ⇐ events.EventEmitter +Communicates with v2 of the Bitfinex WebSocket API + +**Kind**: global class +**Extends**: events.EventEmitter + +* [WSv2](#WSv2) ⇐ events.EventEmitter + * [new WSv2([config])](#new_WSv2_new) + * _instance_ + * [.WSv2.flags](#WSv2+WSv2.flags) + * [.WSv2.info](#WSv2+WSv2.info) + * [.getURL()](#WSv2+getURL) ⇒ string + * [.usesAgent()](#WSv2+usesAgent) ⇒ boolean + * [.updateAuthArgs(args)](#WSv2+updateAuthArgs) + * [.getAuthArgs()](#WSv2+getAuthArgs) ⇒ object + * [.setAPICredentials(apiKey, apiSecret)](#WSv2+setAPICredentials) + * [.getDataChannelCount()](#WSv2+getDataChannelCount) ⇒ number + * [.hasChannel(chanId)](#WSv2+hasChannel) ⇒ boolean + * [.hasSubscriptionRef(channel, identifier)](#WSv2+hasSubscriptionRef) ⇒ boolean + * [.getDataChannelId(type, filter)](#WSv2+getDataChannelId) ⇒ number + * [.hasDataChannel(type, filter)](#WSv2+hasDataChannel) ⇒ boolean + * [.open()](#WSv2+open) ⇒ Promise + * [.close(code, reason)](#WSv2+close) ⇒ Promise + * [.auth([calc], [dms])](#WSv2+auth) ⇒ Promise + * [.reconnect()](#WSv2+reconnect) ⇒ Promise + * [.getOB(symbol)](#WSv2+getOB) ⇒ bfx-api-node-models.OrderBook + * [.getLosslessOB(symbol)](#WSv2+getLosslessOB) ⇒ bfx-api-node-models.OrderBook + * [.getCandles(key)](#WSv2+getCandles) ⇒ bfx-api-node-models.Candle \| Array.<bfx-api-node-models.Candle~ArrayData> + * [.managedSubscribe(channel, identifier, payload)](#WSv2+managedSubscribe) ⇒ boolean + * [.managedUnsubscribe(channel, identifier)](#WSv2+managedUnsubscribe) ⇒ boolean + * [.getChannelData(opts)](#WSv2+getChannelData) ⇒ object + * [.send(msg)](#WSv2+send) + * [.sequencingEnabled()](#WSv2+sequencingEnabled) ⇒ boolean + * [.enableSequencing(args)](#WSv2+enableSequencing) ⇒ Promise + * [.enableFlag(flag)](#WSv2+enableFlag) ⇒ Promise + * [.isFlagEnabled(flag)](#WSv2+isFlagEnabled) ⇒ boolean + * [.onServerRestart(cb)](#WSv2+onServerRestart) + * [.onMaintenanceStart(cb)](#WSv2+onMaintenanceStart) + * [.onMaintenanceEnd(cb)](#WSv2+onMaintenanceEnd) + * [.subscribe(channel, payload)](#WSv2+subscribe) + * [.subscribeTicker(symbol)](#WSv2+subscribeTicker) ⇒ boolean + * [.subscribeTrades(symbol)](#WSv2+subscribeTrades) ⇒ boolean + * [.subscribeOrderBook(symbol, prec, len)](#WSv2+subscribeOrderBook) ⇒ boolean + * [.subscribeCandles(key)](#WSv2+subscribeCandles) ⇒ boolean + * [.subscribeStatus(key)](#WSv2+subscribeStatus) ⇒ boolean + * [.unsubscribe(chanId)](#WSv2+unsubscribe) + * [.unsubscribeTicker(symbol)](#WSv2+unsubscribeTicker) ⇒ boolean + * [.unsubscribeTrades(symbol)](#WSv2+unsubscribeTrades) ⇒ boolean + * [.unsubscribeOrderBook(symbol)](#WSv2+unsubscribeOrderBook) ⇒ boolean + * [.unsubscribeCandles(symbol, frame)](#WSv2+unsubscribeCandles) ⇒ boolean + * [.unsubscribeStatus(key)](#WSv2+unsubscribeStatus) ⇒ boolean + * [.removeListeners(cbGID)](#WSv2+removeListeners) + * [.requestCalc(prefixes)](#WSv2+requestCalc) + * [.submitOrder(order)](#WSv2+submitOrder) ⇒ Promise + * [.updateOrder(changes)](#WSv2+updateOrder) ⇒ Promise + * [.cancelOrder(order)](#WSv2+cancelOrder) ⇒ Promise + * [.cancelOrders(orders)](#WSv2+cancelOrders) ⇒ Promise + * [.submitOrderMultiOp(opPayloads)](#WSv2+submitOrderMultiOp) ⇒ Promise + * [.isAuthenticated()](#WSv2+isAuthenticated) ⇒ boolean + * [.isOpen()](#WSv2+isOpen) ⇒ boolean + * [.isReconnecting()](#WSv2+isReconnecting) ⇒ boolean + * [.notifyUI(opts)](#WSv2+notifyUI) + * [.onInfoMessage(code, cb)](#WSv2+onInfoMessage) + * [.onMessage(opts, cb)](#WSv2+onMessage) + * [.onCandle(opts, cb)](#WSv2+onCandle) + * [.onOrderBook(opts, cb)](#WSv2+onOrderBook) + * [.onOrderBookChecksum(opts, cb)](#WSv2+onOrderBookChecksum) + * [.onTrades(opts, cb)](#WSv2+onTrades) + * [.onTradeEntry(opts, cb)](#WSv2+onTradeEntry) + * [.onAccountTradeEntry(opts, cb)](#WSv2+onAccountTradeEntry) + * [.onAccountTradeUpdate(opts, cb)](#WSv2+onAccountTradeUpdate) + * [.onTicker(opts, cb)](#WSv2+onTicker) + * [.onStatus(opts, cb)](#WSv2+onStatus) + * [.onOrderSnapshot(opts, cb)](#WSv2+onOrderSnapshot) + * [.onOrderNew(opts, cb)](#WSv2+onOrderNew) + * [.onOrderUpdate(opts, cb)](#WSv2+onOrderUpdate) + * [.onOrderClose(opts, cb)](#WSv2+onOrderClose) + * [.onPositionSnapshot(opts, cb)](#WSv2+onPositionSnapshot) + * [.onPositionNew(opts, cb)](#WSv2+onPositionNew) + * [.onPositionUpdate(opts, cb)](#WSv2+onPositionUpdate) + * [.onPositionClose(opts, cb)](#WSv2+onPositionClose) + * [.onFundingOfferSnapshot(opts, cb)](#WSv2+onFundingOfferSnapshot) + * [.onFundingOfferNew(opts, cb)](#WSv2+onFundingOfferNew) + * [.onFundingOfferUpdate(opts, cb)](#WSv2+onFundingOfferUpdate) + * [.onFundingOfferClose(opts, cb)](#WSv2+onFundingOfferClose) + * [.onFundingCreditSnapshot(opts, cb)](#WSv2+onFundingCreditSnapshot) + * [.onFundingCreditNew(opts, cb)](#WSv2+onFundingCreditNew) + * [.onFundingCreditUpdate(opts, cb)](#WSv2+onFundingCreditUpdate) + * [.onFundingCreditClose(opts, cb)](#WSv2+onFundingCreditClose) + * [.onFundingLoanSnapshot(opts, cb)](#WSv2+onFundingLoanSnapshot) + * [.onFundingLoanNew(opts, cb)](#WSv2+onFundingLoanNew) + * [.onFundingLoanUpdate(opts, cb)](#WSv2+onFundingLoanUpdate) + * [.onFundingLoanClose(opts, cb)](#WSv2+onFundingLoanClose) + * [.onWalletSnapshot(opts, cb)](#WSv2+onWalletSnapshot) + * [.onWalletUpdate(opts, cb)](#WSv2+onWalletUpdate) + * [.onBalanceInfoUpdate(opts, cb)](#WSv2+onBalanceInfoUpdate) + * [.onMarginInfoUpdate(opts, cb)](#WSv2+onMarginInfoUpdate) + * [.onFundingInfoUpdate(opts, cb)](#WSv2+onFundingInfoUpdate) + * [.onFundingTradeEntry(opts, cb)](#WSv2+onFundingTradeEntry) + * [.onFundingTradeUpdate(opts, cb)](#WSv2+onFundingTradeUpdate) + * [.onNotification(opts, cb)](#WSv2+onNotification) + * _static_ + * [.url](#WSv2.url) : string + * _inner_ + * [~Configuration](#WSv2..Configuration) : object + + + +### new WSv2([config]) +Instantiate a new ws2 transport. Does not auto-open + + +| Param | Type | Description | +| --- | --- | --- | +| [config] | [Configuration](#WSv2..Configuration) | client configuration | + +**Example** +```js +const ws = new WSv2() + +ws.on('open', async () => { + ws.onTrades({ symbol: 'tBTCUSD' }, (trades) => { + console.log('recv trades: %j', trades) + }) + + await ws.subscribeTrades('tBTCUSD') +}) + +await ws.open() +``` + + +### wSv2.WSv2.flags +Map of flag names and numeric values for usage with the API + +**Kind**: instance constant of [WSv2](#WSv2) +**Properties** + +| Name | Type | Description | +| --- | --- | --- | +| DEC_S | number | flag to request all decimals as strings | +| TIME_S | number | flag to request all timestamps as strings | +| TIMESTAMP | number | flag to request timestamp in milliseconds | +| SEQ_ALL | number | flag to enable sequence numbers & verification | +| CHECKSUM | number | flag to enable order book checksums | + + + +### wSv2.WSv2.info +Map of info event names and their respective codes for usage with the API + +**Kind**: instance constant of [WSv2](#WSv2) +**Properties** + +| Name | Type | Description | +| --- | --- | --- | +| SERVER_RESTART | number | server restart event | +| MAINTENANCE_START | number | maintenance start event | +| MAINTENANCE_END | number | maintenance end event | + + + +### wSv2.getURL() ⇒ string +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: string - url + + +### wSv2.usesAgent() ⇒ boolean +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: boolean - usesAgent + + +### wSv2.updateAuthArgs(args) +Set `calc` and `dms` values to be used on the next +[auth](#WSv2+auth) call + +**Kind**: instance method of [WSv2](#WSv2) +**See**: [auth](#WSv2+auth) + +| Param | Type | Description | +| --- | --- | --- | +| args | object | arguments | +| [args.calc] | number | calc value | +| [args.dms] | number | dms value, active 4 | + + + +### wSv2.getAuthArgs() ⇒ object +Fetch the current default auth parameters + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: object - authArgs +**See** + +- [updateAuthArgs](#WSv2+updateAuthArgs) +- [auth](#WSv2+auth) + + + +### wSv2.setAPICredentials(apiKey, apiSecret) +Update the internal API credentials, used on subsequent +[auth](#WSv2+auth) calls + +**Kind**: instance method of [WSv2](#WSv2) +**See**: [auth](#WSv2+auth) + +| Param | Type | Description | +| --- | --- | --- | +| apiKey | string | API key | +| apiSecret | string | API secret | + + + +### wSv2.getDataChannelCount() ⇒ number +Get the total number of data channels this instance is currently +subscribed too. + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: number - count +**See** + +- [subscribeTrades](#WSv2+subscribeTrades) +- [subscribeTicker](#WSv2+subscribeTicker) +- [subscribeCandles](#WSv2+subscribeCandles) +- [subscribeOrderBook](#WSv2+subscribeOrderBook) + + + +### wSv2.hasChannel(chanId) ⇒ boolean +Check if the instance is subscribed to the specified channel ID + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: boolean - isSubscribed + +| Param | Type | Description | +| --- | --- | --- | +| chanId | number | ID of channel to query | + + + +### wSv2.hasSubscriptionRef(channel, identifier) ⇒ boolean +Check if a channel/identifier pair has been subscribed too + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: boolean - hasRef +**See**: [managedSubscribe](#WSv2+managedSubscribe) + +| Param | Type | Description | +| --- | --- | --- | +| channel | string | channel type | +| identifier | string | unique identifier for the reference | + + + +### wSv2.getDataChannelId(type, filter) ⇒ number +Fetch the ID of a channel matched by type and channel data filter + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: number - channelID + +| Param | Type | Description | +| --- | --- | --- | +| type | string | channel type | +| filter | object | to be matched against channel data | + + + +### wSv2.hasDataChannel(type, filter) ⇒ boolean +Check if the instance is subscribed to a data channel matching the +specified type and filter. + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: boolean - hasChannel + +| Param | Type | Description | +| --- | --- | --- | +| type | string | channel type | +| filter | object | to be matched against channel data | + + + +### wSv2.open() ⇒ Promise +Opens a connection to the API server. Rejects with an error if a +connection is already open. Resolves on success. + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: Promise - p + + +### wSv2.close(code, reason) ⇒ Promise +Closes the active connection. If there is none, rejects with a promise. +Resolves on success + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: Promise - p + +| Param | Type | Description | +| --- | --- | --- | +| code | number | passed to ws | +| reason | string | passed to ws | + + + +### wSv2.auth([calc], [dms]) ⇒ Promise +Generates & sends an authentication packet to the server; if already +authenticated, rejects with an error, resolves on success. + +If a DMS flag of 4 is provided, all open orders are cancelled when the +connection terminates. + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: Promise - p + +| Param | Type | Description | +| --- | --- | --- | +| [calc] | number | default is 0 | +| [dms] | number | dead man switch flag, active 4 | + + + +### wSv2.reconnect() ⇒ Promise +Utility method to close & re-open the ws connection. Re-authenticates if +previously authenticated + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: Promise - p - resolves on completion + + +### wSv2.getOB(symbol) ⇒ bfx-api-node-models.OrderBook +Returns an up-to-date copy of the order book for the specified symbol, or +null if no OB is managed for that symbol. + +Set `managedOrderBooks: true` in the constructor to use. + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: bfx-api-node-models.OrderBook - ob - null if not found + +| Param | Type | Description | +| --- | --- | --- | +| symbol | string | symbol for order book | + +**Example** +```js +const ws = new WSv2({ managedOrderBooks: true }) + +ws.on('open', async () => { + ws.onOrderBook({ symbol: 'tBTCUSD' }, () => { + const book = ws.getOB('tBTCUSD') + + if (!book) return + + const spread = book.midPrice() + console.log('spread for tBTCUSD: %f', spread) + }) + + ws.subscribeOrderBook({ symbol: 'tBTCUSD' }) +}) + +await ws.open() +``` + + +### wSv2.getLosslessOB(symbol) ⇒ bfx-api-node-models.OrderBook +Returns an up-to-date lossless copy of the order book for the specified symbol, or +null if no OB is managed for that symbol. All amounts and prices are in original +string format. + +Set `manageOrderBooks: true` in the constructor to use. + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: bfx-api-node-models.OrderBook - ob - null if not found + +| Param | Type | Description | +| --- | --- | --- | +| symbol | string | symbol for order book | + + + +### wSv2.getCandles(key) ⇒ bfx-api-node-models.Candle \| Array.<bfx-api-node-models.Candle~ArrayData> +Fetch a reference to the full set of synced candles for the specified key. +Set `managedCandles: true` in the constructor to use. + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: bfx-api-node-models.Candle \| Array.<bfx-api-node-models.Candle~ArrayData> - candles - empty array if none exist + +| Param | Type | Description | +| --- | --- | --- | +| key | string | key for candle set | + +**Example** +```js +const ws = new WSv2({ managedCandles: true }) + +ws.on('open', async () => { + ws.onCandles({ key: 'trade:1m:tBTCUSD' }, () => { + const candles = ws.getCandles('trade:1m:tBTCUSD') + + if (!candles) return + + console.log('%d candles in dataset', candles.length) + }) + + ws.subscribeCandles({ key: 'trade:1m:tBTCUSD' }) +}) + +await ws.open() +``` + + +### wSv2.managedSubscribe(channel, identifier, payload) ⇒ boolean +Subscribes and tracks subscriptions per channel/identifier pair. If +already subscribed to the specified pair, nothing happens. + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: boolean - subSent +**See** + +- [subscribeTrades](#WSv2+subscribeTrades) +- [subscribeTicker](#WSv2+subscribeTicker) +- [subscribeCandles](#WSv2+subscribeCandles) +- [subscribeOrderBook](#WSv2+subscribeOrderBook) + +**Todo** + +- [ ] will be refactored to return promise from subscribe() call instead + of sub action taken flag + + +| Param | Type | Description | +| --- | --- | --- | +| channel | string | channel name | +| identifier | string | for uniquely identifying the ref count | +| payload | object | merged with sub packet | + +**Example** +```js +const ws = new WSv2() + +ws.on('open', async () => { + ws.onTrades({ symbol: 'tBTCUSD' }, (trades) => { + console.log('recv trades: %j', trades) + }) + + ws.managedSubscribe('trades', 'tBTCUSD', { symbol: 'tBTCUSD' }) +}) + +await ws.open() +``` + + +### wSv2.managedUnsubscribe(channel, identifier) ⇒ boolean +Decreases the subscription ref count for the channel/identifier pair, and +unsubscribes from the channel if it reaches 0. + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: boolean - unsubSent + +| Param | Type | Description | +| --- | --- | --- | +| channel | string | channel name | +| identifier | string | for uniquely identifying the ref count | + + + +### wSv2.getChannelData(opts) ⇒ object +Fetch a channel definition + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: object - chanData - null if not found + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| opts.chanId | number | channel ID | +| opts.channel | string | channel name | +| [opts.symbol] | string | match by symbol | +| [opts.key] | string | match by key (for candle channels) | + + + +### wSv2.send(msg) +Send a packet to the WS server + +**Kind**: instance method of [WSv2](#WSv2) + +| Param | Type | Description | +| --- | --- | --- | +| msg | Array \| object | packet, gets stringified | + + + +### wSv2.sequencingEnabled() ⇒ boolean +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: boolean - sequencingEnabled + + +### wSv2.enableSequencing(args) ⇒ Promise +Configures the seq flag to enable sequencing (packet number) for this +connection. When enabled, the seq number will be the last value of +channel packet arrays. + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: Promise - p +**See**: [WSv2#flags](WSv2#flags) + +| Param | Type | Description | +| --- | --- | --- | +| args | object | params | +| [args.audit] | boolean | if true, an error is emitted on invalid seq | + + + +### wSv2.enableFlag(flag) ⇒ Promise +Enables a configuration flag. + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: Promise - p +**See**: [WSv2#flags](WSv2#flags) + +| Param | Type | Description | +| --- | --- | --- | +| flag | number | flag to update, as numeric value | + +**Example** +```js +const ws = new WSv2() + +ws.on('open', async () => { + await ws.enableFlag(WSv2.flags.CHECKSUM) + console.log('ob checkums enabled') +}) + +await ws.open() +``` + + +### wSv2.isFlagEnabled(flag) ⇒ boolean +Checks local state, relies on successful server config responses + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: boolean - enabled +**See**: [enableFlag](#WSv2+enableFlag) + +| Param | Type | Description | +| --- | --- | --- | +| flag | number | flag to check for | + + + +### wSv2.onServerRestart(cb) +Register a callback in case of a ws server restart message; Use this to +call reconnect() if needed. (code 20051) + +**Kind**: instance method of [WSv2](#WSv2) + +| Param | Type | Description | +| --- | --- | --- | +| cb | function | called on event trigger | + + + +### wSv2.onMaintenanceStart(cb) +Register a callback in case of a 'maintenance started' message from the +server. This is a good time to pause server packets until maintenance ends + +**Kind**: instance method of [WSv2](#WSv2) + +| Param | Type | Description | +| --- | --- | --- | +| cb | function | called on event trigger | + + + +### wSv2.onMaintenanceEnd(cb) +Register a callback to be notified of a maintenance period ending + +**Kind**: instance method of [WSv2](#WSv2) + +| Param | Type | Description | +| --- | --- | --- | +| cb | function | called on event trigger | + + + +### wSv2.subscribe(channel, payload) +Subscribe to a channel with the given filter payload + +**Kind**: instance method of [WSv2](#WSv2) + +| Param | Type | Description | +| --- | --- | --- | +| channel | string | channel payload/data | +| payload | object | optional extra packet data | + +**Example** +```js +const ws = new WSv2() + +ws.on('open', () => { + ws.onTrades({ symbol: 'tBTCUSD' }, (trades) => { + // ... + }) + + ws.subscribe('trades', { symbol: 'tBTCUSD' }) +}) + +await ws.open() +``` + + +### wSv2.subscribeTicker(symbol) ⇒ boolean +Subscribe to a ticker data channel + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: boolean - subscribed +**See**: [managedSubscribe](#WSv2+managedSubscribe) + +| Param | Type | Description | +| --- | --- | --- | +| symbol | string | symbol of ticker | + +**Example** +```js +await ws.subscribeTicker('tBTCUSD') +``` + + +### wSv2.subscribeTrades(symbol) ⇒ boolean +Subscribe to a trades data channel + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: boolean - subscribed +**See**: [managedSubscribe](#WSv2+managedSubscribe) + +| Param | Type | Description | +| --- | --- | --- | +| symbol | string | symbol of market to monitor | + +**Example** +```js +await ws.subscribeTrades('tBTCUSD') +``` + + +### wSv2.subscribeOrderBook(symbol, prec, len) ⇒ boolean +Subscribe to an order book data channel + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: boolean - subscribed +**See**: [managedSubscribe](#WSv2+managedSubscribe) + +| Param | Type | Default | Description | +| --- | --- | --- | --- | +| symbol | string | | symbol of order book | +| prec | string | "P0" | P0, P1, P2, or P3 (default P0) | +| len | string | "25" | 25 or 100 (default 25) | + +**Example** +```js +await ws.subscribeOrderBook('tBTCUSD', 'R0', '25') +``` + + +### wSv2.subscribeCandles(key) ⇒ boolean +Subscribe to a candle data channel + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: boolean - subscribed +**See**: [managedSubscribe](#WSv2+managedSubscribe) + +| Param | Type | Description | +| --- | --- | --- | +| key | string | 'trade:5m:tBTCUSD' | + +**Example** +```js +await ws.subscribeCandles('trade:5m:tBTCUSD') +``` + + +### wSv2.subscribeStatus(key) ⇒ boolean +Subscribe to a status data channel + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: boolean - subscribed +**See**: [managedSubscribe](#WSv2+managedSubscribe) + +| Param | Type | Description | +| --- | --- | --- | +| key | string | i.e. 'liq:global' | + +**Example** +```js +await ws.subscribeStatus('liq:global') +``` + + +### wSv2.unsubscribe(chanId) +Unsubscribe from a channel by ID + +**Kind**: instance method of [WSv2](#WSv2) + +| Param | Type | Description | +| --- | --- | --- | +| chanId | number | ID of channel to unsubscribe from | + +**Example** +```js +const id = ws.getDataChannelId('ticker', { symbol: 'tBTCUSD' }) + +if (id) { + ws.unsubscribe(id) +} +``` + + +### wSv2.unsubscribeTicker(symbol) ⇒ boolean +Unsubscribe from a ticker data channel + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: boolean - unsubscribed +**See**: [subscribeTicker](#WSv2+subscribeTicker) + +| Param | Type | Description | +| --- | --- | --- | +| symbol | string | symbol of ticker | + +**Example** +```js +await ws.unsubscribeTicker('tBTCUSD') +``` + + +### wSv2.unsubscribeTrades(symbol) ⇒ boolean +Unsubscribe from a trades data channel + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: boolean - unsubscribed +**See**: [subscribeTrades](#WSv2+subscribeTrades) + +| Param | Type | Description | +| --- | --- | --- | +| symbol | string | symbol of market to unsubscribe from | + +**Example** +```js +await ws.unsubcribeTrades('tBTCUSD') +``` + + +### wSv2.unsubscribeOrderBook(symbol) ⇒ boolean +Unsubscribe from an order book data channel + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: boolean - unsubscribed +**See**: [subscribeOrderBook](#WSv2+subscribeOrderBook) + +| Param | Type | Description | +| --- | --- | --- | +| symbol | string | symbol of order book | + +**Example** +```js +await ws.unsubcribeOrderBook('tBTCUSD') +``` + + +### wSv2.unsubscribeCandles(symbol, frame) ⇒ boolean +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: boolean - unsubscribed +**See**: [subscribeCandles](#WSv2+subscribeCandles) + +| Param | Type | Description | +| --- | --- | --- | +| symbol | string | symbol of candles | +| frame | string | time frame | + +**Example** +```js +await ws.unsubscribeCandles('tBTCUSD', '1m') +``` + + +### wSv2.unsubscribeStatus(key) ⇒ boolean +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: boolean - unsubscribed +**See**: [subscribeStatus](#WSv2+subscribeStatus) + +| Param | Type | Description | +| --- | --- | --- | +| key | string | key that was used in initial [subscribeStatus](#WSv2+subscribeStatus) call | + + + +### wSv2.removeListeners(cbGID) +Remove all listeners by callback group ID + +**Kind**: instance method of [WSv2](#WSv2) + +| Param | Type | Description | +| --- | --- | --- | +| cbGID | string | callback group to remove | + +**Example** +```js +await ws.subscribeTrades({ symbol: 'tBTCUSD', cbGID: 42 }) +await ws.subscribeTrades({ symbol: 'tLEOUSD', cbGID: 42 }) +await ws.subscribeTrades({ symbol: 'tETHUSD', cbGID: 42 }) + +// ... + +ws.removeListeners(42) +``` + + +### wSv2.requestCalc(prefixes) +Request a calc operation to be performed on the specified indexes + +**Kind**: instance method of [WSv2](#WSv2) + +| Param | Type | Description | +| --- | --- | --- | +| prefixes | Array.<string> | desired prefixes to be calculated | + + + +### wSv2.submitOrder(order) ⇒ Promise +Sends a new order to the server and resolves the returned promise once the +order submit is confirmed. Emits an error if not authenticated. The order +can be either an array, key/value map, or Order object instance. + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: Promise - p - resolves on submit notification +**See** + +- [cancelOrders](#WSv2+cancelOrders) +- [cancelOrder](#WSv2+cancelOrder) +- [updateOrder](#WSv2+updateOrder) + + +| Param | Type | Description | +| --- | --- | --- | +| order | bfx-api-node-models.Order \| bfx-api-node-models.Order~Data | order | + +**Example** +```js +const o = new Order({ + type: Order.type.EXCHANGE_LIMIT, + amount: 18, + price: 0.75, + symbol: 'tBTCUSD', + hidden: true +}, ws) + +await ws.submitOrder(o) + +console.log('order confirmed! status: %s', o.status) +``` + + +### wSv2.updateOrder(changes) ⇒ Promise +Send a changeset to update an order in-place while maintaining position in +the price queue. The changeset must contain the order ID, and supports a +'delta' key to increase/decrease the total amount. + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: Promise - p - resolves on receiving an confirmation notification +**See**: [submitOrder](#WSv2+submitOrder) + +| Param | Type | Description | +| --- | --- | --- | +| changes | object | requires at least an 'id' | + + + +### wSv2.cancelOrder(order) ⇒ Promise +Cancels an order by ID and resolves the returned promise once the cancel is +confirmed. Emits an error if not authenticated. The ID can be passed as a +number, or taken from an order array/object. + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: Promise - p +**See**: [submitOrder](#WSv2+submitOrder) + +| Param | Type | Description | +| --- | --- | --- | +| order | bfx-api-node-models.Order \| bfx-api-node-models.Order~Data \| number | order model, array, or ID to be cancelled | + + + +### wSv2.cancelOrders(orders) ⇒ Promise +Cancels multiple orders, returns a promise that resolves once all +operations are confirmed. + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: Promise - p +**See**: [submitOrder](#WSv2+submitOrder) + +| Param | Type | Description | +| --- | --- | --- | +| orders | Array.<bfx-api-node-models.Order> \| Array.<bfx-api-node-models.Order~Data> \| Array.<number> | array of order models, arrays or IDs to be cancelled | + + + +### wSv2.submitOrderMultiOp(opPayloads) ⇒ Promise +Sends the op payloads to the server as an 'ox_multi' command. A promise is +returned and resolves immediately if authenticated, as no confirmation is +available for this message type. + +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: Promise - p - rejects if not authenticated + +| Param | Type | Description | +| --- | --- | --- | +| opPayloads | Array.<object> | order operations | + + + +### wSv2.isAuthenticated() ⇒ boolean +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: boolean - authenticated + + +### wSv2.isOpen() ⇒ boolean +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: boolean - open + + +### wSv2.isReconnecting() ⇒ boolean +**Kind**: instance method of [WSv2](#WSv2) +**Returns**: boolean - reconnecting + + +### wSv2.notifyUI(opts) +Sends a broadcast notification, which will be received by any active UI +websocket connections (at bitfinex.com), triggering a desktop notification. + +In the future our mobile app will also support spawning native push +notifications in response to incoming ucm-notify-ui packets. + +**Kind**: instance method of [WSv2](#WSv2) +**Throws**: + +- an error if given no type or message, or the instance is not open + and authenticated + + +| Param | Type | Description | +| --- | --- | --- | +| opts | bfx-api-node-models.Notification~BroadcastPayload | broadcast payload | + + + +### wSv2.onInfoMessage(code, cb) +Registers a new callback to be called when a matching info message is +received. + +**Kind**: instance method of [WSv2](#WSv2) + +| Param | Type | Description | +| --- | --- | --- | +| code | number | from [WSv2.info](WSv2.info) | +| cb | function | callback | + + + +### wSv2.onMessage(opts, cb) +Register a generic handler to be called with each received message + +**Kind**: instance method of [WSv2](#WSv2) + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.cbGID] | string \| number | callback group id | +| cb | function | callback | + + + +### wSv2.onCandle(opts, cb) +Register a handler to be called with each received candle + +**Kind**: instance method of [WSv2](#WSv2) +**See** + +- https://docs.bitfinex.com/v2/reference#ws-public-candle +- [subscribeCandles](#WSv2+subscribeCandles) +- [unsubscribeCandles](#WSv2+unsubscribeCandles) + + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| opts.key | string | candle set key, i.e. trade:30m:tBTCUSD | +| [opts.cbGID] | string \| number | callback group id | +| cb | function | callback | + + + +### wSv2.onOrderBook(opts, cb) +Register a handler to be called with each received candle + +**Kind**: instance method of [WSv2](#WSv2) +**See** + +- https://docs.bitfinex.com/v2/reference#ws-public-order-books +- [subscribeOrderBook](#WSv2+subscribeOrderBook) +- [unsubscribeOrderBook](#WSv2+unsubscribeOrderBook) + + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| opts.symbol | string | book symbol | +| opts.prec | string | book precision, i.e. 'R0' | +| opts.len | string | book length, i.e. '25' | +| [opts.cbGID] | string \| number | callback group id | +| cb | function | callback | + + + +### wSv2.onOrderBookChecksum(opts, cb) +Register a handler to be called with each received order book checksum + +**Kind**: instance method of [WSv2](#WSv2) +**See** + +- https://docs.bitfinex.com/v2/reference#ws-public-order-books +- [subscribeOrderBook](#WSv2+subscribeOrderBook) +- [unsubscribeOrderBook](#WSv2+unsubscribeOrderBook) + + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| opts.symbol | string | book symbol | +| opts.prec | string | book precision, i.e. 'R0' | +| opts.len | string | book length, i.e. '25' | +| [opts.cbGID] | string \| number | callback group id | +| cb | function | callback | + + + +### wSv2.onTrades(opts, cb) +Register a handler to be called with each received trade (pair or symbol +required) + +**Kind**: instance method of [WSv2](#WSv2) +**See** + +- https://docs.bitfinex.com/v2/reference#ws-public-trades +- [subscribeTrades](#WSv2+subscribeTrades) +- [unsubscribeTrades](#WSv2+unsubscribeTrades) + + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.pair] | string | required if no symbol specified | +| [opts.symbol] | string | required if no pair specified | +| [opts.cbGID] | string \| number | callback group id | +| cb | function | callback | + + + +### wSv2.onTradeEntry(opts, cb) +Register a handler to be called on each trade `'te'` event + +**Kind**: instance method of [WSv2](#WSv2) +**See** + +- https://docs.bitfinex.com/v2/reference#ws-public-trades +- [subscribeTrades](#WSv2+subscribeTrades) +- [unsubscribeTrades](#WSv2+unsubscribeTrades) + + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.pair] | string | required if no symbol specified | +| [opts.symbol] | string | required if no pair specified | +| [opts.cbGID] | string \| number | callback group id | +| cb | function | callback | + + + +### wSv2.onAccountTradeEntry(opts, cb) +Register a handler to be called on each personal trade `'te'` event + +**Kind**: instance method of [WSv2](#WSv2) +**See**: https://docs.bitfinex.com/v2/reference#ws-public-trades + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.symbol] | string | required if no pair specified | +| [opts.cbGID] | string \| number | callback group id | +| cb | function | callback | + + + +### wSv2.onAccountTradeUpdate(opts, cb) +Register a handler to be called on each personal trade `'tu'` event + +**Kind**: instance method of [WSv2](#WSv2) +**See**: https://docs.bitfinex.com/v2/reference#ws-auth-trades + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.symbol] | string | required if no pair specified | +| [opts.cbGID] | string \| number | callback group id | +| cb | function | callback | + + + +### wSv2.onTicker(opts, cb) +Register a handler to be called on each received ticker + +**Kind**: instance method of [WSv2](#WSv2) +**See** + +- https://docs.bitfinex.com/v2/reference#ws-public-ticker +- [subscribeTicker](#WSv2+subscribeTicker) +- [unsubscribeTicker](#WSv2+unsubscribeTicker) + + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| opts.symbol | string | symbol for tickers | +| [opts.cbGID] | string \| number | callback group id | +| cb | function | callback | + + + +### wSv2.onStatus(opts, cb) +Register a handler to be called on each message for the desired status +feed. + +**Kind**: instance method of [WSv2](#WSv2) +**See**: [subscribeStatus](#WSv2+subscribeStatus) + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| opts.key | string | key of feed to listen on | +| [opts.cbGID] | string \| number | callback group ID | +| cb | function | callback | + + + +### wSv2.onOrderSnapshot(opts, cb) +Register a handler to be called on each full order snapshot (sent on auth) + +**Kind**: instance method of [WSv2](#WSv2) +**See** + +- https://docs.bitfinex.com/v2/reference#ws-auth-orders +- [auth](#WSv2+auth) + + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.symbol] | string | symbol to match | +| [opts.id] | number | order ID to match | +| [opts.cid] | number | order client ID to match | +| [opts.gid] | number | order group ID to match | +| [opts.cbGID] | string \| number | callback group id | +| cb | function | callback | + + + +### wSv2.onOrderNew(opts, cb) +Register a handler to be called on each new order packet + +**Kind**: instance method of [WSv2](#WSv2) +**See** + +- https://docs.bitfinex.com/v2/reference#ws-auth-orders +- [submitOrder](#WSv2+submitOrder) + + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.symbol] | string | symbol to match | +| [opts.id] | number | order ID to match | +| [opts.cid] | number | order client ID to match | +| [opts.gid] | number | order group ID to match | +| [opts.cbGID] | string | callback group id | +| cb | function | callback | + + + +### wSv2.onOrderUpdate(opts, cb) +Register a handler to be called on each order update packet + +**Kind**: instance method of [WSv2](#WSv2) +**See** + +- https://docs.bitfinex.com/v2/reference#ws-auth-orders +- [updateOrder](#WSv2+updateOrder) + + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.symbol] | string | symbol to match | +| [opts.id] | number | order ID to match | +| [opts.cid] | number | order client ID to match | +| [opts.gid] | number | order group ID to match | +| [opts.cbGID] | string | callback group id | +| cb | function | callback | + + + +### wSv2.onOrderClose(opts, cb) +Register a handler to be called on each order close packet + +**Kind**: instance method of [WSv2](#WSv2) +**See** + +- https://docs.bitfinex.com/v2/reference#ws-auth-orders +- [cancelOrder](#WSv2+cancelOrder) + + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.symbol] | string | symbol to match | +| [opts.id] | number | order ID to match | +| [opts.cid] | number | order client ID to match | +| [opts.gid] | number | order group ID to match | +| [opts.cbGID] | string | callback group id | +| cb | function | callback | + + + +### wSv2.onPositionSnapshot(opts, cb) +Register a handler to be called on each position snapshot (sent on auth) + +**Kind**: instance method of [WSv2](#WSv2) +**See** + +- https://docs.bitfinex.com/v2/reference#ws-auth-position +- [auth](#WSv2+auth) + + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.symbol] | string | symbol to match | +| [opts.cbGID] | string | callback group id | +| cb | function | callback | + + + +### wSv2.onPositionNew(opts, cb) +Register a handler to be called when a position is opened + +**Kind**: instance method of [WSv2](#WSv2) +**See**: https://docs.bitfinex.com/v2/reference#ws-auth-position + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.symbol] | string | symbol to match | +| [opts.cbGID] | string | callback group id | +| cb | function | callback | + + + +### wSv2.onPositionUpdate(opts, cb) +Register a handler to be called when a position is updated + +**Kind**: instance method of [WSv2](#WSv2) +**See**: https://docs.bitfinex.com/v2/reference#ws-auth-position + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.symbol] | string | symbol to match | +| [opts.cbGID] | string | callback group id | +| cb | function | callback | + + + +### wSv2.onPositionClose(opts, cb) +Register a handler to be called when a position is closed + +**Kind**: instance method of [WSv2](#WSv2) +**See**: https://docs.bitfinex.com/v2/reference#ws-auth-position + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.symbol] | string | symbol to match | +| [opts.cbGID] | string | callback group id | +| cb | function | callback | + + + +### wSv2.onFundingOfferSnapshot(opts, cb) +Register a handler to be called on each fundign offer snapshot (sent on +auth) + +**Kind**: instance method of [WSv2](#WSv2) +**See** + +- https://docs.bitfinex.com/v2/reference#ws-auth-offers +- [auth](#WSv2+auth) + + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.symbol] | string | symbol to match | +| [opts.cbGID] | string | callback group id | +| cb | function | callback | + + + +### wSv2.onFundingOfferNew(opts, cb) +Register a handler to be called when a funding offer is created + +**Kind**: instance method of [WSv2](#WSv2) +**See**: https://docs.bitfinex.com/v2/reference#ws-auth-offers + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.symbol] | string | symbol to match | +| [opts.cbGID] | string | callback group id | +| cb | function | callback | + + + +### wSv2.onFundingOfferUpdate(opts, cb) +Register a handler to be called when a funding offer is updated + +**Kind**: instance method of [WSv2](#WSv2) +**See**: https://docs.bitfinex.com/v2/reference#ws-auth-offers + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.symbol] | string | symbol to match | +| [opts.cbGID] | string | callback group id | +| cb | function | callback | + + + +### wSv2.onFundingOfferClose(opts, cb) +Register a handler to be called when a funding offer is closed + +**Kind**: instance method of [WSv2](#WSv2) +**See**: https://docs.bitfinex.com/v2/reference#ws-auth-offers + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.symbol] | string | symbol to match | +| [opts.cbGID] | string | callback group id | +| cb | function | callback | + + + +### wSv2.onFundingCreditSnapshot(opts, cb) +Register a handler to be called on each funding credit snapshot (sent on +auth) + +**Kind**: instance method of [WSv2](#WSv2) +**See** + +- https://docs.bitfinex.com/v2/reference#ws-auth-credits +- [auth](#WSv2+auth) + + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.symbol] | string | symbol to match | +| [opts.cbGID] | string | callback group id | +| cb | function | callback | + + + +### wSv2.onFundingCreditNew(opts, cb) +Register a handler to be called when a funding credit is created + +**Kind**: instance method of [WSv2](#WSv2) +**See**: https://docs.bitfinex.com/v2/reference#ws-auth-credits + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.symbol] | string | symbol to match | +| [opts.cbGID] | string | callback group id | +| cb | function | callback | + + + +### wSv2.onFundingCreditUpdate(opts, cb) +Register a handler to be called when a funding credit is updated + +**Kind**: instance method of [WSv2](#WSv2) +**See**: https://docs.bitfinex.com/v2/reference#ws-auth-credits + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.symbol] | string | symbol to match | +| [opts.cbGID] | string | callback group id | +| cb | function | callback | + + + +### wSv2.onFundingCreditClose(opts, cb) +Register a handler to be called when a funding credit is closed + +**Kind**: instance method of [WSv2](#WSv2) +**See**: https://docs.bitfinex.com/v2/reference#ws-auth-credits + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.symbol] | string | symbol to match | +| [opts.cbGID] | string | callback group id | +| cb | function | callback | + + + +### wSv2.onFundingLoanSnapshot(opts, cb) +Register a handler to be called on each funding loan snapshot (sent on +auth) + +**Kind**: instance method of [WSv2](#WSv2) +**See** + +- https://docs.bitfinex.com/v2/reference#ws-auth-loans +- [auth](#WSv2+auth) + + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.symbol] | string | symbol to match | +| [opts.cbGID] | string | callback group id | +| cb | function | callback | + + + +### wSv2.onFundingLoanNew(opts, cb) +Register a handler to be called when a funding loan is created + +**Kind**: instance method of [WSv2](#WSv2) +**See**: https://docs.bitfinex.com/v2/reference#ws-auth-loans + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.symbol] | string | symbol to match | +| [opts.cbGID] | string | callback group id | +| cb | function | callback | + + + +### wSv2.onFundingLoanUpdate(opts, cb) +Register a handler to be called when a funding loan is updated + +**Kind**: instance method of [WSv2](#WSv2) +**See**: https://docs.bitfinex.com/v2/reference#ws-auth-loans + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.symbol] | string | symbol to match | +| [opts.cbGID] | string | callback group id | +| cb | function | callback | + + + +### wSv2.onFundingLoanClose(opts, cb) +Register a handler to be called when a funding loan is closed + +**Kind**: instance method of [WSv2](#WSv2) +**See**: https://docs.bitfinex.com/v2/reference#ws-auth-loans + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.symbol] | string | symbol to match | +| [opts.cbGID] | string | callback group id | +| cb | function | callback | + + + +### wSv2.onWalletSnapshot(opts, cb) +Register a handler to be called on each wallet snapshot (sent on auth) + +**Kind**: instance method of [WSv2](#WSv2) +**See**: https://docs.bitfinex.com/v2/reference#ws-auth-wallets + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.cbGID] | string | callback group id | +| cb | function | callback | + + + +### wSv2.onWalletUpdate(opts, cb) +Register a handler to be called on each wallet update + +**Kind**: instance method of [WSv2](#WSv2) +**See**: https://docs.bitfinex.com/v2/reference#ws-auth-wallets + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.cbGID] | string | callback group id | +| cb | function | callback | + + + +### wSv2.onBalanceInfoUpdate(opts, cb) +Register a handler to be called on each balance info update + +**Kind**: instance method of [WSv2](#WSv2) +**See**: https://docs.bitfinex.com/v2/reference#ws-auth-balance + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.cbGID] | string | callback group id | +| cb | function | callback | + + + +### wSv2.onMarginInfoUpdate(opts, cb) +Register a handler to be called on each margin info update + +**Kind**: instance method of [WSv2](#WSv2) +**See**: https://docs.bitfinex.com/v2/reference#ws-auth-margin + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.cbGID] | string | callback group id | +| cb | function | callback | + + + +### wSv2.onFundingInfoUpdate(opts, cb) +Register a handler to be called on each funding info update + +**Kind**: instance method of [WSv2](#WSv2) +**See**: https://docs.bitfinex.com/v2/reference#ws-auth-funding + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.cbGID] | string | callback group id | +| cb | function | callback | + + + +### wSv2.onFundingTradeEntry(opts, cb) +Register a handler to be called on each funding trade `'te'` event + +**Kind**: instance method of [WSv2](#WSv2) +**See**: https://docs.bitfinex.com/v2/reference#ws-auth-funding-trades + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.symbol] | string | symbol to match | +| [opts.cbGID] | string | callback group id | +| cb | function | callback | + + + +### wSv2.onFundingTradeUpdate(opts, cb) +Register a handler to be called on each funding trade `'tu'` event + +**Kind**: instance method of [WSv2](#WSv2) +**See**: https://docs.bitfinex.com/v2/reference#ws-auth-funding-trades + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.symbol] | string | symbol to match | +| [opts.cbGID] | string | callback group id | +| cb | function | callback | + + + +### wSv2.onNotification(opts, cb) +Register a handler to be called on each notification + +**Kind**: instance method of [WSv2](#WSv2) +**See**: https://docs.bitfinex.com/v2/reference#ws-auth-notifications + +| Param | Type | Description | +| --- | --- | --- | +| opts | object | options | +| [opts.type] | string | type to match | +| [opts.cbGID] | string | callback group id | +| cb | function | callback | + + + +### WSv2.url : string +Default connection URL + +**Kind**: static constant of [WSv2](#WSv2) +**Default**: "wss://api.bitfinex.com/ws/2" + + +### WSv2~Configuration : object +Configuration options for a WSv2 client instance. + +**Kind**: inner typedef of [WSv2](#WSv2) +**Properties** + +| Name | Type | Default | Description | +| --- | --- | --- | --- | +| [affCode] | string | "''" | affiliate code to be applied to all orders | +| [apiKey] | string | "''" | API key | +| [apiSecret] | string | "''" | API secret | +| [url] | string | "'wss://api.bitfinex.com/ws/2'" | ws connection url | +| [orderOpBufferDelay] | number | | multi-order op batching timeout | +| [transform] | boolean | | if true, packets are converted to models | +| [agent] | object | | node agent for ws connection (proxy) | +| [manageOrderBooks] | boolean | | enable local OB persistence | +| [manageCandles] | boolean | | enable local candle persistence | +| [seqAudit] | boolean | | enable sequence numbers & verification | +| [autoReconnect] | boolean | | if true, we will reconnect on close | +| [reconnectDelay] | number | | optional, defaults to 1000 (ms) | +| [reconnectThrottler] | object | | pt to limit reconnect freq | +| [packetWDDelay] | number | | watch-dog forced reconnection delay | + + + +## CandleChannel : object +An object describing a trade data channel on a [WSv2](#WSv2) data stream. + +**Kind**: global typedef +**Properties** + +| Name | Type | Description | +| --- | --- | --- | +| channel | string | 'candles' | +| chanId | number | channel ID | +| key | string | data key, 'trade:TF:SYMBOL' i.e. 'trade:1m:tBTCUSD' | + + + +## OrderBookChannel : object +An object describing an order book data channel on a WSv2 data stream. + +**Kind**: global typedef +**Properties** + +| Name | Type | Description | +| --- | --- | --- | +| channel | string | 'book' | +| chanId | number | channel ID | +| symbol | string | symbol | +| freq | string | frequency of updates; 'F0' is realtime, 'F1' is once per 2 seconds | +| prec | string | precision, (aggregate 'P0', 'P1', 'P2', 'P3', 'P4', raw 'R0') | +| len | string | book depth, '25' (default) or '100' | + + + +## TickerChannel : object +An object describing a ticker data channel on a WSv2 data stream. + +**Kind**: global typedef +**Properties** + +| Name | Type | Description | +| --- | --- | --- | +| channel | string | 'ticker' | +| chanId | number | channel ID | +| symbol | string | symbol | + + + +## TradeChannel : object +An object describing a trade data channel on a WSv2 data stream. + +**Kind**: global typedef +**Properties** + +| Name | Type | Description | +| --- | --- | --- | +| channel | string | 'trades' | +| chanId | number | channel ID | +| symbol | string | symbol | + diff --git a/docs/scripts/collapse.js b/docs/scripts/collapse.js deleted file mode 100644 index 327039fb..00000000 --- a/docs/scripts/collapse.js +++ /dev/null @@ -1,20 +0,0 @@ -function hideAllButCurrent(){ - //by default all submenut items are hidden - //but we need to rehide them for search - document.querySelectorAll("nav > ul > li > ul li").forEach(function(parent) { - parent.style.display = "none"; - }); - - //only current page (if it exists) should be opened - var file = window.location.pathname.split("/").pop().replace(/\.html/, ''); - document.querySelectorAll("nav > ul > li > a").forEach(function(parent) { - var href = parent.attributes.href.value.replace(/\.html/, ''); - if (file === href) { - parent.parentNode.querySelectorAll("ul li").forEach(function(elem) { - elem.style.display = "block"; - }); - } - }); -} - -hideAllButCurrent(); \ No newline at end of file diff --git a/docs/scripts/linenumber.js b/docs/scripts/linenumber.js deleted file mode 100644 index 8d52f7ea..00000000 --- a/docs/scripts/linenumber.js +++ /dev/null @@ -1,25 +0,0 @@ -/*global document */ -(function() { - var source = document.getElementsByClassName('prettyprint source linenums'); - var i = 0; - var lineNumber = 0; - var lineId; - var lines; - var totalLines; - var anchorHash; - - if (source && source[0]) { - anchorHash = document.location.hash.substring(1); - lines = source[0].getElementsByTagName('li'); - totalLines = lines.length; - - for (; i < totalLines; i++) { - lineNumber++; - lineId = 'line' + lineNumber; - lines[i].id = lineId; - if (lineId === anchorHash) { - lines[i].className += ' selected'; - } - } - } -})(); diff --git a/docs/scripts/nav.js b/docs/scripts/nav.js deleted file mode 100644 index 6dd83134..00000000 --- a/docs/scripts/nav.js +++ /dev/null @@ -1,12 +0,0 @@ -function scrollToNavItem() { - var path = window.location.href.split('/').pop().replace(/\.html/, ''); - document.querySelectorAll('nav a').forEach(function(link) { - var href = link.attributes.href.value.replace(/\.html/, ''); - if (path === href) { - link.scrollIntoView({block: 'center'}); - return; - } - }) - } - - scrollToNavItem(); diff --git a/docs/scripts/polyfill.js b/docs/scripts/polyfill.js deleted file mode 100644 index 44b4c92d..00000000 --- a/docs/scripts/polyfill.js +++ /dev/null @@ -1,4 +0,0 @@ -//IE Fix, src: https://www.reddit.com/r/programminghorror/comments/6abmcr/nodelist_lacks_foreach_in_internet_explorer/ -if (typeof(NodeList.prototype.forEach)!==typeof(alert)){ - NodeList.prototype.forEach=Array.prototype.forEach; -} \ No newline at end of file diff --git a/docs/scripts/prettify/Apache-License-2.0.txt b/docs/scripts/prettify/Apache-License-2.0.txt deleted file mode 100644 index d6456956..00000000 --- a/docs/scripts/prettify/Apache-License-2.0.txt +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/docs/scripts/prettify/lang-css.js b/docs/scripts/prettify/lang-css.js deleted file mode 100644 index 041e1f59..00000000 --- a/docs/scripts/prettify/lang-css.js +++ /dev/null @@ -1,2 +0,0 @@ -PR.registerLangHandler(PR.createSimpleLexer([["pln",/^[\t\n\f\r ]+/,null," \t\r\n "]],[["str",/^"(?:[^\n\f\r"\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*"/,null],["str",/^'(?:[^\n\f\r'\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*'/,null],["lang-css-str",/^url\(([^"')]*)\)/i],["kwd",/^(?:url|rgb|!important|@import|@page|@media|@charset|inherit)(?=[^\w-]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*)\s*:/i],["com",/^\/\*[^*]*\*+(?:[^*/][^*]*\*+)*\//],["com", -/^(?:<\!--|--\>)/],["lit",/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],["lit",/^#[\da-f]{3,6}/i],["pln",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],["pun",/^[^\s\w"']+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[["kwd",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[["str",/^[^"')]+/]]),["css-str"]); diff --git a/docs/scripts/prettify/prettify.js b/docs/scripts/prettify/prettify.js deleted file mode 100644 index eef5ad7e..00000000 --- a/docs/scripts/prettify/prettify.js +++ /dev/null @@ -1,28 +0,0 @@ -var q=null;window.PR_SHOULD_USE_CONTINUATION=!0; -(function(){function L(a){function m(a){var f=a.charCodeAt(0);if(f!==92)return f;var b=a.charAt(1);return(f=r[b])?f:"0"<=b&&b<="7"?parseInt(a.substring(1),8):b==="u"||b==="x"?parseInt(a.substring(2),16):a.charCodeAt(1)}function e(a){if(a<32)return(a<16?"\\x0":"\\x")+a.toString(16);a=String.fromCharCode(a);if(a==="\\"||a==="-"||a==="["||a==="]")a="\\"+a;return a}function h(a){for(var f=a.substring(1,a.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),a= -[],b=[],o=f[0]==="^",c=o?1:0,i=f.length;c122||(d<65||j>90||b.push([Math.max(65,j)|32,Math.min(d,90)|32]),d<97||j>122||b.push([Math.max(97,j)&-33,Math.min(d,122)&-33]))}}b.sort(function(a,f){return a[0]-f[0]||f[1]-a[1]});f=[];j=[NaN,NaN];for(c=0;ci[0]&&(i[1]+1>i[0]&&b.push("-"),b.push(e(i[1])));b.push("]");return b.join("")}function y(a){for(var f=a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),b=f.length,d=[],c=0,i=0;c=2&&a==="["?f[c]=h(j):a!=="\\"&&(f[c]=j.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return f.join("")}for(var t=0,s=!1,l=!1,p=0,d=a.length;p=5&&"lang-"===b.substring(0,5))&&!(o&&typeof o[1]==="string"))c=!1,b="src";c||(r[f]=b)}i=d;d+=f.length;if(c){c=o[1];var j=f.indexOf(c),k=j+c.length;o[2]&&(k=f.length-o[2].length,j=k-c.length);b=b.substring(5);B(l+i,f.substring(0,j),e,p);B(l+i+j,c,C(b,c),p);B(l+i+k,f.substring(k),e,p)}else p.push(l+i,b)}a.e=p}var h={},y;(function(){for(var e=a.concat(m), -l=[],p={},d=0,g=e.length;d=0;)h[n.charAt(k)]=r;r=r[1];n=""+r;p.hasOwnProperty(n)||(l.push(r),p[n]=q)}l.push(/[\S\s]/);y=L(l)})();var t=m.length;return e}function u(a){var m=[],e=[];a.tripleQuotedStrings?m.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?m.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/, -q,"'\"`"]):m.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&e.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var h=a.hashComments;h&&(a.cStyleComments?(h>1?m.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):m.push(["com",/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),e.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,q])):m.push(["com",/^#[^\n\r]*/, -q,"#"]));a.cStyleComments&&(e.push(["com",/^\/\/[^\n\r]*/,q]),e.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));a.regexLiterals&&e.push(["lang-regex",/^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);(h=a.types)&&e.push(["typ",h]);a=(""+a.keywords).replace(/^ | $/g, -"");a.length&&e.push(["kwd",RegExp("^(?:"+a.replace(/[\s,]+/g,"|")+")\\b"),q]);m.push(["pln",/^\s+/,q," \r\n\t\xa0"]);e.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,q],["pun",/^.[^\s\w"-$'./@\\`]*/,q]);return x(m,e)}function D(a,m){function e(a){switch(a.nodeType){case 1:if(k.test(a.className))break;if("BR"===a.nodeName)h(a), -a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)e(a);break;case 3:case 4:if(p){var b=a.nodeValue,d=b.match(t);if(d){var c=b.substring(0,d.index);a.nodeValue=c;(b=b.substring(d.index+d[0].length))&&a.parentNode.insertBefore(s.createTextNode(b),a.nextSibling);h(a);c||a.parentNode.removeChild(a)}}}}function h(a){function b(a,d){var e=d?a.cloneNode(!1):a,f=a.parentNode;if(f){var f=b(f,1),g=a.nextSibling;f.appendChild(e);for(var h=g;h;h=g)g=h.nextSibling,f.appendChild(h)}return e} -for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),e;(e=a.parentNode)&&e.nodeType===1;)a=e;d.push(a)}var k=/(?:^|\s)nocode(?:\s|$)/,t=/\r\n?|\n/,s=a.ownerDocument,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=s.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);for(l=s.createElement("LI");a.firstChild;)l.appendChild(a.firstChild);for(var d=[l],g=0;g=0;){var h=m[e];A.hasOwnProperty(h)?window.console&&console.warn("cannot override language handler %s",h):A[h]=a}}function C(a,m){if(!a||!A.hasOwnProperty(a))a=/^\s*=o&&(h+=2);e>=c&&(a+=2)}}catch(w){"console"in window&&console.log(w&&w.stack?w.stack:w)}}var v=["break,continue,do,else,for,if,return,while"],w=[[v,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"], -"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],F=[w,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],G=[w,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"], -H=[G,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],w=[w,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],I=[v,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"], -J=[v,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],v=[v,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],K=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,N=/\S/,O=u({keywords:[F,H,w,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END"+ -I,J,v],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),A={};k(O,["default-code"]);k(x([],[["pln",/^[^]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]), -["default-markup","htm","html","mxml","xhtml","xml","xsl"]);k(x([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css", -/^style\s*=\s*([^\s"'>]+)/i]]),["in.tag"]);k(x([],[["atv",/^[\S\s]+/]]),["uq.val"]);k(u({keywords:F,hashComments:!0,cStyleComments:!0,types:K}),["c","cc","cpp","cxx","cyc","m"]);k(u({keywords:"null,true,false"}),["json"]);k(u({keywords:H,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:K}),["cs"]);k(u({keywords:G,cStyleComments:!0}),["java"]);k(u({keywords:v,hashComments:!0,multiLineStrings:!0}),["bsh","csh","sh"]);k(u({keywords:I,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}), -["cv","py"]);k(u({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["perl","pl","pm"]);k(u({keywords:J,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb"]);k(u({keywords:w,cStyleComments:!0,regexLiterals:!0}),["js"]);k(u({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes", -hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);k(x([],[["str",/^[\S\s]+/]]),["regex"]);window.prettyPrintOne=function(a,m,e){var h=document.createElement("PRE");h.innerHTML=a;e&&D(h,e);E({g:m,i:e,h:h});return h.innerHTML};window.prettyPrint=function(a){function m(){for(var e=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;p=0){var k=k.match(g),f,b;if(b= -!k){b=n;for(var o=void 0,c=b.firstChild;c;c=c.nextSibling)var i=c.nodeType,o=i===1?o?b:c:i===3?N.test(c.nodeValue)?b:o:o;b=(f=o===b?void 0:o)&&"CODE"===f.tagName}b&&(k=f.className.match(g));k&&(k=k[1]);b=!1;for(o=n.parentNode;o;o=o.parentNode)if((o.tagName==="pre"||o.tagName==="code"||o.tagName==="xmp")&&o.className&&o.className.indexOf("prettyprint")>=0){b=!0;break}b||((b=(b=n.className.match(/\blinenums\b(?::(\d+))?/))?b[1]&&b[1].length?+b[1]:!0:!1)&&D(n,b),d={g:k,h:n,i:b},E(d))}}p ul > li:not(.level-hide)").forEach(function(elem) { - elem.style.display = "block"; - }); - - if (typeof hideAllButCurrent === "function"){ - //let's do what ever collapse wants to do - hideAllButCurrent(); - } else { - //menu by default should be opened - document.querySelectorAll("nav > ul > li > ul li").forEach(function(elem) { - elem.style.display = "block"; - }); - } - } else { - //we are searching - document.documentElement.setAttribute(searchAttr, ''); - - //show all parents - document.querySelectorAll("nav > ul > li").forEach(function(elem) { - elem.style.display = "block"; - }); - //hide all results - document.querySelectorAll("nav > ul > li > ul li").forEach(function(elem) { - elem.style.display = "none"; - }); - //show results matching filter - document.querySelectorAll("nav > ul > li > ul a").forEach(function(elem) { - if (!contains(elem.parentNode, search)) { - return; - } - elem.parentNode.style.display = "block"; - }); - //hide parents without children - document.querySelectorAll("nav > ul > li").forEach(function(parent) { - var countSearchA = 0; - parent.querySelectorAll("a").forEach(function(elem) { - if (contains(elem, search)) { - countSearchA++; - } - }); - - var countUl = 0; - var countUlVisible = 0; - parent.querySelectorAll("ul").forEach(function(ulP) { - // count all elements that match the search - if (contains(ulP, search)) { - countUl++; - } - - // count all visible elements - var children = ulP.children - for (i=0; i ul { - padding: 0 10px; -} - -nav > ul > li > a { - color: #606; - margin-top: 10px; -} - -nav ul ul a { - color: hsl(207, 1%, 60%); - border-left: 1px solid hsl(207, 10%, 86%); -} - -nav ul ul a, -nav ul ul a:active { - padding-left: 20px -} - -nav h2 { - font-size: 13px; - margin: 10px 0 0 0; - padding: 0; -} - -nav > h2 > a { - margin: 10px 0 -10px; - color: #606 !important; -} - -footer { - color: hsl(0, 0%, 28%); - margin-left: 250px; - display: block; - padding: 15px; - font-style: italic; - font-size: 90%; -} - -.ancestors { - color: #999 -} - -.ancestors a { - color: #999 !important; -} - -.clear { - clear: both -} - -.important { - font-weight: bold; - color: #950B02; -} - -.yes-def { - text-indent: -1000px -} - -.type-signature { - color: #CA79CA -} - -.type-signature:last-child { - color: #eee; -} - -.name, .signature { - font-family: Consolas, Monaco, 'Andale Mono', monospace -} - -.signature { - color: #fc83ff; -} - -.details { - margin-top: 6px; - border-left: 2px solid #DDD; - line-height: 20px; - font-size: 14px; -} - -.details dt { - width: auto; - float: left; - padding-left: 10px; -} - -.details dd { - margin-left: 70px; - margin-top: 6px; - margin-bottom: 6px; -} - -.details ul { - margin: 0 -} - -.details ul { - list-style-type: none -} - -.details pre.prettyprint { - margin: 0 -} - -.details .object-value { - padding-top: 0 -} - -.description { - margin-bottom: 1em; - margin-top: 1em; -} - -.code-caption { - font-style: italic; - font-size: 107%; - margin: 0; -} - -.prettyprint { - font-size: 14px; - overflow: auto; -} - -.prettyprint.source { - width: inherit; - line-height: 18px; - display: block; - background-color: #0d152a; - color: #aeaeae; -} - -.prettyprint code { - line-height: 18px; - display: block; - background-color: #0d152a; - color: #4D4E53; -} - -.prettyprint > code { - padding: 15px; -} - -.prettyprint .linenums code { - padding: 0 15px -} - -.prettyprint .linenums li:first-of-type code { - padding-top: 15px -} - -.prettyprint code span.line { - display: inline-block -} - -.prettyprint.linenums { - padding-left: 70px; - -webkit-user-select: none; - -moz-user-select: none; - -ms-user-select: none; - user-select: none; -} - -.prettyprint.linenums ol { - padding-left: 0 -} - -.prettyprint.linenums li { - border-left: 3px #34446B solid; -} - -.prettyprint.linenums li.selected, .prettyprint.linenums li.selected * { - background-color: #34446B; -} - -.prettyprint.linenums li * { - -webkit-user-select: text; - -moz-user-select: text; - -ms-user-select: text; - user-select: text; -} - -.prettyprint.linenums li code:empty:after { - content:""; - display:inline-block; - width:0px; -} - -table { - border-spacing: 0; - border: 1px solid #ddd; - border-collapse: collapse; - border-radius: 3px; - box-shadow: 0 1px 3px rgba(0,0,0,0.1); - width: 100%; - font-size: 14px; - margin: 1em 0; -} - -td, th { - margin: 0px; - text-align: left; - vertical-align: top; - padding: 10px; - display: table-cell; -} - -thead tr, thead tr { - background-color: #fff; - font-weight: bold; - border-bottom: 1px solid #ddd; -} - -.params .type { - white-space: nowrap; -} - -.params code { - white-space: pre; -} - -.params td, .params .name, .props .name, .name code { - color: #4D4E53; - font-family: Consolas, Monaco, 'Andale Mono', monospace; - font-size: 100%; -} - -.params td { - border-top: 1px solid #eee -} - -.params td.description > p:first-child, .props td.description > p:first-child { - margin-top: 0; - padding-top: 0; -} - -.params td.description > p:last-child, .props td.description > p:last-child { - margin-bottom: 0; - padding-bottom: 0; -} - -span.param-type, .params td .param-type, .param-type dd { - color: #606; - font-family: Consolas, Monaco, 'Andale Mono', monospace -} - -.param-type dt, .param-type dd { - display: inline-block -} - -.param-type { - margin: 14px 0; -} - -.disabled { - color: #454545 -} - -/* navicon button */ -.navicon-button { - display: none; - position: relative; - padding: 2.0625rem 1.5rem; - transition: 0.25s; - cursor: pointer; - -webkit-user-select: none; - -moz-user-select: none; - -ms-user-select: none; - user-select: none; - opacity: .8; -} -.navicon-button .navicon:before, .navicon-button .navicon:after { - transition: 0.25s; -} -.navicon-button:hover { - transition: 0.5s; - opacity: 1; -} -.navicon-button:hover .navicon:before, .navicon-button:hover .navicon:after { - transition: 0.25s; -} -.navicon-button:hover .navicon:before { - top: .825rem; -} -.navicon-button:hover .navicon:after { - top: -.825rem; -} - -/* navicon */ -.navicon { - position: relative; - width: 2.5em; - height: .3125rem; - background: #000; - transition: 0.3s; - border-radius: 2.5rem; -} -.navicon:before, .navicon:after { - display: block; - content: ""; - height: .3125rem; - width: 2.5rem; - background: #000; - position: absolute; - z-index: -1; - transition: 0.3s 0.25s; - border-radius: 1rem; -} -.navicon:before { - top: .625rem; -} -.navicon:after { - top: -.625rem; -} - -/* open */ -.nav-trigger:checked + label:not(.steps) .navicon:before, -.nav-trigger:checked + label:not(.steps) .navicon:after { - top: 0 !important; -} - -.nav-trigger:checked + label .navicon:before, -.nav-trigger:checked + label .navicon:after { - transition: 0.5s; -} - -/* Minus */ -.nav-trigger:checked + label { - -webkit-transform: scale(0.75); - transform: scale(0.75); -} - -/* × and + */ -.nav-trigger:checked + label.plus .navicon, -.nav-trigger:checked + label.x .navicon { - background: transparent; -} - -.nav-trigger:checked + label.plus .navicon:before, -.nav-trigger:checked + label.x .navicon:before { - -webkit-transform: rotate(-45deg); - transform: rotate(-45deg); - background: #FFF; -} - -.nav-trigger:checked + label.plus .navicon:after, -.nav-trigger:checked + label.x .navicon:after { - -webkit-transform: rotate(45deg); - transform: rotate(45deg); - background: #FFF; -} - -.nav-trigger:checked + label.plus { - -webkit-transform: scale(0.75) rotate(45deg); - transform: scale(0.75) rotate(45deg); -} - -.nav-trigger:checked ~ nav { - left: 0 !important; -} - -.nav-trigger:checked ~ .overlay { - display: block; -} - -.nav-trigger { - position: fixed; - top: 0; - clip: rect(0, 0, 0, 0); -} - -.overlay { - display: none; - position: fixed; - top: 0; - bottom: 0; - left: 0; - right: 0; - width: 100%; - height: 100%; - background: hsla(0, 0%, 0%, 0.5); - z-index: 1; -} - -/* nav level */ -.level-hide { - display: none; -} -html[data-search-mode] .level-hide { - display: block; -} - - -@media only screen and (max-width: 680px) { - body { - overflow-x: hidden; - } - - nav { - background: #FFF; - width: 250px; - height: 100%; - position: fixed; - top: 0; - right: 0; - bottom: 0; - left: -250px; - z-index: 3; - padding: 0 10px; - transition: left 0.2s; - } - - .navicon-button { - display: inline-block; - position: fixed; - top: 1.5em; - right: 0; - z-index: 2; - } - - #main { - width: 100%; - } - - #main h1.page-title { - margin: 1em 0; - } - - #main section { - padding: 0; - } - - footer { - margin-left: 0; - } -} - -/** Add a '#' to static members */ -[data-type="member"] a::before { - content: '#'; - display: inline-block; - margin-left: -14px; - margin-right: 5px; -} - -#disqus_thread{ - margin-left: 30px; -} - -@font-face { - font-family: 'Montserrat'; - font-style: normal; - font-weight: 400; - src: url('../fonts/Montserrat/Montserrat-Regular.eot'); /* IE9 Compat Modes */ - src: url('../fonts/Montserrat/Montserrat-Regular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ - url('../fonts/Montserrat/Montserrat-Regular.woff2') format('woff2'), /* Super Modern Browsers */ - url('../fonts/Montserrat/Montserrat-Regular.woff') format('woff'), /* Pretty Modern Browsers */ - url('../fonts/Montserrat/Montserrat-Regular.ttf') format('truetype'); /* Safari, Android, iOS */ -} - -@font-face { - font-family: 'Montserrat'; - font-style: normal; - font-weight: 700; - src: url('../fonts/Montserrat/Montserrat-Bold.eot'); /* IE9 Compat Modes */ - src: url('../fonts/Montserrat/Montserrat-Bold.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ - url('../fonts/Montserrat/Montserrat-Bold.woff2') format('woff2'), /* Super Modern Browsers */ - url('../fonts/Montserrat/Montserrat-Bold.woff') format('woff'), /* Pretty Modern Browsers */ - url('../fonts/Montserrat/Montserrat-Bold.ttf') format('truetype'); /* Safari, Android, iOS */ -} - -@font-face { - font-family: 'Source Sans Pro'; - src: url('../fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot'); - src: url('../fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot?#iefix') format('embedded-opentype'), - url('../fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2') format('woff2'), - url('../fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff') format('woff'), - url('../fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf') format('truetype'), - url('../fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg#source_sans_proregular') format('svg'); - font-weight: 400; - font-style: normal; -} - -@font-face { - font-family: 'Source Sans Pro'; - src: url('../fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot'); - src: url('../fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot?#iefix') format('embedded-opentype'), - url('../fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2') format('woff2'), - url('../fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff') format('woff'), - url('../fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf') format('truetype'), - url('../fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg#source_sans_prolight') format('svg'); - font-weight: 300; - font-style: normal; - -} \ No newline at end of file diff --git a/docs/styles/prettify.css b/docs/styles/prettify.css deleted file mode 100644 index d9521ec8..00000000 --- a/docs/styles/prettify.css +++ /dev/null @@ -1,79 +0,0 @@ -.pln { - color: #ddd; -} - -/* string content */ -.str { - color: #61ce3c; -} - -/* a keyword */ -.kwd { - color: #fbde2d; -} - -/* a comment */ -.com { - color: #aeaeae; -} - -/* a type name */ -.typ { - color: #8da6ce; -} - -/* a literal value */ -.lit { - color: #fbde2d; -} - -/* punctuation */ -.pun { - color: #ddd; -} - -/* lisp open bracket */ -.opn { - color: #000000; -} - -/* lisp close bracket */ -.clo { - color: #000000; -} - -/* a markup tag name */ -.tag { - color: #8da6ce; -} - -/* a markup attribute name */ -.atn { - color: #fbde2d; -} - -/* a markup attribute value */ -.atv { - color: #ddd; -} - -/* a declaration */ -.dec { - color: #EF5050; -} - -/* a variable name */ -.var { - color: #c82829; -} - -/* a function name */ -.fun { - color: #4271ae; -} - -/* Specify class=linenums on a pre to get line numbering */ -ol.linenums { - margin-top: 0; - margin-bottom: 0; -} diff --git a/docs/transports_ws2.js.html b/docs/transports_ws2.js.html deleted file mode 100644 index 5208ed65..00000000 --- a/docs/transports_ws2.js.html +++ /dev/null @@ -1,2877 +0,0 @@ - - - - - - transports/ws2.js - Documentation - - - - - - - - - - - - - - - - - - - -
- -

transports/ws2.js

- - - - - - - -
-
-
'use strict'
-
-const { EventEmitter } = require('events')
-const debug = require('debug')('bfx:ws2')
-const WebSocket = require('ws')
-const Promise = require('bluebird')
-const CbQ = require('cbq')
-const _Throttle = require('lodash.throttle') // eslint-disable-line
-const _isArray = require('lodash/isArray')
-const _isEmpty = require('lodash/isEmpty')
-const _isString = require('lodash/isString')
-const _isNumber = require('lodash/isNumber')
-const _includes = require('lodash/includes')
-const _pick = require('lodash/pick')
-const _isEqual = require('lodash/isEqual')
-const _isFinite = require('lodash/isFinite')
-const { genAuthSig, nonce } = require('bfx-api-node-util')
-const LosslessJSON = require('lossless-json')
-const getMessagePayload = require('../util/ws2')
-
-const {
-  BalanceInfo,
-  FundingCredit,
-  FundingInfo,
-  FundingLoan,
-  FundingOffer,
-  FundingTrade,
-  MarginInfo,
-  Notification,
-  Order,
-  Position,
-  Trade,
-  PublicTrade,
-  Wallet,
-  OrderBook,
-  Candle,
-  TradingTicker,
-  FundingTicker
-} = require('bfx-api-node-models')
-
-const DATA_CHANNEL_TYPES = ['ticker', 'book', 'candles', 'trades']
-const UCM_NOTIFICATION_TYPE = 'ucm-notify-ui'
-const MAX_CALC_OPS = 8
-
-/**
- * A Promise Throttle instance
- *
- * @typedef {object} PromiseThrottle
- * @property {Function} add - add a promise to be throttled
- */
-
-/**
- * Communicates with v2 of the Bitfinex WebSocket API
- *
- * @class
- */
-class WSv2 extends EventEmitter {
-  /**
-   * Instantiate a new ws2 transport. Does not auto-open
-   *
-   * @class WSv2
-   * @param {object} [opts] - instance options
-   * @param {string} [opts.affCode] - affiliate code to be applied to all orders
-   * @param {string} [opts.apiKey] - API key
-   * @param {string} [opts.apiSecret] - API secret
-   * @param {string} [opts.url] - ws connection url, defaults to {@link WSv2#url}
-   * @param {number} [opts.orderOpBufferDelay] - multi-order op batching timeout
-   * @param {boolean} [opts.transform] - if true, packets are converted to models
-   * @param {object} [opts.agent] - optional node agent for ws connection (proxy)
-   * @param {boolean} [opts.manageOrderBooks] - enable local OB persistence
-   * @param {boolean} [opts.manageCandles] - enable local candle persistence
-   * @param {boolean} [opts.seqAudit] - enable sequence numbers & verification
-   * @param {boolean} [opts.autoReconnect] - if true, we will reconnect on close
-   * @param {number} [opts.reconnectDelay] - optional, defaults to 1000 (ms)
-   * @param {PromiseThrottle} [opts.reconnectThrottler] - optional pt to limit reconnect freq
-   * @param {number} [opts.packetWDDelay] - watch-dog forced reconnection delay
-   * @example
-   *   const ws = new WSv2()
-   *
-   *   ws.on('open', async () => {
-   *     ws.onTrades({ symbol: 'tBTCUSD' }, (trades) => {
-   *       console.log('recv trades: %j', trades)
-   *     })
-   *
-   *     await ws.subscribeTrades('tBTCUSD')
-   *   })
-   *
-   *   await ws.open()
-   */
-  constructor (opts = {
-    apiKey: '',
-    apiSecret: '',
-    url: WSv2.url,
-    affCode: null
-  }) {
-    super()
-
-    this.setMaxListeners(1000)
-    this._apiKey = opts.apiKey || ''
-    this._apiSecret = opts.apiSecret || ''
-    this._affCode = opts.affCode
-    this._agent = opts.agent
-    this._url = opts.url || WSv2.url
-    this._transform = opts.transform === true
-    this._orderOpBufferDelay = opts.orderOpBufferDelay || -1
-    this._orderOpBuffer = []
-    this._orderOpTimeout = null
-    this._seqAudit = opts.seqAudit === true
-    this._autoReconnect = opts.autoReconnect === true
-    this._reconnectDelay = opts.reconnectDelay || 1000
-    this._reconnectThrottler = opts.reconnectThrottler
-    this._manageOrderBooks = opts.manageOrderBooks === true
-    this._manageCandles = opts.manageCandles === true
-    this._packetWDDelay = opts.packetWDDelay
-    this._packetWDTimeout = null
-    this._packetWDLastTS = 0
-    this._orderBooks = {}
-    this._losslessOrderBooks = {}
-    this._candles = {}
-    this._authArgs = {}
-
-    /**
-     * {
-     *   [groupID]: {
-     *     [eventName]: [{
-     *       modelClass: ..,
-     *       filter: { symbol: 'tBTCUSD' }, // only works w/ serialize
-     *       cb: () => {}
-     *     }]
-     *   }
-     * }
-     *
-     * @private
-     */
-    this._listeners = {}
-    this._infoListeners = {} // { [code]: <listeners> }
-    this._subscriptionRefs = {}
-    this._channelMap = {}
-    this._orderBooks = {}
-    this._enabledFlags = this._seqAudit ? WSv2.flags.SEQ_ALL : 0
-    this._eventCallbacks = new CbQ()
-    this._isAuthenticated = false
-    this._wasEverAuthenticated = false // used for auto-auth on reconnect
-    this._lastPubSeq = -1
-    this._lastAuthSeq = -1
-    this._isOpen = false
-    this._ws = null
-    this._isClosing = false // used to block reconnect on direct close() call
-    this._isReconnecting = false
-
-    this._onWSOpen = this._onWSOpen.bind(this)
-    this._onWSClose = this._onWSClose.bind(this)
-    this._onWSError = this._onWSError.bind(this)
-    this._onWSMessage = this._onWSMessage.bind(this)
-    this._triggerPacketWD = this._triggerPacketWD.bind(this)
-    this._sendCalc = _Throttle(this._sendCalc.bind(this), 1000 / MAX_CALC_OPS)
-  }
-
-  /**
-   * @returns {string} url
-   */
-  getURL () {
-    return this._url
-  }
-
-  /**
-   * @returns {boolean} usesAgent
-   */
-  usesAgent () {
-    return !!this._agent
-  }
-
-  /**
-   * Set `calc` and `dms` values to be used on the next {@link WSv2#auth} call
-   *
-   * @param {object} args - arguments
-   * @param {number} [args.calc] - calc value
-   * @param {number} [args.dms] - dms value, active 4
-   * @see WSv2#auth
-   */
-  updateAuthArgs (args = {}) {
-    this._authArgs = {
-      ...this._authArgs,
-      ...args
-    }
-  }
-
-  /**
-   * Fetch the current default auth parameters
-   *
-   * @returns {object} authArgs
-   * @see WSv2#updateAuthArgs
-   * @see WSv2#auth
-   */
-  getAuthArgs () {
-    return this._authArgs
-  }
-
-  /**
-   * Update the internal API credentials, used on subsequent {@link WSv2#auth}
-   * calls
-   *
-   * @param {string} apiKey - API key
-   * @param {string} apiSecret - API secret
-   * @see WSv2#auth
-   */
-  setAPICredentials (apiKey, apiSecret) {
-    this._apiKey = apiKey
-    this._apiSecret = apiSecret
-  }
-
-  /**
-   * Get the total number of data channels this instance is currently
-   * subscribed too.
-   *
-   * @returns {number} count
-   * @see WSv2#subscribeTrades
-   * @see WSv2#subscribeTicker
-   * @see WSv2#subscribeCandles
-   * @see WSv2#subscribeOrderBook
-   */
-  getDataChannelCount () {
-    return Object
-      .values(this._channelMap)
-      .filter(c => _includes(DATA_CHANNEL_TYPES, c.channel))
-      .length
-  }
-
-  /**
-   * Check if the instance is subscribed to the specified channel ID
-   *
-   * @param {number} chanId - ID of channel to query
-   * @returns {boolean} isSubscribed
-   */
-  hasChannel (chanId) {
-    return _includes(Object.keys(this._channelMap), chanId)
-  }
-
-  /**
-   * Check if a channel/identifier pair has been subscribed too
-   *
-   * @param {string} channel - channel type
-   * @param {string} identifier - unique identifier for the reference
-   * @returns {boolean} hasRef
-   * @see WSv2#managedSubscribe
-   */
-  hasSubscriptionRef (channel, identifier) {
-    const key = `${channel}:${identifier}`
-    return !!Object.keys(this._subscriptionRefs).find(ref => ref === key)
-  }
-
-  /**
-   * Fetch the ID of a channel matched by type and channel data filter
-   *
-   * @param {string} type - channel type
-   * @param {object} filter - to be matched against channel data
-   * @returns {number} channelID
-   */
-  getDataChannelId (type, filter) {
-    return Object
-      .keys(this._channelMap)
-      .find(cid => {
-        const c = this._channelMap[cid]
-        const fv = _pick(c, Object.keys(filter))
-        return c.channel === type && _isEqual(fv, filter)
-      })
-  }
-
-  /**
-   * Check if the instance is subscribed to a data channel matching the
-   * specified type and filter.
-   *
-   * @param {string} type - channel type
-   * @param {object} filter - to be matched against channel data
-   * @returns {boolean} hasChannel
-   */
-  hasDataChannel (type, filter) {
-    return !!this.getDataChannelId(type, filter)
-  }
-
-  /**
-   * Opens a connection to the API server. Rejects with an error if a
-   * connection is already open. Resolves on success.
-   *
-   * @returns {Promise} p
-   */
-  async open () {
-    if (this._isOpen || this._ws !== null) {
-      throw new Error('already open')
-    }
-
-    debug('connecting to %s...', this._url)
-
-    this._ws = new WebSocket(this._url, {
-      agent: this._agent
-    })
-
-    this._subscriptionRefs = {}
-    this._candles = {}
-    this._orderBooks = {}
-
-    this._ws.on('message', this._onWSMessage)
-    this._ws.on('error', this._onWSError)
-    this._ws.on('close', this._onWSClose)
-
-    return new Promise((resolve) => {
-      this._ws.on('open', () => {
-        // call manually instead of binding to open event so it fires at the
-        // right time
-        this._onWSOpen()
-
-        if (this._enabledFlags !== 0) {
-          this.sendEnabledFlags()
-        }
-
-        debug('connected')
-        resolve()
-      })
-    })
-  }
-
-  /**
-   * Closes the active connection. If there is none, rejects with a promise.
-   * Resolves on success
-   *
-   * @param {number} code - passed to ws
-   * @param {string} reason - passed to ws
-   * @returns {Promise} p
-   */
-  async close (code, reason) {
-    if (!this._isOpen || this._ws === null) {
-      throw new Error('not open')
-    }
-
-    debug('disconnecting...')
-
-    return new Promise((resolve) => {
-      this._ws.once('close', () => {
-        this._isOpen = false
-        this._ws = null
-
-        debug('disconnected')
-        resolve()
-      })
-
-      if (!this._isClosing) {
-        this._isClosing = true
-        this._ws.close(code, reason)
-      }
-    })
-  }
-
-  /**
-   * Generates & sends an authentication packet to the server; if already
-   * authenticated, rejects with an error, resolves on success.
-   *
-   * If a DMS flag of 4 is provided, all open orders are cancelled when the
-   * connection terminates.
-   *
-   * @param {number?} calc - optional, default is 0
-   * @param {number?} dms - optional dead man switch flag, active 4
-   * @returns {Promise} p
-   */
-  async auth (calc, dms) {
-    if (!this._isOpen) {
-      throw new Error('not open')
-    }
-
-    if (this._isAuthenticated) {
-      throw new Error('already authenticated')
-    }
-
-    const authNonce = nonce()
-    const authPayload = `AUTH${authNonce}${authNonce}`
-    const { sig } = genAuthSig(this._apiSecret, authPayload)
-    const authArgs = { ...this._authArgs }
-
-    if (_isFinite(calc)) authArgs.calc = calc
-    if (_isFinite(dms)) authArgs.dms = dms
-
-    return new Promise((resolve) => {
-      this.once('auth', () => {
-        debug('authenticated')
-        resolve()
-      })
-
-      this.send({
-        event: 'auth',
-        apiKey: this._apiKey,
-        authSig: sig,
-        authPayload,
-        authNonce,
-        ...authArgs
-      })
-    })
-  }
-
-  /**
-   * Utility method to close & re-open the ws connection. Re-authenticates if
-   * previously authenticated
-   *
-   * @returns {Promise} p - resolves on completion
-   */
-  async reconnect () {
-    this._isReconnecting = true
-
-    if (this._ws !== null && this._isOpen) { // did we get a watchdog timeout and need to close the connection?
-      await this.close()
-
-      return new Promise((resolve) => {
-        this.once(this._wasEverAuthenticated ? 'auth' : 'open', resolve)
-      })
-    }
-
-    return this.reconnectAfterClose() // we are already closed, so reopen and re-auth
-  }
-
-  /**
-   * @private
-   */
-  async reconnectAfterClose () {
-    if (!this._isReconnecting || this._ws !== null || this._isOpen) {
-      return this.reconnect()
-    }
-
-    await this.open()
-
-    if (this._wasEverAuthenticated) {
-      await this.auth()
-    }
-  }
-
-  /**
-   * Returns an error if the message has an invalid (out of order) sequence #
-   * The last-seen sequence #s are updated internally.
-   *
-   * @param {Array} msg - incoming message
-   * @returns {Error} err - null if no error or sequencing not enabled
-   * @private
-   */
-  _validateMessageSeq (msg = []) {
-    if (!this._seqAudit) return null
-    if (!Array.isArray(msg)) return null
-    if (msg.length === 0) return null
-
-    // The auth sequence # is the last value in channel 0 non-heartbeat packets.
-    const authSeq = msg[0] === 0 && msg[1] !== 'hb'
-      ? msg[msg.length - 1]
-      : NaN
-
-    // *-req packets don't include public seq numbers
-    if (`${(msg[2] || [])[1] || ''}`.slice(-4) !== '-req') {
-      // All other packets provide a public sequence # as the last value. For chan
-      // 0 packets, these are included as the 2nd to last value
-      const seq = (
-        (msg[0] === 0) &&
-        (msg[1] !== 'hb') &&
-        !(msg[1] === 'n' && ((msg[2] || [])[1] || '').slice(-4) === '-req')
-      )
-        ? msg[msg.length - 2]
-        : msg[msg.length - 1]
-
-      if (!_isFinite(seq)) return null
-
-      if (this._lastPubSeq === -1) { // first pub seq received
-        this._lastPubSeq = seq
-        return null
-      }
-
-      if (seq !== this._lastPubSeq + 1) { // check pub seq
-        return new Error(`invalid pub seq #; last ${this._lastPubSeq}, got ${seq}`)
-      }
-
-      this._lastPubSeq = seq
-    }
-
-    if (!_isFinite(authSeq)) return null
-    if (authSeq === 0) return null // still syncing
-
-    // notifications don't advance seq
-    if (msg[1] === 'n') {
-      return authSeq !== this._lastAuthSeq
-        ? new Error(
-          `invalid auth seq #, expected no advancement but got ${authSeq}`
-        ) : null
-    }
-
-    if (authSeq === this._lastAuthSeq) {
-      return new Error(
-        `expected auth seq # advancement but got same seq: ${authSeq}`
-      )
-    }
-
-    // check
-    if (this._lastAuthSeq !== -1 && authSeq !== this._lastAuthSeq + 1) {
-      return new Error(
-        `invalid auth seq #; last ${this._lastAuthSeq}, got ${authSeq}`
-      )
-    }
-
-    this._lastAuthSeq = authSeq
-    return null
-  }
-
-  /**
-   * Trigger the packet watch-dog; called when we haven't seen a new WS packet
-   * for longer than our WD duration (if provided)
-   *
-   * @returns {Promise} p
-   * @private
-   */
-  async _triggerPacketWD () {
-    if (!this._packetWDDelay || !this._isOpen) {
-      return Promise.resolve()
-    }
-
-    debug(
-      'packet delay watchdog triggered [last packet %dms ago]',
-      Date.now() - this._packetWDLastTS
-    )
-
-    this._packetWDTimeout = null
-    return this.reconnect()
-  }
-
-  /**
-   * Reset the packet watch-dog timeout. Should be called on every new WS packet
-   * if the watch-dog is enabled
-   *
-   * @private
-   */
-  _resetPacketWD () {
-    if (!this._packetWDDelay) return
-    if (this._packetWDTimeout !== null) {
-      clearTimeout(this._packetWDTimeout)
-    }
-
-    if (!this._isOpen) return
-
-    this._packetWDTimeout = setTimeout(() => {
-      this._triggerPacketWD().catch((err) => {
-        debug('error triggering packet watchdog: %s', err.message)
-      })
-    }, this._packetWDDelay)
-  }
-
-  /**
-   * Subscribes to previously subscribed channels, used after reconnecting
-   *
-   * @private
-   */
-  resubscribePreviousChannels () {
-    Object.values(this._prevChannelMap).forEach((chan) => {
-      const { channel } = chan
-
-      switch (channel) {
-        case 'ticker': {
-          const { symbol } = chan
-          this.subscribeTicker(symbol)
-          break
-        }
-
-        case 'trades': {
-          const { symbol } = chan
-          this.subscribeTrades(symbol)
-          break
-        }
-
-        case 'book': {
-          const { symbol, len, prec } = chan
-          this.subscribeOrderBook(symbol, prec, len)
-          break
-        }
-
-        case 'candles': {
-          const { key } = chan
-          this.subscribeCandles(key)
-          break
-        }
-
-        default: {
-          debug('unknown previously subscribed channel type: %s', channel)
-        }
-      }
-    })
-  }
-
-  /**
-   * @private
-   */
-  _onWSOpen () {
-    this._isOpen = true
-    this._isReconnecting = false
-    this._packetWDLastTS = Date.now()
-    this._lastAuthSeq = -1
-    this._lastPubSeq = -1
-    this.emit('open')
-
-    if (!_isEmpty(this._prevChannelMap)) {
-      this.resubscribePreviousChannels()
-      this._prevChannelMap = {}
-    }
-
-    debug('connection open')
-  }
-
-  /**
-   * @private
-   */
-  async _onWSClose () {
-    this._isOpen = false
-    this._isAuthenticated = false
-    this._lastAuthSeq = -1
-    this._lastPubSeq = -1
-    this._enabledFlags = 0
-    this._ws = null
-    this._subscriptionRefs = {}
-    this.emit('close')
-
-    debug('connection closed')
-
-    // _isReconnecting = true - if a reconnection has been requested. In that case always call reconnectAfterClose
-    // _isClosing = true - if the user explicitly requested a close
-    // _autoReconnect = true - if the user likes to reconnect automatically
-    if (this._isReconnecting || (this._autoReconnect && !this._isClosing)) {
-      this._prevChannelMap = this._channelMap
-
-      setTimeout(async () => {
-        try {
-          if (this._reconnectThrottler) {
-            await this._reconnectThrottler.add(this.reconnectAfterClose.bind(this))
-          } else {
-            await this.reconnectAfterClose()
-          }
-        } catch (err) {
-          debug('error reconnectAfterClose: %s', err.stack)
-        }
-      }, this._reconnectDelay)
-    }
-
-    this._channelMap = {}
-    this._isClosing = false
-  }
-
-  /**
-   * @param {Error} err - error
-   * @private
-   */
-  _onWSError (err) {
-    this.emit('error', err)
-
-    debug('error: %s', err)
-  }
-
-  /**
-   * @param {Array} arrN - notification in ws array format
-   * @private
-   */
-  _onWSNotification (arrN) {
-    const status = arrN[6]
-    const msg = arrN[7]
-
-    if (!arrN[4]) return
-
-    if (arrN[1] === 'on-req') {
-      const [,, cid] = arrN[4]
-      const k = `order-new-${cid}`
-
-      if (status === 'SUCCESS') {
-        this._eventCallbacks.trigger(k, null, arrN[4])
-      } else {
-        this._eventCallbacks.trigger(k, new Error(`${status}: ${msg}`), arrN[4])
-      }
-    } else if (arrN[1] === 'oc-req') {
-      const [id] = arrN[4]
-      const k = `order-cancel-${id}`
-
-      if (status === 'SUCCESS') {
-        this._eventCallbacks.trigger(k, null, arrN[4])
-      } else {
-        this._eventCallbacks.trigger(k, new Error(`${status}: ${msg}`), arrN[4])
-      }
-    } else if (arrN[1] === 'ou-req') {
-      const [id] = arrN[4]
-      const k = `order-update-${id}`
-
-      if (status === 'SUCCESS') {
-        this._eventCallbacks.trigger(k, null, arrN[4])
-      } else {
-        this._eventCallbacks.trigger(k, new Error(`${status}: ${msg}`), arrN[4])
-      }
-    }
-  }
-
-  /**
-   * @param {string} rawMsg - incoming message JSON
-   * @param {string} flags - flags
-   * @private
-   */
-  _onWSMessage (rawMsg, flags) {
-    debug('recv msg: %s', rawMsg)
-
-    this._packetWDLastTS = Date.now()
-    this._resetPacketWD()
-
-    let msg
-
-    try {
-      msg = JSON.parse(rawMsg)
-    } catch (e) {
-      this.emit('error', `invalid message JSON: ${rawMsg}`)
-      return
-    }
-
-    debug('recv msg: %j', msg)
-
-    if (this._seqAudit) {
-      const seqErr = this._validateMessageSeq(msg)
-
-      if (seqErr !== null) {
-        this.emit('error', seqErr)
-        return
-      }
-    }
-
-    this.emit('message', msg, flags)
-
-    if (Array.isArray(msg)) {
-      this._handleChannelMessage(msg, rawMsg)
-    } else if (msg.event) {
-      this._handleEventMessage(msg)
-    } else {
-      debug('recv unidentified message: %j', msg)
-    }
-  }
-
-  /**
-   * @param {Array} msg - message
-   * @param {string} rawMsg - message JSON
-   * @private
-   */
-  _handleChannelMessage (msg, rawMsg) {
-    const [chanId, type] = msg
-    const channelData = this._channelMap[chanId]
-
-    if (!channelData) {
-      debug('recv msg from unknown channel %d: %j', chanId, msg)
-      return
-    }
-
-    if (msg.length < 2) return
-    if (msg[1] === 'hb') return
-
-    if (channelData.channel === 'book') {
-      if (type === 'cs') {
-        this._handleOBChecksumMessage(msg, channelData)
-      } else {
-        this._handleOBMessage(msg, channelData, rawMsg)
-      }
-    } else if (channelData.channel === 'trades') {
-      this._handleTradeMessage(msg, channelData)
-    } else if (channelData.channel === 'ticker') {
-      this._handleTickerMessage(msg, channelData)
-    } else if (channelData.channel === 'candles') {
-      this._handleCandleMessage(msg, channelData)
-    } else if (channelData.channel === 'status') {
-      this._handleStatusMessage(msg, channelData)
-    } else if (channelData.channel === 'auth') {
-      this._handleAuthMessage(msg, channelData)
-    } else {
-      this._propagateMessageToListeners(msg, channelData)
-      this.emit(channelData.channel, msg)
-    }
-  }
-
-  /**
-   * @param {Array} msg - message
-   * @param {object} chanData - channel definition
-   * @private
-   */
-  _handleOBChecksumMessage (msg, chanData) {
-    this.emit('cs', msg)
-
-    if (!this._manageOrderBooks) {
-      return
-    }
-
-    const { symbol, prec } = chanData
-    const cs = msg[2]
-
-    // NOTE: Checksums are temporarily disabled for funding books, due to
-    //       invalid book sorting on the backend. This change is temporary
-    if (symbol[0] === 't') {
-      const err = this._verifyManagedOBChecksum(symbol, prec, cs)
-
-      if (err) {
-        this.emit('error', err)
-        return
-      }
-    }
-
-    const internalMessage = [chanData.chanId, 'ob_checksum', cs]
-    internalMessage.filterOverride = [
-      chanData.symbol,
-      chanData.prec,
-      chanData.len
-    ]
-
-    this._propagateMessageToListeners(internalMessage, false)
-    this.emit('cs', symbol, cs)
-  }
-
-  /**
-   * Called for messages from the 'book' channel. Might be an update or a
-   * snapshot
-   *
-   * @param {Array|Array[]} msg - message
-   * @param {object} chanData - entry from _channelMap
-   * @param {string} rawMsg - message JSON
-   * @private
-   */
-  _handleOBMessage (msg, chanData, rawMsg) {
-    const { symbol, prec } = chanData
-    const raw = prec === 'R0'
-    let data = getMessagePayload(msg)
-
-    if (this._manageOrderBooks) {
-      const err = this._updateManagedOB(symbol, data, raw, rawMsg)
-
-      if (err) {
-        this.emit('error', err)
-        return
-      }
-
-      data = this._orderBooks[symbol]
-    }
-
-    // Always transform an array of entries
-    if (this._transform) {
-      data = new OrderBook((Array.isArray(data[0]) ? data : [data]), raw)
-    }
-
-    const internalMessage = [chanData.chanId, 'orderbook', data]
-    internalMessage.filterOverride = [
-      chanData.symbol,
-      chanData.prec,
-      chanData.len
-    ]
-
-    this._propagateMessageToListeners(internalMessage, chanData, false)
-    this.emit('orderbook', symbol, data)
-  }
-
-  /**
-   * @param {string} symbol - symbol for order book
-   * @param {number[]|number[][]} data - incoming data
-   * @param {boolean} raw - if true, the order book is considered R*
-   * @param {string} rawMsg - source message JSON
-   * @returns {Error} err - null on success
-   * @private
-   */
-  _updateManagedOB (symbol, data, raw, rawMsg) {
-    // parse raw string with lossless parse which takes
-    // the exact strict values rather than converting to floats
-    // [0.00001, [1, 2, 3]] -> ['0.00001', ['1', '2', '3']]
-    const rawLossless = LosslessJSON.parse(rawMsg, (key, value) => {
-      if (value && value.isLosslessNumber) {
-        return value.toString()
-      } else {
-        return value
-      }
-    })
-    const losslessUpdate = rawLossless[1]
-    // Snapshot, new OB. Note that we don't protect against duplicates, as they
-    // could come in on re-sub
-    if (Array.isArray(data[0])) {
-      this._orderBooks[symbol] = data
-      this._losslessOrderBooks[symbol] = losslessUpdate
-      return null
-    }
-
-    // entry, needs to be applied to OB
-    if (!this._orderBooks[symbol]) {
-      return new Error(`recv update for unknown OB: ${symbol}`)
-    }
-
-    OrderBook.updateArrayOBWith(this._orderBooks[symbol], data, raw)
-    OrderBook.updateArrayOBWith(this._losslessOrderBooks[symbol], losslessUpdate, raw)
-    return null
-  }
-
-  /**
-   * @param {string} symbol - symbol for order book
-   * @param {string} prec - precision
-   * @param {number} cs - expected checksum
-   * @returns {Error} err - null if none
-   * @private
-   */
-  _verifyManagedOBChecksum (symbol, prec, cs) {
-    const ob = this._losslessOrderBooks[symbol]
-
-    if (!ob) return null
-
-    const localCS = ob instanceof OrderBook
-      ? ob.checksum()
-      : OrderBook.checksumArr(ob, prec === 'R0')
-
-    return localCS !== cs
-      ? new Error(`OB checksum mismatch: got ${localCS}, want ${cs}`)
-      : null
-  }
-
-  /**
-   * Returns an up-to-date copy of the order book for the specified symbol, or
-   * null if no OB is managed for that symbol.
-   *
-   * Set `managedOrderBooks: true` in the constructor to use.
-   *
-   * @param {string} symbol - symbol for order book
-   * @returns {OrderBook} ob - null if not found
-   * @example
-   *   const ws = new WSv2({ managedOrderBooks: true })
-   *
-   *   ws.on('open', async () => {
-   *       ws.onOrderBook({ symbol: 'tBTCUSD' }, () => {
-   *         const book = ws.getOB('tBTCUSD')
-   *
-   *         if (!book) return
-   *
-   *         const spread = book.midPrice()
-   *         console.log('spread for tBTCUSD: %f', spread)
-   *       })
-   *
-   *       ws.subscribeOrderBook({ symbol: 'tBTCUSD' })
-   *   })
-   *
-   *   await ws.open()
-   */
-  getOB (symbol) {
-    if (!this._orderBooks[symbol]) return null
-
-    return new OrderBook(this._orderBooks[symbol])
-  }
-
-  /**
-   * Returns an up-to-date lossless copy of the order book for the specified symbol, or
-   * null if no OB is managed for that symbol. All amounts and prices are in original
-   * string format.
-   *
-   * Set `manageOrderBooks: true` in the constructor to use.
-   *
-   * @param {string} symbol - symbol for order book
-   * @returns {OrderBook} ob - null if not found
-   */
-  getLosslessOB (symbol) {
-    if (!this._losslessOrderBooks[symbol]) return null
-
-    return new OrderBook(this._losslessOrderBooks[symbol])
-  }
-
-  /**
-   * @param {Array} msg - incoming message
-   * @param {object} chanData - channel definition
-   * @private
-   */
-  _handleTradeMessage (msg, chanData) {
-    const eventName = msg[1][0] === 'f'
-      ? msg[1] // Funding trades are passed to fte/ftu handlers
-      : msg[1] === 'te'
-        ? 'trade-entry'
-        : 'trades'
-
-    let payload = getMessagePayload(msg)
-
-    if (!Array.isArray(payload[0])) {
-      payload = [payload]
-    }
-
-    let data = payload
-
-    if (this._transform) { // correctly parse single trade/array of trades
-      const M = eventName[0] === 'f' ? FundingTrade : PublicTrade
-      const trades = M.unserialize(data)
-
-      if (_isArray(trades) && trades.length === 1) {
-        data = trades[0]
-      } else {
-        data = trades
-      }
-
-      data = new M(data)
-    }
-
-    const internalMessage = [chanData.chanId, eventName, data]
-    internalMessage.filterOverride = [chanData.symbol || chanData.pair]
-
-    this._propagateMessageToListeners(internalMessage, chanData, false)
-    this.emit('trades', chanData.symbol || chanData.pair, data)
-  }
-
-  /**
-   * @param {Array} msg - incoming message
-   * @param {object} chanData - channel definition
-   * @private
-   */
-  _handleTickerMessage (msg = [], chanData = {}) {
-    let data = getMessagePayload(msg)
-
-    if (this._transform) {
-      data = (chanData.symbol || '')[0] === 't'
-        ? new TradingTicker([chanData.symbol, ...msg[1]])
-        : new FundingTicker([chanData.symbol, ...msg[1]])
-    }
-
-    const internalMessage = [chanData.chanId, 'ticker', data]
-    internalMessage.filterOverride = [chanData.symbol]
-
-    this._propagateMessageToListeners(internalMessage, chanData, false)
-    this.emit('ticker', chanData.symbol, data)
-  }
-
-  /**
-   * Called for messages from a 'candles' channel. Might be an update or
-   * snapshot.
-   *
-   * @param {Array|Array[]} msg - incoming message
-   * @param {object} chanData - entry from _channelMap
-   * @private
-   */
-  _handleCandleMessage (msg, chanData) {
-    const { key } = chanData
-    let data = getMessagePayload(msg)
-
-    if (this._manageCandles) {
-      const err = this._updateManagedCandles(key, data)
-
-      if (err) {
-        this.emit('error', err)
-        return
-      }
-
-      data = this._candles[key]
-    } else if (data.length > 0 && !Array.isArray(data[0])) {
-      data = [data] // always pass on an array of candles
-    }
-
-    if (this._transform) {
-      data = Candle.unserialize(data)
-    }
-
-    const internalMessage = [chanData.chanId, 'candle', data]
-    internalMessage.filterOverride = [chanData.key]
-
-    this._propagateMessageToListeners(internalMessage, chanData, false)
-    this.emit('candle', data, key)
-  }
-
-  /**
-   * Called for messages from a 'status' channel.
-   *
-   * @param {Array|Array[]} msg - incoming message
-   * @param {object} chanData - entry from _channelMap
-   * @private
-   */
-  _handleStatusMessage (msg, chanData) {
-    const { key } = chanData
-    const data = getMessagePayload(msg)
-
-    const internalMessage = [chanData.chanId, 'status', data]
-    internalMessage.filterOverride = [chanData.key]
-
-    this._propagateMessageToListeners(internalMessage, chanData, false)
-    this.emit('status', data, key)
-  }
-
-  /**
-   * @param {string} key - key for candle set
-   * @param {number[]|number[][]} data - incoming dataset (single or multiple)
-   * @returns {Error} err - null on success
-   * @private
-   */
-  _updateManagedCandles (key, data) {
-    if (Array.isArray(data[0])) { // snapshot, new candles
-      data.sort((a, b) => b[0] - a[0])
-
-      this._candles[key] = data
-      return null
-    }
-
-    // entry, needs to be applied to candle set
-    if (!this._candles[key]) {
-      return new Error(`recv update for unknown candles: ${key}`)
-    }
-
-    const candles = this._candles[key]
-    let updated = false
-
-    for (let i = 0; i < candles.length; i++) {
-      if (data[0] === candles[i][0]) {
-        candles[i] = data
-        updated = true
-        break
-      }
-    }
-
-    if (!updated) {
-      candles.unshift(data)
-    }
-
-    return null
-  }
-
-  /**
-   * Fetch a reference to the full set of synced candles for the specified key.
-   * Set `managedCandles: true` in the constructor to use.
-   *
-   * @param {string} key - key for candle set
-   * @returns {Array} candles - empty array if none exist
-   * @example
-   *   const ws = new WSv2({ managedCandles: true })
-   *
-   *   ws.on('open', async () => {
-   *       ws.onCandles({ key: 'trade:1m:tBTCUSD' }, () => {
-   *         const candles = ws.getCandles('trade:1m:tBTCUSD')
-   *
-   *         if (!candles) return
-   *
-   *         console.log('%d candles in dataset', candles.length)
-   *       })
-   *
-   *       ws.subscribeCandles({ key: 'trade:1m:tBTCUSD' })
-   *   })
-   *
-   *   await ws.open()
-   */
-  getCandles (key) {
-    return this._candles[key] || []
-  }
-
-  /**
-   * @param {Array} msg - incoming message
-   * @param {object} chanData - channel data
-   * @private
-   */
-  _handleAuthMessage (msg, chanData) {
-    if (msg[1] === 'n') {
-      const payload = getMessagePayload(msg)
-
-      if (payload) {
-        this._onWSNotification(payload)
-      }
-    } else if (msg[1] === 'te') {
-      msg[1] = 'auth-te'
-    } else if (msg[1] === 'tu') {
-      msg[1] = 'auth-tu'
-    }
-
-    this._propagateMessageToListeners(msg, chanData)
-  }
-
-  /**
-   * @param {Array} msg - incoming message
-   * @param {object} chan - channel data
-   * @param {boolean} transform - defaults to internal flag
-   * @private
-   */
-  _propagateMessageToListeners (msg, chan, transform = this._transform) {
-    const listenerGroups = Object.values(this._listeners)
-
-    for (let i = 0; i < listenerGroups.length; i++) {
-      WSv2._notifyListenerGroup(listenerGroups[i], msg, transform, this, chan)
-    }
-  }
-
-  /**
-   * Applies filtering & transform to a packet before sending it out to matching
-   * listeners in the group.
-   *
-   * @param {object} lGroup - listener group to parse & notify
-   * @param {object} msg - passed to each matched listener
-   * @param {boolean} transform - whether or not to instantiate a model
-   * @param {WSv2} ws - instance to pass to models if transforming
-   * @param {object} chanData - channel data
-   * @private
-   */
-  static _notifyListenerGroup (lGroup, msg, transform, ws, chanData) {
-    const [, eventName, data = []] = msg
-    let filterByData
-
-    // Catch-all can't filter/transform
-    WSv2._notifyCatchAllListeners(lGroup, msg)
-
-    if (!lGroup[eventName] || lGroup[eventName].length === 0) return
-
-    const listeners = lGroup[eventName].filter((listener) => {
-      const { filter } = listener
-
-      if (!filter) return true
-
-      // inspect snapshots for matching packets
-      if (Array.isArray(data[0])) {
-        const matchingData = data.filter((item) => {
-          filterByData = msg.filterOverride ? msg.filterOverride : item
-
-          return WSv2._payloadPassesFilter(filterByData, filter)
-        })
-
-        return matchingData.length !== 0
-      }
-
-      // inspect single packet
-      filterByData = msg.filterOverride ? msg.filterOverride : data
-
-      return WSv2._payloadPassesFilter(filterByData, filter)
-    })
-
-    if (listeners.length === 0) return
-
-    listeners.forEach(({ cb, modelClass }) => {
-      const ModelClass = modelClass
-
-      if (!ModelClass || !transform || data.length === 0) {
-        cb(data, chanData)
-      } else if (Array.isArray(data[0])) {
-        cb(data.map((entry) => {
-          return new ModelClass(entry, ws)
-        }), chanData)
-      } else {
-        cb(new ModelClass(data, ws), chanData)
-      }
-    })
-  }
-
-  /**
-   * @param {Array} payload - payload to verify
-   * @param {object} filter - filter to match against payload
-   * @returns {boolean} pass
-   * @private
-   */
-  static _payloadPassesFilter (payload, filter) {
-    const filterIndices = Object.keys(filter)
-    let filterValue
-
-    for (let k = 0; k < filterIndices.length; k++) {
-      filterValue = filter[filterIndices[k]]
-
-      if (_isEmpty(filterValue) || filterValue === '*') {
-        continue
-      }
-
-      if (payload[+filterIndices[k]] !== filterValue) {
-        return false
-      }
-    }
-
-    return true
-  }
-
-  /**
-   * @param {object} lGroup - listener group keyed by event ('' in this case)
-   * @param {*} data - packet to pass to listeners
-   * @private
-   */
-  static _notifyCatchAllListeners (lGroup, data) {
-    if (!lGroup['']) return
-
-    for (let j = 0; j < lGroup[''].length; j++) {
-      lGroup[''][j].cb(data)
-    }
-  }
-
-  /**
-   * @param {object} msg - incoming message
-   * @private
-   */
-  _handleEventMessage (msg) {
-    if (msg.event === 'auth') {
-      this._handleAuthEvent(msg)
-    } else if (msg.event === 'subscribed') {
-      this._handleSubscribedEvent(msg)
-    } else if (msg.event === 'unsubscribed') {
-      this._handleUnsubscribedEvent(msg)
-    } else if (msg.event === 'info') {
-      this._handleInfoEvent(msg)
-    } else if (msg.event === 'conf') {
-      this._handleConfigEvent(msg)
-    } else if (msg.event === 'error') {
-      this._handleErrorEvent(msg)
-    } else if (msg.event === 'pong') {
-      this._handlePongEvent(msg)
-    } else {
-      debug('recv unknown event message: %j', msg)
-    }
-  }
-
-  /**
-   * Emits an error on config failure, otherwise updates the internal flag set
-   * and triggers any callbacks
-   *
-   * @param {object} msg - config message
-   * @private
-   */
-  _handleConfigEvent (msg = {}) {
-    const { status, flags } = msg
-    const k = this._getConfigEventKey(flags)
-
-    if (status !== 'OK') {
-      const err = new Error(`config failed (${status}) for flags ${flags}`)
-      debug('config failed: %s', err.message)
-
-      this.emit('error', err)
-      this._eventCallbacks.trigger(k, err)
-    } else {
-      debug('flags updated to %d', flags)
-
-      this._enabledFlags = flags
-      this._eventCallbacks.trigger(k, null, msg)
-    }
-  }
-
-  /**
-   * @param {object} msg - incoming message
-   * @private
-   */
-  _handlePongEvent (msg) {
-    debug('pong: %s', JSON.stringify(msg))
-
-    this.emit('pong', msg)
-  }
-
-  /**
-   * @param {object} msg - incoming message
-   * @private
-   */
-  _handleErrorEvent (msg) {
-    debug('error: %s', JSON.stringify(msg))
-
-    this.emit('error', msg)
-  }
-
-  /**
-   * @param {object} data - incoming message
-   * @private
-   */
-  _handleAuthEvent (data = {}) {
-    const { chanId, msg = '', status = '' } = data
-
-    if (status !== 'OK') {
-      const err = new Error(msg.match(/nonce/)
-        ? 'auth failed: nonce small; you may need to generate a new API key to reset the nonce counter'
-        : `auth failed: ${msg} (${status})`
-      )
-
-      debug('%s', err.message)
-      this.emit('error', err)
-      return
-    }
-
-    this._channelMap[chanId] = { channel: 'auth' }
-    this._isAuthenticated = true
-    this._wasEverAuthenticated = true
-
-    this.emit('auth', data)
-    debug('authenticated!')
-  }
-
-  /**
-   * @param {object} msg - incoming message
-   * @private
-   */
-  _handleSubscribedEvent (msg) {
-    this._channelMap[msg.chanId] = msg
-
-    debug('subscribed to %s [%d]', msg.channel, msg.chanId)
-    this.emit('subscribed', msg)
-  }
-
-  /**
-   * @param {object} msg - incoming message
-   * @private
-   */
-  _handleUnsubscribedEvent (msg) {
-    delete this._channelMap[msg.chanId]
-    debug('unsubscribed from %d', msg.chanId)
-    this.emit('unsubscribed', msg)
-  }
-
-  /**
-   * @param {object} msg - incoming message
-   * @private
-   */
-  _handleInfoEvent (msg = {}) {
-    const { version, code } = msg
-
-    if (version) {
-      if (version !== 2) {
-        const err = new Error(`server not running API v2: v${version}`)
-
-        this.emit('error', err)
-        this.close().catch((err) => {
-          debug('error closing connection: %s', err.stack)
-        })
-        return
-      }
-
-      const { status } = msg.platform || {}
-
-      debug(
-        'server running API v2 (platform: %s (%d))',
-        status === 0 ? 'under maintenance' : 'operating normally', status
-      )
-    } else if (code) {
-      if (this._infoListeners[code]) {
-        this._infoListeners[code].forEach(cb => cb(msg))
-      }
-
-      if (code === WSv2.INFO_CODES.SERVER_RESTART) {
-        debug('server restarted, please reconnect')
-      } else if (code === WSv2.INFO_CODES.MAINTENANCE_START) {
-        debug('server maintenance period started!')
-      } else if (code === WSv2.INFO_CODES.MAINTENANCE_END) {
-        debug('server maintenance period ended!')
-      }
-    }
-
-    this.emit('info', msg)
-  }
-
-  /**
-   * Subscribes and tracks subscriptions per channel/identifier pair. If
-   * already subscribed to the specified pair, nothing happens.
-   *
-   * @param {string} channel - channel name
-   * @param {string} identifier - for uniquely identifying the ref count
-   * @param {object} payload - merged with sub packet
-   * @returns {boolean} subSent
-   * @todo will be refactored to return promise from subscribe() call instead
-   *   of sub action taken flag
-   * @see WSv2#subscribeTrades
-   * @see WSv2#subscribeTicker
-   * @see WSv2#subscribeCandles
-   * @see WSv2#subscribeOrderBook
-   * @example
-   * const ws = new WSv2()
-   *
-   * ws.on('open', async () => {
-   *   ws.onTrades({ symbol: 'tBTCUSD' }, (trades) => {
-   *     console.log('recv trades: %j', trades)
-   *  })
-   *
-   *   ws.managedSubscribe('trades', 'tBTCUSD', { symbol: 'tBTCUSD' })
-   * })
-   *
-   * await ws.open()
-   */
-  managedSubscribe (channel = '', identifier = '', payload = {}) {
-    const key = `${channel}:${identifier}`
-
-    if (this._subscriptionRefs[key]) {
-      this._subscriptionRefs[key]++
-      return false
-    }
-
-    this._subscriptionRefs[key] = 1
-    this.subscribe(channel, payload)
-
-    return true
-  }
-
-  /**
-   * Decreases the subscription ref count for the channel/identifier pair, and
-   * unsubscribes from the channel if it reaches 0.
-   *
-   * @param {string} channel - channel name
-   * @param {string} identifier - for uniquely identifying the ref count
-   * @returns {boolean} unsubSent
-   */
-  managedUnsubscribe (channel = '', identifier = '') {
-    const key = `${channel}:${identifier}`
-    const chanId = this._chanIdByIdentifier(channel, identifier)
-
-    if (chanId === null || isNaN(this._subscriptionRefs[key])) return false
-
-    this._subscriptionRefs[key]--
-    if (this._subscriptionRefs[key] > 0) return false
-
-    this.unsubscribe(chanId)
-    delete this._subscriptionRefs[key]
-
-    return true
-  }
-
-  /**
-   * Fetch a channel definition
-   *
-   * @param {object} opts - options
-   * @param {number} opts.chanId - channel ID
-   * @param {string} opts.channel - channel name
-   * @param {string} [opts.symbol] - match by symbol
-   * @param {string} [opts.key] - match by key (for candle channels)
-   * @returns {object} chanData - null if not found
-   */
-  getChannelData ({ chanId, channel, symbol, key }) {
-    const id = chanId || this._chanIdByIdentifier(channel, symbol || key)
-
-    return this._channelMap[id] || null
-  }
-
-  /**
-   * @param {string} channel - channel name
-   * @param {string} identifier - unique identifier for the channel
-   * @returns {number} channelID
-   * @private
-   */
-  _chanIdByIdentifier (channel, identifier) {
-    const channelIds = Object.keys(this._channelMap)
-    let chan
-
-    for (let i = 0; i < channelIds.length; i++) {
-      chan = this._channelMap[channelIds[i]]
-
-      if (chan.channel === channel && (
-        chan.symbol === identifier ||
-        chan.key === identifier
-      )) {
-        return channelIds[i]
-      }
-    }
-
-    return null
-  }
-
-  /**
-   * @param {string} key - key for the promise
-   * @returns {Promise} p - resolves on event
-   * @private
-   */
-  _getEventPromise (key) {
-    return new Promise((resolve, reject) => {
-      this._eventCallbacks.push(key, (err, res) => {
-        if (err) {
-          return reject(err)
-        }
-
-        resolve(res)
-      })
-    })
-  }
-
-  /**
-   * Send a packet to the WS server
-   *
-   * @param {*} msg - packet, gets stringified
-   */
-  send (msg) {
-    if (!this._ws || !this._isOpen) {
-      this.emit('error', new Error('no ws client or not open'))
-    } else if (this._isClosing) {
-      this.emit('error', new Error('connection currently closing'))
-    } else {
-      debug('sending %j', msg)
-      this._ws.send(JSON.stringify(msg))
-    }
-  }
-
-  /**
-   * @returns {boolean} sequencingEnabled
-   */
-  sequencingEnabled () {
-    return this._seqAudit
-  }
-
-  /**
-   * Configures the seq flag to enable sequencing (packet number) for this
-   * connection. When enabled, the seq number will be the last value of
-   * channel packet arrays.
-   *
-   * @param {object} args - params
-   * @param {boolean} [args.audit] - if true, an error is emitted on invalid seq
-   * @returns {Promise} p
-   * @see WSv2#flags
-   */
-  async enableSequencing (args = { audit: true }) {
-    this._seqAudit = args.audit === true
-
-    return this.enableFlag(WSv2.flags.SEQ_ALL)
-  }
-
-  /**
-   * Enables a configuration flag.
-   *
-   * @param {number} flag - flag to update, as numeric value
-   * @returns {Promise} p
-   * @see WSv2#flags
-   * @example
-   * const ws = new WSv2()
-   *
-   * ws.on('open', async () => {
-   *   await ws.enableFlag(WSv2.flags.CHECKSUM)
-   *   console.log('ob checkums enabled')
-   * })
-   *
-   * await ws.open()
-   */
-  async enableFlag (flag) {
-    this._enabledFlags = this._enabledFlags | flag
-
-    if (!this._isOpen) {
-      return
-    }
-
-    this.sendEnabledFlags()
-    return this._getEventPromise(this._getConfigEventKey(flag))
-  }
-
-  /**
-   * Sends the local flags value to the server, updating the config
-   *
-   * @private
-   */
-  sendEnabledFlags () {
-    this.send({
-      event: 'conf',
-      flags: this._enabledFlags
-    })
-  }
-
-  /**
-   * Checks local state, relies on successful server config responses
-   *
-   * @see enableFlag
-   *
-   * @param {number} flag - flag to check for
-   * @returns {boolean} enabled
-   */
-  isFlagEnabled (flag) {
-    return (this._enabledFlags & flag) === flag
-  }
-
-  /**
-   * @param {string} flag - flag to fetch event key for
-   * @returns {string} key
-   * @private
-   */
-  _getConfigEventKey (flag) {
-    return `conf-res-${flag}`
-  }
-
-  /**
-   * Register a callback in case of a ws server restart message; Use this to
-   * call reconnect() if needed. (code 20051)
-   *
-   * @param {Function} cb - called on event trigger
-   */
-  onServerRestart (cb) {
-    this.onInfoMessage(WSv2.info.SERVER_RESTART, cb)
-  }
-
-  /**
-   * Register a callback in case of a 'maintenance started' message from the
-   * server. This is a good time to pause server packets until maintenance ends
-   *
-   * @param {Function} cb - called on event trigger
-   */
-  onMaintenanceStart (cb) {
-    this.onInfoMessage(WSv2.info.MAINTENANCE_START, cb)
-  }
-
-  /**
-   * Register a callback to be notified of a maintenance period ending
-   *
-   * @param {Function} cb - called on event trigger
-   */
-  onMaintenanceEnd (cb) {
-    this.onInfoMessage(WSv2.info.MAINTENANCE_END, cb)
-  }
-
-  /**
-   * Subscribe to a channel with the given filter payload
-   *
-   * @param {string} channel - channel payload/data
-   * @param {object} payload - optional extra packet data
-   * @example
-   * const ws = new WSv2()
-   *
-   * ws.on('open', () => {
-   *   ws.onTrades({ symbol: 'tBTCUSD' }, (trades) => {
-   *     // ...
-   *   })
-   *
-   *   ws.subscribe('trades', { symbol: 'tBTCUSD' })
-   * })
-   *
-   * await ws.open()
-   */
-  subscribe (channel, payload) {
-    this.send(Object.assign({
-      event: 'subscribe',
-      channel
-    }, payload))
-  }
-
-  /**
-   * Subscribe to a ticker data channel
-   *
-   * @param {string} symbol - symbol of ticker
-   * @returns {boolean} subscribed
-   * @see WSv2#managedSubscribe
-   * @example
-   * await ws.subscribeTicker('tBTCUSD')
-   */
-  async subscribeTicker (symbol) {
-    return this.managedSubscribe('ticker', symbol, { symbol })
-  }
-
-  /**
-   * Subscribe to a trades data channel
-   *
-   * @param {string} symbol - symbol of market to monitor
-   * @returns {boolean} subscribed
-   * @see WSv2#managedSubscribe
-   * @example
-   * await ws.subscribeTrades('tBTCUSD')
-   */
-  async subscribeTrades (symbol) {
-    return this.managedSubscribe('trades', symbol, { symbol })
-  }
-
-  /**
-   * Subscribe to an order book data channel
-   *
-   * @param {string} symbol - symbol of order book
-   * @param {string} prec - P0, P1, P2, or P3 (default P0)
-   * @param {string} len - 25 or 100 (default 25)
-   * @returns {boolean} subscribed
-   * @see WSv2#managedSubscribe
-   * @example
-   * await ws.subscribeOrderBook('tBTCUSD', 'R0', '25')
-   */
-  async subscribeOrderBook (symbol, prec = 'P0', len = '25') {
-    return this.managedSubscribe('book', symbol, { symbol, len, prec })
-  }
-
-  /**
-   * Subscribe to a candle data channel
-   *
-   * @param {string} key - 'trade:5m:tBTCUSD'
-   * @returns {boolean} subscribed
-   * @see WSv2#managedSubscribe
-   * @example
-   * await ws.subscribeCandles('trade:5m:tBTCUSD')
-   */
-  async subscribeCandles (key) {
-    return this.managedSubscribe('candles', key, { key })
-  }
-
-  /**
-   * Subscribe to a status data channel
-   *
-   * @param {string} key - i.e. 'liq:global'
-   * @returns {boolean} subscribed
-   * @see WSv2#managedSubscribe
-   * @example
-   * await ws.subscribeStatus('liq:global')
-   */
-  async subscribeStatus (key) {
-    return this.managedSubscribe('status', key, { key })
-  }
-
-  /**
-   * Unsubscribe from a channel by ID
-   *
-   * @param {number} chanId - ID of channel to unsubscribe from
-   * @example
-   * const id = ws.getDataChannelId('ticker', { symbol: 'tBTCUSD' })
-   *
-   * if (id) {
-   *   ws.unsubscribe(id)
-   * }
-   */
-  unsubscribe (chanId) {
-    this.send({
-      event: 'unsubscribe',
-      chanId: +chanId
-    })
-  }
-
-  /**
-   * Unsubscribe from a ticker data channel
-   *
-   * @param {string} symbol - symbol of ticker
-   * @returns {boolean} unsubscribed
-   * @see WSv2#subscribeTicker
-   * @example
-   * await ws.unsubscribeTicker('tBTCUSD')
-   */
-  async unsubscribeTicker (symbol) {
-    return this.managedUnsubscribe('ticker', symbol)
-  }
-
-  /**
-   * Unsubscribe from a trades data channel
-   *
-   * @param {string} symbol - symbol of market to unsubscribe from
-   * @returns {boolean} unsubscribed
-   * @see WSv2#subscribeTrades
-   * @example
-   * await ws.unsubcribeTrades('tBTCUSD')
-   */
-  async unsubscribeTrades (symbol) {
-    return this.managedUnsubscribe('trades', symbol)
-  }
-
-  /**
-   * Unsubscribe from an order book data channel
-   *
-   * @param {string} symbol - symbol of order book
-   * @returns {boolean} unsubscribed
-   * @see WSv2#subscribeOrderBook
-   * @example
-   * await ws.unsubcribeOrderBook('tBTCUSD')
-   */
-  async unsubscribeOrderBook (symbol) {
-    return this.managedUnsubscribe('book', symbol)
-  }
-
-  /**
-   * @param {string} symbol - symbol of candles
-   * @param {string} frame - time frame
-   * @returns {boolean} unsubscribed
-   * @see WSv2#subscribeCandles
-   * @example
-   *   await ws.unsubscribeCandles('tBTCUSD', '1m')
-   */
-  async unsubscribeCandles (symbol, frame) {
-    return this.managedUnsubscribe('candles', `trade:${frame}:${symbol}`)
-  }
-
-  /**
-   * @param {string} key - key that was used in initial {@link WSv2#subscribeStatus} call
-   * @returns {boolean} unsubscribed
-   * @see WSv2#subscribeStatus
-   */
-  async unsubscribeStatus (key) {
-    return this.managedUnsubscribe('status', key)
-  }
-
-  /**
-   * Remove all listeners by callback group ID
-   *
-   * @param {string} cbGID - callback group to remove
-   * @example
-   * await ws.subscribeTrades({ symbol: 'tBTCUSD', cbGID: 42 })
-   * await ws.subscribeTrades({ symbol: 'tLEOUSD', cbGID: 42 })
-   * await ws.subscribeTrades({ symbol: 'tETHUSD', cbGID: 42 })
-   *
-   * // ...
-   *
-   * ws.removeListeners(42)
-   */
-  removeListeners (cbGID) {
-    delete this._listeners[cbGID]
-  }
-
-  /**
-   * Request a calc operation to be performed on the specified indexes
-   *
-   * @param {string[]} prefixes - desired prefixes to be calculated
-   */
-  requestCalc (prefixes) {
-    this._sendCalc([0, 'calc', null, prefixes.map(p => [p])])
-  }
-
-  /**
-   * Throttled call to ws.send, max 8 op/s
-   *
-   * @param {Array} msg - message
-   * @private
-   */
-  _sendCalc (msg) {
-    debug('req calc: %j', msg)
-
-    this._ws.send(JSON.stringify(msg))
-  }
-
-  /**
-   * Sends a new order to the server and resolves the returned promise once the
-   * order submit is confirmed. Emits an error if not authenticated. The order
-   * can be either an array, key/value map, or Order object instance.
-   *
-   * @see WSv2#cancelOrders
-   * @see WSv2#cancelOrder
-   * @see WSv2#updateOrder
-   *
-   * @param {object|Array} order - order object model or array
-   * @returns {Promise} p - resolves on submit notification
-   * @example
-   * const o = new Order({
-   *   type: Order.type.EXCHANGE_LIMIT,
-   *   amount: 18,
-   *   price: 0.75,
-   *   symbol: 'tBTCUSD',
-   *   hidden: true
-   * }, ws)
-   *
-   * await ws.submitOrder(o)
-   *
-   * console.log('order confirmed! status: %s', o.status)
-   */
-  async submitOrder (order) {
-    if (!this._isAuthenticated) {
-      throw new Error('not authenticated')
-    }
-
-    const packet = Array.isArray(order)
-      ? order
-      : order instanceof Order
-        ? order.toNewOrderPacket()
-        : new Order(order).toNewOrderPacket()
-
-    if (this._affCode) {
-      if (!packet.meta) {
-        packet.meta = {}
-      }
-
-      packet.meta.aff_code = packet.meta.aff_code || this._affCode // eslint-disable-line
-    }
-
-    this._sendOrderPacket([0, 'on', null, packet])
-
-    return this._getEventPromise(`order-new-${packet.cid}`)
-  }
-
-  /**
-   * Send a changeset to update an order in-place while maintaining position in
-   * the price queue. The changeset must contain the order ID, and supports a
-   * 'delta' key to increase/decrease the total amount.
-   *
-   * @see WSv2#submitOrder
-   *
-   * @param {object} changes - requires at least an 'id'
-   * @returns {Promise} p - resolves on receiving an confirmation notification
-   */
-  async updateOrder (changes = {}) {
-    const { id } = changes
-
-    if (!this._isAuthenticated) {
-      throw new Error('not authenticated')
-    } else if (!id) {
-      throw new Error('order ID required for update')
-    }
-
-    this._sendOrderPacket([0, 'ou', null, changes])
-
-    return this._getEventPromise(`order-update-${id}`)
-  }
-
-  /**
-   * Cancels an order by ID and resolves the returned promise once the cancel is
-   * confirmed. Emits an error if not authenticated. The ID can be passed as a
-   * number, or taken from an order array/object.
-   *
-   * @see WSv2#submitOrder
-   *
-   * @param {object|Array|number} order - order model, array, or ID to be cancelled
-   * @returns {Promise} p
-   */
-  async cancelOrder (order) {
-    if (!this._isAuthenticated) {
-      throw new Error('not authenticated')
-    }
-
-    const id = _isNumber(order)
-      ? order
-      : Array.isArray(order)
-        ? order[0]
-        : order.id
-
-    debug(`cancelling order ${id}`)
-    this._sendOrderPacket([0, 'oc', null, { id }])
-
-    return this._getEventPromise(`order-cancel-${id}`)
-  }
-
-  /**
-   * Cancels multiple orders, returns a promise that resolves once all
-   * operations are confirmed.
-   *
-   * @see WSv2#submitOrder
-   *
-   * @param {object[]|Array[]|number[]} orders - array of order models, arrays
-   *   or IDs to be cancelled
-   * @returns {Promise} p
-   */
-  async cancelOrders (orders) {
-    if (!this._isAuthenticated) {
-      throw new Error('not authenticated')
-    }
-
-    return Promise.all(orders.map(o => {
-      return this.cancelOrder(o)
-    }))
-  }
-
-  /**
-   * Sends the op payloads to the server as an 'ox_multi' command. A promise is
-   * returned and resolves immediately if authenticated, as no confirmation is
-   * available for this message type.
-   *
-   * @param {object[]} opPayloads - order operations
-   * @returns {Promise} p - rejects if not authenticated
-   */
-  async submitOrderMultiOp (opPayloads) {
-    if (!this._isAuthenticated) {
-      throw new Error('not authenticated')
-    }
-
-    // TODO: multi-op tracking
-    this.send([0, 'ox_multi', null, opPayloads])
-  }
-
-  /**
-   * @param {Array} packet - new order packet to be submitted
-   * @private
-   */
-  _sendOrderPacket (packet) {
-    if (this._hasOrderBuff()) {
-      this._ensureOrderBuffTimeout()
-      this._orderOpBuffer.push(packet)
-    } else {
-      this.send(packet)
-    }
-  }
-
-  /**
-   * @returns {boolean} buffEnabled
-   * @private
-   */
-  _hasOrderBuff () {
-    return this._orderOpBufferDelay > 0
-  }
-
-  /**
-   * @private
-   */
-  _ensureOrderBuffTimeout () {
-    if (this._orderOpTimeout !== null) return
-
-    this._orderOpTimeout = setTimeout(
-      this._flushOrderOps.bind(this),
-      this._orderOpBufferDelay
-    )
-  }
-
-  /**
-   * Splits the op buffer into packets of max 15 ops each, and sends them down
-   * the wire.
-   *
-   * @returns {Promise} p - resolves after send
-   * @private
-   */
-  _flushOrderOps () {
-    this._orderOpTimeout = null
-
-    const packets = this._orderOpBuffer.map(p => [p[1], p[3]])
-    this._orderOpBuffer = []
-
-    if (packets.length <= 15) {
-      return this.submitOrderMultiOp(packets)
-    }
-
-    const promises = []
-
-    while (packets.length > 0) {
-      const opPackets = packets.splice(0, Math.min(packets.length, 15))
-      promises.push(this.submitOrderMultiOp(opPackets))
-    }
-
-    return Promise.all(promises)
-  }
-
-  /**
-   * @returns {boolean} authenticated
-   */
-  isAuthenticated () {
-    return this._isAuthenticated
-  }
-
-  /**
-   * @returns {boolean} open
-   */
-  isOpen () {
-    return this._isOpen
-  }
-
-  /**
-   * @returns {boolean} reconnecting
-   */
-  isReconnecting () {
-    return this._isReconnecting
-  }
-
-  /**
-   * Sends a broadcast notification, which will be received by any active UI
-   * websocket connections (at bitfinex.com), triggering a desktop notification.
-   *
-   * In the future our mobile app will also support spawning native push
-   * notifications in response to incoming ucm-notify-ui packets.
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.message] - message to display
-   * @param {string} [opts.type] - notification type, 'ucm-*' for broadcasts
-   * @param {string} [opts.level] - 'info', 'error', or 'success'
-   * @param {string} [opts.image] - link to an image to be shown
-   * @param {string} [opts.link] - URL the notification should forward too
-   * @param {string} [opts.sound] - URL of sound to play
-   * @throws an error if given no type or message, or the instance is not open
-   *   and authenticated
-   */
-  notifyUI (opts = {}) {
-    const { type, message, level, image, link, sound } = opts
-
-    if (!_isString(type) || !_isString(message)) {
-      throw new Error(`notified with invalid type/message: ${type}/${message}`)
-    }
-
-    if (!this._isOpen) {
-      throw new Error('socket not open')
-    }
-
-    if (!this._isAuthenticated) {
-      throw new Error('socket not authenticated')
-    }
-
-    this.send([0, 'n', null, {
-      type: UCM_NOTIFICATION_TYPE,
-      info: {
-        type,
-        message,
-        level,
-        image,
-        link,
-        sound
-      }
-    }])
-  }
-
-  /**
-   * Adds a listener to the internal listener set, with an optional grouping
-   * for batch unsubscribes (GID) & automatic ws packet matching (filterKey)
-   *
-   * @param {string} eventName - as received on ws stream
-   * @param {object} filter - map of index & value in ws packet
-   * @param {object} modelClass - model to use for serialization
-   * @param {string} cbGID - listener group ID for mass removal
-   * @param {Function} cb - listener
-   * @private
-   */
-  _registerListener (eventName, filter, modelClass, cbGID, cb) {
-    if (!cbGID) cbGID = null
-
-    if (!this._listeners[cbGID]) {
-      this._listeners[cbGID] = { [eventName]: [] }
-    }
-
-    const listeners = this._listeners[cbGID]
-
-    if (!listeners[eventName]) {
-      listeners[eventName] = []
-    }
-
-    const l = {
-      cb,
-      modelClass,
-      filter
-    }
-
-    listeners[eventName].push(l)
-  }
-
-  /**
-   * Registers a new callback to be called when a matching info message is
-   * received.
-   *
-   * @param {number} code - from #WSv2.info
-   * @param {Function} cb - callback
-   */
-  onInfoMessage (code, cb) {
-    if (!this._infoListeners[code]) {
-      this._infoListeners[code] = []
-    }
-
-    this._infoListeners[code].push(cb)
-  }
-
-  /**
-   * Register a generic handler to be called with each received message
-   *
-   * @param {object} opts - options
-   * @param {string|number} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   */
-  onMessage ({ cbGID }, cb) {
-    this._registerListener('', null, null, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called with each received candle
-   *
-   * @param {object} opts - options
-   * @param {string} opts.key - candle set key, i.e. trade:30m:tBTCUSD
-   * @param {string|number} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-public-candle
-   * @see WSv2#subscribeCandles
-   * @see WSv2#unsubscribeCandles
-   */
-  onCandle ({ key, cbGID }, cb) {
-    this._registerListener('candle', { 0: key }, Candle, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called with each received candle
-   *
-   * @param {object} opts - options
-   * @param {string} opts.symbol - book symbol
-   * @param {string} opts.prec - book precision, i.e. 'R0'
-   * @param {string} opts.len - book length, i.e. '25'
-   * @param {string|number} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-public-order-books
-   * @see WSv2#subscribeOrderBook
-   * @see WSv2#unsubscribeOrderBook
-   */
-  onOrderBook ({ symbol, prec, len, cbGID }, cb) {
-    this._registerListener('orderbook', {
-      0: symbol,
-      1: prec,
-      2: len
-    }, OrderBook, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called with each received order book checksum
-   *
-   * @param {object} opts - options
-   * @param {string} opts.symbol - book symbol
-   * @param {string} opts.prec - book precision, i.e. 'R0'
-   * @param {string} opts.len - book length, i.e. '25'
-   * @param {string|number} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-public-order-books
-   * @see WSv2#subscribeOrderBook
-   * @see WSv2#unsubscribeOrderBook
-   */
-  onOrderBookChecksum ({ symbol, prec, len, cbGID }, cb) {
-    this._registerListener('ob_checksum', {
-      0: symbol,
-      1: prec,
-      2: len
-    }, null, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called with each received trade (pair or symbol
-   * required)
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.pair] - required if no symbol specified
-   * @param {string} [opts.symbol] - required if no pair specified
-   * @param {string|number} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-public-trades
-   * @see WSv2#subscribeTrades
-   * @see WSv2#unsubscribeTrades
-   */
-  onTrades ({ symbol, pair, cbGID }, cb) {
-    const id = pair || symbol || ''
-    const model = id[0] === 'f' ? FundingTrade : PublicTrade
-
-    this._registerListener('trades', { 0: id }, model, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called on each trade `'te'` event
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.pair] - required if no symbol specified
-   * @param {string} [opts.symbol] - required if no pair specified
-   * @param {string|number} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-public-trades
-   * @see WSv2#subscribeTrades
-   * @see WSv2#unsubscribeTrades
-   */
-  onTradeEntry ({ pair, symbol, cbGID }, cb) {
-    const id = pair || symbol || ''
-    this._registerListener('trade-entry', { 0: id }, PublicTrade, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called on each personal trade `'te'` event
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.pair] - required if no symbol specified
-   * @param {string} [opts.symbol] - required if no pair specified
-   * @param {string|number} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-public-trades
-   */
-  onAccountTradeEntry ({ pair, symbol, cbGID }, cb) {
-    const id = pair || symbol || ''
-    this._registerListener('auth-te', { 1: id }, Trade, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called on each personal trade `'tu'` event
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.pair] - required if no symbol specified
-   * @param {string} [opts.symbol] - required if no pair specified
-   * @param {string|number} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-auth-trades
-   */
-  onAccountTradeUpdate ({ pair, symbol, cbGID }, cb) {
-    const id = pair || symbol || ''
-    this._registerListener('auth-tu', { 1: id }, Trade, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called on each received ticker
-   *
-   * @param {object} opts - options
-   * @param {string} opts.symbol - symbol for tickers
-   * @param {string|number} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-public-ticker
-   * @see WSv2#subscribeTicker
-   * @see WSv2#unsubscribeTicker
-   */
-  onTicker ({ symbol = '', cbGID } = {}, cb) {
-    const m = symbol[0] === 'f' ? FundingTicker : TradingTicker
-    this._registerListener('ticker', { 0: symbol }, m, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called on each message for the desired status
-   * feed.
-   *
-   * @param {object} opts - options
-   * @param {string} opts.key - key of feed to listen on
-   * @param {string|number} [opts.cbGID] - callback group ID
-   * @param {Function} cb - callback
-   * @see WSv2#subscribeStatus
-   */
-  onStatus ({ key = '', cbGID } = {}, cb) {
-    this._registerListener('status', { 0: key }, null, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called on each full order snapshot (sent on auth)
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.symbol] - symbol to match
-   * @param {number} [opts.id] - order ID to match
-   * @param {number} [opts.cid] - order client ID to match
-   * @param {number} [opts.gid] - order group ID to match
-   * @param {string|number} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-auth-orders
-   * @see WSv2#auth
-   */
-  onOrderSnapshot ({ symbol, id, cid, gid, cbGID }, cb) {
-    this._registerListener('os', {
-      0: id,
-      1: gid,
-      2: cid,
-      3: symbol
-    }, Order, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called on each new order packet
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.symbol] - symbol to match
-   * @param {number} [opts.id] - order ID to match
-   * @param {number} [opts.cid] - order client ID to match
-   * @param {number} [opts.gid] - order group ID to match
-   * @param {string} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-auth-orders
-   * @see WSv2#submitOrder
-   */
-  onOrderNew ({ symbol, id, cid, gid, cbGID }, cb) {
-    this._registerListener('on', {
-      0: id,
-      1: gid,
-      2: cid,
-      3: symbol
-    }, Order, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called on each order update packet
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.symbol] - symbol to match
-   * @param {number} [opts.id] - order ID to match
-   * @param {number} [opts.cid] - order client ID to match
-   * @param {number} [opts.gid] - order group ID to match
-   * @param {string} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-auth-orders
-   * @see WSv2#updateOrder
-   */
-  onOrderUpdate ({ symbol, id, cid, gid, cbGID }, cb) {
-    this._registerListener('ou', {
-      0: id,
-      1: gid,
-      2: cid,
-      3: symbol
-    }, Order, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called on each order close packet
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.symbol] - symbol to match
-   * @param {number} [opts.id] - order ID to match
-   * @param {number} [opts.cid] - order client ID to match
-   * @param {number} [opts.gid] - order group ID to match
-   * @param {string} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-auth-orders
-   * @see WSv2#cancelOrder
-   */
-  onOrderClose ({ symbol, id, cid, gid, cbGID }, cb) {
-    this._registerListener('oc', {
-      0: id,
-      1: gid,
-      2: cid,
-      3: symbol
-    }, Order, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called on each position snapshot (sent on auth)
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.symbol] - symbol to match
-   * @param {string} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-auth-position
-   * @see WSv2#auth
-   */
-  onPositionSnapshot ({ symbol, cbGID }, cb) {
-    this._registerListener('ps', { 0: symbol }, Position, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called when a position is opened
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.symbol] - symbol to match
-   * @param {string} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-auth-position
-   */
-  onPositionNew ({ symbol, cbGID }, cb) {
-    this._registerListener('pn', { 0: symbol }, Position, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called when a position is updated
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.symbol] - symbol to match
-   * @param {string} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-auth-position
-   */
-  onPositionUpdate ({ symbol, cbGID }, cb) {
-    this._registerListener('pu', { 0: symbol }, Position, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called when a position is closed
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.symbol] - symbol to match
-   * @param {string} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-auth-position
-   */
-  onPositionClose ({ symbol, cbGID }, cb) {
-    this._registerListener('pc', { 0: symbol }, Position, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called on each fundign offer snapshot (sent on
-   * auth)
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.symbol] - symbol to match
-   * @param {string} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-auth-offers
-   * @see WSv2#auth
-   */
-  onFundingOfferSnapshot ({ symbol, cbGID }, cb) {
-    this._registerListener('fos', { 1: symbol }, FundingOffer, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called when a funding offer is created
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.symbol] - symbol to match
-   * @param {string} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-auth-offers
-   */
-  onFundingOfferNew ({ symbol, cbGID }, cb) {
-    this._registerListener('fon', { 1: symbol }, FundingOffer, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called when a funding offer is updated
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.symbol] - symbol to match
-   * @param {string} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-auth-offers
-   */
-  onFundingOfferUpdate ({ symbol, cbGID }, cb) {
-    this._registerListener('fou', { 1: symbol }, FundingOffer, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called when a funding offer is closed
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.symbol] - symbol to match
-   * @param {string} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-auth-offers
-   */
-  onFundingOfferClose ({ symbol, cbGID }, cb) {
-    this._registerListener('foc', { 1: symbol }, FundingOffer, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called on each funding credit snapshot (sent on
-   * auth)
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.symbol] - symbol to match
-   * @param {string} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-auth-credits
-   * @see WSv2#auth
-   */
-  onFundingCreditSnapshot ({ symbol, cbGID }, cb) {
-    this._registerListener('fcs', { 1: symbol }, FundingCredit, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called when a funding credit is created
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.symbol] - symbol to match
-   * @param {string} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-auth-credits
-   */
-  onFundingCreditNew ({ symbol, cbGID }, cb) {
-    this._registerListener('fcn', { 1: symbol }, FundingCredit, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called when a funding credit is updated
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.symbol] - symbol to match
-   * @param {string} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-auth-credits
-   */
-  onFundingCreditUpdate ({ symbol, cbGID }, cb) {
-    this._registerListener('fcu', { 1: symbol }, FundingCredit, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called when a funding credit is closed
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.symbol] - symbol to match
-   * @param {string} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-auth-credits
-   */
-  onFundingCreditClose ({ symbol, cbGID }, cb) {
-    this._registerListener('fcc', { 1: symbol }, FundingCredit, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called on each funding loan snapshot (sent on
-   * auth)
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.symbol] - symbol to match
-   * @param {string} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-auth-loans
-   * @see WSv2#auth
-   */
-  onFundingLoanSnapshot ({ symbol, cbGID }, cb) {
-    this._registerListener('fls', { 1: symbol }, FundingLoan, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called when a funding loan is created
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.symbol] - symbol to match
-   * @param {string} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-auth-loans
-   */
-  onFundingLoanNew ({ symbol, cbGID }, cb) {
-    this._registerListener('fln', { 1: symbol }, FundingLoan, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called when a funding loan is updated
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.symbol] - symbol to match
-   * @param {string} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-auth-loans
-   */
-  onFundingLoanUpdate ({ symbol, cbGID }, cb) {
-    this._registerListener('flu', { 1: symbol }, FundingLoan, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called when a funding loan is closed
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.symbol] - symbol to match
-   * @param {string} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-auth-loans
-   */
-  onFundingLoanClose ({ symbol, cbGID }, cb) {
-    this._registerListener('flc', { 1: symbol }, FundingLoan, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called on each wallet snapshot (sent on auth)
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-auth-wallets
-   */
-  onWalletSnapshot ({ cbGID }, cb) {
-    this._registerListener('ws', null, Wallet, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called on each wallet update
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-auth-wallets
-   */
-  onWalletUpdate ({ cbGID }, cb) {
-    this._registerListener('wu', null, Wallet, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called on each balance info update
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-auth-balance
-   */
-  onBalanceInfoUpdate ({ cbGID }, cb) {
-    this._registerListener('bu', null, BalanceInfo, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called on each margin info update
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-auth-margin
-   */
-  onMarginInfoUpdate ({ cbGID }, cb) {
-    this._registerListener('miu', null, MarginInfo, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called on each funding info update
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-auth-funding
-   */
-  onFundingInfoUpdate ({ cbGID }, cb) {
-    this._registerListener('fiu', null, FundingInfo, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called on each funding trade `'te'` event
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.symbol] - symbol to match
-   * @param {string} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-auth-funding-trades
-   */
-  onFundingTradeEntry ({ symbol, cbGID }, cb) {
-    this._registerListener('fte', { 0: symbol }, FundingTrade, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called on each funding trade `'tu'` event
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.symbol] - symbol to match
-   * @param {string} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-auth-funding-trades
-   */
-  onFundingTradeUpdate ({ symbol, cbGID }, cb) {
-    this._registerListener('ftu', { 0: symbol }, FundingTrade, cbGID, cb)
-  }
-
-  /**
-   * Register a handler to be called on each notification
-   *
-   * @param {object} opts - options
-   * @param {string} [opts.type] - type to match
-   * @param {string} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @see https://docs.bitfinex.com/v2/reference#ws-auth-notifications
-   */
-  onNotification ({ type, cbGID }, cb) {
-    this._registerListener('n', { 1: type }, Notification, cbGID, cb)
-  }
-}
-
-/**
- * Map of flag names and numeric values for usage with the API
- *
- * @constant
- * @property {number} DEC_S - flag to request all decimals as strings
- * @property {number} TIME_S - flag to request all timestamps as strings
- * @property {number} TIMESTAMP - flag to request timestamp in milliseconds
- * @property {number} SEQ_ALL - flag to enable sequence numbers & verification
- * @property {number} CHECKSUM - flag to enable order book checksums
- * @memberof! WSv2#
- */
-WSv2.flags = {
-  DEC_S: 8, // enables all decimals as strings
-  TIME_S: 32, // enables all timestamps as strings
-  TIMESTAMP: 32768, // timestamps in milliseconds
-  SEQ_ALL: 65536, // enable sequencing
-  CHECKSUM: 131072 // enable checksum per OB change, top 25 levels per-side
-}
-
-/**
- * Map of info event names and their respective codes for usage with the API
- *
- * @constant
- * @property {number} SERVER_RESTART - server restart event
- * @property {number} MAINTENANCE_START - maintenance start event
- * @property {number} MAINTENANCE_END - maintenance end event
- * @memberof! WSv2#
- */
-WSv2.info = {
-  SERVER_RESTART: 20051,
-  MAINTENANCE_START: 20060,
-  MAINTENANCE_END: 20061
-}
-
-/**
- * Default connection URL
- *
- * @constant
- * @type {string}
- * @memberof! WSv2#
- * @default
- */
-WSv2.url = 'wss://api.bitfinex.com/ws/2'
-
-module.exports = WSv2
-
-
-
- - - - - - -
- -
- -
- Documentation generated by JSDoc 3.6.3 on Tue Mar 10 2020 21:05:28 GMT+0700 (Indochina Time) using the docdash theme. -
- - - - - - - - - diff --git a/docs/util_precision.js.html b/docs/util_precision.js.html deleted file mode 100644 index 2c4cc4fa..00000000 --- a/docs/util_precision.js.html +++ /dev/null @@ -1,116 +0,0 @@ - - - - - - util/precision.js - Documentation - - - - - - - - - - - - - - - - - - - -
- -

util/precision.js

- - - - - - - -
-
-
const Big = require('bignumber.js')
-
-const DEFAULT_SIG_FIGS = 5
-const PRICE_SIG_FIGS = 5
-const AMOUNT_DECIMALS = 8
-
-/**
- * Smartly set the precision (decimal) on a value based off of the significant
- * digit maximum. For example, calling with 3.34 when the max sig figs allowed
- * is 5 would return '3.3400', the representation number of decimals IF they
- * weren't zeros.
- *
- * @param {number} number - number to manipulate
- * @param {number} [maxSigs] - default 5
- * @returns {string} str
- */
-const setSigFig = (number = 0, maxSigs = DEFAULT_SIG_FIGS) => {
-  const n = +(number)
-  if (!isFinite(n)) {
-    return number
-  }
-  const value = n.toPrecision(maxSigs)
-
-  return /e/.test(value)
-    ? new Big(value).toString()
-    : value
-}
-
-const setPrecision = (number = 0, decimals = 0) => {
-  const n = +(number)
-
-  return (isFinite(n))
-    ? n.toFixed(decimals)
-    : number
-}
-
-const prepareAmount = (amount = 0) => {
-  return setPrecision(amount, AMOUNT_DECIMALS)
-}
-
-const preparePrice = (price = 0) => {
-  return setSigFig(price, PRICE_SIG_FIGS)
-}
-
-module.exports = {
-  setSigFig, setPrecision, prepareAmount, preparePrice
-}
-
-
-
- - - - - - -
- -
- -
- Documentation generated by JSDoc 3.6.3 on Tue Mar 10 2020 21:05:28 GMT+0700 (Indochina Time) using the docdash theme. -
- - - - - - - - - diff --git a/docs/util_ws2.js.html b/docs/util_ws2.js.html deleted file mode 100644 index 4cb138ee..00000000 --- a/docs/util_ws2.js.html +++ /dev/null @@ -1,82 +0,0 @@ - - - - - - util/ws2.js - Documentation - - - - - - - - - - - - - - - - - - - -
- -

util/ws2.js

- - - - - - - -
-
-
'use strict'
-
-const _findLast = require('lodash/findLast')
-
-/**
- * Resolves the message payload; useful for getting around sequence numbers
- *
- * @param {Array} msg - message to parse
- * @returns {Array} payload - undefined if not found
- */
-module.exports = (msg = []) => {
-  return _findLast(msg, i => Array.isArray(i))
-}
-
-
-
- - - - - - -
- -
- -
- Documentation generated by JSDoc 3.6.3 on Tue Mar 10 2020 21:05:28 GMT+0700 (Indochina Time) using the docdash theme. -
- - - - - - - - - diff --git a/docs/ws2_manager.js.html b/docs/ws2_manager.js.html deleted file mode 100644 index bd680b80..00000000 --- a/docs/ws2_manager.js.html +++ /dev/null @@ -1,629 +0,0 @@ - - - - - - ws2_manager.js - Documentation - - - - - - - - - - - - - - - - - - - -
- -

ws2_manager.js

- - - - - - - -
-
-
'use strict'
-
-const { EventEmitter } = require('events')
-const debug = require('debug')('bfx:ws2:manager')
-const _isEqual = require('lodash/isEqual')
-const _isFinite = require('lodash/isFinite')
-const _includes = require('lodash/includes')
-const _pick = require('lodash/pick')
-const Promise = require('bluebird')
-const PromiseThrottle = require('promise-throttle')
-const WSv2 = require('./transports/ws2')
-
-const DATA_CHANNEL_LIMIT = 30
-const reconnectThrottler = new PromiseThrottle({
-  requestsPerSecond: 10 / 60.0,
-  promiseImplementation: Promise
-})
-
-/**
- * Provides a wrapper around the WSv2 class, opening new sockets when a
- * subscription would push a single socket over the data channel limit.
- *
- * For more complex operations, grab a socket reference with getSocket() or
- * getFreeDataSocket(), or create a new WSv2 instance manually
- *
- * @example
- * const rest = new RESTv2()
- * const details = await rest.symbolDetails()
- * const symbols = details.map(d => `t${d.pair.toUpperCase()}`)
- * const timeFrames = ['1m', '5m', '30m', '1h', '6h']
- * const keys = _flatten(symbols.map(s => {
- *   return timeFrames.map(tf => `trade:${tf}:${s}`)
- * }))
- *
- * const m = new Manager()
- *
- * m.on('error', (err) => {
- *   debug('error: %s', err)
- * })
- *
- * m.once('open', () => {
- *   debug('open')
- *
- *   keys.forEach(key => {
- *     m.subscribeCandles(key)
- *     m.onCandle({ key }, (candles) => {
- *       debug('recv %d candles on channel %s', candles.length, key)
- *     })
- *   })
- *
- *   symbols.forEach(symbol => {
- *     m.subscribeTrades(symbol)
- *     m.onTrades({ symbol }, (trades) => {
- *       debug('recv %d trades on channel %s', trades.length, symbol)
- *     })
- *   })
- *
- *   symbols.forEach(symbol => {
- *     m.subscribeTicker(symbol)
- *     m.onTicker({ symbol }, (ticker) => {
- *       debug('recv ticker on channel %s: %j', symbol, ticker)
- *     })
- *   })
- *
- *   symbols.forEach(symbol => {
- *     m.subscribeOrderBook(symbol)
- *     m.onOrderBook({ symbol }, (update) => {
- *       debug('recv book update on channel %s: %j', symbol, update)
- *     })
- *   })
- *
- *   setInterval(() => {
- *     debug('num keys: %d', keys.length)
- *     debug('num sockets: %d', m.getNumSockets())
- *     debug('socket info: %j', m.getSocketInfo())
- *   }, 5000)
- * })
- *
- * m.openSocket()
- */
-class WS2Manager extends EventEmitter {
-  /**
-   * @param {object} socketArgs - passed to WSv2 constructors
-   * @param {object} [authArgs] - cached for all internal socket auth() calls
-   * @param {object} [authArgs.calc] - default 0
-   * @param {object} [authArgs.dms] - default 0
-   */
-  constructor (socketArgs, authArgs = { calc: 0, dms: 0 }) {
-    super()
-
-    this.setMaxListeners(1000)
-
-    this._authArgs = authArgs
-    this._sockets = []
-    this._socketArgs = {
-      ...(socketArgs || {}),
-      reconnectThrottler
-    }
-  }
-
-  /**
-   * Update authentication arguments on all sockets
-   *
-   * @param {object} args - arguments
-   * @param {object} [args.calc] - calc value
-   * @param {object} [args.dms] - active 4
-   */
-  setAuthArgs (args = {}) {
-    this._authArgs = {
-      ...this._authArgs,
-      ...args
-    }
-
-    this._sockets.forEach(socket => socket.ws.updateAuthArgs(this._authArgs))
-  }
-
-  /**
-   * Retrieve internal authentication arguments
-   *
-   * @returns {object} args
-   */
-  getAuthArgs () {
-    return this._authArgs
-  }
-
-  /**
-   * Reconnects all open sockets
-   *
-   * @returns {Promise} p
-   */
-  async reconnect () {
-    return Promise.all(this._sockets.map(socket => socket.ws.reconnect()))
-  }
-
-  /**
-   * Closes all open sockets
-   *
-   * @returns {Promise} p
-   */
-  async close () {
-    return Promise.all(this._sockets.map(socket => socket.ws.close()))
-  }
-
-  /**
-   * @param {object} s - socket state
-   * @returns {number} count - # of subscribed/pending data channels
-   */
-  static getDataChannelCount (s) {
-    let count = s.ws.getDataChannelCount()
-
-    count += s.pendingSubscriptions.length
-    count -= s.pendingUnsubscriptions.length
-
-    return count
-  }
-
-  /**
-   * @returns {number} n
-   */
-  getNumSockets () {
-    return this._sockets.length
-  }
-
-  /**
-   * @param {number} i - index into pool
-   * @returns {object} state
-   */
-  getSocket (i) {
-    return this._sockets[i]
-  }
-
-  /**
-   * Returns an object which can be logged to inspect the socket pool
-   *
-   * @returns {object[]} socketInfo
-   */
-  getSocketInfo () {
-    return this._sockets.map(s => ({
-      nChannels: WS2Manager.getDataChannelCount(s)
-    }))
-  }
-
-  /**
-   * Authenticates all existing & future sockets with the provided credentials.
-   * Does nothing if an apiKey/apiSecret pair are already known.
-   *
-   * @param {object} args - arguments
-   * @param {object} args.apiKey - saved if not already provided
-   * @param {object} args.apiSecret - saved if not already provided
-   * @param {object} [args.calc] - default 0
-   * @param {object} [args.dms] - dead man switch, active 4
-   */
-  auth ({ apiKey, apiSecret, calc, dms } = {}) {
-    if (this._socketArgs.apiKey || this._socketArgs.apiSecret) {
-      debug('error: auth credentials already provided! refusing auth')
-      return
-    }
-
-    this._socketArgs.apiKey = apiKey
-    this._socketArgs.apiSecret = apiSecret
-
-    if (_isFinite(calc)) this._authArgs.calc = calc
-    if (_isFinite(dms)) this._authArgs.dms = dms
-
-    this._sockets.forEach(s => {
-      if (!s.ws.isAuthenticated()) {
-        s.ws.setAPICredentials(apiKey, apiSecret)
-        s.ws.updateAuthArgs(this._authArgs)
-        s.ws.auth()
-      }
-    })
-  }
-
-  /**
-   * Creates a new socket/state instance and adds it to the internal pool. Binds
-   * event listeners to forward via our own event emitter, and to manage pending
-   * subs/unsubs.
-   *
-   * @returns {object} state
-   */
-  openSocket () {
-    const { apiKey, apiSecret } = this._socketArgs
-    const ws = new WSv2(this._socketArgs)
-    const wsState = {
-      pendingSubscriptions: [],
-      pendingUnsubscriptions: [],
-      ws
-    }
-
-    ws.updateAuthArgs(this._authArgs)
-    ws.on('open', () => this.emit('open', ws))
-    ws.on('message', (msg = {}) => this.emit('message', msg, ws))
-    ws.on('error', (error) => this.emit('error', error, ws))
-    ws.on('auth', () => this.emit('auth', ws))
-    ws.on('close', () => this.emit('close', ws))
-    ws.on('subscribed', (msg = {}) => {
-      this.emit('subscribed', msg)
-
-      const i = wsState.pendingSubscriptions.find(sub => {
-        const fv = _pick(msg, Object.keys(sub[1]))
-
-        return (
-          (sub[0] === msg.channel) &&
-          _isEqual(fv, sub[1])
-        )
-      })
-
-      if (i === -1) {
-        debug('error removing pending sub: %j', msg)
-        return
-      }
-
-      wsState.pendingSubscriptions.splice(i, 1)
-    })
-
-    ws.on('unsubscribed', (msg = {}) => {
-      this.emit('unsubscribed', msg)
-
-      const { chanId } = msg
-      const i = wsState.pendingUnsubscriptions.findIndex(cid => (
-        cid === `${chanId}`
-      ))
-
-      if (i === -1) {
-        debug('error removing pending unsub: %j', msg)
-        return
-      }
-
-      wsState.pendingUnsubscriptions.splice(i, 1)
-    })
-
-    if (apiKey && apiSecret) { // auto-auth
-      ws.once('open', () => {
-        debug('authenticating socket...')
-
-        ws.auth().then(() => {
-          return debug('socket authenticated')
-        }).catch((err) => {
-          debug('error authenticating socket: %s', err.message)
-        })
-      })
-    }
-
-    ws.open().then(() => {
-      return debug('socket connection opened')
-    }).catch((err) => {
-      debug('error opening socket: %s', err.stack)
-    })
-
-    this._sockets.push(wsState)
-    return wsState
-  }
-
-  /**
-   * @returns {object} state
-   */
-  getAuthenticatedSocket () {
-    return this._sockets.find(s => s.ws.isAuthenticated())
-  }
-
-  /**
-   * Returns the first socket that has less active/pending channels than the
-   * DATA_CHANNEL_LIMIT
-   *
-   * @returns {object} state - undefined if none found
-   */
-  getFreeDataSocket () {
-    return this._sockets.find(s => (
-      WS2Manager.getDataChannelCount(s) < DATA_CHANNEL_LIMIT
-    ))
-  }
-
-  /**
-   * Returns the first socket that is subscribed/pending sub to the specified
-   * channel.
-   *
-   * @param {string} type - i.e. 'book'
-   * @param {object} filter - i.e. { symbol: 'tBTCUSD', prec: 'R0' }
-   * @returns {object} wsState - undefined if not found
-   */
-  getSocketWithDataChannel (type, filter) {
-    return this._sockets.find(s => {
-      const subI = s.pendingSubscriptions.findIndex(s => (
-        s[0] === type && _isEqual(s[1], filter)
-      ))
-
-      if (subI !== -1) {
-        return true
-      }
-
-      // Confirm unsub is not pending
-      const cid = s.ws.getDataChannelId(type, filter)
-
-      if (!cid) {
-        return false
-      }
-
-      return cid && !_includes(s.pendingUnsubscriptions, cid)
-    })
-  }
-
-  /**
-   * NOTE: Cannot filter against pending subscriptions, due to unknown chanId
-   *
-   * @param {number} chanId - channel ID
-   * @returns {object} wsState - undefined if not found
-   */
-  getSocketWithChannel (chanId) {
-    return this._sockets.find(s => {
-      return (
-        s.ws.hasChannel(chanId) &&
-        !_includes(s.pendingUnsubscriptions, chanId)
-      )
-    })
-  }
-
-  /**
-   * @param {string} channel - channel type
-   * @param {string} identifier - unique channel identifier
-   * @returns {object} wsState - undefined if not found
-   */
-  getSocketWithSubRef (channel, identifier) {
-    return this._sockets.find(s => s.ws.hasSubscriptionRef(channel, identifier))
-  }
-
-  /**
-   * Calls the provided cb with all internal socket instances
-   *
-   * @param {Function} cb - callback
-   */
-  withAllSockets (cb) {
-    this._sockets.forEach((ws2) => {
-      cb(ws2)
-    })
-  }
-
-  /**
-   * Subscribes a free data socket if available to the specified channel, or
-   * opens a new socket & subs if needed.
-   *
-   * @param {string} type - i.e. 'book'
-   * @param {string} ident - i.e. 'tBTCUSD'
-   * @param {object} filter - i.e. { symbol: 'tBTCUSD', prec: 'R0' }
-   */
-  subscribe (type, ident, filter) {
-    let s = this.getFreeDataSocket()
-    if (!s) {
-      s = this.openSocket()
-    }
-
-    const doSub = () => {
-      s.ws.managedSubscribe(type, ident, filter)
-    }
-
-    if (!s.ws.isOpen()) {
-      s.ws.once('open', doSub)
-    } else {
-      doSub()
-    }
-
-    s.pendingSubscriptions.push([type, filter])
-  }
-
-  /**
-   * @param {string} channel - channel type
-   * @param {string} identifier - unique channel identifier
-   */
-  managedUnsubscribe (channel, identifier) {
-    const s = this.getSocketWithSubRef(channel, identifier)
-
-    if (!s) {
-      debug('cannot unsub from unknown channel %s: %s', channel, identifier)
-      return
-    }
-
-    const chanId = s.ws._chanIdByIdentifier(channel, identifier)
-    s.ws.managedUnsubscribe(channel, identifier)
-    s.pendingUnsubscriptions.push(chanId)
-  }
-
-  /**
-   * Unsubscribes the first socket w/ the specified channel. Does nothing if no
-   * such socket is found.
-   *
-   * @param {number} chanId - channel ID
-   */
-  unsubscribe (chanId) {
-    const s = this.getSocketWithChannel(chanId)
-
-    if (!s) {
-      debug('cannot unsub from unknown channel: %d', chanId)
-      return
-    }
-
-    s.ws.unsubscribe(chanId)
-    s.pendingUnsubscriptions.push(chanId)
-  }
-
-  /**
-   * @param {string} symbol - symbol for ticker
-   */
-  subscribeTicker (symbol) {
-    this.subscribe('ticker', symbol, { symbol })
-  }
-
-  /**
-   * @param {string} symbol - symbol for trades
-   */
-  subscribeTrades (symbol) {
-    this.subscribe('trades', symbol, { symbol })
-  }
-
-  /**
-   * @param {string} symbol - symbol for order book
-   * @param {string} [prec] - precision, i.e. 'R0', default 'P0'
-   * @param {string} [len] - length, default '25'
-   * @param {string} [freq] - default 'F0'
-   */
-  subscribeOrderBook (symbol, prec = 'P0', len = '25', freq = 'F0') {
-    const filter = {}
-
-    if (symbol) filter.symbol = symbol
-    if (prec) filter.prec = prec
-    if (len) filter.len = len
-    if (freq) filter.freq = freq
-
-    this.subscribe('book', symbol, filter)
-  }
-
-  /**
-   * @param {string} key - candle channel key
-   */
-  subscribeCandles (key) {
-    this.subscribe('candles', key, { key })
-  }
-
-  /**
-   * @param {object} opts - options
-   * @param {string} opts.key - candle set key, i.e. trade:30m:tBTCUSD
-   * @param {string} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @throws an error if no data socket is available
-   * @see https://docs.bitfinex.com/v2/reference#ws-public-candle
-   */
-  onCandle ({ key, cbGID }, cb) {
-    const s = this.getSocketWithDataChannel('candles', { key })
-
-    if (!s) {
-      throw new Error('no data socket available; did you provide a key?')
-    }
-
-    s.ws.onCandle({ key, cbGID }, cb)
-  }
-
-  /**
-   * @param {object} opts - options
-   * @param {string} opts.symbol - order book symbol
-   * @param {string} [opts.prec] - precision, i.e. 'R0', default 'P0'
-   * @param {string} [opts.len] - length, default '25'
-   * @param {string} [opts.freq] - default 'F0'
-   * @param {string} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @throws an error if no data socket is available
-   * @see https://docs.bitfinex.com/v2/reference#ws-public-order-books
-   */
-  onOrderBook ({ symbol, prec = 'P0', len = '25', freq = 'F0', cbGID }, cb) {
-    const filter = {}
-
-    if (symbol) filter.symbol = symbol
-    if (prec) filter.prec = prec
-    if (len) filter.len = len
-    if (freq) filter.freq = freq
-
-    const s = this.getSocketWithDataChannel('book', filter)
-
-    if (!s) {
-      throw new Error('no data socket available; did you provide a symbol?')
-    }
-
-    s.ws.onOrderBook({ cbGID, ...filter }, cb)
-  }
-
-  /**
-   * @param {object} opts - options
-   * @param {string} [opts.symbol] - symbol for trades
-   * @param {string} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @throws an error if no data socket is available
-   * @see https://docs.bitfinex.com/v2/reference#ws-public-trades
-   */
-  onTrades ({ symbol, cbGID }, cb) {
-    const s = this.getSocketWithDataChannel('trades', { symbol })
-
-    if (!s) {
-      throw new Error('no data socket available; did you provide a symbol?')
-    }
-
-    s.ws.onTrades({ symbol, cbGID }, cb)
-  }
-
-  /**
-   * @param {object} opts - options
-   * @param {string} [opts.symbol] - symbol for ticker
-   * @param {string} [opts.cbGID] - callback group id
-   * @param {Function} cb - callback
-   * @throws an error if no data socket is available
-   * @see https://docs.bitfinex.com/v2/reference#ws-public-ticker
-   */
-  onTicker ({ symbol = '', cbGID } = {}, cb) {
-    const s = this.getSocketWithDataChannel('ticker', { symbol })
-
-    if (!s) {
-      throw new Error('no data socket available; did you provide a symbol?')
-    }
-
-    s.ws.onTicker({ symbol, cbGID }, cb)
-  }
-}
-
-module.exports = WS2Manager
-
-
-
- - - - - - -
- -
- -
- Documentation generated by JSDoc 3.6.3 on Tue Mar 10 2020 21:05:28 GMT+0700 (Indochina Time) using the docdash theme. -
- - - - - - - - - diff --git a/examples/util/run_example.js b/examples/util/run_example.js index a9c31fdf..e455e744 100644 --- a/examples/util/run_example.js +++ b/examples/util/run_example.js @@ -5,7 +5,7 @@ const _isobject = require('lodash/isObject') const { RESTv2 } = require('bfx-api-node-rest') const Readline = require('readline-promise').default -const WSv2 = require('../../lib/transports/ws2') +const WSv2 = require('../../lib/ws2') const argsFromEnv = require('./args_from_env') const debugTableUtil = require('./debug_table') const D = require('./debug').get() diff --git a/examples/ws2/ob_checksum.js b/examples/ws2/ob_checksum.js index a0ac5311..cfb07f86 100644 --- a/examples/ws2/ob_checksum.js +++ b/examples/ws2/ob_checksum.js @@ -1,6 +1,6 @@ 'use strict' -const WSv2 = require('../../lib/transports/ws2') +const WSv2 = require('../../lib/ws2') const runExample = require('../util/run_example') const SYMBOL = 'tXRPBTC' diff --git a/index.js b/index.js index a74268c1..676f0f82 100644 --- a/index.js +++ b/index.js @@ -1,124 +1,92 @@ 'use strict' -const { RESTv1, RESTv2 } = require('bfx-api-node-rest') -const WSv1 = require('bfx-api-node-ws1') -const WSv2 = require('./lib/transports/ws2') -const WS2Manager = require('./lib/ws2_manager') - /** - * Provides access to versions 1 & 2 of the HTTP & WebSocket Bitfinex APIs + * A Node.JS reference implementation of the Bitfinex API + * + * @module bitfinex-api-node + * @license MIT + * @example sending an order & tracking status + * const ws = bfx.ws() + * + * ws.on('error', (err) => console.log(err)) + * ws.on('open', ws.auth.bind(ws)) + * + * ws.once('auth', () => { + * const o = new Order({ + * cid: Date.now(), + * symbol: 'tETHUSD', + * amount: 0.1, + * type: Order.type.MARKET + * }, ws) + * + * // Enable automatic updates + * o.registerListeners() + * + * o.on('update', () => { + * console.log(`order updated: ${o.serialize()}`) + * }) + * + * o.on('close', () => { + * console.log(`order closed: ${o.status}`) + * ws.close() + * }) + * + * o.submit().then(() => { + * console.log(`submitted order ${o.id}`) + * }).catch((err) => { + * console.error(err) + * ws.close() + * }) + * }) + * + * ws.open() + * + * @example cancel all open orders + * const ws = bfx.ws(2) + * + * ws.on('error', (err) => console.log(err)) + * ws.on('open', ws.auth.bind(ws)) + * + * ws.onOrderSnapshot({}, (orders) => { + * if (orders.length === 0) { + * console.log('no open orders') + * return + * } + * + * console.log(`recv ${orders.length} open orders`) + * + * ws.cancelOrders(orders).then(() => { + * console.log('cancelled orders') + * }) + * }) + * + * ws.open() + * + * @example subscribe to trades by pair + * const ws = bfx.ws(2) + * + * ws.on('error', (err) => console.log(err)) + * ws.on('open', () => { + * ws.subscribeTrades('BTCUSD') + * }) + * + * ws.onTrades({ symbol: 'tBTCUSD' }, (trades) => { + * console.log(`trades: ${JSON.stringify(trades)}`) + * }) + * ws.onTradeEntry({ symbol: 'tBTCUSD' }, (trades) => { + * console.log(`te: ${JSON.stringify(trades)}`) + * }) + * + * ws.open() */ -class BFX { - /** - * @param {object} opts - options - * @param {string} opts.apiKey - API key - * @param {string} opts.apiSecret - API secret - * @param {string} opts.authToken - optional auth option - * @param {string} opts.transform - if true, packets are converted to models - * @param {string} opts.nonceGenerator - optional - * @param {string} opts.ws - ws transport options - * @param {string} opts.rest - rest transport options - */ - constructor (opts = { - apiKey: '', - apiSecret: '', - authToken: '', - company: '', - transform: false, - ws: {}, - rest: {} - }) { - if (opts.constructor.name !== 'Object') { - throw new Error([ - 'constructor takes an object since version 2.0.0, see:', - 'https://github.com/bitfinexcom/bitfinex-api-node#version-200-breaking-changes\n' - ].join('\n')) - } - - this._apiKey = opts.apiKey || '' - this._apiSecret = opts.apiSecret || '' - this._authToken = opts.authToken || '' - this._company = opts.company || '' - this._transform = opts.transform === true - this._wsArgs = opts.ws || {} - this._restArgs = opts.rest || {} - this._transportCache = { - rest: {}, - ws: {} - } - } - - /** - * Returns an arguments map ready to pass to a transport constructor - * - * @param {object} extraOpts - options to pass to transport - * @returns {object} payload - */ - _getTransportPayload (extraOpts) { - return { - apiKey: this._apiKey, - apiSecret: this._apiSecret, - authToken: this._authToken, - company: this._company, - transform: this._transform, - ...extraOpts - } - } - - /** - * Returns a new REST API class instance (cached by version) - * - * @param {number} version - 1 or 2 (default) - * @param {object} extraOpts - passed to transport constructor - * @returns {RESTv1|RESTv2} transport - */ - rest (version = 2, extraOpts = {}) { - if (version !== 1 && version !== 2) { - throw new Error(`invalid http API version: ${version}`) - } - - const key = `${version}|${JSON.stringify(extraOpts)}` - - if (!this._transportCache.rest[key]) { - Object.assign(extraOpts, this._restArgs) - const payload = this._getTransportPayload(extraOpts) - this._transportCache.rest[key] = version === 2 - ? new RESTv2(payload) - : new RESTv1(payload) - } - - return this._transportCache.rest[key] - } - - /** - * Returns a new WebSocket API class instance (cached by version) - * - * @param {number} version - 1 or 2 (default) - * @param {object} extraOpts - passed to transport constructor - * @returns {WSv1|WSv2} transport - */ - ws (version = 2, extraOpts = {}) { - if (version !== 1 && version !== 2) { - throw new Error(`invalid websocket API version: ${version}`) - } - - const key = `${version}|${JSON.stringify(extraOpts)}` - - if (!this._transportCache.ws[key]) { - Object.assign(extraOpts, this._wsArgs) - const payload = this._getTransportPayload(extraOpts) - - this._transportCache.ws[key] = version === 2 - ? new WSv2(payload) - : new WSv1(payload) - } - - return this._transportCache.ws[key] - } -} +const { RESTv1, RESTv2 } = require('bfx-api-node-rest') +const WSv1 = require('bfx-api-node-ws1') +const WSv2 = require('./lib/ws2') +const WS2Manager = require('./lib/ws2_manager') +const ClientManager = require('./lib/client_manager') -module.exports = BFX +module.exports = ClientManager module.exports.RESTv1 = RESTv1 module.exports.RESTv2 = RESTv2 module.exports.WSv1 = WSv1 diff --git a/lib/client_manager.js b/lib/client_manager.js new file mode 100644 index 00000000..ea9e58dc --- /dev/null +++ b/lib/client_manager.js @@ -0,0 +1,128 @@ +'use strict' + +const { RESTv1, RESTv2 } = require('bfx-api-node-rest') +const WSv1 = require('bfx-api-node-ws1') +const WSv2 = require('./ws2') + +/** + * Provides access to versions 1 & 2 of the HTTP & WebSocket Bitfinex APIs. + * + * @see {@link WSv2} + * @class + */ +class ClientManager { + /** + * @param {object} opts - options + * @param {string} opts.apiKey - API key + * @param {string} opts.apiSecret - API secret + * @param {string} opts.authToken - optional auth option + * @param {string} opts.transform - if true, packets are converted to models + * @param {string} opts.nonceGenerator - optional + * @param {WSv2~Configuration} opts.ws - ws transport options + * @param {string} opts.rest - rest transport options + */ + constructor (opts = { + apiKey: '', + apiSecret: '', + authToken: '', + company: '', + transform: false, + ws: {}, + rest: {} + }) { + if (opts.constructor.name !== 'Object') { + throw new Error([ + 'constructor takes an object since version 2.0.0, see:', + 'https://github.com/bitfinexcom/bitfinex-api-node#version-200-breaking-changes\n' + ].join('\n')) + } + + this._apiKey = opts.apiKey || '' + this._apiSecret = opts.apiSecret || '' + this._authToken = opts.authToken || '' + this._company = opts.company || '' + this._transform = opts.transform === true + this._wsArgs = opts.ws || {} + this._restArgs = opts.rest || {} + this._transportCache = { + rest: {}, + ws: {} + } + } + + /** + * Returns an arguments map ready to pass to a transport constructor + * + * @private + * @param {object} [extraOpts={}] - options to pass to transport + * @returns {object} payload + */ + _getTransportPayload (extraOpts = {}) { + return { + apiKey: this._apiKey, + apiSecret: this._apiSecret, + authToken: this._authToken, + company: this._company, + transform: this._transform, + ...extraOpts + } + } + + /** + * Returns a new REST API class instance (cached by version) + * + * @param {number} [version=2] - 1 or 2 + * @param {object} [extraOpts={}] - passed to transport constructor + * @returns {( + * bfx-api-node-rest.RESTv1| + * bfx-api-node-rest.RESTv2 + * )} transport + */ + rest (version = 2, extraOpts = {}) { + if (version !== 1 && version !== 2) { + throw new Error(`invalid http API version: ${version}`) + } + + const key = `${version}|${JSON.stringify(extraOpts)}` + + if (!this._transportCache.rest[key]) { + Object.assign(extraOpts, this._restArgs) + const payload = this._getTransportPayload(extraOpts) + + this._transportCache.rest[key] = version === 2 + ? new RESTv2(payload) + : new RESTv1(payload) + } + + return this._transportCache.rest[key] + } + + /** + * Returns a new WebSocket API class instance (cached by version) + * + * @param {number} [version=2] - 1 or 2 + * @param {WSv2~Configuration} [extraOpts={}] - passed to transport + * constructor + * @returns {WSv2|bfx-api-node-ws1.WSv1} transport + */ + ws (version = 2, extraOpts = {}) { + if (version !== 1 && version !== 2) { + throw new Error(`invalid websocket API version: ${version}`) + } + + const key = `${version}|${JSON.stringify(extraOpts)}` + + if (!this._transportCache.ws[key]) { + Object.assign(extraOpts, this._wsArgs) + const payload = this._getTransportPayload(extraOpts) + + this._transportCache.ws[key] = version === 2 + ? new WSv2(payload) + : new WSv1(payload) + } + + return this._transportCache.ws[key] + } +} + +module.exports = ClientManager diff --git a/lib/types/candle_channel.js b/lib/types/candle_channel.js new file mode 100644 index 00000000..605d05b1 --- /dev/null +++ b/lib/types/candle_channel.js @@ -0,0 +1,10 @@ +'use strict' + +/** + * An object describing a trade data channel on a {@link WSv2} data stream. + * + * @typedef {object} CandleChannel + * @property {string} channel - 'candles' + * @property {number} chanId - channel ID + * @property {string} key - data key, 'trade:TF:SYMBOL' i.e. 'trade:1m:tBTCUSD' + */ diff --git a/lib/types/order_book_channel.js b/lib/types/order_book_channel.js new file mode 100644 index 00000000..575b3337 --- /dev/null +++ b/lib/types/order_book_channel.js @@ -0,0 +1,15 @@ +'use strict' + +/** + * An object describing an order book data channel on a WSv2 data stream. + * + * @typedef {object} OrderBookChannel + * @property {string} channel - 'book' + * @property {number} chanId - channel ID + * @property {string} symbol - symbol + * @property {string} freq - frequency of updates; 'F0' is realtime, 'F1' is + * once per 2 seconds + * @property {string} prec - precision, (aggregate 'P0', 'P1', 'P2', 'P3', + * 'P4', raw 'R0') + * @property {string} len - book depth, '25' (default) or '100' + */ diff --git a/lib/types/ticker_channel.js b/lib/types/ticker_channel.js new file mode 100644 index 00000000..216d25d2 --- /dev/null +++ b/lib/types/ticker_channel.js @@ -0,0 +1,10 @@ +'use strict' + +/** + * An object describing a ticker data channel on a WSv2 data stream. + * + * @typedef {object} TickerChannel + * @property {string} channel - 'ticker' + * @property {number} chanId - channel ID + * @property {string} symbol - symbol + */ diff --git a/lib/types/trade_channel.js b/lib/types/trade_channel.js new file mode 100644 index 00000000..434b6ca5 --- /dev/null +++ b/lib/types/trade_channel.js @@ -0,0 +1,10 @@ +'use strict' + +/** + * An object describing a trade data channel on a WSv2 data stream. + * + * @typedef {object} TradeChannel + * @property {string} channel - 'trades' + * @property {number} chanId - channel ID + * @property {string} symbol - symbol + */ diff --git a/lib/types/ws2_configuration.js b/lib/types/ws2_configuration.js new file mode 100644 index 00000000..388c22d5 --- /dev/null +++ b/lib/types/ws2_configuration.js @@ -0,0 +1,21 @@ +'use strict' + +/** + * Configuration options for a WSv2 client instance. + * + * @typedef {object} WSv2~Configuration + * @property {string} [affCode=''] - affiliate code to be applied to all orders + * @property {string} [apiKey=''] - API key + * @property {string} [apiSecret=''] - API secret + * @property {string} [url='wss://api.bitfinex.com/ws/2'] - ws connection url + * @property {number} [orderOpBufferDelay] - multi-order op batching timeout + * @property {boolean} [transform] - if true, packets are converted to models + * @property {object} [agent] - node agent for ws connection (proxy) + * @property {boolean} [manageOrderBooks] - enable local OB persistence + * @property {boolean} [manageCandles] - enable local candle persistence + * @property {boolean} [seqAudit] - enable sequence numbers & verification + * @property {boolean} [autoReconnect] - if true, we will reconnect on close + * @property {number} [reconnectDelay] - optional, defaults to 1000 (ms) + * @property {object} [reconnectThrottler] - pt to limit reconnect freq + * @property {number} [packetWDDelay] - watch-dog forced reconnection delay + */ diff --git a/lib/types/ws2_socket_state.js b/lib/types/ws2_socket_state.js new file mode 100644 index 00000000..e94f39ea --- /dev/null +++ b/lib/types/ws2_socket_state.js @@ -0,0 +1,12 @@ +'use strict' + +/** + * Object containing socket state for {@link WS2Manager}. + * + * @typedef {object} WS2Manager~SocketState + * @property {WSv2} ws - client instance + * @property {Array[]} pendingSubscriptions - array of sent but unconfirmed + * channel subscriptions + * @property {Array[]} pendingUnsubscriptions - array of sent but unconfirmed + * channel unsubscribe packets + */ diff --git a/lib/util/index.js b/lib/util/index.js deleted file mode 100644 index 439a1a37..00000000 --- a/lib/util/index.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict' - -const isClass = require('./is_class') -const isSnapshot = require('./is_snapshot') - -module.exports = { - isClass, - isSnapshot -} diff --git a/lib/util/is_class.js b/lib/util/is_class.js deleted file mode 100644 index 36156e49..00000000 --- a/lib/util/is_class.js +++ /dev/null @@ -1,12 +0,0 @@ -'use strict' - -const _isFunction = require('lodash/isFunction') - -const isClass = (f) => { - return ( - (_isFunction(f)) && - (/^class\s/.test(Function.prototype.toString.call(f))) - ) -} - -module.exports = isClass diff --git a/lib/util/is_snapshot.js b/lib/util/is_snapshot.js deleted file mode 100644 index 3ef52cab..00000000 --- a/lib/util/is_snapshot.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict' - -const isSnapshot = msg => msg[0] && Array.isArray(msg[0]) - -module.exports = isSnapshot diff --git a/lib/util/precision.js b/lib/util/precision.js deleted file mode 100644 index 29352d03..00000000 --- a/lib/util/precision.js +++ /dev/null @@ -1,47 +0,0 @@ -const Big = require('bignumber.js') - -const DEFAULT_SIG_FIGS = 5 -const PRICE_SIG_FIGS = 5 -const AMOUNT_DECIMALS = 8 - -/** - * Smartly set the precision (decimal) on a value based off of the significant - * digit maximum. For example, calling with 3.34 when the max sig figs allowed - * is 5 would return '3.3400', the representation number of decimals IF they - * weren't zeros. - * - * @param {number} number - number to manipulate - * @param {number} [maxSigs] - default 5 - * @returns {string} str - */ -const setSigFig = (number = 0, maxSigs = DEFAULT_SIG_FIGS) => { - const n = +(number) - if (!isFinite(n)) { - return number - } - const value = n.toPrecision(maxSigs) - - return /e/.test(value) - ? new Big(value).toString() - : value -} - -const setPrecision = (number = 0, decimals = 0) => { - const n = +(number) - - return (isFinite(n)) - ? n.toFixed(decimals) - : number -} - -const prepareAmount = (amount = 0) => { - return setPrecision(amount, AMOUNT_DECIMALS) -} - -const preparePrice = (price = 0) => { - return setSigFig(price, PRICE_SIG_FIGS) -} - -module.exports = { - setSigFig, setPrecision, prepareAmount, preparePrice -} diff --git a/lib/util/ws2.js b/lib/util/ws2.js deleted file mode 100644 index d4576c8c..00000000 --- a/lib/util/ws2.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict' - -const _findLast = require('lodash/findLast') - -/** - * Resolves the message payload; useful for getting around sequence numbers - * - * @param {Array} msg - message to parse - * @returns {Array} payload - undefined if not found - */ -module.exports = (msg = []) => { - return _findLast(msg, i => Array.isArray(i)) -} diff --git a/lib/transports/ws2.js b/lib/ws2.js similarity index 92% rename from lib/transports/ws2.js rename to lib/ws2.js index facba4d0..715345b1 100644 --- a/lib/transports/ws2.js +++ b/lib/ws2.js @@ -5,18 +5,18 @@ const debug = require('debug')('bfx:ws2') const WebSocket = require('ws') const Promise = require('bluebird') const CbQ = require('cbq') -const _Throttle = require('lodash.throttle') // eslint-disable-line +const _pick = require('lodash/pick') +const _isEqual = require('lodash/isEqual') const _isArray = require('lodash/isArray') const _isEmpty = require('lodash/isEmpty') const _isString = require('lodash/isString') const _isNumber = require('lodash/isNumber') const _includes = require('lodash/includes') -const _pick = require('lodash/pick') -const _isEqual = require('lodash/isEqual') const _isFinite = require('lodash/isFinite') +const _findLast = require('lodash/findLast') +const _Throttle = require('lodash.throttle') // eslint-disable-line const { genAuthSig, nonce } = require('bfx-api-node-util') const LosslessJSON = require('lossless-json') -const getMessagePayload = require('../util/ws2') const { BalanceInfo, @@ -43,51 +43,44 @@ const UCM_NOTIFICATION_TYPE = 'ucm-notify-ui' const MAX_CALC_OPS = 8 /** - * A Promise Throttle instance + * Resolves the message payload; useful for getting around sequence numbers * - * @typedef {object} PromiseThrottle - * @property {Function} add - add a promise to be throttled + * @private + * + * @param {Array} msg - message to parse + * @returns {Array} payload - undefined if not found */ +const getMessagePayload = (msg = []) => { + return _findLast(msg, i => _isArray(i)) +} /** * Communicates with v2 of the Bitfinex WebSocket API * * @class + * @augments events.EventEmitter */ class WSv2 extends EventEmitter { /** * Instantiate a new ws2 transport. Does not auto-open * - * @class WSv2 - * @param {object} [opts] - instance options - * @param {string} [opts.affCode] - affiliate code to be applied to all orders - * @param {string} [opts.apiKey] - API key - * @param {string} [opts.apiSecret] - API secret - * @param {string} [opts.url] - ws connection url, defaults to {@link WSv2#url} - * @param {number} [opts.orderOpBufferDelay] - multi-order op batching timeout - * @param {boolean} [opts.transform] - if true, packets are converted to models - * @param {object} [opts.agent] - optional node agent for ws connection (proxy) - * @param {boolean} [opts.manageOrderBooks] - enable local OB persistence - * @param {boolean} [opts.manageCandles] - enable local candle persistence - * @param {boolean} [opts.seqAudit] - enable sequence numbers & verification - * @param {boolean} [opts.autoReconnect] - if true, we will reconnect on close - * @param {number} [opts.reconnectDelay] - optional, defaults to 1000 (ms) - * @param {PromiseThrottle} [opts.reconnectThrottler] - optional pt to limit reconnect freq - * @param {number} [opts.packetWDDelay] - watch-dog forced reconnection delay * @example - * const ws = new WSv2() - * - * ws.on('open', async () => { - * ws.onTrades({ symbol: 'tBTCUSD' }, (trades) => { - * console.log('recv trades: %j', trades) - * }) + * const ws = new WSv2() * - * await ws.subscribeTrades('tBTCUSD') + * ws.on('open', async () => { + * ws.onTrades({ symbol: 'tBTCUSD' }, (trades) => { + * console.log('recv trades: %j', trades) * }) * - * await ws.open() + * await ws.subscribeTrades('tBTCUSD') + * }) + * + * await ws.open() + * + * @param {WSv2~Configuration} [config] - client + * configuration */ - constructor (opts = { + constructor (config = { apiKey: '', apiSecret: '', url: WSv2.url, @@ -96,22 +89,22 @@ class WSv2 extends EventEmitter { super() this.setMaxListeners(1000) - this._apiKey = opts.apiKey || '' - this._apiSecret = opts.apiSecret || '' - this._affCode = opts.affCode - this._agent = opts.agent - this._url = opts.url || WSv2.url - this._transform = opts.transform === true - this._orderOpBufferDelay = opts.orderOpBufferDelay || -1 + this._apiKey = config.apiKey || '' + this._apiSecret = config.apiSecret || '' + this._affCode = config.affCode + this._agent = config.agent + this._url = config.url || WSv2.url + this._transform = config.transform === true + this._orderOpBufferDelay = config.orderOpBufferDelay || -1 this._orderOpBuffer = [] this._orderOpTimeout = null - this._seqAudit = opts.seqAudit === true - this._autoReconnect = opts.autoReconnect === true - this._reconnectDelay = opts.reconnectDelay || 1000 - this._reconnectThrottler = opts.reconnectThrottler - this._manageOrderBooks = opts.manageOrderBooks === true - this._manageCandles = opts.manageCandles === true - this._packetWDDelay = opts.packetWDDelay + this._seqAudit = config.seqAudit === true + this._autoReconnect = config.autoReconnect === true + this._reconnectDelay = config.reconnectDelay || 1000 + this._reconnectThrottler = config.reconnectThrottler + this._manageOrderBooks = config.manageOrderBooks === true + this._manageCandles = config.manageCandles === true + this._packetWDDelay = config.packetWDDelay this._packetWDTimeout = null this._packetWDLastTS = 0 this._orderBooks = {} @@ -171,12 +164,13 @@ class WSv2 extends EventEmitter { } /** - * Set `calc` and `dms` values to be used on the next {@link WSv2#auth} call + * Set `calc` and `dms` values to be used on the next + * {@link WSv2#auth} call * * @param {object} args - arguments * @param {number} [args.calc] - calc value * @param {number} [args.dms] - dms value, active 4 - * @see WSv2#auth + * @see {@link WSv2#auth} */ updateAuthArgs (args = {}) { this._authArgs = { @@ -189,20 +183,20 @@ class WSv2 extends EventEmitter { * Fetch the current default auth parameters * * @returns {object} authArgs - * @see WSv2#updateAuthArgs - * @see WSv2#auth + * @see {@link WSv2#updateAuthArgs} + * @see {@link WSv2#auth} */ getAuthArgs () { return this._authArgs } /** - * Update the internal API credentials, used on subsequent {@link WSv2#auth} - * calls + * Update the internal API credentials, used on subsequent + * {@link WSv2#auth} calls * * @param {string} apiKey - API key * @param {string} apiSecret - API secret - * @see WSv2#auth + * @see {@link WSv2#auth} */ setAPICredentials (apiKey, apiSecret) { this._apiKey = apiKey @@ -214,10 +208,10 @@ class WSv2 extends EventEmitter { * subscribed too. * * @returns {number} count - * @see WSv2#subscribeTrades - * @see WSv2#subscribeTicker - * @see WSv2#subscribeCandles - * @see WSv2#subscribeOrderBook + * @see {@link WSv2#subscribeTrades} + * @see {@link WSv2#subscribeTicker} + * @see {@link WSv2#subscribeCandles} + * @see {@link WSv2#subscribeOrderBook} */ getDataChannelCount () { return Object @@ -242,7 +236,7 @@ class WSv2 extends EventEmitter { * @param {string} channel - channel type * @param {string} identifier - unique identifier for the reference * @returns {boolean} hasRef - * @see WSv2#managedSubscribe + * @see {@link WSv2#managedSubscribe} */ hasSubscriptionRef (channel, identifier) { const key = `${channel}:${identifier}` @@ -357,8 +351,8 @@ class WSv2 extends EventEmitter { * If a DMS flag of 4 is provided, all open orders are cancelled when the * connection terminates. * - * @param {number?} calc - optional, default is 0 - * @param {number?} dms - optional dead man switch flag, active 4 + * @param {number} [calc] - default is 0 + * @param {number} [dms] - dead man switch flag, active 4 * @returns {Promise} p */ async auth (calc, dms) { @@ -417,10 +411,13 @@ class WSv2 extends EventEmitter { /** * @private + * + * @returns {Promise} p */ async reconnectAfterClose () { if (!this._isReconnecting || this._ws !== null || this._isOpen) { - return this.reconnect() + this.reconnect() + return } await this.open() @@ -916,25 +913,26 @@ class WSv2 extends EventEmitter { * * Set `managedOrderBooks: true` in the constructor to use. * - * @param {string} symbol - symbol for order book - * @returns {OrderBook} ob - null if not found * @example - * const ws = new WSv2({ managedOrderBooks: true }) + * const ws = new WSv2({ managedOrderBooks: true }) * - * ws.on('open', async () => { - * ws.onOrderBook({ symbol: 'tBTCUSD' }, () => { - * const book = ws.getOB('tBTCUSD') - * - * if (!book) return + * ws.on('open', async () => { + * ws.onOrderBook({ symbol: 'tBTCUSD' }, () => { + * const book = ws.getOB('tBTCUSD') * - * const spread = book.midPrice() - * console.log('spread for tBTCUSD: %f', spread) - * }) + * if (!book) return * - * ws.subscribeOrderBook({ symbol: 'tBTCUSD' }) + * const spread = book.midPrice() + * console.log('spread for tBTCUSD: %f', spread) * }) * - * await ws.open() + * ws.subscribeOrderBook({ symbol: 'tBTCUSD' }) + * }) + * + * await ws.open() + * + * @param {string} symbol - symbol for order book + * @returns {bfx-api-node-models.OrderBook} ob - null if not found */ getOB (symbol) { if (!this._orderBooks[symbol]) return null @@ -950,7 +948,7 @@ class WSv2 extends EventEmitter { * Set `manageOrderBooks: true` in the constructor to use. * * @param {string} symbol - symbol for order book - * @returns {OrderBook} ob - null if not found + * @returns {bfx-api-node-models.OrderBook} ob - null if not found */ getLosslessOB (symbol) { if (!this._losslessOrderBooks[symbol]) return null @@ -1114,24 +1112,28 @@ class WSv2 extends EventEmitter { * Fetch a reference to the full set of synced candles for the specified key. * Set `managedCandles: true` in the constructor to use. * - * @param {string} key - key for candle set - * @returns {Array} candles - empty array if none exist * @example - * const ws = new WSv2({ managedCandles: true }) - * - * ws.on('open', async () => { - * ws.onCandles({ key: 'trade:1m:tBTCUSD' }, () => { - * const candles = ws.getCandles('trade:1m:tBTCUSD') + * const ws = new WSv2({ managedCandles: true }) * - * if (!candles) return + * ws.on('open', async () => { + * ws.onCandles({ key: 'trade:1m:tBTCUSD' }, () => { + * const candles = ws.getCandles('trade:1m:tBTCUSD') * - * console.log('%d candles in dataset', candles.length) - * }) + * if (!candles) return * - * ws.subscribeCandles({ key: 'trade:1m:tBTCUSD' }) + * console.log('%d candles in dataset', candles.length) * }) * - * await ws.open() + * ws.subscribeCandles({ key: 'trade:1m:tBTCUSD' }) + * }) + * + * await ws.open() + * + * @param {string} key - key for candle set + * @returns {( + * bfx-api-node-models.Candle| + * bfx-api-node-models.Candle~ArrayData[] + * )} candles - empty array if none exist */ getCandles (key) { return this._candles[key] || [] @@ -1430,16 +1432,13 @@ class WSv2 extends EventEmitter { * Subscribes and tracks subscriptions per channel/identifier pair. If * already subscribed to the specified pair, nothing happens. * - * @param {string} channel - channel name - * @param {string} identifier - for uniquely identifying the ref count - * @param {object} payload - merged with sub packet - * @returns {boolean} subSent * @todo will be refactored to return promise from subscribe() call instead * of sub action taken flag - * @see WSv2#subscribeTrades - * @see WSv2#subscribeTicker - * @see WSv2#subscribeCandles - * @see WSv2#subscribeOrderBook + * + * @see {@link WSv2#subscribeTrades} + * @see {@link WSv2#subscribeTicker} + * @see {@link WSv2#subscribeCandles} + * @see {@link WSv2#subscribeOrderBook} * @example * const ws = new WSv2() * @@ -1452,6 +1451,11 @@ class WSv2 extends EventEmitter { * }) * * await ws.open() + * + * @param {string} channel - channel name + * @param {string} identifier - for uniquely identifying the ref count + * @param {object} payload - merged with sub packet + * @returns {boolean} subSent */ managedSubscribe (channel = '', identifier = '', payload = {}) { const key = `${channel}:${identifier}` @@ -1550,7 +1554,7 @@ class WSv2 extends EventEmitter { /** * Send a packet to the WS server * - * @param {*} msg - packet, gets stringified + * @param {Array|object} msg - packet, gets stringified */ send (msg) { if (!this._ws || !this._isOpen) { @@ -1575,10 +1579,11 @@ class WSv2 extends EventEmitter { * connection. When enabled, the seq number will be the last value of * channel packet arrays. * + * @see {@link WSv2#flags} + * * @param {object} args - params * @param {boolean} [args.audit] - if true, an error is emitted on invalid seq * @returns {Promise} p - * @see WSv2#flags */ async enableSequencing (args = { audit: true }) { this._seqAudit = args.audit === true @@ -1589,9 +1594,7 @@ class WSv2 extends EventEmitter { /** * Enables a configuration flag. * - * @param {number} flag - flag to update, as numeric value - * @returns {Promise} p - * @see WSv2#flags + * @see {@link WSv2#flags} * @example * const ws = new WSv2() * @@ -1601,6 +1604,9 @@ class WSv2 extends EventEmitter { * }) * * await ws.open() + * + * @param {number} flag - flag to update, as numeric value + * @returns {Promise} p */ async enableFlag (flag) { this._enabledFlags = this._enabledFlags | flag @@ -1628,7 +1634,7 @@ class WSv2 extends EventEmitter { /** * Checks local state, relies on successful server config responses * - * @see enableFlag + * @see {@link WSv2#enableFlag} * * @param {number} flag - flag to check for * @returns {boolean} enabled @@ -1678,8 +1684,6 @@ class WSv2 extends EventEmitter { /** * Subscribe to a channel with the given filter payload * - * @param {string} channel - channel payload/data - * @param {object} payload - optional extra packet data * @example * const ws = new WSv2() * @@ -1692,6 +1696,9 @@ class WSv2 extends EventEmitter { * }) * * await ws.open() + * + * @param {string} channel - channel payload/data + * @param {object} payload - optional extra packet data */ subscribe (channel, payload) { this.send(Object.assign({ @@ -1703,11 +1710,12 @@ class WSv2 extends EventEmitter { /** * Subscribe to a ticker data channel * - * @param {string} symbol - symbol of ticker - * @returns {boolean} subscribed - * @see WSv2#managedSubscribe + * @see {@link WSv2#managedSubscribe} * @example * await ws.subscribeTicker('tBTCUSD') + * + * @param {string} symbol - symbol of ticker + * @returns {boolean} subscribed */ async subscribeTicker (symbol) { return this.managedSubscribe('ticker', symbol, { symbol }) @@ -1716,11 +1724,12 @@ class WSv2 extends EventEmitter { /** * Subscribe to a trades data channel * - * @param {string} symbol - symbol of market to monitor - * @returns {boolean} subscribed - * @see WSv2#managedSubscribe + * @see {@link WSv2#managedSubscribe} * @example * await ws.subscribeTrades('tBTCUSD') + * + * @param {string} symbol - symbol of market to monitor + * @returns {boolean} subscribed */ async subscribeTrades (symbol) { return this.managedSubscribe('trades', symbol, { symbol }) @@ -1729,13 +1738,14 @@ class WSv2 extends EventEmitter { /** * Subscribe to an order book data channel * + * @see {@link WSv2#managedSubscribe} + * @example + * await ws.subscribeOrderBook('tBTCUSD', 'R0', '25') + * * @param {string} symbol - symbol of order book * @param {string} prec - P0, P1, P2, or P3 (default P0) * @param {string} len - 25 or 100 (default 25) * @returns {boolean} subscribed - * @see WSv2#managedSubscribe - * @example - * await ws.subscribeOrderBook('tBTCUSD', 'R0', '25') */ async subscribeOrderBook (symbol, prec = 'P0', len = '25') { return this.managedSubscribe('book', symbol, { symbol, len, prec }) @@ -1744,11 +1754,12 @@ class WSv2 extends EventEmitter { /** * Subscribe to a candle data channel * - * @param {string} key - 'trade:5m:tBTCUSD' - * @returns {boolean} subscribed - * @see WSv2#managedSubscribe + * @see {@link WSv2#managedSubscribe} * @example * await ws.subscribeCandles('trade:5m:tBTCUSD') + * + * @param {string} key - 'trade:5m:tBTCUSD' + * @returns {boolean} subscribed */ async subscribeCandles (key) { return this.managedSubscribe('candles', key, { key }) @@ -1757,11 +1768,12 @@ class WSv2 extends EventEmitter { /** * Subscribe to a status data channel * - * @param {string} key - i.e. 'liq:global' - * @returns {boolean} subscribed - * @see WSv2#managedSubscribe + * @see {@link WSv2#managedSubscribe} * @example * await ws.subscribeStatus('liq:global') + * + * @param {string} key - i.e. 'liq:global' + * @returns {boolean} subscribed */ async subscribeStatus (key) { return this.managedSubscribe('status', key, { key }) @@ -1770,13 +1782,14 @@ class WSv2 extends EventEmitter { /** * Unsubscribe from a channel by ID * - * @param {number} chanId - ID of channel to unsubscribe from * @example * const id = ws.getDataChannelId('ticker', { symbol: 'tBTCUSD' }) * * if (id) { * ws.unsubscribe(id) * } + * + * @param {number} chanId - ID of channel to unsubscribe from */ unsubscribe (chanId) { this.send({ @@ -1788,11 +1801,12 @@ class WSv2 extends EventEmitter { /** * Unsubscribe from a ticker data channel * - * @param {string} symbol - symbol of ticker - * @returns {boolean} unsubscribed - * @see WSv2#subscribeTicker + * @see {@link WSv2#subscribeTicker} * @example * await ws.unsubscribeTicker('tBTCUSD') + * + * @param {string} symbol - symbol of ticker + * @returns {boolean} unsubscribed */ async unsubscribeTicker (symbol) { return this.managedUnsubscribe('ticker', symbol) @@ -1801,11 +1815,12 @@ class WSv2 extends EventEmitter { /** * Unsubscribe from a trades data channel * - * @param {string} symbol - symbol of market to unsubscribe from - * @returns {boolean} unsubscribed - * @see WSv2#subscribeTrades + * @see {@link WSv2#subscribeTrades} * @example * await ws.unsubcribeTrades('tBTCUSD') + * + * @param {string} symbol - symbol of market to unsubscribe from + * @returns {boolean} unsubscribed */ async unsubscribeTrades (symbol) { return this.managedUnsubscribe('trades', symbol) @@ -1814,32 +1829,35 @@ class WSv2 extends EventEmitter { /** * Unsubscribe from an order book data channel * - * @param {string} symbol - symbol of order book - * @returns {boolean} unsubscribed - * @see WSv2#subscribeOrderBook + * @see {@link WSv2#subscribeOrderBook} * @example * await ws.unsubcribeOrderBook('tBTCUSD') + * + * @param {string} symbol - symbol of order book + * @returns {boolean} unsubscribed */ async unsubscribeOrderBook (symbol) { return this.managedUnsubscribe('book', symbol) } /** + * @see {@link WSv2#subscribeCandles} + * @example + * await ws.unsubscribeCandles('tBTCUSD', '1m') + * * @param {string} symbol - symbol of candles * @param {string} frame - time frame * @returns {boolean} unsubscribed - * @see WSv2#subscribeCandles - * @example - * await ws.unsubscribeCandles('tBTCUSD', '1m') */ async unsubscribeCandles (symbol, frame) { return this.managedUnsubscribe('candles', `trade:${frame}:${symbol}`) } /** + * @see {@link WSv2#subscribeStatus} + * * @param {string} key - key that was used in initial {@link WSv2#subscribeStatus} call * @returns {boolean} unsubscribed - * @see WSv2#subscribeStatus */ async unsubscribeStatus (key) { return this.managedUnsubscribe('status', key) @@ -1848,7 +1866,6 @@ class WSv2 extends EventEmitter { /** * Remove all listeners by callback group ID * - * @param {string} cbGID - callback group to remove * @example * await ws.subscribeTrades({ symbol: 'tBTCUSD', cbGID: 42 }) * await ws.subscribeTrades({ symbol: 'tLEOUSD', cbGID: 42 }) @@ -1857,6 +1874,8 @@ class WSv2 extends EventEmitter { * // ... * * ws.removeListeners(42) + * + * @param {string} cbGID - callback group to remove */ removeListeners (cbGID) { delete this._listeners[cbGID] @@ -1888,12 +1907,10 @@ class WSv2 extends EventEmitter { * order submit is confirmed. Emits an error if not authenticated. The order * can be either an array, key/value map, or Order object instance. * - * @see WSv2#cancelOrders - * @see WSv2#cancelOrder - * @see WSv2#updateOrder + * @see {@link WSv2#cancelOrders} + * @see {@link WSv2#cancelOrder} + * @see {@link WSv2#updateOrder} * - * @param {object|Array} order - order object model or array - * @returns {Promise} p - resolves on submit notification * @example * const o = new Order({ * type: Order.type.EXCHANGE_LIMIT, @@ -1906,6 +1923,13 @@ class WSv2 extends EventEmitter { * await ws.submitOrder(o) * * console.log('order confirmed! status: %s', o.status) + * + * @param {( + * bfx-api-node-models.Order| + * bfx-api-node-models.Order~Data + * )} order - order + * + * @returns {Promise} p - resolves on submit notification */ async submitOrder (order) { if (!this._isAuthenticated) { @@ -1936,7 +1960,7 @@ class WSv2 extends EventEmitter { * the price queue. The changeset must contain the order ID, and supports a * 'delta' key to increase/decrease the total amount. * - * @see WSv2#submitOrder + * @see {@link WSv2#submitOrder} * * @param {object} changes - requires at least an 'id' * @returns {Promise} p - resolves on receiving an confirmation notification @@ -1960,9 +1984,14 @@ class WSv2 extends EventEmitter { * confirmed. Emits an error if not authenticated. The ID can be passed as a * number, or taken from an order array/object. * - * @see WSv2#submitOrder + * @see {@link WSv2#submitOrder} + * + * @param {( + * bfx-api-node-models.Order| + * bfx-api-node-models.Order~Data| + * number + * )} order - order model, array, or ID to be cancelled * - * @param {object|Array|number} order - order model, array, or ID to be cancelled * @returns {Promise} p */ async cancelOrder (order) { @@ -1986,10 +2015,14 @@ class WSv2 extends EventEmitter { * Cancels multiple orders, returns a promise that resolves once all * operations are confirmed. * - * @see WSv2#submitOrder + * @see {@link WSv2#submitOrder} + * + * @param {( + * bfx-api-node-models.Order[]| + * bfx-api-node-models.Order~Data[]| + * number[] + * )} orders - array of order models, arrays or IDs to be cancelled * - * @param {object[]|Array[]|number[]} orders - array of order models, arrays - * or IDs to be cancelled * @returns {Promise} p */ async cancelOrders (orders) { @@ -2107,15 +2140,11 @@ class WSv2 extends EventEmitter { * In the future our mobile app will also support spawning native push * notifications in response to incoming ucm-notify-ui packets. * - * @param {object} opts - options - * @param {string} [opts.message] - message to display - * @param {string} [opts.type] - notification type, 'ucm-*' for broadcasts - * @param {string} [opts.level] - 'info', 'error', or 'success' - * @param {string} [opts.image] - link to an image to be shown - * @param {string} [opts.link] - URL the notification should forward too - * @param {string} [opts.sound] - URL of sound to play * @throws an error if given no type or message, or the instance is not open * and authenticated + * + * @param {bfx-api-node-models.Notification~BroadcastPayload} opts - + * broadcast payload */ notifyUI (opts = {}) { const { type, message, level, image, link, sound } = opts @@ -2182,7 +2211,7 @@ class WSv2 extends EventEmitter { * Registers a new callback to be called when a matching info message is * received. * - * @param {number} code - from #WSv2.info + * @param {number} code - from {@link WSv2.info} * @param {Function} cb - callback */ onInfoMessage (code, cb) { @@ -2212,8 +2241,8 @@ class WSv2 extends EventEmitter { * @param {string|number} [opts.cbGID] - callback group id * @param {Function} cb - callback * @see https://docs.bitfinex.com/v2/reference#ws-public-candle - * @see WSv2#subscribeCandles - * @see WSv2#unsubscribeCandles + * @see {@link WSv2#subscribeCandles} + * @see {@link WSv2#unsubscribeCandles} */ onCandle ({ key, cbGID }, cb) { this._registerListener('candle', { 0: key }, Candle, cbGID, cb) @@ -2229,8 +2258,8 @@ class WSv2 extends EventEmitter { * @param {string|number} [opts.cbGID] - callback group id * @param {Function} cb - callback * @see https://docs.bitfinex.com/v2/reference#ws-public-order-books - * @see WSv2#subscribeOrderBook - * @see WSv2#unsubscribeOrderBook + * @see {@link WSv2#subscribeOrderBook} + * @see {@link WSv2#unsubscribeOrderBook} */ onOrderBook ({ symbol, prec, len, cbGID }, cb) { this._registerListener('orderbook', { @@ -2250,8 +2279,8 @@ class WSv2 extends EventEmitter { * @param {string|number} [opts.cbGID] - callback group id * @param {Function} cb - callback * @see https://docs.bitfinex.com/v2/reference#ws-public-order-books - * @see WSv2#subscribeOrderBook - * @see WSv2#unsubscribeOrderBook + * @see {@link WSv2#subscribeOrderBook} + * @see {@link WSv2#unsubscribeOrderBook} */ onOrderBookChecksum ({ symbol, prec, len, cbGID }, cb) { this._registerListener('ob_checksum', { @@ -2271,8 +2300,8 @@ class WSv2 extends EventEmitter { * @param {string|number} [opts.cbGID] - callback group id * @param {Function} cb - callback * @see https://docs.bitfinex.com/v2/reference#ws-public-trades - * @see WSv2#subscribeTrades - * @see WSv2#unsubscribeTrades + * @see {@link WSv2#subscribeTrades} + * @see {@link WSv2#unsubscribeTrades} */ onTrades ({ symbol, pair, cbGID }, cb) { const id = pair || symbol || '' @@ -2290,8 +2319,8 @@ class WSv2 extends EventEmitter { * @param {string|number} [opts.cbGID] - callback group id * @param {Function} cb - callback * @see https://docs.bitfinex.com/v2/reference#ws-public-trades - * @see WSv2#subscribeTrades - * @see WSv2#unsubscribeTrades + * @see {@link WSv2#subscribeTrades} + * @see {@link WSv2#unsubscribeTrades} */ onTradeEntry ({ pair, symbol, cbGID }, cb) { const id = pair || symbol || '' @@ -2302,7 +2331,6 @@ class WSv2 extends EventEmitter { * Register a handler to be called on each personal trade `'te'` event * * @param {object} opts - options - * @param {string} [opts.pair] - required if no symbol specified * @param {string} [opts.symbol] - required if no pair specified * @param {string|number} [opts.cbGID] - callback group id * @param {Function} cb - callback @@ -2316,7 +2344,6 @@ class WSv2 extends EventEmitter { * Register a handler to be called on each personal trade `'tu'` event * * @param {object} opts - options - * @param {string} [opts.pair] - required if no symbol specified * @param {string} [opts.symbol] - required if no pair specified * @param {string|number} [opts.cbGID] - callback group id * @param {Function} cb - callback @@ -2334,8 +2361,8 @@ class WSv2 extends EventEmitter { * @param {string|number} [opts.cbGID] - callback group id * @param {Function} cb - callback * @see https://docs.bitfinex.com/v2/reference#ws-public-ticker - * @see WSv2#subscribeTicker - * @see WSv2#unsubscribeTicker + * @see {@link WSv2#subscribeTicker} + * @see {@link WSv2#unsubscribeTicker} */ onTicker ({ symbol = '', cbGID } = {}, cb) { const m = symbol[0] === 'f' ? FundingTicker : TradingTicker @@ -2350,7 +2377,7 @@ class WSv2 extends EventEmitter { * @param {string} opts.key - key of feed to listen on * @param {string|number} [opts.cbGID] - callback group ID * @param {Function} cb - callback - * @see WSv2#subscribeStatus + * @see {@link WSv2#subscribeStatus} */ onStatus ({ key = '', cbGID } = {}, cb) { this._registerListener('status', { 0: key }, null, cbGID, cb) @@ -2367,7 +2394,7 @@ class WSv2 extends EventEmitter { * @param {string|number} [opts.cbGID] - callback group id * @param {Function} cb - callback * @see https://docs.bitfinex.com/v2/reference#ws-auth-orders - * @see WSv2#auth + * @see {@link WSv2#auth} */ onOrderSnapshot ({ symbol, id, cid, gid, cbGID }, cb) { this._registerListener('os', { @@ -2389,7 +2416,7 @@ class WSv2 extends EventEmitter { * @param {string} [opts.cbGID] - callback group id * @param {Function} cb - callback * @see https://docs.bitfinex.com/v2/reference#ws-auth-orders - * @see WSv2#submitOrder + * @see {@link WSv2#submitOrder} */ onOrderNew ({ symbol, id, cid, gid, cbGID }, cb) { this._registerListener('on', { @@ -2411,7 +2438,7 @@ class WSv2 extends EventEmitter { * @param {string} [opts.cbGID] - callback group id * @param {Function} cb - callback * @see https://docs.bitfinex.com/v2/reference#ws-auth-orders - * @see WSv2#updateOrder + * @see {@link WSv2#updateOrder} */ onOrderUpdate ({ symbol, id, cid, gid, cbGID }, cb) { this._registerListener('ou', { @@ -2433,7 +2460,7 @@ class WSv2 extends EventEmitter { * @param {string} [opts.cbGID] - callback group id * @param {Function} cb - callback * @see https://docs.bitfinex.com/v2/reference#ws-auth-orders - * @see WSv2#cancelOrder + * @see {@link WSv2#cancelOrder} */ onOrderClose ({ symbol, id, cid, gid, cbGID }, cb) { this._registerListener('oc', { @@ -2452,7 +2479,7 @@ class WSv2 extends EventEmitter { * @param {string} [opts.cbGID] - callback group id * @param {Function} cb - callback * @see https://docs.bitfinex.com/v2/reference#ws-auth-position - * @see WSv2#auth + * @see {@link WSv2#auth} */ onPositionSnapshot ({ symbol, cbGID }, cb) { this._registerListener('ps', { 0: symbol }, Position, cbGID, cb) @@ -2506,7 +2533,7 @@ class WSv2 extends EventEmitter { * @param {string} [opts.cbGID] - callback group id * @param {Function} cb - callback * @see https://docs.bitfinex.com/v2/reference#ws-auth-offers - * @see WSv2#auth + * @see {@link WSv2#auth} */ onFundingOfferSnapshot ({ symbol, cbGID }, cb) { this._registerListener('fos', { 1: symbol }, FundingOffer, cbGID, cb) @@ -2560,7 +2587,7 @@ class WSv2 extends EventEmitter { * @param {string} [opts.cbGID] - callback group id * @param {Function} cb - callback * @see https://docs.bitfinex.com/v2/reference#ws-auth-credits - * @see WSv2#auth + * @see {@link WSv2#auth} */ onFundingCreditSnapshot ({ symbol, cbGID }, cb) { this._registerListener('fcs', { 1: symbol }, FundingCredit, cbGID, cb) @@ -2614,7 +2641,7 @@ class WSv2 extends EventEmitter { * @param {string} [opts.cbGID] - callback group id * @param {Function} cb - callback * @see https://docs.bitfinex.com/v2/reference#ws-auth-loans - * @see WSv2#auth + * @see {@link WSv2#auth} */ onFundingLoanSnapshot ({ symbol, cbGID }, cb) { this._registerListener('fls', { 1: symbol }, FundingLoan, cbGID, cb) @@ -2796,10 +2823,10 @@ WSv2.info = { /** * Default connection URL * + * @static * @constant * @type {string} - * @memberof! WSv2# - * @default + * @default wss://api.bitfinex.com/ws/2 */ WSv2.url = 'wss://api.bitfinex.com/ws/2' diff --git a/lib/ws2_manager.js b/lib/ws2_manager.js index c9edafc0..b7dc1930 100644 --- a/lib/ws2_manager.js +++ b/lib/ws2_manager.js @@ -8,7 +8,7 @@ const _includes = require('lodash/includes') const _pick = require('lodash/pick') const Promise = require('bluebird') const PromiseThrottle = require('promise-throttle') -const WSv2 = require('./transports/ws2') +const WSv2 = require('./ws2') const DATA_CHANNEL_LIMIT = 30 const reconnectThrottler = new PromiseThrottle({ @@ -23,6 +23,8 @@ const reconnectThrottler = new PromiseThrottle({ * For more complex operations, grab a socket reference with getSocket() or * getFreeDataSocket(), or create a new WSv2 instance manually * + * @class + * @augments events.EventEmitter * @example * const rest = new RESTv2() * const details = await rest.symbolDetails() @@ -80,7 +82,8 @@ const reconnectThrottler = new PromiseThrottle({ */ class WS2Manager extends EventEmitter { /** - * @param {object} socketArgs - passed to WSv2 constructors + * @param {WSv2~Configuration} socketArgs - passed to {@link WSv2} + * constructor * @param {object} [authArgs] - cached for all internal socket auth() calls * @param {object} [authArgs.calc] - default 0 * @param {object} [authArgs.dms] - default 0 @@ -142,7 +145,7 @@ class WS2Manager extends EventEmitter { } /** - * @param {object} s - socket state + * @param {WS2Manager~SocketState} s - socket state * @returns {number} count - # of subscribed/pending data channels */ static getDataChannelCount (s) { @@ -163,7 +166,7 @@ class WS2Manager extends EventEmitter { /** * @param {number} i - index into pool - * @returns {object} state + * @returns {WS2Manager~SocketState} state */ getSocket (i) { return this._sockets[i] @@ -216,7 +219,7 @@ class WS2Manager extends EventEmitter { * event listeners to forward via our own event emitter, and to manage pending * subs/unsubs. * - * @returns {object} state + * @returns {WS2Manager~SocketState} state */ openSocket () { const { apiKey, apiSecret } = this._socketArgs @@ -292,7 +295,7 @@ class WS2Manager extends EventEmitter { } /** - * @returns {object} state + * @returns {WS2Manager~SocketState} state */ getAuthenticatedSocket () { return this._sockets.find(s => s.ws.isAuthenticated()) @@ -302,7 +305,7 @@ class WS2Manager extends EventEmitter { * Returns the first socket that has less active/pending channels than the * DATA_CHANNEL_LIMIT * - * @returns {object} state - undefined if none found + * @returns {WS2Manager~SocketState} state - undefined if none found */ getFreeDataSocket () { return this._sockets.find(s => ( @@ -316,7 +319,8 @@ class WS2Manager extends EventEmitter { * * @param {string} type - i.e. 'book' * @param {object} filter - i.e. { symbol: 'tBTCUSD', prec: 'R0' } - * @returns {object} wsState - undefined if not found + * @returns {WS2Manager~SocketState} wsState - + * undefined if not found */ getSocketWithDataChannel (type, filter) { return this._sockets.find(s => { @@ -343,7 +347,8 @@ class WS2Manager extends EventEmitter { * NOTE: Cannot filter against pending subscriptions, due to unknown chanId * * @param {number} chanId - channel ID - * @returns {object} wsState - undefined if not found + * @returns {WS2Manager~SocketState} wsState - + * undefined if not found */ getSocketWithChannel (chanId) { return this._sockets.find(s => { @@ -357,7 +362,8 @@ class WS2Manager extends EventEmitter { /** * @param {string} channel - channel type * @param {string} identifier - unique channel identifier - * @returns {object} wsState - undefined if not found + * @returns {WS2Manager~SocketState} wsState - + * undefined if not found */ getSocketWithSubRef (channel, identifier) { return this._sockets.find(s => s.ws.hasSubscriptionRef(channel, identifier)) diff --git a/package.json b/package.json index 291d28f2..9af2332a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bitfinex-api-node", - "version": "4.0.14", + "version": "4.0.15", "description": "Node reference library for Bitfinex API", "engines": { "node": ">=8.3.0" @@ -12,11 +12,13 @@ } }, "scripts": { - "lint": "eslint lib/ examples/ test/ index.js", + "lint": "./node_modules/.bin/eslint lib/ examples/ test/ index.js", "test": "npm run lint && npm run unit", "unit": "NODE_ENV=test nyc --check-coverage --lines 80 --branches 65 --functions 70 --statements 75 --reporter=lcov --reporter=html mocha -b --recursive", - "docs": "rm -rf docs && node_modules/.bin/jsdoc --configure .jsdoc.json --verbose", - "build": "babel -q ./index.js -d ./dist && babel -q ./lib -d ./dist/lib && copy package.json dist" + "build-docs": "rm -rf docs/*.md && ./node_modules/.bin/jsdoc2md -f index.js 'lib/**/*.js' > docs/reference.md", + "build-lib": "babel ./index.js -d ./dist && babel ./lib -d ./dist/lib && copy package.json dist", + "build": "npm run build-lib && npm run build-docs", + "dist": "npm run build" }, "repository": { "type": "git", @@ -41,27 +43,27 @@ }, "homepage": "http://bitfinexcom.github.io/bitfinex-api-node/", "devDependencies": { - "babel-plugin-transform-object-rest-spread": "^6.26.0", - "babel-plugin-transform-regenerator": "^6.26.0", - "babel-preset-env": "^1.7.0", + "@babel/cli": "^7.8.4", + "@babel/plugin-proposal-object-rest-spread": "^7.9.6", + "@babel/plugin-transform-regenerator": "^7.8.7", + "@babel/preset-env": "^7.9.6", "bfx-api-mock-srv": "^1.0.4", "chai": "^4.2.0", - "docdash": "^1.2.0", "dotenv": "^8.2.0", - "eslint": "^6.8.0", + "husky": "^4.2.3", + "mocha": "^7.1.0", + "nyc": "^15.0.0", + "socks-proxy-agent": "^5.0.0", + "eslint": "^7.2.0", "eslint-config-standard": "^14.1.0", "eslint-plugin-import": "^2.20.1", - "eslint-plugin-jsdoc": "^22.0.0", - "eslint-plugin-lodash": "^6.0.0", + "eslint-plugin-jsdoc": "^27.0.4", + "eslint-plugin-lodash": "^7.1.0", + "eslint-plugin-mocha": "^7.0.1", "eslint-plugin-node": "^11.0.0", "eslint-plugin-promise": "^4.2.1", "eslint-plugin-standard": "^4.0.1", - "husky": "^4.2.3", - "jsdoc-to-markdown": "^5.0.1", - "mocha": "^7.1.0", - "nyc": "^15.0.0", - "socks-proxy-agent": "^5.0.0", - "standard": "^14.3.1" + "jsdoc-to-markdown": "^6.0.1" }, "dependencies": { "readline-promise": "^1.0.4", diff --git a/test/examples/run_example.js b/test/examples/run_example.js index d564b904..af605254 100644 --- a/test/examples/run_example.js +++ b/test/examples/run_example.js @@ -8,7 +8,7 @@ const _isFunction = require('lodash/isFunction') const { RESTv2 } = require('bfx-api-node-rest') const runExample = require('../../examples/util/run_example') -const WSv2 = require('../../lib/transports/ws2') +const WSv2 = require('../../lib/ws2') const getRunArgs = (override = {}) => ({ name: 'self-test', diff --git a/test/index.js b/test/index.js index 2ed8dd31..61ef8aaf 100644 --- a/test/index.js +++ b/test/index.js @@ -5,7 +5,7 @@ const assert = require('assert') const BFX = require('../index') const { RESTv1, RESTv2 } = require('bfx-api-node-rest') const WSv1 = require('bfx-api-node-ws1') -const WSv2 = require('../lib/transports/ws2') +const WSv2 = require('../lib/ws2') describe('BFX', () => { it('should be loaded', () => { diff --git a/test/lib/transports/ws2-integration.js b/test/lib/transports/ws2-integration.js index 23d58abd..a7e94172 100644 --- a/test/lib/transports/ws2-integration.js +++ b/test/lib/transports/ws2-integration.js @@ -3,7 +3,7 @@ const assert = require('assert') const Promise = require('bluebird') -const WSv2 = require('../../../lib/transports/ws2') +const WSv2 = require('../../../lib/ws2') const { Order } = require('bfx-api-node-models') const { MockWSv2Server } = require('bfx-api-mock-srv') diff --git a/test/lib/transports/ws2-unit.js b/test/lib/transports/ws2-unit.js index a5870e95..79c73256 100644 --- a/test/lib/transports/ws2-unit.js +++ b/test/lib/transports/ws2-unit.js @@ -17,7 +17,7 @@ const { Trade, TradingTicker, FundingTicker } = require('bfx-api-node-models') -const WSv2 = require('../../../lib/transports/ws2') +const WSv2 = require('../../../lib/ws2') const API_KEY = 'dummy' const API_SECRET = 'dummy' diff --git a/test/lib/util/is_class.js b/test/lib/util/is_class.js deleted file mode 100644 index 9933dd96..00000000 --- a/test/lib/util/is_class.js +++ /dev/null @@ -1,28 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const assert = require('assert') -const { TradingTicker } = require('bfx-api-node-models') -const { isClass } = require('../../../lib/util') - -describe('isClass', () => { - it('returns true for classes', () => { - assert(isClass(TradingTicker)) - }) - - it('returns false for functions', () => { - assert(!isClass(() => {})) - }) - - it('returns false for class instances', () => { - const t = new TradingTicker() - assert(!isClass(t)) - }) - - it('returns false for primitives', () => { - assert(!isClass(42)) - assert(!isClass('42')) - assert(!isClass({})) - assert(!isClass([])) - }) -}) diff --git a/test/lib/util/is_snapshot.js b/test/lib/util/is_snapshot.js deleted file mode 100644 index dd8033d8..00000000 --- a/test/lib/util/is_snapshot.js +++ /dev/null @@ -1,20 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const assert = require('assert') - -const { isSnapshot } = require('../../../lib/util') - -describe('isSnapshot - detects snapshots by data structure', () => { - it('returns false for heartbeats', () => { - assert.strictEqual(isSnapshot(['hb']), false) - }) - - it('returns false simple lists (data updates)', () => { - assert.strictEqual(isSnapshot([1337]), false) - }) - - it('returns true for nested lists (snapshots)', () => { - assert.strictEqual(isSnapshot([['a'], ['b']]), true) - }) -}) diff --git a/test/lib/ws2_manager.js b/test/lib/ws2_manager.js index 8999f72e..ec41aee5 100644 --- a/test/lib/ws2_manager.js +++ b/test/lib/ws2_manager.js @@ -6,7 +6,7 @@ const Promise = require('bluebird') const _isObject = require('lodash/isObject') const _isArray = require('lodash/isArray') const WS2Manager = require('../../lib/ws2_manager') -const WSv2 = require('../../lib/transports/ws2') +const WSv2 = require('../../lib/ws2') describe('WS2Manager', () => { let m