npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bfx-hf-models

v2.3.0

Published

HF DB models

Downloads

350

Readme

Bitfinex Honey Framework Database System for Node.JS

Build Status

This repo implements a backend-agnostic database system for the Bitfinex Honey Framework. It is used by all HF repos for data storage, i.e:

  • bfx-hf-data-server
  • bfx-hf-algo-server
  • bfx-hf-server

Both the DB backend and exchange-specific schema methods can be configured upon initialization. There are currently two official exchange adapters:

  • bfx-hf-ext-plugin-bitfinex - implements Bitfinex-specific model methods
  • bfx-hf-ext-plugin-dummy - provides the base set of DB methods

Besides these, two DB backends are available:

  • bfx-hf-models-adapter-lowdb
  • bfx-hf-models-adapter-sql - uses knex internally, allowing flexibility in DB selection

Features

  • DB-agnostic; currently two official backends are supported: lowdb and knex for SQL databases.
  • Exchange-agnostic; exchange-specific sync logic is provided via a plugin system

Available Models

  • AlgoOrder
  • Backtest
  • Candle
  • Credential
  • Market
  • Strategy
  • Trade

Installation

npm i --save bfx-hf-models

Quickstart

const HFDB = require('bfx-hf-models')
const HFDBLowDBAdapter = require('bfx-hf-models-adapter-lowdb')
const { schema: DummySchema } = require('bfx-hf-ext-plugin-dummy')

const db = new HFDB({
  schema: DummySchema,
  adapter: HFDBLowDBAdapter({
    dbPath: './db.json',
  })
})

// db is now ready to be used; see examples below

Docs

Refer to docs/models.md for an overview of the available models and their schema, and docs/methods.md for a list of methods available for both map & collection models.

Executable examples are available within examples/.

Examples

Usage of built-in models & methods

const HFDB = require('bfx-hf-models')
const HFDBLowDBAdapter = require('bfx-hf-models-adapter-lowdb')
const { schema: DummySchema } = require('bfx-hf-ext-plugin-dummy')

const db = new HFDB({
  schema: DummySchema,
  adapter: HFDBLowDBAdapter({
    dbPath: './db.json',
  })
})

// All default models are available, but will lack exchange specific methods (i.e Candle.sync_range())
const {
  AlgoOrder, Backtest, Candle, Credential, Market, Strategy, Trade
} = db

const allCandles = await Candle.getAll()
const allTrades = await Trade.getAll()
const activeAlgoOrders = await AlgoOrder.find(['active', '=', true])
const allCredentialsByCID = await Credential.getAll()
const allCredentials = Object.values(allCredentialsByCID)
const credential = await Credential.create({
  cid: Date.now(),
  key: 'some_public_key',
  secret: 'some_secret_key',
  meta: 'credential information'
})

//  etc...

Usage of bitfinex model methods

As above, but with the bitfinex plugin the Candle and Trade models will gain a syncRange() method which populates the local DB with data from the exchange API.

const HFDB = require('bfx-hf-models')
const HFDBLowDBAdapter = require('bfx-hf-models-adapter-lowdb')
const { schema: BitfinexSchema } = require('bfx-hf-ext-plugin-bitfinex')

const db = new HFDB({
  schema: BitfinexSchema,
  adapter: HFDBLowDBAdapter({
    dbPath: './db.json',
  })
})

const SYMBOL = 'tBTCUSD'
const TIME_FRAME = '1m'
const END_MTS = Date.now()
const START_MTS = END_MTS - (60 * 60 * 1000)
const { Candle } = db

// sync range
await Candle.syncRange({
  exchange: 'bitfinex',
  type: 'trade',
  symbol: SYMBOL,
  tf: TIME_FRAME,
}, {
  start: START_MTS,
  end: END_MTS,
})

// candles are now in DB, and can be queried
const bitfinexCandles = await Candle.getInRange([
  ['exchange', '=', 'bitfinex'],
  ['symbol', '=', SYMBOL],
  ['tf', '=', TIME_FRAME]
], {
  key: 'mts',
  start: START_MTS,
  end: END_MTS
})

// etc...

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