# bfx-hf-strategy

> HF strategy module

Latest version **1.1.0** (published 2020-09-22) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install bfx-hf-strategy
pnpm add bfx-hf-strategy
yarn add bfx-hf-strategy
bun add bfx-hf-strategy
```

## 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.1.0 |
| Published | 2020-09-22 |
| First published | 2018-10-23 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 180.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 27 |
| Author | Bitfinex |
| Maintainers | robertkowalski |
| Keywords | honey framework, bitfinex, bitcoin, BTC |

## Links

- npm: https://www.npmjs.com/package/bfx-hf-strategy
- Repository: https://github.com/bitfinexcom/bfx-hf-strategy
- Homepage: https://github.com/bitfinexcom/bfx-hf-strategy#readme
- Issues: https://github.com/bitfinexcom/bfx-hf-strategy/issues
- npm.io page: https://npm.io/package/bfx-hf-strategy

## Dependencies (8)

- [debug](https://npm.io/package/debug.md) ^4.1.1
- [lodash](https://npm.io/package/lodash.md) ^4.17.10
- [bluebird](https://npm.io/package/bluebird.md) ^3.7.2
- [bfx-hf-util](https://npm.io/package/bfx-hf-util.md) ^1.0.1
- [bfx-api-node-core](https://npm.io/package/bfx-api-node-core.md) ^1.1.0
- [bfx-api-node-util](https://npm.io/package/bfx-api-node-util.md) ^1.0.2
- [bfx-hf-indicators](https://npm.io/package/bfx-hf-indicators.md) ^2.0.0
- [bfx-api-node-models](https://npm.io/package/bfx-api-node-models.md) ^1.0.12

## Recent versions

- 1.1.0 (latest) — 2020-09-22
- 1.0.5 — 2020-08-20
- 1.0.4 — 2020-02-25
- 1.0.3 — 2019-10-10
- 1.0.2 — 2019-09-26
- 1.0.1 — 2019-09-23
- 1.0.0 — 2019-09-11
- 1.0.0-alpha.2 — 2018-10-29
- 1.0.0-alpha.1 — 2018-10-24
- 1.0.0-alpha — 2018-10-23

## README

## Bitfinex Honey Framework Trading Strategy Library for Node.JS

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

This repo serves as a framework for creating trading bots/strategies on the Bitfinex platform. It consists of a set of order methods and an architecture compatible with `bfx-hf-data-server` and `bfx-hf-backtest` for backtests on historical candle/trade data, which can be transitioned seamlessly to trading on the live markets.

Strategies written using this framework must define a set of update methods, called on each tick (with either a trade or a candle), along with a set of indicators which are automatically updated on each tick. The indicators are made available to the strategy methods, and can be queried to direct trading behavior.

### Features
* Event-driven design approach allowing strategies to react to market updates in real-time
* Compatibility with `bfx-hf-backtest` for backtest execution
* Compatibility with `bfx-hf-strategy-exec` for execution on live markets

### Installation

```bash
npm i --save bfx-hf-strategy
```

### Quickstart & Example

Using `bfx-hf-stratey` implies writing a custom strategy utilizing the methods provided by the library. The following is an example of a valid strategy as defined within `examples/macd_cross`:

```js
const { MACD } = require('bfx-hf-indicators')
const { SYMBOLS, TIME_FRAMES } = require('bfx-hf-util')
const HFS = require('bfx-hf-strategy')

module.exports = ({
  symbol = SYMBOLS.BTC_USD,
  tf = TIME_FRAMES.ONE_HOUR
} = {}) => HFS.define({
  id: 'quickstart_example',
  name: 'quickstart_example',
  symbol,
  tf,

  indicators: {
    macd: new MACD([10, 26, 9])
  },

  // This quickstart example immediately opens a long position, and then no
  // longer reacts to future market updates
  onPriceUpdate: async (state = {}, update = {}) => {
    const position = HFS.getPosition(state)

    if (position) {
      return state
    }

    return HFS.openLongPositionMarket(state, {
      mtsCreate: mts,
      amount: 1,
      price
    })
  }
})
```

### Docs

[Refer to `docs/usage.md`](/docs/usage.md) for an overview of the strategy system and methods available at runtime, [and `docs/api.md`](/docs/api.md) for JSDoc-generated API documentation.

Ready to run examples can be found in the [`examples/` folder](/examples)

### 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-hf-strategy · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
