diff --git a/Projects/ProjectsSchema.json b/Projects/ProjectsSchema.json index ff131c3c2..a591ad01b 100644 --- a/Projects/ProjectsSchema.json +++ b/Projects/ProjectsSchema.json @@ -346,11 +346,23 @@ } ], "functionLibraries": [ + { + "name": "Task Functions", + "propertyName": "taskFunctions", + "functionName": "newSuperalgosFunctionLibrariesTastFunctions", + "fileName": "TaskFunctions.js" + }, { "name": "Process Functions", "propertyName": "processFunctions", "functionName": "newSuperalgosFunctionLibrariesProcessFunctions", "fileName": "ProcessFunctions.js" + }, + { + "name": "Session Functions", + "propertyName": "sessionFunctions", + "functionName": "newSuperalgosFunctionLibrariesSessionFunctions", + "fileName": "SessionFunctions.js" } ], "utilities": [ diff --git a/Projects/Superalgos/TS/Function-Libraries/SessionFunctions.js b/Projects/Superalgos/TS/Function-Libraries/SessionFunctions.js new file mode 100644 index 000000000..bf9539ab1 --- /dev/null +++ b/Projects/Superalgos/TS/Function-Libraries/SessionFunctions.js @@ -0,0 +1,30 @@ +exports.newSuperalgosFunctionLibrariesSessionFunctions = function () { + + let thisObject = { + emitSessionStatus: emitSessionStatus, + finalizeSessions: finalizeSessions + } + + return thisObject + + function emitSessionStatus (status, key) { + switch (status) { + case 'Running': { + global.EVENT_SERVER_CLIENT_MODULE.raiseEvent(key, 'Running') + break + } + case 'Stopped': { + global.EVENT_SERVER_CLIENT_MODULE.raiseEvent(key, 'Stopped') + break + } + } + } + + function finalizeSessions () { + global.SESSION_MAP.forEach(forEachSession) + + function forEachSession(session) { + global.EVENT_SERVER_CLIENT_MODULE.raiseEvent(session, 'Stopped') + } + } +} \ No newline at end of file diff --git a/Projects/Superalgos/TS/Function-Libraries/TaskFunctions.js b/Projects/Superalgos/TS/Function-Libraries/TaskFunctions.js new file mode 100644 index 000000000..865e6d2bb --- /dev/null +++ b/Projects/Superalgos/TS/Function-Libraries/TaskFunctions.js @@ -0,0 +1,26 @@ +exports.newSuperalgosFunctionLibrariesTastFunctions = function () { + + let thisObject = { + taskError: taskError + } + + return thisObject + + function taskError(node, errorMessage) { + let event + if (node !== undefined) { + event = { + nodeName: node.name, + nodeType: node.type, + nodeId: node.id, + errorMessage: errorMessage + } + } else { + event = { + errorMessage: errorMessage + } + } + let key = global.TASK_NODE.name + '-' + global.TASK_NODE.type + '-' + global.TASK_NODE.id + global.EVENT_SERVER_CLIENT_MODULE.raiseEvent(key, 'Error', event) + } +} \ No newline at end of file diff --git a/TaskServer/Globals.js b/TaskServer/Globals.js index 6ee5d68e7..9470e09c6 100644 --- a/TaskServer/Globals.js +++ b/TaskServer/Globals.js @@ -33,20 +33,6 @@ exports.newGlobals = function newGlobals() { return new Date(date.getUTCFullYear() + "-" + (date.getUTCMonth() + 1) + "-" + date.getUTCDate() + " " + "00:00" + GMT_SECONDS); } - global.EMIT_SESSION_STATUS = function (status, key) { - switch (status) { - case 'Running': { - global.EVENT_SERVER_CLIENT_MODULE.raiseEvent(key, 'Running') - break - } - case 'Stopped': { - global.EVENT_SERVER_CLIENT_MODULE.raiseEvent(key, 'Stopped') - break - } - } - } - - global.FINALIZE_LOGGERS = function () { global.LOGGER_MAP.forEach(forEachLogger) @@ -57,27 +43,19 @@ exports.newGlobals = function newGlobals() { } } - global.FINALIZE_SESSIONS = function () { - global.SESSION_MAP.forEach(forEachSession) - - function forEachSession(session) { - global.EVENT_SERVER_CLIENT_MODULE.raiseEvent(session, 'Stopped') - } - } - global.SHUTTING_DOWN_PROCESS = false global.EXIT_NODE_PROCESS = function exitProcess() { if (global.unexpectedError !== undefined) { - global.TASK_ERROR(undefined, "An unexpected error caused the Task to stop.") + TS.projects.superalgos.functionLibraries.taskFunctions.taskError(undefined, "An unexpected error caused the Task to stop.") } if (global.SHUTTING_DOWN_PROCESS === true) { return } global.SHUTTING_DOWN_PROCESS = true /* Signal that all sessions are stopping. */ - global.FINALIZE_SESSIONS() + TS.projects.superalgos.functionLibraries.sessionFunctions.finalizeSessions() /* Cleaning Before Exiting. */ clearInterval(global.HEARTBEAT_INTERVAL_HANDLER) @@ -134,23 +112,5 @@ exports.newGlobals = function newGlobals() { return false } } - - global.TASK_ERROR = function taskError(node, errorMessage) { - let event - if (node !== undefined) { - event = { - nodeName: node.name, - nodeType: node.type, - nodeId: node.id, - errorMessage: errorMessage - } - } else { - event = { - errorMessage: errorMessage - } - } - let key = global.TASK_NODE.name + '-' + global.TASK_NODE.type + '-' + global.TASK_NODE.id - global.EVENT_SERVER_CLIENT_MODULE.raiseEvent(key, 'Error', event) - } } } \ No newline at end of file diff --git a/TaskServer/LowFrequencyTrading/TradingProcess.js b/TaskServer/LowFrequencyTrading/TradingProcess.js index 0cbb0ddb8..f29b0cc04 100644 --- a/TaskServer/LowFrequencyTrading/TradingProcess.js +++ b/TaskServer/LowFrequencyTrading/TradingProcess.js @@ -159,7 +159,7 @@ } else { /* We are processing Daily Files */ do { - global.EMIT_SESSION_STATUS(bot.TRADING_SESSION_STATUS, bot.TRADING_SESSIONKey) + TS.projects.superalgos.functionLibraries.sessionFunctions.emitSessionStatus(bot.TRADING_SESSION_STATUS, bot.TRADING_SESSIONKey) /* We update the Trading Process Date with the date calculated at the simulation. We will use this date to load indicator and output files. After that we will diff --git a/TaskServer/ReinforcementLearning/LearningBot.js b/TaskServer/ReinforcementLearning/LearningBot.js index 1c2ccf6d9..15ae914c7 100644 --- a/TaskServer/ReinforcementLearning/LearningBot.js +++ b/TaskServer/ReinforcementLearning/LearningBot.js @@ -101,7 +101,7 @@ exports.newLearningBot = function newLearningBot(bot, parentLogger) { bot.SESSION_STATUS = 'Stopped' } - global.EMIT_SESSION_STATUS (bot.SESSION_STATUS, bot.sessionKey) + TS.projects.superalgos.functionLibraries.sessionFunctions.emitSessionStatus (bot.SESSION_STATUS, bot.sessionKey) /* Checking if we should process this loop or not.*/ if (bot.STOP_SESSION === true) { diff --git a/TaskServer/ReinforcementLearning/LearningProcess.js b/TaskServer/ReinforcementLearning/LearningProcess.js index 8fcf11c7c..1bb5aad9b 100644 --- a/TaskServer/ReinforcementLearning/LearningProcess.js +++ b/TaskServer/ReinforcementLearning/LearningProcess.js @@ -159,7 +159,7 @@ exports.newLearningProcess = function newLearningProcess(bot, logger, UTILITIES) } else { /* We are processing Daily Files */ do { - global.EMIT_SESSION_STATUS(bot.TRADING_SESSION_STATUS, bot.TRADING_SESSIONKey) + TS.projects.superalgos.functionLibraries.sessionFunctions.emitSessionStatus(bot.TRADING_SESSION_STATUS, bot.TRADING_SESSIONKey) /* We update the Trading Process Date with the date calculated at the simulation. We will use this date to load indicator and output files. After that we will diff --git a/TaskServer/TradingBot.js b/TaskServer/TradingBot.js index 4e3b8b260..914dd98f2 100644 --- a/TaskServer/TradingBot.js +++ b/TaskServer/TradingBot.js @@ -101,7 +101,7 @@ bot.TRADING_SESSION_STATUS = 'Stopped' } - global.EMIT_SESSION_STATUS(bot.TRADING_SESSION_STATUS, bot.TRADING_SESSIONKey) + TS.projects.superalgos.functionLibraries.sessionFunctions.emitSessionStatus(bot.TRADING_SESSION_STATUS, bot.TRADING_SESSIONKey) /* Checking if we should process this loop or not.*/ if (bot.STOP_SESSION === true) {