diff --git a/IndicatorBot.js b/IndicatorBot.js index 117d8fe30..ae0ac799b 100644 --- a/IndicatorBot.js +++ b/IndicatorBot.js @@ -8,6 +8,7 @@ let thisObject = { initialize: initialize, + finalize: finalize, start: start }; @@ -19,6 +20,13 @@ return thisObject; + function finalize() { + thisObject = undefined + utilities = undefined + fileStorage = undefined + commons = undefined + } + function initialize(callBackFunction) { try { diff --git a/IndicatorBotProcessMainLoop.js b/IndicatorBotProcessMainLoop.js index 962719483..e29c7ac60 100644 --- a/IndicatorBotProcessMainLoop.js +++ b/IndicatorBotProcessMainLoop.js @@ -412,12 +412,12 @@ switch (processConfig.framework.name) { case 'Multi-Period-Market': { - processFramework = MULTI_PERIOD_MARKET.newMultiPeriodMarket(bot, logger, UTILITIES, USER_BOT_MODULE, FILE_STORAGE); + processFramework = MULTI_PERIOD_MARKET.newMultiPeriodMarket(bot, logger, UTILITIES, FILE_STORAGE); intitializeProcessFramework(); break; } case 'Multi-Period-Daily': { - processFramework = MULTI_PERIOD_DAILY.newMultiPeriodDaily(bot, logger, UTILITIES, USER_BOT_MODULE, FILE_STORAGE); + processFramework = MULTI_PERIOD_DAILY.newMultiPeriodDaily(bot, logger, UTILITIES, FILE_STORAGE); intitializeProcessFramework(); break; } diff --git a/MultiPeriod.js b/MultiPeriod.js index 9d40e4433..f2aeb825d 100644 --- a/MultiPeriod.js +++ b/MultiPeriod.js @@ -1,4 +1,4 @@ -exports.newMultiPeriod = function newMultiPeriod(bot, logger, COMMONS, UTILITIES, USER_BOT_MODULE, COMMONS_MODULE) { +exports.newMultiPeriod = function newMultiPeriod(bot, logger, UTILITIES, USER_BOT_MODULE, USER_BOT_COMMONS) { const FULL_LOG = true; const LOG_FILE_CONTENT = false; @@ -20,7 +20,7 @@ let dataFiles = []; let multiPeriodDataFiles = new Map(); - let usertBot; + let botInstance; const FILE_STORAGE = require('./FileStorage.js'); let fileStorage = FILE_STORAGE.newFileStorage(logger); @@ -60,8 +60,10 @@ } - usertBot = USER_BOT_MODULE.newUserBot(bot, logger, COMMONS_MODULE, UTILITIES, fileStorage); - usertBot.initialize(callBackFunction, pAssistant); + let USER_BOT_MODULE = require("./TradingBot") + + botInstance = USER_BOT_MODULE.newTradingBot(bot, logger, UTILITIES, FILE_STORAGE); + botInstance.initialize(callBackFunction); } catch (err) { logger.write(MODULE_NAME, "[ERROR] initialize -> err = " + err.stack); @@ -75,8 +77,8 @@ multiPeriodDataFiles = undefined statusDependencies = undefined dataDependencies = undefined - usertBot.finalize() - usertBot = undefined + botInstance.finalize() + botInstance = undefined fileStorage = undefined processConfig = undefined thisObject = undefined @@ -839,7 +841,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> callTheBot -> Entering function."); } - usertBot.start( + botInstance.start( multiPeriodDataFiles, currentTimePeriod, currentOutputPeriodName, diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index 898c092aa..ea4a030f9 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -1,4 +1,4 @@ -exports.newMultiPeriodDaily = function newMultiPeriodDaily(bot, logger, UTILITIES, USER_BOT_MODULE, FILE_STORAGE) { +exports.newMultiPeriodDaily = function newMultiPeriodDaily(bot, logger, UTILITIES, FILE_STORAGE) { const FULL_LOG = true; const LOG_FILE_CONTENT = false; diff --git a/MultiPeriodMarket.js b/MultiPeriodMarket.js index 2b6c480a3..11dadbe2a 100644 --- a/MultiPeriodMarket.js +++ b/MultiPeriodMarket.js @@ -1,4 +1,4 @@ -exports.newMultiPeriodMarket = function newMultiPeriodMarket(bot, logger, UTILITIES, USER_BOT_MODULE, FILE_STORAGE) { +exports.newMultiPeriodMarket = function newMultiPeriodMarket(bot, logger, UTILITIES, FILE_STORAGE) { const FULL_LOG = true; const LOG_FILE_CONTENT = false; diff --git a/TradingBot.js b/TradingBot.js index 6ad3f07e2..a8e1d7c2c 100644 --- a/TradingBot.js +++ b/TradingBot.js @@ -1,4 +1,4 @@ -exports.newTradingBot = function newTradingBot(bot, logger, USER_BOT_COMMONS, UTILITIES, FILE_STORAGE) { +exports.newTradingBot = function newTradingBot(bot, logger, UTILITIES, FILE_STORAGE) { const FULL_LOG = true; const LOG_FILE_CONTENT = false; @@ -8,6 +8,7 @@ let thisObject = { initialize: initialize, + finalize: finalize, start: start }; @@ -19,6 +20,13 @@ return thisObject; + function finalize() { + thisObject = undefined + utilities = undefined + fileStorage = undefined + commons = undefined + } + function initialize(callBackFunction) { try { @@ -42,7 +50,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> Entering function."); } - let products = {} + let chart = {} let mainDependency = {} let processingDailyFiles @@ -62,24 +70,33 @@ /* The second phase is about transforming the inputs into a format that can be used to apply the user defined code. */ for (let j = 0; j < global.marketFilesPeriods.length; j++) { - let mapKey = marketFilesPeriods[j][1] - let dataFiles = multiPeriodDataFiles.get(mapKey) - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> Building Dataset for timePeriod = " + mapKey); } + let timePeriodLabel = marketFilesPeriods[j][1] + let dataFiles = multiPeriodDataFiles.get(timePeriodLabel) + let products = {} + + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> Inflating Data Files for timePeriod = " + timePeriodLabel); } if (dataFiles !== undefined) { commons.inflateDatafiles(dataFiles, dataDependencies, products, mainDependency, timePeriod) + + let propertyName = 'at' + timePeriodLabel.replace('-', ''); + chart[propertyName] = products } } for (let j = 0; j < global.dailyFilePeriods.length; j++) { - let mapKey = global.dailyFilePeriods[j][1] - let dataFiles = multiPeriodDataFiles.get(mapKey) + let timePeriodLabel = global.dailyFilePeriods[j][1] + let dataFiles = multiPeriodDataFiles.get(timePeriodLabel) + let products = {} - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> Building Dataset for timePeriod = " + mapKey); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> Inflating Data Files for timePeriod = " + timePeriodLabel); } if (dataFiles !== undefined) { commons.inflateDatafiles(dataFiles, dataDependencies, products, mainDependency, timePeriod) + + let propertyName = 'at' + timePeriodLabel.replace('-', ''); + chart[propertyName] = products } } diff --git a/TradingBotProcessMainLoop.js b/TradingBotProcessMainLoop.js index cb321b0ca..bbb5f013b 100644 --- a/TradingBotProcessMainLoop.js +++ b/TradingBotProcessMainLoop.js @@ -6,7 +6,7 @@ const FULL_LOG = true; let USER_BOT_MODULE; - let COMMONS_MODULE; + let USER_BOT_COMMONS; const MULTI_PERIOD_MARKET = require(ROOT_DIR + 'MultiPeriodMarket'); const MULTI_PERIOD_DAILY = require(ROOT_DIR + 'MultiPeriodDaily'); @@ -81,9 +81,9 @@ return; } - COMMONS_MODULE = {} - //COMMONS_MODULE.newCommons = require(process.env.BOTS_PATH + '/aamasters/AAMasters/bots/AAJason-Trading-Engine-Bot/Commons').newCommons // Use this for a better debugging experience. You need to bring this js module to this folder in order to work. - COMMONS_MODULE.newCommons = eval(text); // Use this for production + USER_BOT_COMMONS = {} + //USER_BOT_COMMONS.newCommons = require(process.env.BOTS_PATH + '/aamasters/AAMasters/bots/AAJason-Trading-Engine-Bot/Commons').newCommons // Use this for a better debugging experience. You need to bring this js module to this folder in order to work. + USER_BOT_COMMONS.newCommons = eval(text); // Use this for production session.initialize(onSessionInitialized) @@ -673,18 +673,8 @@ } switch (processConfig.framework.name) { - case 'Multi-Period-Market': { - processFramework = MULTI_PERIOD_MARKET.newMultiPeriodMarket(bot, logger, COMMONS_MODULE, UTILITIES, USER_BOT_MODULE, COMMONS_MODULE); - intitializeProcessFramework(); - break; - } - case 'Multi-Period-Daily': { - processFramework = MULTI_PERIOD_DAILY.newMultiPeriodDaily(bot, logger, COMMONS_MODULE, UTILITIES, USER_BOT_MODULE, COMMONS_MODULE); - intitializeProcessFramework(); - break; - } case 'Multi-Period': { - processFramework = MULTI_PERIOD.newMultiPeriod(bot, logger, COMMONS_MODULE, UTILITIES, USER_BOT_MODULE, COMMONS_MODULE); + processFramework = MULTI_PERIOD.newMultiPeriod(bot, logger, UTILITIES, USER_BOT_MODULE, USER_BOT_COMMONS); intitializeProcessFramework(); break; }