Skip to content
This repository was archived by the owner on Feb 16, 2020. It is now read-only.

Commit 51bc47e

Browse files
authored
Merge pull request #2216 from askmike/pre-v0.6
Release v0.6.0
2 parents b389855 + 49692be commit 51bc47e

File tree

218 files changed

+25660
-4417
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

218 files changed

+25660
-4417
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
language: node_js
22
node_js:
3-
- "8.0.0"
3+
- "8.11.2"

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ init:
22
- git config --global core.autocrlf input
33

44
environment:
5-
nodejs_version: "6"
5+
nodejs_version: "9"
66

77
install:
88
- ps: Install-Product node $env:nodejs_version

core/budfox/budfox.js

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,24 @@ var BudFox = function(config) {
3030

3131
// BudFox data flow:
3232

33+
// relay a marketUpdate event
34+
this.marketDataProvider.on(
35+
'marketUpdate',
36+
e => this.emit('marketUpdate', e)
37+
);
38+
39+
// relay a marketStart event
40+
this.marketDataProvider.on(
41+
'marketStart',
42+
e => this.emit('marketStart', e)
43+
);
44+
45+
// Output the candles
46+
this.candleManager.on(
47+
'candles',
48+
this.pushCandles
49+
);
50+
3351
// on every `tick` retrieve trade data
3452
this.heart.on(
3553
'tick',
@@ -42,26 +60,7 @@ var BudFox = function(config) {
4260
this.candleManager.processTrades
4361
);
4462

45-
// Output the candles
46-
this.candleManager.on(
47-
'candles',
48-
this.pushCandles
49-
);
50-
5163
this.heart.pump();
52-
53-
// Budfox also reports:
54-
55-
// Trades & last trade
56-
//
57-
// this.marketDataProvider.on(
58-
// 'trades',
59-
// this.broadcast('trades')
60-
// );
61-
// this.marketDataProvider.on(
62-
// 'trades',
63-
// this.broadcastTrade
64-
// );
6564
}
6665

6766
var Readable = require('stream').Readable;
@@ -76,18 +75,4 @@ BudFox.prototype.pushCandles = function(candles) {
7675
_.each(candles, this.push);
7776
}
7877

79-
// BudFox.prototype.broadcastTrade = function(trades) {
80-
// _.defer(function() {
81-
// this.emit('trade', trades.last);
82-
// }.bind(this));
83-
// }
84-
85-
// BudFox.prototype.broadcast = function(message) {
86-
// return function(payload) {
87-
// _.defer(function() {
88-
// this.emit(message, payload);
89-
// }.bind(this));
90-
// }.bind(this);
91-
// }
92-
9378
module.exports = BudFox;

core/budfox/candleCreator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ CandleCreator.prototype.calculateCandles = function() {
109109

110110
// catch error from high volume getTrades
111111
if (this.lastTrade !== undefined)
112-
// create a string referencing to minute this trade happened in
112+
// create a string referencing the minute this trade happened in
113113
var lastMinute = this.lastTrade.date.format('YYYY-MM-DD HH:mm');
114114

115115
var candles = _.map(this.buckets, function(bucket, name) {

core/budfox/candleManager.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ var util = require(__dirname + '/../util');
1010
var dirs = util.dirs();
1111
var config = util.getConfig();
1212
var log = require(dirs.core + 'log');
13-
var cp = require(dirs.core + 'cp');
1413

1514
var CandleCreator = require(dirs.budfox + 'candleCreator');
1615

@@ -21,10 +20,6 @@ var Manager = function() {
2120

2221
this.candleCreator
2322
.on('candles', this.relayCandles);
24-
25-
this.messageFirstCandle = _.once(candle => {
26-
cp.firstCandle(candle);
27-
})
2823
};
2924

3025
util.makeEventEmitter(Manager);
@@ -34,12 +29,6 @@ Manager.prototype.processTrades = function(tradeBatch) {
3429

3530
Manager.prototype.relayCandles = function(candles) {
3631
this.emit('candles', candles);
37-
38-
if(!_.size(candles))
39-
return;
40-
41-
this.messageFirstCandle(_.first(candles));
42-
cp.lastCandle(_.last(candles));
4332
}
4433

4534
module.exports = Manager;

core/budfox/marketDataProvider.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const util = require(__dirname + '/../util');
1010

1111
const MarketFetcher = require('./marketFetcher');
1212
const dirs = util.dirs();
13-
const cp = require(dirs.core + 'cp');
1413

1514
const Manager = function(config) {
1615

@@ -33,14 +32,14 @@ Manager.prototype.retrieve = function() {
3332

3433

3534
Manager.prototype.relayTrades = function(batch) {
36-
this.emit('trades', batch);
35+
this.sendMarketStart(batch);
36+
this.emit('marketUpdate', batch.last.date);
3737

38-
this.sendStartAt(batch);
39-
cp.update(batch.last.date.format());
38+
this.emit('trades', batch);
4039
}
4140

42-
Manager.prototype.sendStartAt = _.once(function(batch) {
43-
cp.startAt(batch.first.date.format())
41+
Manager.prototype.sendMarketStart = _.once(function(batch) {
42+
this.emit('marketStart', batch.first.date);
4443
});
4544

4645
module.exports = Manager;

core/budfox/marketFetcher.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,24 @@
66
// - `trades batch` - all new trades.
77
// - `trade` - the most recent trade after every fetch
88

9-
var _ = require('lodash');
10-
var moment = require('moment');
11-
var utc = moment.utc;
12-
var util = require(__dirname + '/../util');
9+
const _ = require('lodash');
10+
const moment = require('moment');
11+
const utc = moment.utc;
12+
const util = require(__dirname + '/../util');
13+
const dirs = util.dirs();
1314

14-
var config = util.getConfig();
15-
var log = require(util.dirs().core + 'log');
16-
var exchangeChecker = require(util.dirs().core + 'exchangeChecker');
15+
const config = util.getConfig();
16+
const log = require(dirs.core + 'log');
17+
const exchangeChecker = require(dirs.gekko + 'exchange/exchangeChecker');
1718

18-
var TradeBatcher = require(util.dirs().budfox + 'tradeBatcher');
19+
const TradeBatcher = require(util.dirs().budfox + 'tradeBatcher');
1920

20-
var Fetcher = function(config) {
21+
const Fetcher = function(config) {
2122
if(!_.isObject(config))
2223
throw 'TradeFetcher expects a config';
2324

24-
var exchangeName = config.watch.exchange.toLowerCase();
25-
var DataProvider = require(util.dirs().gekko + 'exchanges/' + exchangeName);
25+
const exchangeName = config.watch.exchange.toLowerCase();
26+
const DataProvider = require(util.dirs().gekko + 'exchange/wrappers/' + exchangeName);
2627
_.bindAll(this);
2728

2829
// Create a public dataProvider object which can retrieve live

core/candleBatcher.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var CandleBatcher = function(candleSize) {
1818

1919
this.candleSize = candleSize;
2020
this.smallCandles = [];
21+
this.calculatedCandles = [];
2122

2223
_.bindAll(this);
2324
}
@@ -28,22 +29,37 @@ CandleBatcher.prototype.write = function(candles) {
2829
if(!_.isArray(candles))
2930
throw 'candles is not an array';
3031

32+
this.emitted = 0;
33+
3134
_.each(candles, function(candle) {
3235
this.smallCandles.push(candle);
3336
this.check();
3437
}, this);
38+
39+
return this.emitted;
3540
}
3641

3742
CandleBatcher.prototype.check = function() {
3843
if(_.size(this.smallCandles) % this.candleSize !== 0)
3944
return;
4045

41-
this.emit('candle', this.calculate());
46+
this.emitted++;
47+
this.calculatedCandles.push(this.calculate());
4248
this.smallCandles = [];
4349
}
4450

51+
CandleBatcher.prototype.flush = function() {
52+
_.each(
53+
this.calculatedCandles,
54+
candle => this.emit('candle', candle)
55+
);
56+
57+
this.calculatedCandles = [];
58+
}
59+
4560
CandleBatcher.prototype.calculate = function() {
46-
var first = this.smallCandles.shift();
61+
// remove the id property of the small candle
62+
var { id, ...first } = this.smallCandles.shift();
4763

4864
first.vwp = first.vwp * first.volume;
4965

core/cp.js

Lines changed: 0 additions & 90 deletions
This file was deleted.

core/emitter.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Gekko uses a custom event emitter within the GekkoStream (the plugins) to guarantee
2+
// the correct order of events that are triggered by eachother. Turns sync events from
3+
// LIFO into a FIFO stack based model.
4+
//
5+
// More details here: https://forum.gekko.wizb.it/thread-56579.html
6+
7+
const util = require('util');
8+
const events = require('events');
9+
const NativeEventEmitter = events.EventEmitter;
10+
11+
const GekkoEventEmitter = function() {
12+
NativeEventEmitter.call(this);
13+
this.defferedEvents = [];
14+
}
15+
16+
util.inherits(GekkoEventEmitter, NativeEventEmitter);
17+
18+
// push to stack
19+
GekkoEventEmitter.prototype.deferredEmit = function(name, payload) {
20+
this.defferedEvents.push({name, payload});
21+
}
22+
23+
// resolve FIFO
24+
GekkoEventEmitter.prototype.broadcastDeferredEmit = function() {
25+
if(this.defferedEvents.length === 0)
26+
return false;
27+
28+
const event = this.defferedEvents.shift();
29+
30+
this.emit(event.name, event.payload);
31+
return true;
32+
}
33+
34+
module.exports = GekkoEventEmitter;

0 commit comments

Comments
 (0)