## Functions
auth(state, opts) ⇒ Promise

Attempts to authenticate with the connection's configured API credentials, and the provided flags. Returns a promise that resolves/rejects on success/failure.

initState(opts) ⇒ Object

Creates & opens a WSv2 API connection, and returns the resulting state object

open(url, agent) ⇒ Object

Opens a websocket connection to the provided Bitfinex API URL and prepares an event emitter to capture and report API stream events.

send(state, msg)

Sends the provided data to the active WebSocket connection, or buffers it if the connection is not yet open.

subscribe(state, channel, payload) ⇒ Object

Subscribes to the specified channel, buffers if the connection is not open.

unsubscribe(state, chanId) ⇒ Object

Unsubscribes from the specified channel, buffers if the connection is not open.

cancelOrder(state, order) ⇒ Promise

Cancels an order from either an order object, array, or raw ID.

cancelOrderWithDelay(state, delay, order) ⇒ Promise

Cancels an order from either an order object, array, or raw ID, after the specified delay.

submitOrder(state, order) ⇒ Promise

Submits an order with either an order model or raw order object.

submitOrderWithDelay(state, delay, order) ⇒ Promise

Submits an order with either an order model or raw order object, after the specified delay.

updateOrder(state, changes) ⇒ Promise

Updates an order in-place.

disableFlag(state, flag, silent) ⇒ Object

Disables a flag; updates the connection flag set

enableFlag(state, flag, silent) ⇒ Object

Enables a flag; updates the connection flag set

isFlagEnabled(state, flag) ⇒ boolean
setFlags(state, flags, silent) ⇒ Object

Updates the connections flags

## auth(state, opts) ⇒ Promise Attempts to authenticate with the connection's configured API credentials, and the provided flags. Returns a promise that resolves/rejects on success/failure. **Kind**: global function **Returns**: Promise - p - resolves on successful auth | Param | Type | Description | | --- | --- | --- | | state | Object | | | opts | Object | | | opts.dms | number | dead man switch, active 4 | | opts.calc | number | | ## initState(opts) ⇒ Object Creates & opens a WSv2 API connection, and returns the resulting state object **Kind**: global function **Returns**: Object - state | Param | Type | Description | | --- | --- | --- | | opts | Object | | | opts.url | string | defaults to production Bitfinex WSv2 API url | | opts.agent | Object | connection agent | | opts.transform | boolean | if true, raw API data arrays will be automatically converted to bfx-api-node-models instances | | opts.authArgs | Object | auth details | | opts.authArgs.apiKey | string | for later authentication | | opts.authArgs.apiSecret | string | for later authentication | | opts.authArgs.authToken | string | for later authentication; takes priority over apiKey and apiSecret | | opts.plugins | Object | optional set of plugins to use with the connection | ## open(url, agent) ⇒ Object Opens a websocket connection to the provided Bitfinex API URL and prepares an event emitter to capture and report API stream events. **Kind**: global function **Returns**: Object - connectionState - see @initState | Param | Type | Description | | --- | --- | --- | | url | string | defaults to production Bitfinex WSv2 API url | | agent | Object | connection agent | ## send(state, msg) Sends the provided data to the active WebSocket connection, or buffers it if the connection is not yet open. **Kind**: global function | Param | Type | Description | | --- | --- | --- | | state | Object | | | msg | \* | converted to a JSON string before being sent | ## subscribe(state, channel, payload) ⇒ Object Subscribes to the specified channel, buffers if the connection is not open. **Kind**: global function **Returns**: Object - state - original ref | Param | Type | Description | | --- | --- | --- | | state | Object | | | channel | string | channel type, i.e. 'trades' | | payload | Object | channel filter, i.e. { symbol: '...' } | ## unsubscribe(state, chanId) ⇒ Object Unsubscribes from the specified channel, buffers if the connection is not open. **Kind**: global function **Returns**: Object - state - original ref | Param | Type | Description | | --- | --- | --- | | state | Object | | | chanId | string \| number | ID of channel to unsubscribe from | ## cancelOrder(state, order) ⇒ Promise Cancels an order from either an order object, array, or raw ID. **Kind**: global function **Returns**: Promise - p - resolves/rejects upon confirmation | Param | Type | | --- | --- | | state | Object | | order | Object \| Array \| number | ## cancelOrderWithDelay(state, delay, order) ⇒ Promise Cancels an order from either an order object, array, or raw ID, after the specified delay. **Kind**: global function **Returns**: Promise - p - resolves/rejects upon confirmation | Param | Type | Description | | --- | --- | --- | | state | Object | | | delay | number | in ms | | order | Object \| Array \| number | | ## submitOrder(state, order) ⇒ Promise Submits an order with either an order model or raw order object. **Kind**: global function **Returns**: Promise - p - resolves/rejects upon confirmation | Param | Type | | --- | --- | | state | Object | | order | Object \| Array | ## submitOrderWithDelay(state, delay, order) ⇒ Promise Submits an order with either an order model or raw order object, after the specified delay. **Kind**: global function **Returns**: Promise - p - resolves/rejects upon confirmation | Param | Type | Description | | --- | --- | --- | | state | Object | | | delay | number | in ms | | order | Object \| Array | | ## updateOrder(state, changes) ⇒ Promise Updates an order in-place. **Kind**: global function **Returns**: Promise - p - resolves/rejects upon confirmation | Param | Type | Description | | --- | --- | --- | | state | Object | | | changes | Object | order update packet | | changes.id | Object | id of order to apply update to | ## disableFlag(state, flag, silent) ⇒ Object Disables a flag; updates the connection flag set **Kind**: global function **Returns**: Object - nextState | Param | Type | Description | | --- | --- | --- | | state | Object | | | flag | number | individual flag to disable | | silent | boolean | if true, no event is emitted | ## enableFlag(state, flag, silent) ⇒ Object Enables a flag; updates the connection flag set **Kind**: global function **Returns**: Object - nextState | Param | Type | Description | | --- | --- | --- | | state | Object | | | flag | number | individual flag to enable | | silent | boolean | if true, no event is emitted | ## isFlagEnabled(state, flag) ⇒ boolean **Kind**: global function **Returns**: boolean - enabled | Param | Type | | --- | --- | | state | Object | | flag | number | ## setFlags(state, flags, silent) ⇒ Object Updates the connections flags **Kind**: global function **Returns**: Object - nextState | Param | Type | Description | | --- | --- | --- | | state | Object | | | flags | number | full flag set | | silent | boolean | if true, no event is emitted |