Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bfx-hf-backtest

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bfx-hf-backtest - npm Package Compare versions

Comparing version 1.1.3 to 2.0.0

test/backtest-offline.js

73

lib/util/simulate_live_candle.js
'use strict'
const { onCandle, onTrade } = require('bfx-hf-strategy')
const { onCandle } = require('bfx-hf-strategy')
const N_TRADES = 5
const DUST = 0.0000001
module.exports = async (btState = {}, candle = {}) => {
const { strategy } = btState
const { open, high, low, close, vol, mts } = candle
let nextStrategyState = await onCandle(strategy, candle)
const nextStrategyState = await onCandle(strategy, candle)
if (!(vol === 0 || (open === close && high === low && open === high))) {
const trades = []
let dir = Math.random() > 0.5 ? 1 : -1
let highReached = open === high
let lowReached = open === low
let currPrice = open
let priceStep = dir === 1 // go to high or low
? high === open ? 0 : (high - open) / N_TRADES
: open === low ? 0 : (open - low) / N_TRADES
trades.push({
amount: 0,
price: currPrice,
mts
})
while (true) {
// Handle hitting high point (go to low, or close)
if (!highReached && Math.abs(currPrice - high) < DUST) {
dir *= -1
highReached = true
priceStep = lowReached
? high === close ? 0 : (high - close) / N_TRADES // go to close
: high === low ? 0 : (high - low) / N_TRADES // go to low
// Handle hitting low point (go to high, or close)
} else if (!lowReached && Math.abs(currPrice - low) < DUST) {
dir *= -1
lowReached = true
priceStep = highReached
? close === low ? 0 : (close - low) / N_TRADES // go to close
: high === low ? 0 : (high - low) / N_TRADES // go to high
} else if (highReached && lowReached && Math.abs(currPrice - close) < DUST) {
break
}
if (priceStep === 0) {
break
}
currPrice += priceStep * dir
trades.push({
amount: 0, // set evenly at the end
price: +currPrice.toFixed(7), // starts with open
mts
})
}
// Set trade amounts & pass to strategy
const singleTradeAmount = vol / trades.length
let trade
for (let i = 0; i < trades.length; i += 1) {
trade = trades[i]
trade.amount = singleTradeAmount
nextStrategyState = await onTrade(nextStrategyState, trade)
btState.lastPrice = trade.price
btState.nTrades += 1
btState.strategy = nextStrategyState
}
}
return nextStrategyState
}
{
"name": "bfx-hf-backtest",
"version": "1.1.3",
"version": "2.0.0",
"description": "HF backtesting logic module",

@@ -23,4 +23,3 @@ "main": "index.js",

"test": "npm run lint && npm run unit",
"unit": "DEBUG='bfx:hf:*' NODE_PATH=lib/ NODE_ENV=test istanbul cover _mocha -- -R spec -b --recursive",
"test-without-coverage": "NODE_ENV=test mocha -R spec -b --recursive",
"unit": "NODE_ENV=test mocha -R spec -b --recursive",
"exec_docs": "node_modules/jsdoc-to-markdown/bin/cli.js lib/*.js > docs/exec.md",

@@ -55,14 +54,8 @@ "docs": "npm run exec_docs"

"devDependencies": {
"@hyperswarm/replicator": "^1.7.2",
"async": "^3.2.0",
"bitfinex-terminal-key-encoding": "^1.0.0",
"bitfinex-terminal-terms-of-use": "^1.0.0",
"bitfinex-terminal-terms-of-use": "^4.0.0",
"dazaar": "^1.2.0",
"eslint": "^4.19.1",
"eslint-config-standard": "^7.0.0",
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-standard": "^2.0.1",
"hyperbee": "0.0.18",
"hyperbee": "^1.3.0",
"hypercore": "^9.5.0",
"istanbul": "^0.4.5",
"jsdoc-to-markdown": "^5.0.1",

@@ -69,0 +62,0 @@ "mocha": "^6.2.0",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc