diff --git a/Context.js b/Context.js index dfa757cba..c3e7a9b6a 100644 --- a/Context.js +++ b/Context.js @@ -165,7 +165,7 @@ let fileName = "Execution.History." + bot.startMode + "." + runIndex + ".json"; let filePath = bot.filePathRoot + "/Output/Trading-Process/" + fileName; - fileStorage.getTextFile(global.DEV_TEAM, filePath, onFileReceived); + fileStorage.getTextFile(bot.devTeam, filePath, onFileReceived); function onFileReceived(err, text) { @@ -226,7 +226,7 @@ let dateForPath = date.getUTCFullYear() + '/' + utilities.pad(date.getUTCMonth() + 1, 2) + '/' + utilities.pad(date.getUTCDate(), 2) + '/' + utilities.pad(date.getUTCHours(), 2) + '/' + utilities.pad(date.getUTCMinutes(), 2); let filePath = bot.filePathRoot + "/Output/Trading-Process/" + dateForPath + fileName; - fileStorage.getTextFile(global.DEV_TEAM, filePath, onFileReceived); + fileStorage.getTextFile(bot.devTeam, filePath, onFileReceived); function onFileReceived(err, text) { @@ -408,7 +408,7 @@ if (global.LOG_CONTROL[MODULE_NAME].logContent === true) { logger.write(MODULE_NAME, "[INFO] saveThemAll -> writeExecutionContext -> fileContent = " + fileContent); } - fileStorage.createTextFile(global.DEV_TEAM, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { @@ -469,7 +469,7 @@ let fileContent = JSON.stringify(thisObject.executionHistory); - fileStorage.createTextFile(global.DEV_TEAM, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { @@ -491,7 +491,7 @@ fileName = "Execution.History." + bot.startMode + "." + "Sequence" + ".json"; filePath = bot.filePathRoot + "/Output/Trading-Process/" + fileName; - fileStorage.createTextFile(global.DEV_TEAM, filePath, fileContent + '\n', onSequenceFileCreated); + fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onSequenceFileCreated); function onSequenceFileCreated(err) { diff --git a/DebugLog.js b/DebugLog.js index 5112b0882..baa9fc203 100644 --- a/DebugLog.js +++ b/DebugLog.js @@ -89,7 +89,7 @@ exports.newDebugLog = function newDebugLog() { function writeLog() { - fileStorage.createTextFile(global.DEV_TEAM, filePath + '/' + fileName, contentToPersist + '\r\n' + "]", onFileCreated); + fileStorage.createTextFile(thisObject.bot.devTeam, filePath + '/' + fileName, contentToPersist + '\r\n' + "]", onFileCreated); function onFileCreated(err) { diff --git a/IndicatorBotProcessMainLoop.js b/IndicatorBotProcessMainLoop.js index a152d2ed2..abc233a36 100644 --- a/IndicatorBotProcessMainLoop.js +++ b/IndicatorBotProcessMainLoop.js @@ -39,10 +39,10 @@ UI_COMMANDS = pUI_COMMANDS; processConfig = pProcessConfig; - let filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.name + let filePath = bot.devTeam + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.name filePath += "/User.Bot.js" - fileStorage.getTextFile(global.DEV_TEAM, filePath, onBotDownloaded); + fileStorage.getTextFile(bot.devTeam, filePath, onBotDownloaded); function onBotDownloaded(err, text) { @@ -56,10 +56,10 @@ USER_BOT_MODULE = {} USER_BOT_MODULE.newUserBot = eval(text); // TODO This needs to be changed function - filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo; + filePath = bot.devTeam + "/" + "bots" + "/" + bot.repo; filePath += "/Commons.js" - fileStorage.getTextFile(global.DEV_TEAM, filePath, onCommonsDownloaded); + fileStorage.getTextFile(bot.devTeam, filePath, onCommonsDownloaded); function onCommonsDownloaded(err, text) { @@ -923,7 +923,7 @@ } function hearBeat() { - let key = global.USER_DEFINITION.bot.processes[bot.processIndex].name + '-' + global.USER_DEFINITION.bot.processes[bot.processIndex].type + '-' + global.USER_DEFINITION.bot.processes[bot.processIndex].id + let key = global.TASK_NODE.bot.processes[bot.processIndex].name + '-' + global.TASK_NODE.bot.processes[bot.processIndex].type + '-' + global.TASK_NODE.bot.processes[bot.processIndex].id let event = { seconds: (new Date()).getSeconds() diff --git a/MultiPeriod.js b/MultiPeriod.js index 4d1c8b81f..646254c90 100644 --- a/MultiPeriod.js +++ b/MultiPeriod.js @@ -1018,7 +1018,7 @@ let fileName = '/Data.Range.' + market.assetA + '_' + market.assetB + '.json'; let filePath = bot.filePathRoot + "/Output/" + pProductFolder + "/" + 'Multi-Period-Daily' + fileName; - fileStorage.createTextFile(global.DEV_TEAM, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index 8a7ce9d1b..7544c5404 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -722,7 +722,7 @@ let fileName = '/Data.Range.' + market.assetA + '_' + market.assetB + '.json'; let filePath = bot.filePathRoot + "/Output/" + pProductFolder + "/" + bot.process + fileName; - fileStorage.createTextFile(global.DEV_TEAM, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { diff --git a/Root.js b/Root.js index b26b69501..b160dbba1 100644 --- a/Root.js +++ b/Root.js @@ -143,9 +143,9 @@ const FILE_STORAGE = require('./Integrations/FileStorage.js'); let fileStorage = FILE_STORAGE.newFileStorage(); - let filePath = global.DEV_TEAM + '/bots/' + global.CURRENT_BOT_REPO + '/this.bot.config.json'; + let filePath = global.TASK_NODE.bot.processes[processIndex].code.team + '/bots/' + global.TASK_NODE.bot.processes[processIndex].code.repo + '/this.bot.config.json'; - fileStorage.getTextFile(global.DEV_TEAM, filePath, onFileReceived); + fileStorage.getTextFile(global.TASK_NODE.bot.processes[processIndex].code.team, filePath, onFileReceived); function onFileReceived(err, text) { @@ -338,7 +338,7 @@ runIndicatorBot(botConfig, processConfig, month, year); break; } - case 'Trading-Engine': { + case 'Trading Engine': { runTradingEngine(botConfig, processConfig); break; } @@ -388,7 +388,7 @@ } switch (botConfig.type) { - case 'Trading-Engine': { + case 'Trading Engine': { runTradingEngine(botConfig, processConfig); break; } @@ -632,14 +632,14 @@ function exitProcessInstance() { global.ENDED_PROCESSES_COUNTER++ - console.log("[INFO] Task Server -> " + global.USER_DEFINITION.name + " -> exitProcessInstance -> Process #" + global.ENDED_PROCESSES_COUNTER + " from " + global.TOTAL_PROCESS_INSTANCES_CREATED + " exiting."); + console.log("[INFO] Task Server -> " + global.TASK_NODE.name + " -> exitProcessInstance -> Process #" + global.ENDED_PROCESSES_COUNTER + " from " + global.TOTAL_PROCESS_INSTANCES_CREATED + " exiting."); if (global.ENDED_PROCESSES_COUNTER === global.TOTAL_PROCESS_INSTANCES_CREATED) { global.EXIT_NODE_PROCESS() } } } catch (err) { - console.log("[ERROR] Task Server -> " + global.USER_DEFINITION.name + " -> Root -> Start -> Err = " + err.stack); + console.log("[ERROR] Task Server -> " + global.TASK_NODE.name + " -> Root -> Start -> Err = " + err.stack); } } } diff --git a/SensorBotProcessMainLoop.js b/SensorBotProcessMainLoop.js index dda3a4a8f..b3307aba0 100644 --- a/SensorBotProcessMainLoop.js +++ b/SensorBotProcessMainLoop.js @@ -37,10 +37,10 @@ UI_COMMANDS = pUI_COMMANDS; processConfig = pProcessConfig; - let filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.name; + let filePath = bot.devTeam + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.name; filePath += "/User.Bot.js" - fileStorage.getTextFile(global.DEV_TEAM, filePath, onBotDownloaded); + fileStorage.getTextFile(bot.devTeam, filePath, onBotDownloaded); function onBotDownloaded(err, text) { @@ -56,10 +56,10 @@ } USER_BOT_MODULE.newUserBot = eval(text); // TODO This needs to be changed function - filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo; + filePath = bot.devTeam + "/" + "bots" + "/" + bot.repo; filePath += "/Commons.js" - fileStorage.getTextFile(global.DEV_TEAM, filePath, onCommonsDownloaded); + fileStorage.getTextFile(bot.devTeam, filePath, onCommonsDownloaded); function onCommonsDownloaded(err, text) { @@ -696,7 +696,7 @@ } function hearBeat() { - let key = global.USER_DEFINITION.bot.processes[bot.processIndex].name + '-' + global.USER_DEFINITION.bot.processes[bot.processIndex].type + '-' + global.USER_DEFINITION.bot.processes[bot.processIndex].id + let key = global.TASK_NODE.bot.processes[bot.processIndex].name + '-' + global.TASK_NODE.bot.processes[bot.processIndex].type + '-' + global.TASK_NODE.bot.processes[bot.processIndex].id let event = { seconds: (new Date()).getSeconds() diff --git a/TradingEngineProcessMainLoop.js b/TradingEngineProcessMainLoop.js index 3eadcadf0..e41ebff71 100644 --- a/TradingEngineProcessMainLoop.js +++ b/TradingEngineProcessMainLoop.js @@ -41,10 +41,10 @@ UI_COMMANDS = pUI_COMMANDS; processConfig = pProcessConfig; - let filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.name + let filePath = bot.devTeam + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.name filePath += "/User.Bot.js" - fileStorage.getTextFile(global.DEV_TEAM, filePath, onBotDownloaded); + fileStorage.getTextFile(bot.devTeam, filePath, onBotDownloaded); function onBotDownloaded(err, text) { @@ -59,10 +59,10 @@ //USER_BOT_MODULE.newUserBot = require(process.env.BOTS_PATH + '/aamasters/AAMasters/bots/AAJason-Trading-Engine-Bot/Multi-Period/User.Bot').newUserBot // Use this for a better debugging experience. You need to bring this js module to this folder in order to work. USER_BOT_MODULE.newUserBot = eval(text); // Use this for production - filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo; + filePath = bot.devTeam + "/" + "bots" + "/" + bot.repo; filePath += "/Commons.js" - fileStorage.getTextFile(global.DEV_TEAM, filePath, onCommonsDownloaded); + fileStorage.getTextFile(bot.devTeam, filePath, onCommonsDownloaded); function onCommonsDownloaded(err, text) { @@ -1075,7 +1075,7 @@ } function hearBeat() { - let key = global.USER_DEFINITION.bot.processes[bot.processIndex].name + '-' + global.USER_DEFINITION.bot.processes[bot.processIndex].type + '-' + global.USER_DEFINITION.bot.processes[bot.processIndex].id + let key = global.TASK_NODE.bot.processes[bot.processIndex].name + '-' + global.TASK_NODE.bot.processes[bot.processIndex].type + '-' + global.TASK_NODE.bot.processes[bot.processIndex].id let event = { seconds: (new Date()).getSeconds() diff --git a/server.js b/server.js index ac33d8bd6..940984e45 100644 --- a/server.js +++ b/server.js @@ -54,21 +54,21 @@ We read the first string sent as an argument when the process was created by the of this Task and know exactly what to run within this server instance. */ -global.USER_DEFINITION = process.argv[2] +global.TASK_NODE = process.argv[2] -if (global.USER_DEFINITION !== undefined) { - console.log('[INFO] Task Server -> server -> global.USER_DEFINITION = ' + global.USER_DEFINITION) +if (global.TASK_NODE !== undefined) { + console.log('[INFO] Task Server -> server -> global.TASK_NODE = ' + global.TASK_NODE) try { - global.USER_DEFINITION = JSON.parse(global.USER_DEFINITION) + global.TASK_NODE = JSON.parse(global.TASK_NODE) } catch (err) { - console.log('[ERROR] Task Server -> server -> global.USER_DEFINITION -> ' + err.stack) + console.log('[ERROR] Task Server -> server -> global.TASK_NODE -> ' + err.stack) } } else { // I use this section to debug in standalone mode. - let argument = ' {"type":"Task","name":"Runs Backtests, Fordwardtests & Live Trades ","bot":{"type":"Trading Engine","processes":[{"type":"Process","name":"Multi Period","code":{"devTeam":"AAMasters","bot":"AAJason","mode":"live","resumeExecution":true,"type":"Trading-Engine","exchangeName":"Poloniex","process":"Multi-Period-Daily","beginDatetime":"2019-08-01T08:00:00.000Z","timePeriod":"05-min"},"id":"1bfce24d-8c05-4be9-bd25-328f07c85265"}]},"id":"cbb13086-608d-4bb4-960a-17a81038877b"}' + let argument = '{"type":"Task","name":"Runs Backtests, Fordwardtests & Live Trades ","bot":{"type":"Trading Engine","processes":[{"type":"Process","name":"Multi Period","code":{"team":"AAMasters","bot":"AAJason","process":"Multi-Period","repo":"AAJason-Trading-Engine-Bot"},"id":"1bfce24d-8c05-4be9-bd25-328f07c85265"}]},"id":"cbb13086-608d-4bb4-960a-17a81038877b"}' try { - global.USER_DEFINITION = JSON.parse(argument) + global.TASK_NODE = JSON.parse(argument) } catch (err) { console.log(err.stack) } @@ -81,7 +81,7 @@ global.DEFINITION = require(process.env.INTER_PROCESS_FILES_PATH + '/Definition' global.WRITE_LOGS_TO_FILES = process.env.WRITE_LOGS_TO_FILES /* Default parameters can be changed by the execution configuration */ -global.EXCHANGE_NAME = process.env.EXCHANGE_NAME +global.EXCHANGE_NAME = 'Poloniex' global.MARKET = { assetA: 'USDT', assetB: 'BTC' } global.CLONE_EXECUTOR = { codeName: 'AACloud', version: '1.1' } @@ -115,12 +115,12 @@ global.EXIT_NODE_PROCESS = function exitProcess() { /* Cleaning Before Exiting. */ clearInterval(global.HEARTBEAT_INTERVAL_HANDLER) - for (let i = 0; i < global.USER_DEFINITION.bot.processes.length; i++) { - let code = global.USER_DEFINITION.bot.processes[i].code + for (let i = 0; i < global.TASK_NODE.bot.processes.length; i++) { + let code = global.TASK_NODE.bot.processes[i].code /* Delete the event handler for each process. */ - let key = code.devTeam + "-" + code.codeName + "-" + code.process + let key = code.team + "-" + code.bot + "-" + code.process let event = { reason: 'Signal Received to Terminate this Process.' } @@ -130,7 +130,7 @@ global.EXIT_NODE_PROCESS = function exitProcess() { global.SYSTEM_EVENT_HANDLER.finalize() global.SYSTEM_EVENT_HANDLER = undefined - console.log("[INFO] Task Server -> " + global.USER_DEFINITION.name + " -> EXIT_NODE_PROCESS -> Task Server Stopped."); + console.log("[INFO] Task Server -> " + global.TASK_NODE.name + " -> EXIT_NODE_PROCESS -> Task Server Stopped."); process.exit() } @@ -147,21 +147,38 @@ global.SYSTEM_EVENT_HANDLER.initialize('Task Server', bootLoader) function bootLoader() { - for (let i = 0; i < global.USER_DEFINITION.bot.processes.length; i++) { - let code = global.USER_DEFINITION.bot.processes[i].code + for (let i = 0; i < global.TASK_NODE.bot.processes.length; i++) { + let code = global.TASK_NODE.bot.processes[i].code + + /* Validate that the minimun amount of parameters required are defined. */ + + if (global.TASK_NODE.bot.processes[i].code.bot === undefined) { + console.log("[INFO] Task Server -> server -> bootLoader -> Parameter 'bot' is undefined. This process will not be executed. -> Process = " + global.TASK_NODE.bot.processes[i].name); + continue + } + + if (global.TASK_NODE.bot.processes[i].code.team === undefined) { + console.log("[INFO] Task Server -> server -> bootLoader -> Parameter 'team' is undefined. This process will not be executed. -> Process = " + global.TASK_NODE.bot.processes[i].name); + continue + } + + if (global.TASK_NODE.bot.processes[i].code.process === undefined) { + console.log("[INFO] Task Server -> server -> bootLoader -> Parameter 'process' is undefined. This process will not be executed. -> Process = " + global.TASK_NODE.bot.processes[i].name); + continue + } /* Add to the execution sequence list. */ sequenceList.push(code) /* Create the event handler for each process. This event handlers are where the status reports updated events are raised. */ - let key = code.devTeam + "-" + code.bot + "-" + code.process + let key = code.team + "-" + code.bot + "-" + code.process global.SYSTEM_EVENT_HANDLER.createEventHandler(key) } /* Heartbeat sent to the UI */ - let key = global.USER_DEFINITION.name + '-' + global.USER_DEFINITION.type + '-' + global.USER_DEFINITION.id + let key = global.TASK_NODE.name + '-' + global.TASK_NODE.type + '-' + global.TASK_NODE.id global.SYSTEM_EVENT_HANDLER.createEventHandler(key) global.HEARTBEAT_INTERVAL_HANDLER = setInterval(hearBeat, 1000) @@ -182,20 +199,20 @@ function bootLoader() { function startSequence() { - for (let processIndex = 0; processIndex < global.USER_DEFINITION.bot.processes.length; processIndex++) { + for (let processIndex = 0; processIndex < global.TASK_NODE.bot.processes.length; processIndex++) { let execution = sequenceList[processIndex]; global.STOP_TASK_GRACEFULLY = false; - execution.devTeam ? process.env.DEV_TEAM = execution.devTeam : undefined; + execution.bot ? process.env.BOT = execution.bot : undefined; execution.resumeExecution = true; - execution.type ? process.env.TYPE = execution.type : undefined; + execution.process ? process.env.PROCESS = execution.process : undefined; execution.baseAsset ? process.env.BASE_ASSET = execution.baseAsset : undefined; execution.balanceAssetA ? process.env.INITIAL_BALANCE_ASSET_A = execution.balanceAssetA : undefined; execution.balanceAssetB ? process.env.INITIAL_BALANCE_ASSET_B = execution.balanceAssetB : undefined; - execution.type === 'Trading' ? process.env.CLONE_ID = 1 : undefined; + execution.exchangeName ? global.EXCHANGE_NAME = execution.exchangeName : undefined; @@ -228,7 +245,7 @@ async function readExecutionConfiguration(execution, processIndex) { let botProcess - if (execution.type === 'Trading-Engine') { + if (global.TASK_NODE.bot.type === 'Trading Engine') { /* The Trading Engine only resumes its execution after the first sequence was completed. */ if (notFirstSequence === false) { @@ -281,17 +298,17 @@ async function readExecutionConfiguration(execution, processIndex) { } } - // General Financial Being Configuration - global.DEV_TEAM = process.env.DEV_TEAM - global.CURRENT_BOT_REPO = process.env.BOT + "-" + process.env.TYPE + "-Bot" + if (global.TASK_NODE.bot.processes[processIndex].code.repo === undefined) { + global.TASK_NODE.bot.processes[processIndex].code.repo = global.TASK_NODE.bot.processes[processIndex].code.bot + "-" + global.TASK_NODE.bot.type + "-Bot" + } if (botProcess === undefined) { botProcess = process.env.PROCESS } // Only use the .env when nothing comes at Definition.json let cloneToExecute = { enabled: "true", - devTeam: process.env.DEV_TEAM, - bot: process.env.BOT, - process: botProcess, - repo: global.CURRENT_BOT_REPO + devTeam: global.TASK_NODE.bot.processes[processIndex].code.team, + bot: global.TASK_NODE.bot.processes[processIndex].code.bot, + process: global.TASK_NODE.bot.processes[processIndex].code.process, + repo: global.TASK_NODE.bot.processes[processIndex].code.repo } global.EXECUTION_CONFIG = {