# bfx-api-node-core

> Core Bitfinex Node API

Latest version **1.6.1** (published 2022-08-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install bfx-api-node-core
pnpm add bfx-api-node-core
yarn add bfx-api-node-core
bun add bfx-api-node-core
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.6.1 |
| Published | 2022-08-01 |
| First published | 2018-10-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=7 |
| Dependencies | 8 |
| Unpacked size | 91.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Bitfinex |
| Maintainers | bitfinexorg, vigan-abd, prdn, mafintosh |
| Keywords | bitfinex, bitcoin, BTC |

## Links

- npm: https://www.npmjs.com/package/bfx-api-node-core
- Repository: https://github.com/bitfinexcom/bfx-api-node-core
- Homepage: http://bitfinexcom.github.io/bfx-api-node-core/
- Issues: https://github.com/bitfinexcom/bfx-api-node-core/issues
- npm.io page: https://npm.io/package/bfx-api-node-core

## Dependencies (8)

- [ws](https://npm.io/package/ws.md) ^8.2.1
- [debug](https://npm.io/package/debug.md) ^4.3.1
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [bluebird](https://npm.io/package/bluebird.md) ^3.7.2
- [bfx-api-node-ws1](https://npm.io/package/bfx-api-node-ws1.md) ^1.0.3
- [bfx-api-node-rest](https://npm.io/package/bfx-api-node-rest.md) ^4.1.2
- [bfx-api-node-util](https://npm.io/package/bfx-api-node-util.md) ^1.0.10
- [bfx-api-node-models](https://npm.io/package/bfx-api-node-models.md) ^1.6.2

## Recent versions

- 1.6.1 (latest) — 2022-08-01
- 1.6.0 — 2022-07-11
- 1.5.8 — 2022-02-18
- 1.5.7 — 2022-02-17
- 1.5.6 — 2022-01-10
- 1.5.5 — 2021-10-07
- 1.5.4 — 2021-09-06
- 1.5.3 — 2021-08-18
- 1.5.2 — 2021-07-26
- 1.5.1 — 2021-07-06
- 1.5.0 — 2021-06-03
- 1.4.0 — 2021-06-02
- 1.3.1 — 2021-05-25
- 1.3.0 — 2021-04-20
- 1.2.1 — 2021-04-14
- … 13 more at https://npm.io/package/bfx-api-node-core/versions

## README

# Bitfinex Modular WSv2 API Library for Node.JS

[![Build Status](https://travis-ci.org/bitfinexcom/bfx-api-node-core.svg?branch=master)](https://travis-ci.org/bitfinexcom/bfx-api-node-core)

Modular Bitfinex Node.JS API library as an alternative to `bitfinex-api-node`, supporting a plugin system. Connection instances are POJOs as opposed to the
WSv2 class instances returned by `bitfinex-api-node` and are manipulated in a
functional style. A connection pool manager is also provided for multiplexing.

### Features

* POJO connection instances
* Multiplexing connection pool manager
* Plugin system for extending the default events

### Installation

```bash
npm i --save bfx-api-node-core
```

### Quickstart

```js
const { Manager, initState } = require('bfx-api-node-core')

// Create a Manager instance with an internal connection pool, and add a
// connection to the pool
const m = new Manager({ transform: true })
const managedConnection = m.openWS()

// Alternatively, create & open a single connection yourself
const connection = initState({ transform: true })

// do something with connections, see below for examples
```

### Docs

[`See docs/manager_docs.md`](/docs/manager_docs.md) for the Manager class documentation, and [`docs/ws2_funcs.md`](/docs/ws2_funcs.md) for documentation on the functions available for manipulating a connection instance.

### Examples

Subscribing to a candle channel:
```js
const debug = require('debug')('bfx:api:core:examples:candles')
const { subscribe, Manager } = require('../')

const CANDLE_KEY = 'trade:1m:tBTCUSD'

debug('opening connection...')

const m = new Manager({ transform: true })
const wsState = m.openWS()

m.on('ws2:open', () => debug('connection opened'))
m.on('ws2:close', () => debug('connection closed'))

m.on('ws2:candles', (candles, meta) => {
  const { chanFilter } = meta
  const { key } = chanFilter
  const [candle] = candles
  const nCandles = candles.length

  debug('recv %d candles on key', nCandles, key)
  debug(
    'latest candle: open %d, high %d, low %d, close %d, volume: %d, mts: %s',
    candle.open, candle.high, candle.low, candle.close, candle.volume,
    new Date(candle.mts).toLocaleString()
  )
})

debug('subscribing to candles channel %s', CANDLE_KEY)

subscribe(wsState, 'candles', { key: CANDLE_KEY })
```

Using a plugin:
```js
const debug = require('debug')('bfx:api:core:examples:candles')
const Watchdog = require('bfx-api-node-plugin-wd')
const { Manager } = require('../')

const WATCHDOG_DELAY = 5 * 1000

debug('opening connection...')

const m = new Manager({
  transform: true,
  plugins: [Watchdog({ pachetWDDelay: WATCHDOG_DELAY })]
})

m.on('ws2:open', () => debug('connection opened'))
m.on('ws2:reopen', () => debug('connection re-opened'))
m.on('ws2:close', () => debug('connection closed'))
m.openWS()

debug('awaiting watchdog trigger [no subscriptions]')
```

### Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request

---
_Source: https://npm.io/package/bfx-api-node-core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
