https://github.com/bitfinexcom/bfx-api-node-plugin-managed-candles
https://github.com/bitfinexcom/bfx-api-node-plugin-managed-candles
Last synced: 9 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/bitfinexcom/bfx-api-node-plugin-managed-candles
- Owner: bitfinexcom
- License: mit
- Created: 2018-09-07T08:25:34.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-02-18T14:26:01.000Z (over 4 years ago)
- Last Synced: 2025-08-05T03:51:26.004Z (10 months ago)
- Language: JavaScript
- Size: 14.6 KB
- Stars: 2
- Watchers: 6
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG
- License: LICENSE.md
Awesome Lists containing this project
README
# Bitfinex Managed Candle Dataset Plugin for the Node.JS API
[](https://travis-ci.org/bitfinexcom/bfx-api-node-plugin-managed-candles)
This plugin maintains a full sorted candle set on its internal state, and emits it with every candle update with the event name `data:managed:candles`. The internal dataset is populated when receiving data from candle channels.
Note that the manager proxies the event as `managed:candles`. If subscribing on a socket instance (`wsState.ev.on(...)`) use the internal event name, otherwise use the manager name with `manager.onWS(...)`.
### Features
* Maintains an up-to-date array of all received candles
* Emits a new 'managed:candles' event with the full dataset on each update
### Installation
```bash
npm i --save bfx-api-node-plugin-managed-candles
```
### Quickstart
```js
const { Manager } = require('bfx-api-node-core')
const ManagedCandlesPlugin = require('bfx-api-node-plugin-managed-candles')
const mgr = new Manager({
plugins: [ManagedCandlesPlugin()]
})
// set up a connection, event listeners, etc
mgr.onWS('managed:candles', {}, (candles) => {
debug(JSON.stringify(candles.toJS(), null, 2))
})
```
### Docs
For an executable example, [see `examples/usage.js`](/examples/usage.js)
### Example
```js
const debug = require('debug')('bfx:api:plugins:managed-candles:example')
const { Manager, subscribe } = require('bfx-api-node-core')
const ManagedCandlesPlugin = require('../')
const SYMBOL = 'tBTCUSD'
const mgr = new Manager({
transform: true,
plugins: [ManagedCandlesPlugin()]
})
mgr.onWS('open', {}, () => debug('connection open'))
// Receive updated dataset
mgr.onWS('managed:candles', {}, (candles) => {
debug('updated dataset for %s contains %d candles', SYMBOL, candles.length)
debug('latest candle follows')
debug(JSON.stringify(candles[0].toJS(), null, 2))
})
const wsState = mgr.openWS()
subscribe(wsState, 'candles', { key: `trade:1m:${SYMBOL}` })
```
### 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