Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
bfx-hf-backtest
Advanced tools
This repo provides an interface for executing backtests using either offline data, or a bfx-hf-data-server
instance for historical Bitfinex market data.
bfx-hf-data-server
npm i --save bfx-hf-backtest
const HFS = require('bfx-hf-strategy')
const HFBT = require('bfx-hf-backtest')
const Strategy = ... // strategy instance
const candles = [/* ... */]
const candleKey = HFS.candleMarketDataKey({
symbol: SYMBOLS.BTC_USD,
tf: TIME_FRAMES.ONE_HOUR
})
HFBT.execOffline(strat, {
trades: {},
candles: {
[candleKey]: candles,
}
}).then((btState) => {
const { trades = [] } = btState
// analyze backtest trades...
})
Refer to docs/exec.md
for JSDoc-generated API documentation, and the examples/
folder for executable examples.
To execute a backtest of a trading strategy using historical data, the execOffline
method is provided which will run the strategy against each trade & candle in-order by timestamp:
const HFS = require('bfx-hf-strategy')
const HFBT = require('bfx-hf-backtest')
const EMAStrategy = require('bfx-hf-strategy/examples/ema_cross')
const { Candle } = require('bfx-api-node-models')
const { SYMBOLS, TIME_FRAMES } = require('bfx-hf-util')
const rawCandleData = require('./btc_candle_data.json')
// During real execution, candles can arrive from any market/at any time (if
// sub'ed to multiple time frames); hence, each candle must include its origin
// symbol/time frame pair.
const market = {
symbol: SYMBOLS.BTC_USD,
tf: TIME_FRAMES.ONE_HOUR
}
const candleKey = HFS.candleMarketDataKey(market)
const strat = EMAStrategy(market)
const candles = rawCandleData
.sort((a, b) => a[0] - b[0])
.map(c => ({
...(new Candle(c).toJS()),
...market // attach market data
}))
const run = async () => {
await HFBT.execOffline(strat, {
trades: {},
candles: {
[candleKey]: candles,
}
})
}
try {
run()
} catch (e) {
console.error(e)
}
Online backtests are executed a running bfx-hf-data-server
instance, which will automatically synchronize historical data as needed and pass it to the backtesting logic:
const HFBT = require('bfx-hf-backtest')
const EMAStrategy = require('bfx-hf-strategy/examples/ema_cross')
const { SYMBOLS, TIME_FRAMES } = require('bfx-hf-util')
const now = Date.now()
const market = {
symbol: SYMBOLS.XMR_USD,
tf: TIME_FRAMES.ONE_MINUTE
}
const strat = EMAStrategy(market)
const run = async () => {
await HFBT.execOnline([strat], {
exchange: 'bitfinex',
from: now - (2 * 24 * 60 * 60 * 1000),
to: now,
trades: true,
candles: true,
...market
})
}
try {
run()
} catch (e) {
console.error(e)
}
Dazaar Market data can be used to run a strategy:
const hypercore = require('hypercore')
const Hyperbee = require('hyperbee')
const replicate = require('@hyperswarm/replicator')
const HFBT = require('bfx-hf-backtest')
const { SYMBOLS, TIME_FRAMES } = require('bfx-hf-util')
const EMAStrategy = require('bfx-hf-strategy/examples/ema_cross')
const hopts = {}
const hbOpts = {
valueEncoding: 'json'
}
const strat = EMAStrategy(market)
// pu in your dazaar market data key here
const key = Buffer.from('7c6057e7ac2f19fcacbee2853554b9a24da85797b1cef31b330465d0f24d7fb1', 'hex')
const feed = hypercore(path.join(__dirname, 'dbs', 'testCOPY'), key, { sparse: true })
const db = new Hyperbee(feed, hbOpts)
db.feed.ready(async () => {
replicate(feed, { lookup: true, live: true })
const { exec, onEnd } = await HFBT.execStream(strat, market, {
from,
to
})
// dazaar market data 5min candles
const kp = 'c!5m!'
const from = 1358182044000
const to = 1358342119000
const s = db.createReadStream({ gte: kp + from, lte: kp + to })
let btState
s.on('data', async (data) => {
const { key, value } = data
btState = await exec(key, value)
})
s.on('end', async () => {
btState = await onEnd(btState)
})
})
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
HF backtesting logic module
The npm package bfx-hf-backtest receives a total of 1 weekly downloads. As such, bfx-hf-backtest popularity was classified as not popular.
We found that bfx-hf-backtest demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.