Package Exports
- bfx-hf-models
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (bfx-hf-models) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Bitfinex Honey Framework Database System for Node.JS
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-serverbfx-hf-algo-serverbfx-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 methodsbfx-hf-ext-plugin-dummy- provides the base set of DB methods
Besides these, two DB backends are available:
bfx-hf-models-adapter-lowdbbfx-hf-models-adapter-sql- uses knex internally, allowing flexibility in DB selection
Features
- DB-agnostic; currently two official backends are supported:
lowdbandknexfor 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-modelsQuickstart
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 belowDocs
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
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request