_.forEach(files, (file) => { const loadedModule = this.load(path.join(dirPath, file)); /* eslint no-magic-numbers: "off" */ const fileName = file.slice(0, _.findLastIndex(1, '.') -2); modules.push(fn ? fn(loadedModule, fileName) : loadedModule); });
getLastPriceByAction(action) { if (action.toLowerCase() !== 'sell' && action.toLowerCase() !== 'buy') { return false; } if (this.tradeLog.length === 0) { return false; } const buyIndex = _.findLastIndex(this.tradeLog, { action }); if (buyIndex === -1) { return false; } return (this.tradeLog[buyIndex].price); }
getLastAverageBuyPrice() { if (this.tradeLog.length === 0) { return false; } const buyIndex = _.findLastIndex(this.tradeLog, { action: 'buy' }); if (buyIndex === -1) { return false; } const spliced = _.cloneDeep(this.tradeLog).splice(0, buyIndex + 1); let sellIndex = _.findLastIndex(spliced, { action: 'sell' }); if (sellIndex === -1) { sellIndex = 0; } else { sellIndex += 1; } const buyTrades = spliced.splice(sellIndex, spliced.length); const count = buyTrades.length; const sum = buyTrades .map(trade => trade.price) .reduce((accumulator, currentValue) => accumulator + currentValue); return (sum / count); }