-
Notifications
You must be signed in to change notification settings - Fork 0
/
budfox.js
78 lines (59 loc) · 1.78 KB
/
budfox.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Budfox is the realtime market for Gekko!
//
// Read more here:
// @link https://github.com/askmike/gekko/blob/stable/docs/internals/budfox.md
//
// > [getting up] I don't know. I guess I realized that I'm just Bud Fox.
// > As much as I wanted to be Gordon Gekko, I'll *always* be Bud Fox.
// > [tosses back the handkerchief and walks away]
var _ = require('lodash');
var async = require('async');
var util = require(__dirname + '/../util');
var dirs = util.dirs();
var Heart = require(dirs.budfox + 'heart');
var MarketDataProvider = require(dirs.budfox + 'marketDataProvider');
var CandleManager = require(dirs.budfox + 'candleManager');
var BudFox = function(config) {
_.bindAll(this);
Readable.call(this, {objectMode: true});
// BudFox internal modules:
this.heart = new Heart;
this.marketDataProvider = new MarketDataProvider(config);
this.candleManager = new CandleManager;
// BudFox data flow:
// relay a marketUpdate event
this.marketDataProvider.on(
'marketUpdate',
e => this.emit('marketUpdate', e)
);
// relay a marketStart event
this.marketDataProvider.on(
'marketStart',
e => this.emit('marketStart', e)
);
// Output the candles
this.candleManager.on(
'candles',
this.pushCandles
);
// on every `tick` retrieve trade data
this.heart.on(
'tick',
this.marketDataProvider.retrieve
);
// on new trade data create candles
this.marketDataProvider.on(
'trades',
this.candleManager.processTrades
);
this.heart.pump();
}
var Readable = require('stream').Readable;
BudFox.prototype = Object.create(Readable.prototype, {
constructor: { value: BudFox }
});
BudFox.prototype._read = function noop() {}
BudFox.prototype.pushCandles = function(candles) {
_.each(candles, this.push);
}
module.exports = BudFox;