Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packages upgrade #7

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion core/budfox/budfox.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ var MarketDataProvider = require(dirs.budfox + 'marketDataProvider');
var CandleManager = require(dirs.budfox + 'candleManager');

var BudFox = function(config) {
_.bindAll(this);
// Pierolalune, 17.02.2021: Prepare Bind all for lodash upgrade
// _.bindAll(this);
_.bindAll(this, _.functionsIn(this).sort());

Readable.call(this, {objectMode: true});

Expand Down
34 changes: 22 additions & 12 deletions core/budfox/candleCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ var moment = require('moment');
var util = require(__dirname + '/../util');

var CandleCreator = function() {
_.bindAll(this);
// Pierolalune, 17.02.2021: Prepare Bind all for lodash upgrade
// _.bindAll(this);
_.bindAll(this, _.functionsIn(this).sort());

// TODO: remove fixed date
this.threshold = moment("1970-01-01", "YYYY-MM-DD");
Expand Down Expand Up @@ -84,21 +86,29 @@ CandleCreator.prototype.write = function(batch) {
CandleCreator.prototype.filter = function(trades) {
// make sure we only include trades more recent
// than the previous emitted candle
return _.filter(trades, function(trade) {
return _.filter(trades, _.bind(function(trade) {
return trade.date > this.threshold;
}, this);
}, this));
}

// put each trade in a per minute bucket
// Pierolalune, 18.02.2021, prepare _.each for lodash upgrade.
// thisArgs disappears, can be solved with binding function with this.
CandleCreator.prototype.fillBuckets = function(trades) {
_.each(trades, function(trade) {
var minute = trade.date.format('YYYY-MM-DD HH:mm');
_.each(
trades,
_.bind(
function(trade) {
var minute = trade.date.format('YYYY-MM-DD HH:mm');

if(!(minute in this.buckets))
this.buckets[minute] = [];
if(!(minute in this.buckets))
this.buckets[minute] = [];

this.buckets[minute].push(trade);
}, this);
this.buckets[minute].push(trade);
},
this
)
);

this.lastTrade = _.last(trades);
}
Expand All @@ -112,7 +122,7 @@ CandleCreator.prototype.calculateCandles = function() {
// create a string referencing the minute this trade happened in
var lastMinute = this.lastTrade.date.format('YYYY-MM-DD HH:mm');

var candles = _.map(this.buckets, function(bucket, name) {
var candles = _.map(this.buckets, _.bind(function(bucket, name) {
var candle = this.calculateCandle(bucket);

// clean all buckets, except the last one:
Expand All @@ -121,7 +131,7 @@ CandleCreator.prototype.calculateCandles = function() {
delete this.buckets[name];

return candle;
}, this);
}, this));

return candles;
}
Expand Down Expand Up @@ -178,7 +188,7 @@ CandleCreator.prototype.addEmptyCandles = function(candles) {
i = +start;
j++;

if(_.contains(minutes, i))
if(_.includes(minutes, i))
continue; // we have a candle for this minute

var lastPrice = candles[j].close;
Expand Down
4 changes: 3 additions & 1 deletion core/budfox/candleManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ var log = require(dirs.core + 'log');
var CandleCreator = require(dirs.budfox + 'candleCreator');

var Manager = function() {
_.bindAll(this);
// Pierolalune, 17.02.2021: Prepare Bind all for lodash upgrade
// _.bindAll(this);
_.bindAll(this, _.functionsIn(this).sort());

this.candleCreator = new CandleCreator;

Expand Down
4 changes: 3 additions & 1 deletion core/budfox/heart.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ else
var Heart = function() {
this.lastTick = false;

_.bindAll(this);
// Pierolalune, 17.02.2021: Prepare Bind all for lodash upgrade
// _.bindAll(this);
_.bindAll(this, _.functionsIn(this).sort());
}

util.makeEventEmitter(Heart);
Expand Down
4 changes: 3 additions & 1 deletion core/budfox/marketDataProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ const dirs = util.dirs();

const Manager = function(config) {

_.bindAll(this);
// Pierolalune, 17.02.2021: Prepare Bind all for lodash upgrade
// _.bindAll(this);
_.bindAll(this, _.functionsIn(this).sort());

// fetch trades
this.source = new MarketFetcher(config);
Expand Down
4 changes: 3 additions & 1 deletion core/budfox/marketFetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ const Fetcher = function(config) {

const exchangeName = config.watch.exchange.toLowerCase();
const DataProvider = require(util.dirs().gekko + 'exchange/wrappers/' + exchangeName);
_.bindAll(this);
// Pierolalune, 17.02.2021: Prepare Bind all for lodash upgrade
// _.bindAll(this);
_.bindAll(this, _.functionsIn(this).sort());

// Create a public dataProvider object which can retrieve live
// trade information from an exchange.
Expand Down
8 changes: 5 additions & 3 deletions core/budfox/tradeBatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ var TradeBatcher = function(tid) {
if(!_.isString(tid))
throw new Error('tid is not a string');

_.bindAll(this);
// Pierolalune, 17.02.2021: Prepare Bind all for lodash upgrade
// _.bindAll(this);
_.bindAll(this, _.functionsIn(this).sort());
this.tid = tid;
this.last = -1;
}
Expand Down Expand Up @@ -110,9 +112,9 @@ TradeBatcher.prototype.filter = function(batch) {
// weed out known trades
// TODO: optimize by stopping as soon as the
// first trade is too old (reverse first)
return _.filter(batch, function(trade) {
return _.filter(batch, _.bind(function(trade) {
return this.last < trade[this.tid];
}, this);
}, this));
}

TradeBatcher.prototype.convertDates = function(batch) {
Expand Down
27 changes: 18 additions & 9 deletions core/candleBatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ var CandleBatcher = function(candleSize) {
this.smallCandles = [];
this.calculatedCandles = [];

_.bindAll(this);
// Pierolalune, 17.02.2021: Prepare Bind all for lodash upgrade
// _.bindAll(this);
_.bindAll(this, _.functionsIn(this).sort());
}

util.makeEventEmitter(CandleBatcher);
Expand Down Expand Up @@ -60,14 +62,21 @@ CandleBatcher.prototype.write = async function(candles) {

this.emitted = 0;

_.each(candles, function(candle) {
if (this.prevcandle == undefined) this.prevcandle = _.clone(candle);
candle = this.addHeikinAshi(candle, this.prevcandle);
this.prevcandle = _.clone(candle);

this.smallCandles.push(candle);
this.check();
}, this);
// Pierolalune, 18.02.2021, prepare _.each for lodash upgrade
// _.each(candles, function(candle) {
// this.smallCandles.push(candle);
// this.check();
// }, this);
_.each(
candles,
_.bind(
function(candle) {
this.smallCandles.push(candle);
this.check();
},
this
)
);

return this.emitted;
}
Expand Down
36 changes: 28 additions & 8 deletions core/gekkoStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,22 @@ if(config.debug && mode !== 'importer') {
this.flushDefferedEvents();
_done();
});
_.each(this.candleConsumers, function(c) {
at = c.meta.name;
c.processCandle(chunk, flushEvents);
}, this);
// Pierolalune, 18.02.2021, prepare _.each for lodash upgrade
// _.each(this.candleConsumers, function(c) {
// at = c.meta.name;
// c.processCandle(chunk, flushEvents);
// }, this);
_.each(
this.candleConsumers,
_.bind(
function(c) {
at = c.meta.name;
c.processCandle(chunk, flushEvents);
},
this
)
);

}
} else {
// skip decoration
Expand All @@ -68,9 +80,17 @@ if(config.debug && mode !== 'importer') {
this.flushDefferedEvents();
_done();
});
_.each(this.candleConsumers, async function(c) {
await c.processCandle(chunk, flushEvents);
}, this);
// Pierolalune, 18.02.2021, prepare _.each for lodash upgrade.
// thisArgs disappears, can be solved with binding function with this.
_.each(
this.candleConsumers,
_.bind(
function(c) {
c.processCandle(chunk, flushEvents);
},
this
)
);
}
}

Expand All @@ -80,7 +100,7 @@ Gekko.prototype.flushDefferedEvents = function() {
producer => producer.broadcastDeferredEmit()
);

// If we broadcasted anything, we might have
// If we had broadcasted anything, we might have
// triggered more events, recurse until we
// have fully broadcasted everything.
if(broadcasted)
Expand Down
4 changes: 3 additions & 1 deletion core/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ var sendToParent = function() {
}

var Log = function() {
_.bindAll(this);
// Pierolalune, 17.02.2021: Prepare Bind all for lodash upgrade
// _.bindAll(this);
_.bindAll(this, _.functionsIn(this).sort());
this.env = util.gekkoEnv();

if(this.env === 'standalone')
Expand Down
20 changes: 15 additions & 5 deletions core/markets/backtest.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ if(!to.isValid())

var Market = function() {

_.bindAll(this);
// Pierolalune, 17.02.2021: Prepare Bind all for lodash upgrade
// _.bindAll(this);
_.bindAll(this, _.functionsIn(this).sort());
this.pushing = false;
this.ended = false;
this.closed = false;
Expand Down Expand Up @@ -97,10 +99,18 @@ Market.prototype.processCandles = function(err, candles) {
log.warn(`Simulation based on incomplete market data (${this.batchSize - amount} missing between ${from} and ${to}).`);
}

_.each(candles, function(c, i) {
c.start = moment.unix(c.start);
this.push(c);
}, this);
// Pierolalune, 18.02.2021, prepare _.each for lodash upgrade.
// thisArgs disappears, can be solved with binding function with this.
_.each(
candles,
_.bind(
function(c, i) {
c.start = moment.unix(c.start);
this.push(c);
},
this
)
);

this.pushing = false;

Expand Down
4 changes: 3 additions & 1 deletion core/markets/cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ if(error)


var Market = function(config, plugins) {
_.bindAll(this);
// Pierolalune, 17.02.2021: Prepare Bind all for lodash upgrade
// _.bindAll(this);
_.bindAll(this, _.functionsIn(this).sort());
Readable.call(this, {objectMode: true});

var context = this;
Expand Down
4 changes: 3 additions & 1 deletion core/markets/importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ if(to <= from)
util.die('This daterange does not make sense.')

var Market = function() {
_.bindAll(this);
// Pierolalune, 17.02.2021: Prepare Bind all for lodash upgrade
// _.bindAll(this);
_.bindAll(this, _.functionsIn(this).sort());
this.exchangeSettings = exchangeChecker.settings(config.watch);

this.tradeBatcher = new TradeBatcher(this.exchangeSettings.tid);
Expand Down
19 changes: 14 additions & 5 deletions core/markets/leech.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ else

var Market = function() {

_.bindAll(this);
// Pierolalune, 17.02.2021: Prepare Bind all for lodash upgrade
// _.bindAll(this);
_.bindAll(this, _.functionsIn(this).sort());

Readable.call(this, {objectMode: true});

Expand Down Expand Up @@ -99,10 +101,17 @@ Market.prototype.processCandles = function(err, candles) {
// we know we are missing 57 candles...

context = this;
_.each(candles, function(c, i) {
c.start = moment.unix(c.start).utc();
// this.push(c);
}, this);
// Pierolalune, 18.02.2021, prepare _.each for lodash upgrade.
// thisArgs disappears, can be solved with binding function with this.
_.each(
candles,
_.bind(
function(c, i) {
c.start = moment.unix(c.start).utc();
this.push(c);
}, this
)
);
this.batchHistoryData(candles, 0);

this.latestTs = _.last(candles).start.unix() + 1;
Expand Down
4 changes: 2 additions & 2 deletions core/pluginUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ var pluginHelper = {

plugin.config = config[plugin.slug];

if(_.contains(plugin.mandatoryOn, gekkoMode)) {
if(_.includes(plugin.mandatoryOn, gekkoMode)) {
log.warn(
'The plugin',
plugin.name,
Expand All @@ -81,7 +81,7 @@ var pluginHelper = {
if(!plugin.config || !plugin.config.enabled)
return next();

if(!_.contains(plugin.modes, gekkoMode)) {
if(!_.includes(plugin.modes, gekkoMode)) {
log.warn(
'The plugin',
plugin.name,
Expand Down
4 changes: 3 additions & 1 deletion core/prepareDateRange.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var _ = require('lodash');
var prompt = require('prompt-lite');
//Pierolalune, 12.02.2021: Replace prompt-lite with prompt
//var prompt = require('prompt-lite');
var prompt = require('prompt');
var moment = require('moment');

var util = require('./util');
Expand Down
Loading