diff --git a/TaskServer/DataDependencies.js b/TaskServer/DataDependencies.js index 1f92cac95..fecaf9905 100644 --- a/TaskServer/DataDependencies.js +++ b/TaskServer/DataDependencies.js @@ -19,8 +19,8 @@ function initialize(callBackFunction) { try { /* Basic Valdidations */ - if (bot.processNode.referenceParent.processDependencies !== undefined) { - thisObject.nodeArray = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray(bot.processNode.referenceParent.processDependencies, 'Data Dependency') + if (TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processDependencies !== undefined) { + thisObject.nodeArray = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray(TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processDependencies, 'Data Dependency') if (thisObject.nodeArray.length === 0) { logger.write(MODULE_NAME, "[ERROR] initialize -> onInitilized -> It is not possible to not have data dependencies at all."); callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE) diff --git a/TaskServer/IndicatorBot.js b/TaskServer/IndicatorBot.js index f476043d7..c7c62bf54 100644 --- a/TaskServer/IndicatorBot.js +++ b/TaskServer/IndicatorBot.js @@ -36,11 +36,11 @@ /* This bot is not ready for taking its code from the UI, then we need to load it from its repo. */ let filePath = - bot.processNode.referenceParent.parentNode.parentNode.project + // project + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.project + // project '/Bots-Plotters-Code/' + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.config.codeName + "/" + "bots" + "/" + - bot.processNode.referenceParent.parentNode.config.repo + "/" + + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.config.repo + "/" + pProcessConfig.codeName filePath += "/User.Bot.js" @@ -59,7 +59,7 @@ USER_BOT_MODULE = {} USER_BOT_MODULE.newUserBot = eval(text); // TODO This needs to be changed function - filePath = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.config.codeName + "/" + "bots" + "/" + bot.processNode.referenceParent.parentNode.config.repo + filePath = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.config.codeName + "/" + "bots" + "/" + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.config.repo filePath += "/Commons.js" fileStorage.getTextFile(filePath, onCommonsDownloaded); diff --git a/TaskServer/IndicatorOutput.js b/TaskServer/IndicatorOutput.js index 4e8cbd790..db4f4f31d 100644 --- a/TaskServer/IndicatorOutput.js +++ b/TaskServer/IndicatorOutput.js @@ -50,11 +50,11 @@ } /* The first phase here is about checking that we have everything we need at the definition level. */ - let dataDependencies = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray(bot.processNode.referenceParent.processDependencies, 'Data Dependency') + let dataDependencies = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray(TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processDependencies, 'Data Dependency') if (commons.validateDataDependencies(dataDependencies, callBackFunction) !== true) { return } - let outputDatasets = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray (bot.processNode.referenceParent.processOutput, 'Output Dataset') + let outputDatasets = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray (TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset') if (commons.validateOutputDatasets(outputDatasets, callBackFunction) !== true) { return } /* The second phase is about transforming the inputs into a format that can be used to apply the user defined code. */ diff --git a/TaskServer/LearningSession.js b/TaskServer/LearningSession.js index 85743af61..875d42854 100644 --- a/TaskServer/LearningSession.js +++ b/TaskServer/LearningSession.js @@ -1,4 +1,4 @@ -exports.newLearningSession = function newLearningSession(bot, parentLogger) { +exports.newLearningSession = function (processIndex, bot, parentLogger) { const MODULE_NAME = "Learning Session" @@ -15,26 +15,26 @@ exports.newLearningSession = function newLearningSession(bot, parentLogger) { try { /* Initialize this info so that everything is logged propeerly */ bot.LEARNING_SESSION = { - name: bot.processNode.session.name, - id: bot.processNode.session.id + name: TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.name, + id: TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.id } /* Set the folderName for early logging */ - if (bot.processNode.session.config.folderName === undefined) { - bot.LEARNING_SESSION.folderName = bot.processNode.session.type.replace(' ', '-').replace(' ', '-') + '-' + bot.LEARNING_SESSION.id + if (TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.config.folderName === undefined) { + bot.LEARNING_SESSION.folderName = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type.replace(' ', '-').replace(' ', '-') + '-' + bot.LEARNING_SESSION.id } else { - bot.LEARNING_SESSION.folderName = bot.processNode.session.type.replace(' ', '-').replace(' ', '-') + '-' + bot.processNode.session.config.folderName + bot.LEARNING_SESSION.folderName = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type.replace(' ', '-').replace(' ', '-') + '-' + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.config.folderName } /* Check if there is a session */ - if (bot.processNode.session === undefined) { + if (TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session === undefined) { parentLogger.write(MODULE_NAME, "[ERROR] initialize -> Cannot run without a Session."); callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_FAIL_RESPONSE); return; } /* Listen to event to start or stop the session. */ - bot.sessionKey = bot.processNode.session.name + '-' + bot.processNode.session.type + '-' + bot.processNode.session.id + bot.sessionKey = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.name + '-' + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type + '-' + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.id TS.projects.superalgos.globals.taskVariables.SESSION_MAP.set(bot.sessionKey, bot.sessionKey) global.EVENT_SERVER_CLIENT_MODULE.listenToEvent(bot.sessionKey, 'Learning Session Status', undefined, bot.sessionKey, undefined, onSessionStatus) @@ -169,9 +169,9 @@ exports.newLearningSession = function newLearningSession(bot, parentLogger) { if (bot.LEARNING_SESSION.config !== undefined) { config = bot.LEARNING_SESSION.config if (config.folderName === undefined) { - bot.LEARNING_SESSION.folderName = bot.processNode.session.type.replace(' ', '-').replace(' ', '-') + '-' + bot.LEARNING_SESSION.id + bot.LEARNING_SESSION.folderName = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type.replace(' ', '-').replace(' ', '-') + '-' + bot.LEARNING_SESSION.id } else { - bot.LEARNING_SESSION.folderName = bot.processNode.session.type.replace(' ', '-').replace(' ', '-') + '-' + bot.processNode.session.config.folderName + bot.LEARNING_SESSION.folderName = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type.replace(' ', '-').replace(' ', '-') + '-' + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.config.folderName } } } diff --git a/TaskServer/LowFrequencyTrading/Announcements.js b/TaskServer/LowFrequencyTrading/Announcements.js index a5bff8a8f..5278089b1 100644 --- a/TaskServer/LowFrequencyTrading/Announcements.js +++ b/TaskServer/LowFrequencyTrading/Announcements.js @@ -1,4 +1,4 @@ -exports.newAnnouncements = function newAnnouncements(bot, logger) { +exports.newAnnouncements = function (processIndex, bot, logger) { const MODULE_NAME = 'Announcements' diff --git a/TaskServer/LowFrequencyTrading/ExchangeAPI.js b/TaskServer/LowFrequencyTrading/ExchangeAPI.js index 4917a9c09..3c2565f05 100644 --- a/TaskServer/LowFrequencyTrading/ExchangeAPI.js +++ b/TaskServer/LowFrequencyTrading/ExchangeAPI.js @@ -1,4 +1,4 @@ -exports.newExchangeAPI = function newExchangeAPI(bot, logger) { +exports.newExchangeAPI = function (processIndex, bot, logger) { let MODULE_NAME = "Exchange API"; diff --git a/TaskServer/LowFrequencyTrading/Snapshots.js b/TaskServer/LowFrequencyTrading/Snapshots.js index d926e4ba5..461846a9e 100644 --- a/TaskServer/LowFrequencyTrading/Snapshots.js +++ b/TaskServer/LowFrequencyTrading/Snapshots.js @@ -1,4 +1,4 @@ -exports.newSnapshots = function newSnapshots(bot, logger) { +exports.newSnapshots = function (processIndex, bot, logger) { /* This module encapsulates the snapshots functionality. */ diff --git a/TaskServer/LowFrequencyTrading/TradingEpisode.js b/TaskServer/LowFrequencyTrading/TradingEpisode.js index f4afdbe7c..7759ff3a5 100644 --- a/TaskServer/LowFrequencyTrading/TradingEpisode.js +++ b/TaskServer/LowFrequencyTrading/TradingEpisode.js @@ -1,4 +1,4 @@ -exports.newTradingEpisode = function newTradingEpisode(bot, logger, tradingEngineModule) { +exports.newTradingEpisode = function (processIndex, bot, logger, tradingEngineModule) { /* This module packages all functions related to Episodes. */ diff --git a/TaskServer/LowFrequencyTrading/TradingExecution.js b/TaskServer/LowFrequencyTrading/TradingExecution.js index b1e5e3e25..0a6a42543 100644 --- a/TaskServer/LowFrequencyTrading/TradingExecution.js +++ b/TaskServer/LowFrequencyTrading/TradingExecution.js @@ -1,4 +1,4 @@ -exports.newTradingExecution = function newTradingExecution(bot, logger, tradingEngineModule) { +exports.newTradingExecution = function (processIndex, bot, logger, tradingEngineModule) { /* The Trading Execution modules manages the execution nodes and execution algoritms. */ @@ -17,7 +17,7 @@ exports.newTradingExecution = function newTradingExecution(bot, logger, tradingE let sessionParameters const TRADING_ORDERS_MODULE = require('./TradingOrders.js') - let tradingOrdersModule = TRADING_ORDERS_MODULE.newTradingOrders(bot, logger, tradingEngineModule) + let tradingOrdersModule = TRADING_ORDERS_MODULE.newTradingOrders(processIndex, bot, logger, tradingEngineModule) return thisObject diff --git a/TaskServer/LowFrequencyTrading/TradingOrders.js b/TaskServer/LowFrequencyTrading/TradingOrders.js index dbb147677..f1ba3575c 100644 --- a/TaskServer/LowFrequencyTrading/TradingOrders.js +++ b/TaskServer/LowFrequencyTrading/TradingOrders.js @@ -1,4 +1,4 @@ -exports.newTradingOrders = function newTradingOrders(bot, logger, tradingEngineModule) { +exports.newTradingOrders = function (processIndex, bot, logger, tradingEngineModule) { /* The Trading Orders modules manages the execution of orders against the exchanges. */ @@ -17,10 +17,10 @@ exports.newTradingOrders = function newTradingOrders(bot, logger, tradingEngineM let sessionParameters const EXCHANGE_API_MODULE = require('./ExchangeAPI.js') - let exchangeAPIModule = EXCHANGE_API_MODULE.newExchangeAPI(bot, logger) + let exchangeAPIModule = EXCHANGE_API_MODULE.newExchangeAPI(processIndex, bot, logger) const ANNOUNCEMENTS_MODULE = require('./Announcements.js') - let announcementsModule = ANNOUNCEMENTS_MODULE.newAnnouncements(bot, logger) + let announcementsModule = ANNOUNCEMENTS_MODULE.newAnnouncements(processIndex, bot, logger) return thisObject diff --git a/TaskServer/LowFrequencyTrading/TradingOutput.js b/TaskServer/LowFrequencyTrading/TradingOutput.js index baae5bf28..efb8ce9a0 100644 --- a/TaskServer/LowFrequencyTrading/TradingOutput.js +++ b/TaskServer/LowFrequencyTrading/TradingOutput.js @@ -40,7 +40,7 @@ exports.newTradingOutput = function (processIndex, bot, logger, tradingEngineMod const TRADING_SIMULATION = require('./TradingSimulation.js') let tradingSimulation = TRADING_SIMULATION.newTradingSimulation(processIndex, bot, logger, tradingEngineModule, UTILITIES) - let outputDatasets = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray(bot.processNode.referenceParent.processOutput, 'Output Dataset') + let outputDatasets = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray(TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset') let outputDatasetsMap = new Map() if (bot.processingDailyFiles === true) { diff --git a/TaskServer/LowFrequencyTrading/TradingPosition.js b/TaskServer/LowFrequencyTrading/TradingPosition.js index 1f598f384..2fa99d69e 100644 --- a/TaskServer/LowFrequencyTrading/TradingPosition.js +++ b/TaskServer/LowFrequencyTrading/TradingPosition.js @@ -1,4 +1,4 @@ -exports.newTradingPosition = function newTradingPosition(bot, logger, tradingEngineModule) { +exports.newTradingPosition = function (processIndex, bot, logger, tradingEngineModule) { /* This module packages all functions related to Positions. */ diff --git a/TaskServer/LowFrequencyTrading/TradingProcess.js b/TaskServer/LowFrequencyTrading/TradingProcess.js index ed3a3d737..a4b8b8143 100644 --- a/TaskServer/LowFrequencyTrading/TradingProcess.js +++ b/TaskServer/LowFrequencyTrading/TradingProcess.js @@ -555,7 +555,7 @@ let mainDependency = {} /* The first phase here is about checking that we have everything we need at the definition level. */ - let dataDependencies = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray(bot.processNode.referenceParent.processDependencies, 'Data Dependency') + let dataDependencies = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray(TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processDependencies, 'Data Dependency') /* We will filter ourt declared dependencies that are not present in the workspace. This will allow the user to have less Data Mines loaded at the workspace @@ -565,7 +565,7 @@ if (commons.validateDataDependencies(dataDependencies, callBackFunction) !== true) { return } - let outputDatasets = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray(bot.processNode.referenceParent.processOutput, 'Output Dataset') + let outputDatasets = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray(TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset') if (commons.validateOutputDatasets(outputDatasets, callBackFunction) !== true) { return } /* The second phase is about transforming the inputs into a format that can be used to apply the user defined code. */ @@ -624,7 +624,7 @@ } async function writeProcessFiles() { - let outputDatasets = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray(bot.processNode.referenceParent.processOutput, 'Output Dataset') + let outputDatasets = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray(TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset') await writeTimeFramesFiles(currentTimeFrame, currentTimeFrameLabel) await writeDataRanges() @@ -703,7 +703,7 @@ } async function writeDailyStatusReport(currentTimeFrameLabel) { - let reportKey = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.config.codeName + "-" + bot.codeName + "-" + bot.processNode.referenceParent.config.codeName + let reportKey = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.config.codeName + "-" + bot.codeName + "-" + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.config.codeName let thisReport = statusDependencies.statusReports.get(reportKey) thisReport.file.lastExecution = bot.currentDaytime @@ -714,7 +714,7 @@ } async function writeMarketStatusReport(currentTimeFrameLabel) { - let reportKey = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.config.codeName + "-" + bot.codeName + "-" + bot.processNode.referenceParent.config.codeName + let reportKey = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.config.codeName + "-" + bot.codeName + "-" + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.config.codeName let thisReport = statusDependencies.statusReports.get(reportKey); thisReport.file.lastExecution = bot.processDatetime diff --git a/TaskServer/LowFrequencyTrading/TradingRecords.js b/TaskServer/LowFrequencyTrading/TradingRecords.js index 12599a70c..bef58532e 100644 --- a/TaskServer/LowFrequencyTrading/TradingRecords.js +++ b/TaskServer/LowFrequencyTrading/TradingRecords.js @@ -1,4 +1,4 @@ -exports.newTradingRecords = function newTradingRecords(bot, logger) { +exports.newTradingRecords = function (processIndex, bot, logger) { /* This module facilitates the appending of records to the output of the process. */ @@ -37,7 +37,7 @@ exports.newTradingRecords = function newTradingRecords(bot, logger) { we have a pointer to the node that have the information we need to extract. Later, based on the product record definition we will extract each individual value. */ - let outputDatasets = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray(bot.processNode.referenceParent.processOutput, 'Output Dataset') + let outputDatasets = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray(TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset') for (let i = 0; i < outputDatasets.length; i++) { let outputDatasetNode = outputDatasets[i] diff --git a/TaskServer/LowFrequencyTrading/TradingSimulation.js b/TaskServer/LowFrequencyTrading/TradingSimulation.js index f8065a072..ed8fe75cd 100644 --- a/TaskServer/LowFrequencyTrading/TradingSimulation.js +++ b/TaskServer/LowFrequencyTrading/TradingSimulation.js @@ -35,15 +35,15 @@ exports.newTradingSimulation = function (processIndex, bot, logger, tradingEngin /* These are the Modules we will need to run the Simulation */ const TRADING_RECORDS_MODULE = require('./TradingRecords.js') - let tradingRecordsModule = TRADING_RECORDS_MODULE.newTradingRecords(bot, logger) + let tradingRecordsModule = TRADING_RECORDS_MODULE.newTradingRecords(processIndex, bot, logger) tradingRecordsModule.initialize(outputDatasetsMap) const TRADING_SYSTEM_MODULE = require('./TradingSystem.js') - let tradingSystemModule = TRADING_SYSTEM_MODULE.newTradingSystem(bot, logger, tradingEngineModule) + let tradingSystemModule = TRADING_SYSTEM_MODULE.newTradingSystem(processIndex, bot, logger, tradingEngineModule) tradingSystemModule.initialize() const TRADING_EPISODE_MODULE = require('./TradingEpisode.js') - let tradingEpisodeModule = TRADING_EPISODE_MODULE.newTradingEpisode(bot, logger, tradingEngineModule) + let tradingEpisodeModule = TRADING_EPISODE_MODULE.newTradingEpisode(processIndex, bot, logger, tradingEngineModule) tradingEpisodeModule.initialize() /* Setting up the candles array: The whole simulation is based on the array of candles at the time-frame defined at the session parameters. */ @@ -313,7 +313,7 @@ exports.newTradingSimulation = function (processIndex, bot, logger, tradingEngin easy access to the current candle for instance, or the current bollinger band, meaning the one the Simulation is currently standing at. For that reason we do the following processing, to have at the chart data structure the current objects of each indicator / time frame. */ - let dataDependencies = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray(bot.processNode.referenceParent.processDependencies, 'Data Dependency') + let dataDependencies = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray(TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processDependencies, 'Data Dependency') dataDependencies = TS.projects.superalgos.utilities.nodeFunctions.filterOutNodeWihtoutReferenceParentFromNodeArray(dataDependencies) /* Finding the Current Element on Market Files */ diff --git a/TaskServer/LowFrequencyTrading/TradingStages.js b/TaskServer/LowFrequencyTrading/TradingStages.js index aa2919ceb..6ded05b52 100644 --- a/TaskServer/LowFrequencyTrading/TradingStages.js +++ b/TaskServer/LowFrequencyTrading/TradingStages.js @@ -1,4 +1,4 @@ -exports.newTradingStages = function newTradingStages(bot, logger, tradingEngineModule) { +exports.newTradingStages = function (processIndex, bot, logger, tradingEngineModule) { /* This module packages all functions related to Stages. */ @@ -21,22 +21,22 @@ exports.newTradingStages = function newTradingStages(bot, logger, tradingEngineM } const TRADING_STRATEGY_MODULE = require('./TradingStrategy.js') - let tradingStrategyModule = TRADING_STRATEGY_MODULE.newTradingStrategy(bot, logger, tradingEngineModule) + let tradingStrategyModule = TRADING_STRATEGY_MODULE.newTradingStrategy(processIndex, bot, logger, tradingEngineModule) const TRADING_POSITION_MODULE = require('./TradingPosition.js') - let tradingPositionModule = TRADING_POSITION_MODULE.newTradingPosition(bot, logger, tradingEngineModule) + let tradingPositionModule = TRADING_POSITION_MODULE.newTradingPosition(processIndex, bot, logger, tradingEngineModule) const TRADING_ENGINE_EXECUTION = require('./TradingExecution.js') - let tradingExecutionModule = TRADING_ENGINE_EXECUTION.newTradingExecution(bot, logger, tradingEngineModule) + let tradingExecutionModule = TRADING_ENGINE_EXECUTION.newTradingExecution(processIndex, bot, logger, tradingEngineModule) const ANNOUNCEMENTS_MODULE = require('./Announcements.js') - let announcementsModule = ANNOUNCEMENTS_MODULE.newAnnouncements(bot, logger) + let announcementsModule = ANNOUNCEMENTS_MODULE.newAnnouncements(processIndex, bot, logger) const SNAPSHOTS_MODULE = require('./Snapshots.js') - let snapshotsModule = SNAPSHOTS_MODULE.newSnapshots(bot, logger) + let snapshotsModule = SNAPSHOTS_MODULE.newSnapshots(processIndex, bot, logger) const TRADING_EPISODE_MODULE = require('./TradingEpisode.js') - let tradingEpisodeModule = TRADING_EPISODE_MODULE.newTradingEpisode(bot, logger) + let tradingEpisodeModule = TRADING_EPISODE_MODULE.newTradingEpisode(processIndex, bot, logger) let tradingEngine let tradingSystem @@ -907,7 +907,7 @@ exports.newTradingStages = function newTradingStages(bot, logger, tradingEngineM case 'Base Asset': { if ( ( - tradingEngineStage.stageBaseAsset.sizeFilled.value + tradingEngineStage.stageBaseAsset.sizeFilled.value ) * ROUNDING_ERROR_CORRECTION_FACTOR >= @@ -922,7 +922,7 @@ exports.newTradingStages = function newTradingStages(bot, logger, tradingEngineM case 'Quoted Asset': { if ( ( - tradingEngineStage.stageQuotedAsset.sizeFilled.value + tradingEngineStage.stageQuotedAsset.sizeFilled.value ) * ROUNDING_ERROR_CORRECTION_FACTOR >= diff --git a/TaskServer/LowFrequencyTrading/TradingStrategy.js b/TaskServer/LowFrequencyTrading/TradingStrategy.js index 7c53fe393..3183705c9 100644 --- a/TaskServer/LowFrequencyTrading/TradingStrategy.js +++ b/TaskServer/LowFrequencyTrading/TradingStrategy.js @@ -1,4 +1,4 @@ -exports.newTradingStrategy = function newTradingStrategy(bot, logger, tradingEngineModule) { +exports.newTradingStrategy = function (processIndex, bot, logger, tradingEngineModule) { /* This module packages all functions related to Strategies. */ diff --git a/TaskServer/LowFrequencyTrading/TradingSystem.js b/TaskServer/LowFrequencyTrading/TradingSystem.js index 3c0890d86..e2e748702 100644 --- a/TaskServer/LowFrequencyTrading/TradingSystem.js +++ b/TaskServer/LowFrequencyTrading/TradingSystem.js @@ -1,4 +1,4 @@ -exports.newTradingSystem = function newTradingSystem(bot, logger, tradingEngineModule) { +exports.newTradingSystem = function (processIndex, bot, logger, tradingEngineModule) { /* The Trading System is the user defined set of rules compliant with the Trading Protocol that defines the trading logic to be applied during each cycle of the Simulation. @@ -20,7 +20,7 @@ exports.newTradingSystem = function newTradingSystem(bot, logger, tradingEngineM let dynamicIndicators const TRADING_STAGES_MODULE = require('./TradingStages.js') - let tradingStagesModule = TRADING_STAGES_MODULE.newTradingStages(bot, logger, tradingEngineModule) + let tradingStagesModule = TRADING_STAGES_MODULE.newTradingStages(processIndex, bot, logger, tradingEngineModule) return thisObject diff --git a/TaskServer/MultiPeriodDaily.js b/TaskServer/MultiPeriodDaily.js index fd320326f..00874c9a4 100644 --- a/TaskServer/MultiPeriodDaily.js +++ b/TaskServer/MultiPeriodDaily.js @@ -467,7 +467,7 @@ } function writeDataRanges(callBack) { - let outputDatasets = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray(bot.processNode.referenceParent.processOutput, 'Output Dataset') + let outputDatasets = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray(TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset') let outputDatasetIndex = -1; controlLoop() diff --git a/TaskServer/MultiPeriodMarket.js b/TaskServer/MultiPeriodMarket.js index 33e773316..440947a22 100644 --- a/TaskServer/MultiPeriodMarket.js +++ b/TaskServer/MultiPeriodMarket.js @@ -141,7 +141,7 @@ } function writeTimeFramesFiles(callBack) { - let outputDatasets = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray (bot.processNode.referenceParent.processOutput, 'Output Dataset') + let outputDatasets = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray (TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset') let outputDatasetIndex = -1; controlLoop() diff --git a/TaskServer/ProcessExecutionEvents.js b/TaskServer/ProcessExecutionEvents.js index 670f4a019..8c93c1ae2 100644 --- a/TaskServer/ProcessExecutionEvents.js +++ b/TaskServer/ProcessExecutionEvents.js @@ -30,14 +30,14 @@ let name = 'Not Depends on any Process' logger.fileName = MODULE_NAME + "." + name; - if (bot.processNode.referenceParent === undefined) { + if (TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent === undefined) { callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_FAIL_RESPONSE); logger.write(MODULE_NAME, "[ERROR] initialize -> Initialization Failed because the Process Instance needs to have a Reference Parent."); return } let market = TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.baseAsset.referenceParent.config.codeName + '/' + TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.quotedAsset.referenceParent.config.codeName - currentProcessKey = bot.processNode.referenceParent.name + "-" + bot.processNode.referenceParent.type + "-" + bot.processNode.referenceParent.id + "-" + TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.parentNode.parentNode.name + "-" + market + currentProcessKey = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.name + "-" + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.type + "-" + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.id + "-" + TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.parentNode.parentNode.name + "-" + market /* A process can depend for its own execution on another process to finish, and @@ -51,10 +51,10 @@ /* Here we check if we can find this relationship at the Data Mine level. */ - if (bot.processNode.referenceParent.executionStartedEvent !== undefined) { - if (bot.processNode.referenceParent.executionStartedEvent.referenceParent !== undefined) { - if (bot.processNode.referenceParent.executionStartedEvent.referenceParent.parentNode !== undefined) { - processThisDependsOn = bot.processNode.referenceParent.executionStartedEvent.referenceParent.parentNode + if (TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.executionStartedEvent !== undefined) { + if (TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.executionStartedEvent.referenceParent !== undefined) { + if (TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.executionStartedEvent.referenceParent.parentNode !== undefined) { + processThisDependsOn = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.executionStartedEvent.referenceParent.parentNode name = processThisDependsOn.name logger.write(MODULE_NAME, "[INFO] initialize -> " + currentProcessKey + " based on the Data Mine depends on " + name) @@ -65,10 +65,10 @@ /* Here we check if at the task level if there is an overriding configuration. */ - if (bot.processNode.executionStartedEvent !== undefined) { - if (bot.processNode.executionStartedEvent.referenceParent !== undefined) { - if (bot.processNode.executionStartedEvent.referenceParent.parentNode !== undefined) { - processThisDependsOn = bot.processNode.executionStartedEvent.referenceParent.parentNode + if (TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].executionStartedEvent !== undefined) { + if (TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].executionStartedEvent.referenceParent !== undefined) { + if (TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].executionStartedEvent.referenceParent.parentNode !== undefined) { + processThisDependsOn = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].executionStartedEvent.referenceParent.parentNode name = processThisDependsOn.name logger.write(MODULE_NAME, "[INFO] initialize -> " + currentProcessKey + " based on the User's Task depends on " + name) diff --git a/TaskServer/ProcessInstance.js b/TaskServer/ProcessInstance.js index 79fcb1b9e..ebcdcd816 100644 --- a/TaskServer/ProcessInstance.js +++ b/TaskServer/ProcessInstance.js @@ -32,9 +32,7 @@ TS.projects.superalgos.globals.taskVariables.LOGGER_MAP.set('Pre-Bot-Main-Loop' + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].id, logger) logger.bot = botConfig; - botConfig.process = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.config.codeName botConfig.debug = {}; - botConfig.processNode = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex] /* Logs Mantainance Stuff */ botConfig.LOGS_TO_DELETE_QUEUE = [] diff --git a/TaskServer/ProcessOutput.js b/TaskServer/ProcessOutput.js index 88bfcf6ce..beabe87ac 100644 --- a/TaskServer/ProcessOutput.js +++ b/TaskServer/ProcessOutput.js @@ -1,4 +1,4 @@ -exports.newProcessOutput = function newProcessOutput(BOT, logger) { +exports.newProcessOutput = function (processIndex, BOT, logger) { /* Here we emit the events that signals that a Dataset was updated. @@ -19,8 +19,8 @@ try { /* We will reaise the events for the datasets impacted by the process that just finished. */ - if (bot.processNode.referenceParent.processOutput !== undefined) { - let outputDatasets = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray(bot.processNode.referenceParent.processOutput, 'Output Dataset') + if (TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput !== undefined) { + let outputDatasets = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray(TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset') for (let j = 0; j < outputDatasets.length; j++) { let outputDataset = outputDatasets[j] @@ -109,8 +109,8 @@ function asyncRaiseEvents(lastFile, timeFrames) { - if (bot.processNode.referenceParent.processOutput !== undefined) { - let outputDatasets = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray(bot.processNode.referenceParent.processOutput, 'Output Dataset') + if (TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput !== undefined) { + let outputDatasets = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray(TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset') for (let j = 0; j < outputDatasets.length; j++) { let outputDataset = outputDatasets[j] diff --git a/TaskServer/ReinforcementLearning/LearningBot.js b/TaskServer/ReinforcementLearning/LearningBot.js index cd96d7637..b8d815014 100644 --- a/TaskServer/ReinforcementLearning/LearningBot.js +++ b/TaskServer/ReinforcementLearning/LearningBot.js @@ -1,4 +1,4 @@ -exports.newLearningBot = function newLearningBot(processIndex, bot, parentLogger) { +exports.newLearningBot = function (processIndex, bot, parentLogger) { const MODULE_NAME = "Learning Bot"; const FULL_LOG = true; @@ -8,7 +8,7 @@ exports.newLearningBot = function newLearningBot(processIndex, bot, parentLogger const SESSION = require(TS.projects.superalgos.globals.nodeJSConstants.REQUIRE_ROOT_DIR + 'TradingSession'); let fileStorage = FILE_STORAGE.newFileStorage(parentLogger); - let session = SESSION.newLearningSession(bot, parentLogger) + let session = SESSION.newLearningSession(processIndex, bot, parentLogger) const DEBUG_MODULE = require(TS.projects.superalgos.globals.nodeJSConstants.REQUIRE_ROOT_DIR + 'DebugLog'); let logger; // We need this here in order for the loopHealth function to work and be able to rescue the loop when it gets in trouble. @@ -90,7 +90,7 @@ exports.newLearningBot = function newLearningBot(processIndex, bot, parentLogger /* High level log entry */ console.log(new Date().toISOString() + " " + pad(TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.parentNode.parentNode.name, 20) + " " + pad(TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.baseAsset.referenceParent.config.codeName + '/' + TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.quotedAsset.referenceParent.config.codeName, 10) + " " + pad(bot.codeName, 30) + " " + pad(TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.config.codeName, 30) - + " Main Loop # " + pad(Number(bot.loopCounter), 8) + " " + bot.processNode.session.type + " " + bot.processNode.session.name) + + " Main Loop # " + pad(Number(bot.loopCounter), 8) + " " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type + " " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.name) /* Checking if we need to need to emit any event */ if (bot.SESSION_STATUS === 'Idle' && bot.STOP_SESSION === false) { @@ -106,10 +106,10 @@ exports.newLearningBot = function newLearningBot(processIndex, bot, parentLogger /* Checking if we should process this loop or not.*/ if (bot.STOP_SESSION === true) { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> Waiting for " + bot.processNode.session.type + " " + bot.processNode.session.name + " to be run."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> Waiting for " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type + " " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.name + " to be run."); } console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.config.codeName, 30) - + " Waiting for " + bot.processNode.session.type + " " + bot.processNode.session.name + " to be run. "); + + " Waiting for " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type + " " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.name + " to be run. "); nextWaitTime = 'Waiting for Session'; loopControl(nextWaitTime); @@ -548,7 +548,7 @@ exports.newLearningBot = function newLearningBot(processIndex, bot, parentLogger waitingTime = waitTime / 1000 label = 'seconds' } - processHeartBeat(undefined, undefined, "Waiting " + waitingTime + " " + label + " for " + bot.processNode.session.type + " " + bot.processNode.session.name + " to be run. ") + processHeartBeat(undefined, undefined, "Waiting " + waitingTime + " " + label + " for " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type + " " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.name + " to be run. ") logger.persist(); } break diff --git a/TaskServer/ReinforcementLearning/LearningProcess.js b/TaskServer/ReinforcementLearning/LearningProcess.js index ce0286a4b..7d77e1f43 100644 --- a/TaskServer/ReinforcementLearning/LearningProcess.js +++ b/TaskServer/ReinforcementLearning/LearningProcess.js @@ -555,7 +555,7 @@ exports.newLearningProcess = function (processIndex, bot, logger, UTILITIES) { let mainDependency = {} /* The first phase here is about checking that we have everything we need at the definition level. */ - let dataDependencies = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray(bot.processNode.referenceParent.processDependencies, 'Data Dependency') + let dataDependencies = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray(TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processDependencies, 'Data Dependency') /* We will filter ourt declared dependencies that are not present in the workspace. This will allow the user to have less Data Mines loaded at the workspace @@ -565,7 +565,7 @@ exports.newLearningProcess = function (processIndex, bot, logger, UTILITIES) { if (commons.validateDataDependencies(dataDependencies, callBackFunction) !== true) { return } - let outputDatasets = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray(bot.processNode.referenceParent.processOutput, 'Output Dataset') + let outputDatasets = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray(TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset') if (commons.validateOutputDatasets(outputDatasets, callBackFunction) !== true) { return } /* The second phase is about transforming the inputs into a format that can be used to apply the user defined code. */ @@ -624,7 +624,7 @@ exports.newLearningProcess = function (processIndex, bot, logger, UTILITIES) { } async function writeProcessFiles() { - let outputDatasets = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray(bot.processNode.referenceParent.processOutput, 'Output Dataset') + let outputDatasets = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray(TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset') await writeTimeFramesFiles(currentTimeFrame, currentTimeFrameLabel) await writeDataRanges() @@ -703,7 +703,7 @@ exports.newLearningProcess = function (processIndex, bot, logger, UTILITIES) { } async function writeDailyStatusReport(currentTimeFrameLabel) { - let reportKey = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.config.codeName + "-" + bot.codeName + "-" + bot.processNode.referenceParent.config.codeName + let reportKey = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.config.codeName + "-" + bot.codeName + "-" + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.config.codeName let thisReport = statusDependencies.statusReports.get(reportKey) thisReport.file.lastExecution = bot.currentDaytime @@ -714,7 +714,7 @@ exports.newLearningProcess = function (processIndex, bot, logger, UTILITIES) { } async function writeMarketStatusReport(currentTimeFrameLabel) { - let reportKey = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.config.codeName + "-" + bot.codeName + "-" + bot.processNode.referenceParent.config.codeName + let reportKey = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.config.codeName + "-" + bot.codeName + "-" + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.config.codeName let thisReport = statusDependencies.statusReports.get(reportKey); thisReport.file.lastExecution = bot.processDatetime diff --git a/TaskServer/SensorBot.js b/TaskServer/SensorBot.js index 5ada906e5..215fd1fb5 100644 --- a/TaskServer/SensorBot.js +++ b/TaskServer/SensorBot.js @@ -35,11 +35,11 @@ } let filePath = - bot.processNode.referenceParent.parentNode.parentNode.project + // project + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.project + // project '/Bots-Plotters-Code/' + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.config.codeName + "/" + "bots" + "/" + - bot.processNode.referenceParent.parentNode.config.repo + "/" + + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.config.repo + "/" + pProcessConfig.codeName filePath += "/User.Bot.js" @@ -62,7 +62,7 @@ callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_FAIL_RESPONSE); } - filePath = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.config.codeName + "/" + "bots" + "/" + bot.processNode.referenceParent.parentNode.config.repo; + filePath = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.config.codeName + "/" + "bots" + "/" + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.config.repo; filePath += "/Commons.js" fileStorage.getTextFile(filePath, onCommonsDownloaded); diff --git a/TaskServer/StatusDependencies.js b/TaskServer/StatusDependencies.js index 1e8262b3b..ccffccbac 100644 --- a/TaskServer/StatusDependencies.js +++ b/TaskServer/StatusDependencies.js @@ -18,9 +18,9 @@ function initialize(callBackFunction) { try { /* Basic Valdidations */ - if (bot.processNode.referenceParent.processDependencies !== undefined) { - if (bot.processNode.referenceParent.processDependencies.statusDependencies !== undefined) { - thisObject.nodeArray = bot.processNode.referenceParent.processDependencies.statusDependencies + if (TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processDependencies !== undefined) { + if (TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processDependencies.statusDependencies !== undefined) { + thisObject.nodeArray = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processDependencies.statusDependencies } else { logger.write(MODULE_NAME, "[ERROR] initialize -> onInitilized -> It is not possible to not have status dependencies at all."); callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE) diff --git a/TaskServer/StatusReport.js b/TaskServer/StatusReport.js index 47367ed28..1a25a5723 100644 --- a/TaskServer/StatusReport.js +++ b/TaskServer/StatusReport.js @@ -146,7 +146,7 @@ if (processThisDependsOn.id === processDefinition.id) { if (process.type === 'Trading Process Instance') { if (process.session !== undefined) { - if (bot.processNode.session.id !== process.session.id) { + if (TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.id !== process.session.id) { continue } } else { @@ -197,7 +197,7 @@ if (processThisDependsOn.id === processDefinition.id) { if (process.type === 'Trading Process Instance') { if (process.session !== undefined) { - if (bot.processNode.session.id !== process.session.id) { + if (TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.id !== process.session.id) { continue } } else { @@ -372,7 +372,7 @@ /* All good, lets emit the event that means data has been updated. */ - let processOutput = PROCESS_OUTPUT.newProcessOutput(bot, logger) + let processOutput = PROCESS_OUTPUT.newProcessOutput(processIndex, bot, logger) processOutput.raiseEvents(thisObject.file.lastFile, thisObject.file.timeFrames, callBackFunction); return } @@ -399,7 +399,7 @@ } /* All good, lets emit the event that means data has been updated. */ - let processOutput = PROCESS_OUTPUT.newProcessOutput(bot, logger) + let processOutput = PROCESS_OUTPUT.newProcessOutput(processIndex, bot, logger) processOutput.asyncRaiseEvents(thisObject.file.lastFile, thisObject.file.timeFrames) } } diff --git a/TaskServer/TradingBot.js b/TaskServer/TradingBot.js index f259d61d0..a5f375e79 100644 --- a/TaskServer/TradingBot.js +++ b/TaskServer/TradingBot.js @@ -8,7 +8,7 @@ const SESSION = require(TS.projects.superalgos.globals.nodeJSConstants.REQUIRE_ROOT_DIR + 'TradingSession'); let fileStorage = FILE_STORAGE.newFileStorage(parentLogger); - let session = SESSION.newTradingSession(bot, parentLogger) + let session = SESSION.newTradingSession(processIndex, bot, parentLogger) const DEBUG_MODULE = require(TS.projects.superalgos.globals.nodeJSConstants.REQUIRE_ROOT_DIR + 'DebugLog'); let logger; // We need this here in order for the loopHealth function to work and be able to rescue the loop when it gets in trouble. @@ -90,7 +90,7 @@ /* High level log entry */ console.log(new Date().toISOString() + " " + pad(TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.parentNode.parentNode.name, 20) + " " + pad(TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.baseAsset.referenceParent.config.codeName + '/' + TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.quotedAsset.referenceParent.config.codeName, 10) + " " + pad(bot.codeName, 30) + " " + pad(TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.config.codeName, 30) - + " Main Loop # " + pad(Number(bot.loopCounter), 8) + " " + bot.processNode.session.type + " " + bot.processNode.session.name) + + " Main Loop # " + pad(Number(bot.loopCounter), 8) + " " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type + " " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.name) /* Checking if we need to need to emit any event */ if (bot.TRADING_SESSION_STATUS === 'Idle' && bot.STOP_SESSION === false) { @@ -106,10 +106,10 @@ /* Checking if we should process this loop or not.*/ if (bot.STOP_SESSION === true) { - logger.write(MODULE_NAME, "[INFO] run -> loop -> Waiting for " + bot.processNode.session.type + " " + bot.processNode.session.name + " to be run.") + logger.write(MODULE_NAME, "[INFO] run -> loop -> Waiting for " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type + " " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.name + " to be run.") console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.config.codeName, 30) - + " Waiting for " + bot.processNode.session.type + " " + bot.processNode.session.name + " to be run. "); + + " Waiting for " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type + " " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.name + " to be run. "); nextWaitTime = 'Waiting for Session'; loopControl(nextWaitTime); @@ -548,7 +548,7 @@ waitingTime = waitTime / 1000 label = 'seconds' } - processHeartBeat(undefined, undefined, "Waiting " + waitingTime + " " + label + " for " + bot.processNode.session.type + " " + bot.processNode.session.name + " to be run. ") + processHeartBeat(undefined, undefined, "Waiting " + waitingTime + " " + label + " for " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type + " " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.name + " to be run. ") logger.persist(); } break diff --git a/TaskServer/TradingSession.js b/TaskServer/TradingSession.js index 2ad296188..71a51287c 100644 --- a/TaskServer/TradingSession.js +++ b/TaskServer/TradingSession.js @@ -1,4 +1,4 @@ -exports.newTradingSession = function newTradingSession(bot, parentLogger) { +exports.newTradingSession = function (processIndex, bot, parentLogger) { const MODULE_NAME = "Trading Session" @@ -15,26 +15,26 @@ try { /* Initialize this info so that everything is logged propeerly */ bot.TRADING_SESSION = { - name: bot.processNode.session.name, - id: bot.processNode.session.id + name: TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.name, + id: TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.id } /* Set the folderName for early logging */ - if (bot.processNode.session.config.folderName === undefined) { - bot.TRADING_SESSION.folderName = bot.processNode.session.type.replace(' ', '-').replace(' ', '-') + '-' + bot.TRADING_SESSION.id + if (TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.config.folderName === undefined) { + bot.TRADING_SESSION.folderName = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type.replace(' ', '-').replace(' ', '-') + '-' + bot.TRADING_SESSION.id } else { - bot.TRADING_SESSION.folderName = bot.processNode.session.type.replace(' ', '-').replace(' ', '-') + '-' + bot.processNode.session.config.folderName + bot.TRADING_SESSION.folderName = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type.replace(' ', '-').replace(' ', '-') + '-' + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.config.folderName } /* Check if there is a session */ - if (bot.processNode.session === undefined) { + if (TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session === undefined) { parentLogger.write(MODULE_NAME, "[ERROR] initialize -> Cannot run without a Session."); callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_FAIL_RESPONSE); return; } /* Listen to event to start or stop the session. */ - bot.TRADING_SESSIONKey = bot.processNode.session.name + '-' + bot.processNode.session.type + '-' + bot.processNode.session.id + bot.TRADING_SESSIONKey = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.name + '-' + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type + '-' + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.id TS.projects.superalgos.globals.taskVariables.SESSION_MAP.set(bot.TRADING_SESSIONKey, bot.TRADING_SESSIONKey) global.EVENT_SERVER_CLIENT_MODULE.listenToEvent(bot.TRADING_SESSIONKey, 'Trading Session Status', undefined, bot.TRADING_SESSIONKey, undefined, onSessionStatus) @@ -169,9 +169,9 @@ if (bot.TRADING_SESSION.config !== undefined) { config = bot.TRADING_SESSION.config if (config.folderName === undefined) { - bot.TRADING_SESSION.folderName = bot.processNode.session.type.replace(' ', '-').replace(' ', '-') + '-' + bot.TRADING_SESSION.id + bot.TRADING_SESSION.folderName = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type.replace(' ', '-').replace(' ', '-') + '-' + bot.TRADING_SESSION.id } else { - bot.TRADING_SESSION.folderName = bot.processNode.session.type.replace(' ', '-').replace(' ', '-') + '-' + bot.processNode.session.config.folderName + bot.TRADING_SESSION.folderName = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type.replace(' ', '-').replace(' ', '-') + '-' + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.config.folderName } } }