Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
this adjusts the examples for the bitfinex terminal release, adds the dazaar card and updates the readme
- Loading branch information
1 parent
c778314
commit f38b465
Showing
6 changed files
with
107 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,4 @@ npm-debug.log | |
.DS_Store | ||
package-lock.json | ||
|
||
examples/dbs | ||
dbs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
'use strict' | ||
|
||
process.env.DEBUG = process.env.DEBUG || 'bfx:*' | ||
|
||
const dazaar = require('dazaar') | ||
const swarm = require('dazaar/swarm') | ||
const Hyperbee = require('hyperbee') | ||
const keyEncoding = require('bitfinex-terminal-key-encoding') | ||
|
||
const HFBT = require('../') | ||
const { SYMBOLS, TIME_FRAMES } = require('bfx-hf-util') | ||
const EMAStrategy = require('bfx-hf-strategy/examples/ema_cross') | ||
|
||
const terms = require('bitfinex-terminal-terms-of-use') | ||
|
||
const get24HoursAgo = (date) => { | ||
const res = date.getTime() - (1 * 86400 * 1000) | ||
|
||
return new Date(res) | ||
} | ||
|
||
const market = { | ||
symbol: SYMBOLS.BTC_USD, | ||
tf: TIME_FRAMES.FIVE_MINUTES | ||
} | ||
|
||
const strat = EMAStrategy(market) | ||
|
||
const dmarket = dazaar('dbs/terminal-backtest') | ||
|
||
const card = require('./bitfinex.terminal.btcusd.candles.json') | ||
const buyer = dmarket.buy(card, { sparse: true, terms }) | ||
|
||
let replication | ||
buyer.on('feed', async function () { | ||
console.log('got feed') | ||
|
||
const db = new Hyperbee(buyer.feed, { | ||
keyEncoding, | ||
valueEncoding: 'json' | ||
}) | ||
|
||
await runTest(db) | ||
}) | ||
|
||
async function runTest (db) { | ||
const from = get24HoursAgo(new Date()) | ||
const to = new Date() | ||
|
||
const { exec, onEnd } = await HFBT.execStream(strat, market, { | ||
from, | ||
to | ||
}) | ||
|
||
const stream = db.createReadStream({ | ||
gte: { candle: '5m', timestamp: from }, | ||
lte: { candle: '5m', timestamp: to } | ||
}) | ||
|
||
let btState | ||
for await (const data of stream) { | ||
const { key, value } = data | ||
btState = await exec(key, value) | ||
} | ||
|
||
await onEnd(btState) | ||
|
||
buyer.feed.close() | ||
replication.destroy() | ||
} | ||
|
||
replication = swarm(buyer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "Bitfinex Terminal BTCUSD Candles Dazaar Card", | ||
"id": "76ef1d766eee63ff473e33e1f231c3b65cf1042b1a353c027b48bdbeba00b969", | ||
"payment": [] | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters