diff --git a/Commons.js b/Commons.js index fcc9ded0b..bea993f51 100644 --- a/Commons.js +++ b/Commons.js @@ -12,7 +12,7 @@ validateOutputDatasets: validateOutputDatasets, inflateDatafiles: inflateDatafiles, dataBuildingProcedure: dataBuildingProcedure, - calculationsProcedure: calculationsProcedure, + calculationsProcedure: calculationsProcedure, generateFileContent: generateFileContent, writeFile: writeFile }; @@ -25,15 +25,15 @@ function validateDataDependencies(dataDependencies, callBackFunction) { for (let i = 0; i < dataDependencies.length; i++) { - let dataDependencyNode = dataDependencies[i] + let dataDependencyNode = dataDependencies[i] /* Basic validations to see if we have everything we need. */ - if (dataDependencyNode.referenceParent.parentNode.code.singularVariableName === undefined) { + if (dataDependencyNode.referenceParent.parentNode.config.singularVariableName === undefined) { logger.write(MODULE_NAME, "[ERROR] start -> Product Definition without a Single Variable Name defined. Product Definition = " + JSON.stringify(dataDependencyNode.referenceParent.parentNode)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return } - if (dataDependencyNode.referenceParent.parentNode.code.pluralVariableName === undefined) { + if (dataDependencyNode.referenceParent.parentNode.config.pluralVariableName === undefined) { logger.write(MODULE_NAME, "[ERROR] start -> Product Definition without a Plural Variable Name defined. Product Definition = " + JSON.stringify(dataDependencyNode.referenceParent.parentNode)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return @@ -61,12 +61,12 @@ callBackFunction(global.DEFAULT_FAIL_RESPONSE); return } - if (outputDatasetNode.referenceParent.parentNode.code.singularVariableName === undefined) { + if (outputDatasetNode.referenceParent.parentNode.config.singularVariableName === undefined) { logger.write(MODULE_NAME, "[ERROR] start -> Product Definition without a Single Variable Name defined. Product Definition = " + JSON.stringify(outputDatasetNode.referenceParent.parentNode)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return } - if (outputDatasetNode.referenceParent.parentNode.code.pluralVariableName === undefined) { + if (outputDatasetNode.referenceParent.parentNode.config.pluralVariableName === undefined) { logger.write(MODULE_NAME, "[ERROR] start -> Product Definition without a Plural Variable Name defined. Product Definition = " + JSON.stringify(outputDatasetNode.referenceParent.parentNode)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return @@ -79,7 +79,7 @@ if (outputDatasetNode.referenceParent.parentNode.dataBuilding === undefined) { logger.write(MODULE_NAME, "[WARN] start -> Product Definition " + outputDatasetNode.referenceParent.parentNode.name + " without a Data Building Procedure. Product Definition = " + JSON.stringify(outputDatasetNode.referenceParent.parentNode)); } - if (outputDatasetNode.referenceParent.code.codeName === undefined) { + if (outputDatasetNode.referenceParent.config.codeName === undefined) { logger.write(MODULE_NAME, "[ERROR] start -> Dataset witn no codeName defined. Product Dataset = " + JSON.stringify(outputDatasetNode.referenceParent)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return @@ -91,7 +91,7 @@ return } - if (outputDatasetNode.referenceParent.parentNode.code.codeName === undefined) { + if (outputDatasetNode.referenceParent.parentNode.config.codeName === undefined) { logger.write(MODULE_NAME, "[ERROR] start -> Product Definition witn no codeName defined. Product Definition = " + JSON.stringify(outputDatasetNode.referenceParent.parentNode)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return @@ -103,7 +103,7 @@ return } - if (outputDatasetNode.referenceParent.parentNode.parentNode.code.codeName === undefined) { + if (outputDatasetNode.referenceParent.parentNode.parentNode.config.codeName === undefined) { logger.write(MODULE_NAME, "[ERROR] start -> Bot witn no codeName defined. Bot = " + JSON.stringify(outputDatasetNode.referenceParent.parentNode.parentNode)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return @@ -115,7 +115,7 @@ return } - if (outputDatasetNode.referenceParent.parentNode.parentNode.parentNode.code.codeName === undefined) { + if (outputDatasetNode.referenceParent.parentNode.parentNode.parentNode.config.codeName === undefined) { logger.write(MODULE_NAME, "[ERROR] start -> Data Mine witn no codeName defined. Data Mine = " + JSON.stringify(outputDatasetNode.referenceParent.parentNode.parentNode.parentNode)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return @@ -132,19 +132,19 @@ */ for (let i = 0; i < dataDependencies.length; i++) { - let dataFile + let dataFile let jsonData // Datafile converted into Json objects let inputData // Includes calculated properties let singularVariableName // name of the variable for this product let recordDefinition - let dataDependencyNode = dataDependencies[i] + let dataDependencyNode = dataDependencies[i] dataFile = dataFiles.get(dataDependencyNode.id) if (dataFile === undefined) { continue } // When a datafile is not found it might be because we are processing market or daily and at the dependency array there are both types mixed up. recordDefinition = dataDependencyNode.referenceParent.parentNode.record - singularVariableName = dataDependencyNode.referenceParent.parentNode.code.singularVariableName + singularVariableName = dataDependencyNode.referenceParent.parentNode.config.singularVariableName /* Transform the raw data into JSON objects */ jsonData = jsonifyDataFile(dataFile, recordDefinition) /* Add the calculated properties */ @@ -153,7 +153,7 @@ } else { inputData = jsonData } - products[dataDependencyNode.referenceParent.parentNode.code.pluralVariableName] = inputData + products[dataDependencyNode.referenceParent.parentNode.config.pluralVariableName] = inputData /* The main dependency is defined as the first dependency processed. */ if (mainDependency.records === undefined) { @@ -177,8 +177,8 @@ let record = {} for (let j = 0; j < recordDefinition.properties.length; j++) { let property = recordDefinition.properties[j] - if (property.code.isCalculated !== true) { - record[property.code.codeName] = dataFile[i][j] + if (property.config.isCalculated !== true) { + record[property.config.codeName] = dataFile[i][j] } } @@ -238,13 +238,13 @@ /* For each calculated property we apply its formula*/ for (let j = 0; j < recordDefinition.properties.length; j++) { let property = recordDefinition.properties[j] - if (property.code.isCalculated === true) { + if (property.config.isCalculated === true) { if (property.formula !== undefined) { if (property.formula.code !== undefined) { try { let newValue = eval(property.formula.code) let currentRecord = product[variableName] - currentRecord[property.code.codeName] = newValue + currentRecord[property.config.codeName] = newValue } catch (err) { logger.write(MODULE_NAME, "[ERROR] calculationsProcedure -> loop -> formula -> Error executing User Code. Error = " + err.stack) logger.write(MODULE_NAME, "[ERROR] calculationsProcedure -> loop -> formula -> Error executing User Code. product = " + JSON.stringify(product)) @@ -277,7 +277,7 @@ interExecutionMemory, processingDailyFiles, currentDay - ) { + ) { /* This function has as an input the products object, with all the information @@ -286,7 +286,7 @@ a new set of information. */ - let lastInstantOfTheDay + let lastInstantOfTheDay let yesterday = {} let system = { // These are the available system variables to be used in User Code and Formulas timeFrame: timeFrame, @@ -313,7 +313,7 @@ let dataDependencyMap = new Map() for (let j = 0; j < dataDependecyArray.length; j++) { let record = dataDependecyArray[j] - let key = record.begin.toString() + '-' + record.end.toString() + let key = record.begin.toString() + '-' + record.end.toString() dataDependencyMap.set(key, record) } dataDependencies[dataDependencyName] = dataDependencyMap @@ -321,7 +321,7 @@ } function getElement(dependencyName, currentRecordPrimaryDataDependency) { - let key = currentRecordPrimaryDataDependency.begin.toString() + '-' + currentRecordPrimaryDataDependency.end.toString() + let key = currentRecordPrimaryDataDependency.begin.toString() + '-' + currentRecordPrimaryDataDependency.end.toString() return dataDependencies[dependencyName].get(key) } @@ -349,7 +349,7 @@ } else { /* We override the initialization, since the valid stuff is already at the Inter Execution Memory */ - variable = JSON.parse(JSON.stringify(interExecutionMemory[productName].variable)) + variable = JSON.parse(JSON.stringify(interExecutionMemory[productName].variable)) } } @@ -387,13 +387,13 @@ /* For each non-calculated property we apply its formula*/ for (let j = 0; j < recordDefinition.properties.length; j++) { let property = recordDefinition.properties[j] - if (property.code.isCalculated !== true) { + if (property.config.isCalculated !== true) { if (property.formula !== undefined) { if (property.formula.code !== undefined) { try { let newValue = eval(property.formula.code) let currentRecord = product[variableName] - currentRecord[property.code.codeName] = newValue + currentRecord[property.config.codeName] = newValue } catch (err) { logger.write(MODULE_NAME, "[ERROR] dataBuildingProcedure -> loop -> formula -> Error executing User Code. Error = " + err.stack) logger.write(MODULE_NAME, "[ERROR] dataBuildingProcedure -> loop -> formula -> Error executing User Code. product = " + JSON.stringify(product)) @@ -474,13 +474,13 @@ let propertySeparator = "" for (let j = 0; j < recordDefinition.properties.length; j++) { let property = recordDefinition.properties[j] - if (property.code.isCalculated !== true) { + if (property.config.isCalculated !== true) { fileContent = fileContent + propertySeparator - if (property.code.isString === true) { + if (property.config.isString === true) { fileContent = fileContent + '"' } - fileContent = fileContent + record[property.code.codeName] - if (property.code.isString === true) { + fileContent = fileContent + record[property.config.codeName] + if (property.config.isString === true) { fileContent = fileContent + '"' } if (propertySeparator === "") { propertySeparator = ","; } diff --git a/DataSet.js b/DataSet.js index aa0c6bb1c..1a6364b7a 100644 --- a/DataSet.js +++ b/DataSet.js @@ -16,7 +16,7 @@ exports.newDataSet = function newDataSet(BOT, logger) { /* Storage account to be used here. */ const FILE_STORAGE = require('./FileStorage.js'); - let fileStorage + let fileStorage return thisObject; @@ -36,7 +36,7 @@ exports.newDataSet = function newDataSet(BOT, logger) { return } - if (thisObject.node.code.codeName === undefined) { + if (thisObject.node.config.codeName === undefined) { logger.write(MODULE_NAME, "[ERROR] initialize -> Dataset witn no codeName defined -> Product Dataset = " + JSON.stringify(thisObject.node)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return @@ -48,7 +48,7 @@ exports.newDataSet = function newDataSet(BOT, logger) { return } - if (thisObject.node.parentNode.code.codeName === undefined) { + if (thisObject.node.parentNode.config.codeName === undefined) { logger.write(MODULE_NAME, "[ERROR] initialize -> Product Definition witn no codeName defined -> Product Definition = " + JSON.stringify(thisObject.node.parentNode)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return @@ -60,7 +60,7 @@ exports.newDataSet = function newDataSet(BOT, logger) { return } - if (thisObject.node.parentNode.parentNode.code.codeName === undefined) { + if (thisObject.node.parentNode.parentNode.config.codeName === undefined) { logger.write(MODULE_NAME, "[ERROR] initialize -> Bot witn no codeName defined. Bot = " + JSON.stringify(thisObject.node.parentNode.parentNode)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return @@ -72,14 +72,14 @@ exports.newDataSet = function newDataSet(BOT, logger) { return } - if (thisObject.node.parentNode.parentNode.parentNode.code.codeName === undefined) { + if (thisObject.node.parentNode.parentNode.parentNode.config.codeName === undefined) { logger.write(MODULE_NAME, "[ERROR] initialize -> Data Mine witn no codeName defined. Data Mine = " + JSON.stringify(thisObject.node.parentNode.parentNode.parentNode)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return } /* Now we will see where do we need to fetch this data from. */ - let network = global.TASK_NETWORK + let network = global.TASK_NETWORK let datasetProductDefinition = thisObject.node.parentNode for (let i = 0; i < network.networkNodes.length; i++) { @@ -102,9 +102,9 @@ exports.newDataSet = function newDataSet(BOT, logger) { if (datasetProductDefinition.id === productDefinition.id) { /* We found where the data is located on the network. */ - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> Retrieving data from " + networkNode.name + " -> host = " + networkNode.code.host + ' -> port = ' + networkNode.code.webPort + '.'); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> Retrieving data from " + networkNode.name + " -> host = " + networkNode.config.host + ' -> port = ' + networkNode.config.webPort + '.'); } - fileStorage = FILE_STORAGE.newFileStorage(logger, networkNode.code.host, networkNode.code.webPort); + fileStorage = FILE_STORAGE.newFileStorage(logger, networkNode.config.host, networkNode.config.webPort); callBackFunction(global.DEFAULT_OK_RESPONSE); return } @@ -133,9 +133,9 @@ exports.newDataSet = function newDataSet(BOT, logger) { if (datasetProductDefinition.id === productDefinition.id) { /* We found where the data is located on the network. */ - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> Retrieving data from " + networkNode.name + " -> host = " + networkNode.code.host + ' -> port = ' + networkNode.code.webPort + '.'); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> Retrieving data from " + networkNode.name + " -> host = " + networkNode.config.host + ' -> port = ' + networkNode.config.webPort + '.'); } - fileStorage = FILE_STORAGE.newFileStorage(logger, networkNode.code.host, networkNode.code.webPort); + fileStorage = FILE_STORAGE.newFileStorage(logger, networkNode.config.host, networkNode.config.webPort); callBackFunction(global.DEFAULT_OK_RESPONSE); return } @@ -155,7 +155,7 @@ exports.newDataSet = function newDataSet(BOT, logger) { callBackFunction(global.DEFAULT_FAIL_RESPONSE); } catch (err) { - logger.write(MODULE_NAME, "[ERROR] initialize -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] initialize -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -173,8 +173,8 @@ exports.newDataSet = function newDataSet(BOT, logger) { if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] getTextFile -> Entering function."); } - let dataMineCodeName = thisObject.node.parentNode.parentNode.parentNode.code.codeName - let botCodeName = thisObject.node.parentNode.parentNode.code.codeName + let dataMineCodeName = thisObject.node.parentNode.parentNode.parentNode.config.codeName + let botCodeName = thisObject.node.parentNode.parentNode.config.codeName let filePathRoot = bot.exchange + "/" + bot.market.baseAsset + "-" + bot.market.quotedAsset + "/" + dataMineCodeName + "/" + botCodeName; let filePath = filePathRoot + "/Output/" + pFolderPath; @@ -191,7 +191,7 @@ exports.newDataSet = function newDataSet(BOT, logger) { } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] 'getTextFile' -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] 'getTextFile' -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -232,7 +232,7 @@ exports.newDataSet = function newDataSet(BOT, logger) { } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] 'createTextFile' -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] 'createTextFile' -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } diff --git a/IndicatorBot.js b/IndicatorBot.js index 004ed077f..fc28afeae 100644 --- a/IndicatorBot.js +++ b/IndicatorBot.js @@ -65,7 +65,7 @@ if (commons.validateDataDependencies(dataDependencies, callBackFunction) !== true) { return } let outputDatasets = bot.processNode.referenceParent.processOutput.outputDatasets - if (commons.validateOutputDatasets(outputDatasets, callBackFunction) !== true) { return } + 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. */ commons.inflateDatafiles(dataFiles, dataDependencies, products, mainDependency, timeFrame) @@ -86,7 +86,7 @@ */ recordDefinition = outputDatasetNode.referenceParent.parentNode.record - singularVariableName = outputDatasetNode.referenceParent.parentNode.code.singularVariableName + singularVariableName = outputDatasetNode.referenceParent.parentNode.config.singularVariableName /* Check Irregular Periods */ @@ -103,7 +103,7 @@ recordDefinition, outputDatasetNode.referenceParent.parentNode.dataBuilding, singularVariableName, - outputDatasetNode.referenceParent.parentNode.code.codeName, + outputDatasetNode.referenceParent.parentNode.config.codeName, timeFrame, timeFrameLabel, resultsWithIrregularPeriods, @@ -118,14 +118,14 @@ } else { outputData = jsonData } - products[outputDatasetNode.referenceParent.parentNode.code.pluralVariableName] = outputData + products[outputDatasetNode.referenceParent.parentNode.config.pluralVariableName] = outputData } /*At the fourth and last phase, we will save the new information generated into files corresponding to each output outputDatasetNode.*/ let totalFilesWritten = 0 for (let i = 0; i < outputDatasets.length; i++) { let outputDatasetNode = outputDatasets[i] - let outputData = products[outputDatasetNode.referenceParent.parentNode.code.pluralVariableName] + let outputData = products[outputDatasetNode.referenceParent.parentNode.config.pluralVariableName] let resultsWithIrregularPeriods // A product will have irregular periods when the User Code inserts new result records at will, in contrast with normal procedure where the platform insert one record per loop execution. let contextSummary = {} @@ -136,10 +136,10 @@ /* Simplifying the access to basic info */ - contextSummary.dataset = outputDatasetNode.referenceParent.code.codeName - contextSummary.product = outputDatasetNode.referenceParent.parentNode.code.codeName - contextSummary.bot = outputDatasetNode.referenceParent.parentNode.parentNode.code.codeName - contextSummary.dataMine = outputDatasetNode.referenceParent.parentNode.parentNode.parentNode.code.codeName + contextSummary.dataset = outputDatasetNode.referenceParent.config.codeName + contextSummary.product = outputDatasetNode.referenceParent.parentNode.config.codeName + contextSummary.bot = outputDatasetNode.referenceParent.parentNode.parentNode.config.codeName + contextSummary.dataMine = outputDatasetNode.referenceParent.parentNode.parentNode.parentNode.config.codeName /* This stuff is still hardcoded and unresolved. */ contextSummary.botVersion = { diff --git a/MultiPeriod.js b/MultiPeriod.js index f29d1c0fa..bf46a4b85 100644 --- a/MultiPeriod.js +++ b/MultiPeriod.js @@ -231,18 +231,18 @@ try { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processSingleFiles -> dependencyLoopBody -> getFile -> Entering function."); } - if (datasetModule.node.code.codeName !== "Single-File") { + if (datasetModule.node.config.codeName !== "Single-File") { dependencyControlLoop(); return } - if (dataDependenciesModule.isItADepenency('atAnyTimeFrame', datasetModule.node.parentNode.code.singularVariableName) !== true) { + if (dataDependenciesModule.isItADepenency('atAnyTimeFrame', datasetModule.node.parentNode.config.singularVariableName) !== true) { dependencyControlLoop(); return } let fileName = "Data.json"; - let filePath = datasetModule.node.parentNode.code.codeName + '/' + datasetModule.node.code.codeName; + let filePath = datasetModule.node.parentNode.config.codeName + '/' + datasetModule.node.config.codeName; datasetModule.getTextFile(filePath, fileName, onFileReceived); function onFileReceived(err, text) { @@ -365,20 +365,20 @@ try { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processMarketFiles -> timeFramesLoopBody -> dependencyLoopBody -> getFile -> Entering function."); } - if (dependency.referenceParent.code.codeName !== "Multi-Period-Market") { + if (dependency.referenceParent.config.codeName !== "Multi-Period-Market") { dependencyControlLoop(); return } - if (dataDependenciesModule.isItADepenency(timeFrameLabel, datasetModule.node.parentNode.code.singularVariableName) !== true) { - if (!(bot.VALUES_TO_USE.timeFrame === timeFrameLabel && datasetModule.node.parentNode.code.pluralVariableName === 'candles')) { + if (dataDependenciesModule.isItADepenency(timeFrameLabel, datasetModule.node.parentNode.config.singularVariableName) !== true) { + if (!(bot.VALUES_TO_USE.timeFrame === timeFrameLabel && datasetModule.node.parentNode.config.pluralVariableName === 'candles')) { dependencyControlLoop(); return } } let fileName = "Data.json"; - let filePath = dependency.referenceParent.parentNode.code.codeName + '/' + dependency.referenceParent.code.codeName + "/" + timeFrameLabel; + let filePath = dependency.referenceParent.parentNode.config.codeName + '/' + dependency.referenceParent.config.codeName + "/" + timeFrameLabel; datasetModule.getTextFile(filePath, fileName, onFileReceived); function onFileReceived(err, text) { @@ -624,13 +624,13 @@ try { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processDailyFiles -> timeFramesLoopBody -> dependencyLoopBody -> getPreviousFile -> Entering function."); } - if (dependency.referenceParent.code.codeName !== "Multi-Period-Daily") { + if (dependency.referenceParent.config.codeName !== "Multi-Period-Daily") { dependencyControlLoop(); return } - if (dataDependenciesModule.isItADepenency(timeFrameLabel, datasetModule.node.parentNode.code.singularVariableName) !== true) { - if (!(bot.VALUES_TO_USE.timeFrame === timeFrameLabel && datasetModule.node.parentNode.code.pluralVariableName === 'candles')) { + if (dataDependenciesModule.isItADepenency(timeFrameLabel, datasetModule.node.parentNode.config.singularVariableName) !== true) { + if (!(bot.VALUES_TO_USE.timeFrame === timeFrameLabel && datasetModule.node.parentNode.config.pluralVariableName === 'candles')) { dependencyControlLoop(); return } @@ -639,10 +639,10 @@ let dateForPath = previousDay.getUTCFullYear() + '/' + utilities.pad(previousDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(previousDay.getUTCDate(), 2); let filePath - if (dependency.referenceParent.code.codeName === "Multi-Period-Daily") { - filePath = dependency.referenceParent.parentNode.code.codeName + '/' + dependency.referenceParent.code.codeName + "/" + timeFrameLabel + "/" + dateForPath; + if (dependency.referenceParent.config.codeName === "Multi-Period-Daily") { + filePath = dependency.referenceParent.parentNode.config.codeName + '/' + dependency.referenceParent.config.codeName + "/" + timeFrameLabel + "/" + dateForPath; } else { - filePath = dependency.referenceParent.parentNode.code.codeName + '/' + dependency.referenceParent.code.codeName + "/" + dateForPath; + filePath = dependency.referenceParent.parentNode.config.codeName + '/' + dependency.referenceParent.config.codeName + "/" + dateForPath; } let fileName = "Data.json"; @@ -702,13 +702,13 @@ try { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processDailyFiles -> timeFramesLoopBody -> dependencyLoopBody -> getCurrentFile -> Entering function."); } - if (dependency.referenceParent.code.codeName !== "Multi-Period-Daily") { + if (dependency.referenceParent.config.codeName !== "Multi-Period-Daily") { dependencyControlLoop(); return } - if (dataDependenciesModule.isItADepenency(timeFrameLabel, datasetModule.node.parentNode.code.singularVariableName) !== true) { - if (!(bot.VALUES_TO_USE.timeFrame === timeFrameLabel && datasetModule.node.parentNode.code.pluralVariableName === 'candles')) { + if (dataDependenciesModule.isItADepenency(timeFrameLabel, datasetModule.node.parentNode.config.singularVariableName) !== true) { + if (!(bot.VALUES_TO_USE.timeFrame === timeFrameLabel && datasetModule.node.parentNode.config.pluralVariableName === 'candles')) { dependencyControlLoop(); return } @@ -716,10 +716,10 @@ let dateForPath = bot.multiPeriodProcessDatetime.getUTCFullYear() + '/' + utilities.pad(bot.multiPeriodProcessDatetime.getUTCMonth() + 1, 2) + '/' + utilities.pad(bot.multiPeriodProcessDatetime.getUTCDate(), 2); let filePath - if (dependency.referenceParent.code.codeName === "Multi-Period-Daily") { - filePath = dependency.referenceParent.parentNode.code.codeName + '/' + dependency.referenceParent.code.codeName + "/" + timeFrameLabel + "/" + dateForPath; + if (dependency.referenceParent.config.codeName === "Multi-Period-Daily") { + filePath = dependency.referenceParent.parentNode.config.codeName + '/' + dependency.referenceParent.config.codeName + "/" + timeFrameLabel + "/" + dateForPath; } else { - filePath = dependency.referenceParent.parentNode.code.codeName + '/' + dependency.referenceParent.code.codeName + "/" + dateForPath; + filePath = dependency.referenceParent.parentNode.config.codeName + '/' + dependency.referenceParent.config.codeName + "/" + dateForPath; } let fileName = "Data.json"; @@ -927,7 +927,7 @@ controlLoop(); function productLoopBody() { - let productCodeName = bot.processNode.referenceParent.processOutput.outputDatasets[outputDatasetIndex].referenceParent.parentNode.code.codeName; + let productCodeName = bot.processNode.referenceParent.processOutput.outputDatasets[outputDatasetIndex].referenceParent.parentNode.config.codeName; writeDataRange(contextVariables.dateBeginOfMarket, bot.multiPeriodProcessDatetime, productCodeName, currentTimeFrameLabel, controlLoop); } diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index 4e384081d..096df4c62 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -22,7 +22,7 @@ let fileStorage = FILE_STORAGE.newFileStorage(logger); - let bootstrappingTheProcess = false + let bootstrappingTheProcess = false let processConfig; let beginingOfMarket @@ -48,7 +48,7 @@ botInstance.initialize(callBackFunction); } catch (err) { - logger.write(MODULE_NAME, "[ERROR] initialize -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] initialize -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -248,7 +248,7 @@ } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> getContextVariables -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> getContextVariables -> err = " + err.stack); if (err.message === "Cannot read property 'file' of undefined") { logger.write(MODULE_NAME, "[HINT] start -> getContextVariables -> Check the bot configuration to see if all of its statusDependencies declarations are correct. "); logger.write(MODULE_NAME, "[HINT] start -> getContextVariables -> Dependencies loaded -> keys = " + JSON.stringify(statusDependencies.keys)); @@ -280,7 +280,7 @@ bot.multiPeriodDailyProcessDatetime = new Date(bot.multiPeriodDailyProcessDatetime.valueOf() + ONE_DAY_IN_MILISECONDS); previousDay = new Date(bot.multiPeriodDailyProcessDatetime.valueOf() - ONE_DAY_IN_MILISECONDS); - + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> advanceTime -> bot.multiPeriodDailyProcessDatetime = " + bot.multiPeriodDailyProcessDatetime); } if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> advanceTime -> previousDay = " + previousDay); } @@ -300,7 +300,7 @@ let currentDateString = bot.multiPeriodDailyProcessDatetime.getUTCFullYear() + '-' + utilities.pad(bot.multiPeriodDailyProcessDatetime.getUTCMonth() + 1, 2) + '-' + utilities.pad(bot.multiPeriodDailyProcessDatetime.getUTCDate(), 2); let currentDate = new Date(bot.multiPeriodDailyProcessDatetime) let percentage = global.getPercentage(fromDate, currentDate, lastDate) - bot.processHeartBeat(currentDateString, percentage) + bot.processHeartBeat(currentDateString, percentage) if (global.areEqualDates(currentDate, new Date()) === false) { logger.newInternalLoop(bot.codeName, bot.process, currentDate, percentage); @@ -309,7 +309,7 @@ checkStopTaskGracefully(); } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> advanceTime -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> advanceTime -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -355,7 +355,7 @@ } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoop -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoop -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -395,9 +395,9 @@ let dependency = dataDependenciesModule.nodeArray[dependencyIndex]; - if (dependency === undefined ) { + if (dependency === undefined) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> You need to add at least one Data Dependency to the process Multi Period Daily. Aborting process." ); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> You need to add at least one Data Dependency to the process Multi Period Daily. Aborting process."); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } @@ -422,10 +422,10 @@ let dateForPath = previousDay.getUTCFullYear() + '/' + utilities.pad(previousDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(previousDay.getUTCDate(), 2); let filePath - if (dependency.referenceParent.code.codeName === "Multi-Period-Daily") { - filePath = dependency.referenceParent.parentNode.code.codeName + '/' + dependency.referenceParent.code.codeName + "/" + timeFrameLabel + "/" + dateForPath; + if (dependency.referenceParent.config.codeName === "Multi-Period-Daily") { + filePath = dependency.referenceParent.parentNode.config.codeName + '/' + dependency.referenceParent.config.codeName + "/" + timeFrameLabel + "/" + dateForPath; } else { - filePath = dependency.referenceParent.parentNode.code.codeName + '/' + dependency.referenceParent.code.codeName + "/" + dateForPath; + filePath = dependency.referenceParent.parentNode.config.codeName + '/' + dependency.referenceParent.config.codeName + "/" + dateForPath; } let fileName = "Data.json"; @@ -455,14 +455,14 @@ if ((err.result === "Fail Because" && err.message === "File does not exist.") || err.code === 'The specified key does not exist.') { - logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> err = " + err.stack); callBackFunction(global.DEFAULT_RETRY_RESPONSE); return; } if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> err = " + err.stack); callBackFunction(err); return; } @@ -473,13 +473,13 @@ } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -492,12 +492,12 @@ let dateForPath = bot.multiPeriodDailyProcessDatetime.getUTCFullYear() + '/' + utilities.pad(bot.multiPeriodDailyProcessDatetime.getUTCMonth() + 1, 2) + '/' + utilities.pad(bot.multiPeriodDailyProcessDatetime.getUTCDate(), 2); let filePath - if (dependency.referenceParent.code.codeName === "Multi-Period-Daily") { - filePath = dependency.referenceParent.parentNode.code.codeName + '/' + dependency.referenceParent.code.codeName + "/" + timeFrameLabel + "/" + dateForPath; + if (dependency.referenceParent.config.codeName === "Multi-Period-Daily") { + filePath = dependency.referenceParent.parentNode.config.codeName + '/' + dependency.referenceParent.config.codeName + "/" + timeFrameLabel + "/" + dateForPath; } else { - filePath = dependency.referenceParent.parentNode.code.codeName + '/' + dependency.referenceParent.code.codeName + "/" + dateForPath; + filePath = dependency.referenceParent.parentNode.config.codeName + '/' + dependency.referenceParent.config.codeName + "/" + dateForPath; } - let fileName = "Data.json"; + let fileName = "Data.json"; datasetModule.getTextFile(filePath, fileName, onFileReceived); @@ -543,19 +543,19 @@ } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> Catch Error -> onFileReceived -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> Catch Error -> onFileReceived -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoop -> dependencyLoopBody -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoop -> dependencyLoopBody -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -579,7 +579,7 @@ } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> dependencyControlLoop -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> dependencyControlLoop -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -617,19 +617,19 @@ periodsControlLoop(); } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> callTheBot -> onBotFinished -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> callTheBot -> onBotFinished -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> callTheBot -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> callTheBot -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -659,7 +659,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> controlLoop -> onWritten -> Entering function."); } if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> controlLoop -> onWritten -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> controlLoop -> onWritten -> err = " + err.stack); callBackFunction(err); return; } @@ -667,21 +667,21 @@ writeStatusReport(bot.multiPeriodDailyProcessDatetime, advanceTime); } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> controlLoop -> onWritten -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> controlLoop -> onWritten -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsControlLoop -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsControlLoop -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -696,7 +696,7 @@ controlLoop(); function productLoopBody() { - let productCodeName = bot.processNode.referenceParent.processOutput.outputDatasets[outputDatasetIndex].referenceParent.parentNode.code.codeName; + let productCodeName = bot.processNode.referenceParent.processOutput.outputDatasets[outputDatasetIndex].referenceParent.parentNode.config.codeName; writeDataRange(contextVariables.dateBeginOfMarket, bot.multiPeriodDailyProcessDatetime, productCodeName, controlLoop); } @@ -712,7 +712,7 @@ } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> writeDataRanges -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> writeDataRanges -> err = " + err.stack); callBack(global.DEFAULT_FAIL_RESPONSE); } @@ -741,7 +741,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeDataRange -> onFileCreated -> Entering function."); } if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write(MODULE_NAME, "[ERROR] start -> writeDataRange -> onFileCreated -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> writeDataRange -> onFileCreated -> err = " + err.stack); callBack(err); return; } @@ -750,7 +750,7 @@ logger.write(MODULE_NAME, "[INFO] start -> writeDataRange -> onFileCreated -> Content written = " + fileContent); } - let key = bot.dataMine + "-" + bot.codeName + "-" + productCodeName + "-" + bot.exchange + "-" + bot.market.baseAsset + '/' + bot.market.quotedAsset + let key = bot.dataMine + "-" + bot.codeName + "-" + productCodeName + "-" + bot.exchange + "-" + bot.market.baseAsset + '/' + bot.market.quotedAsset let event = { dateRange: dataRange } @@ -761,7 +761,7 @@ } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> writeDataRange -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> writeDataRange -> err = " + err.stack); callBack(global.DEFAULT_FAIL_RESPONSE); } } @@ -786,14 +786,14 @@ } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> writeStatusReport -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> writeStatusReport -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } diff --git a/MultiPeriodMarket.js b/MultiPeriodMarket.js index 3c8b10f07..11bc7ae40 100644 --- a/MultiPeriodMarket.js +++ b/MultiPeriodMarket.js @@ -41,7 +41,7 @@ botInstance.initialize(callBackFunction); } catch (err) { - logger.write(MODULE_NAME, "[ERROR] initialize -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] initialize -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -100,7 +100,7 @@ } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoop -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoop -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -137,13 +137,13 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getFile -> Entering function."); } let dateForPath = bot.processDatetime.getUTCFullYear() + '/' + utilities.pad(bot.processDatetime.getUTCMonth() + 1, 2) + '/' + utilities.pad(bot.processDatetime.getUTCDate(), 2); - let fileName = "Data.json"; + let fileName = "Data.json"; let filePath - if (dependency.referenceParent.code.codeName === "Multi-Period-Market") { - filePath = dependency.referenceParent.parentNode.code.codeName + '/' + dependency.referenceParent.code.codeName + "/" + timeFrameLabel; + if (dependency.referenceParent.config.codeName === "Multi-Period-Market") { + filePath = dependency.referenceParent.parentNode.config.codeName + '/' + dependency.referenceParent.config.codeName + "/" + timeFrameLabel; } else { - filePath = dependency.referenceParent.parentNode.code.codeName + '/' + dependency.referenceParent.code.codeName + "/" + dateForPath; + filePath = dependency.referenceParent.parentNode.config.codeName + '/' + dependency.referenceParent.config.codeName + "/" + dateForPath; } datasetModule.getTextFile(filePath, fileName, onFileReceived); @@ -156,7 +156,7 @@ if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getFile -> onFileReceived -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getFile -> onFileReceived -> err = " + err.stack); callBackFunction(err); return; } @@ -168,20 +168,20 @@ } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getFile -> onFileReceived -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getFile -> onFileReceived -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getFile -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getFile -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoop -> dependencyLoopBody -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoop -> dependencyLoopBody -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -205,7 +205,7 @@ } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> dependencyControlLoop -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> dependencyControlLoop -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -242,19 +242,19 @@ periodsControlLoop(); } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> callTheBot -> onBotFinished -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> callTheBot -> onBotFinished -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } - catch(err){ - logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> callTheBot -> err = "+ err.stack); + catch (err) { + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> callTheBot -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -278,14 +278,14 @@ } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsControlLoop -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsControlLoop -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -304,23 +304,23 @@ if (global.areEqualDates(bot.processDatetime, new Date()) === false) { logger.newInternalLoop(bot.codeName, bot.process, bot.processDatetime); - } - + } + /* Telling the world we are alive and doing well */ let currentDateString = bot.processDatetime.getUTCFullYear() + '-' + utilities.pad(bot.processDatetime.getUTCMonth() + 1, 2) + '-' + utilities.pad(bot.processDatetime.getUTCDate(), 2); let currentDate = new Date(bot.processDatetime) let lastDate = new Date() - bot.processHeartBeat(currentDateString, global.getPercentage(currentDate, currentDate, lastDate)) + bot.processHeartBeat(currentDateString, global.getPercentage(currentDate, currentDate, lastDate)) } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> writeStatusReport -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> writeStatusReport -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } diff --git a/ProcessExecutionEvents.js b/ProcessExecutionEvents.js index 8731bf55a..b304be111 100644 --- a/ProcessExecutionEvents.js +++ b/ProcessExecutionEvents.js @@ -8,7 +8,7 @@ */ const MODULE_NAME = "Process Execution Events"; - logger.fileName = MODULE_NAME + logger.fileName = MODULE_NAME let bot = BOT; @@ -43,7 +43,7 @@ return } - let market = bot.market.baseAsset + '/' + bot.market.quotedAsset + let market = bot.market.baseAsset + '/' + bot.market.quotedAsset currentProcessKey = bot.processNode.referenceParent.name + "-" + bot.processNode.referenceParent.type + "-" + bot.processNode.referenceParent.id + "-" + bot.exchange + "-" + market if (bot.processNode.referenceParent.executionStartedEvent !== undefined) { @@ -52,7 +52,7 @@ processThisDependsOn = bot.processNode.referenceParent.executionStartedEvent.referenceParent.parentNode name = processThisDependsOn.name - if (processThisDependsOn.code.monthlyInstances === true) { + if (processThisDependsOn.config.monthlyInstances === true) { logger.fileName = MODULE_NAME + "." + name; } if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> " + currentProcessKey + " depends on " + name); } @@ -90,13 +90,13 @@ /* We found where the task that runs the process definition we are waiting for is located on the network. */ thisObject.networkNode = networkNode - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> Connecting to Websockets Server " + networkNode.name + " -> host = " + networkNode.code.host + ' -> port = ' + networkNode.code.webSocketsPort + '.'); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> Connecting to Websockets Server " + networkNode.name + " -> host = " + networkNode.config.host + ' -> port = ' + networkNode.config.webSocketsPort + '.'); } - eventServerClient = EVENT_SERVER_CLIENT.newEventsServerClient(networkNode.code.host, networkNode.code.webSocketsPort) + eventServerClient = EVENT_SERVER_CLIENT.newEventsServerClient(networkNode.config.host, networkNode.config.webSocketsPort) eventServerClient.initialize(onConnected) function onConnected() { - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> Connected to Websockets Server " + networkNode.name + " -> host = " + networkNode.code.host + ' -> port = ' + networkNode.code.webSocketsPort + '.'); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> Connected to Websockets Server " + networkNode.name + " -> host = " + networkNode.config.host + ' -> port = ' + networkNode.config.webSocketsPort + '.'); } callBackFunction(global.DEFAULT_OK_RESPONSE); return @@ -119,7 +119,7 @@ return } callBackFunction(global.DEFAULT_OK_RESPONSE); - + } catch (err) { logger.write(MODULE_NAME, "[ERROR] initialize -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); @@ -151,7 +151,7 @@ let extraCallerId = '-' + Math.trunc(Math.random() * 10000) + '-' - let market = bot.market.baseAsset + '/' + bot.market.quotedAsset + let market = bot.market.baseAsset + '/' + bot.market.quotedAsset let key = processThisDependsOn.name + "-" + processThisDependsOn.type + "-" + processThisDependsOn.id + "-" + bot.exchange + "-" + market let callerId = bot.dataMine + "-" + bot.codeName + "-" + bot.process + extraCallerId @@ -163,7 +163,7 @@ eventServerClient.listenToEvent(key, 'Process Execution Finished', undefined, callerId, responseCallBack, eventsCallBack) - bot.processHeartBeat(undefined, undefined, "Waiting for " + thisObject.networkNode.name + "->" + processThisDependsOn.parentNode.parentNode.name + "->" + processThisDependsOn.parentNode.code.codeName + "->" + processThisDependsOn.code.codeName) + bot.processHeartBeat(undefined, undefined, "Waiting for " + thisObject.networkNode.name + "->" + processThisDependsOn.parentNode.parentNode.name + "->" + processThisDependsOn.parentNode.config.codeName + "->" + processThisDependsOn.config.codeName) function responseCallBack(message) { if (message.result !== global.DEFAULT_OK_RESPONSE.result) { @@ -192,9 +192,9 @@ global.EVENT_SERVER_CLIENT.createEventHandler(currentProcessKey, 'Process Execution Started') global.EVENT_SERVER_CLIENT.raiseEvent(currentProcessKey, 'Process Execution Started', event) - bot.processHeartBeat(undefined, undefined,"Running...") + bot.processHeartBeat(undefined, undefined, "Running...") - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> eventsCallBack -> " + currentProcessKey + " Process Execution Started because " + key + " Finished."); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> eventsCallBack -> " + currentProcessKey + " Process Execution Started because " + key + " Finished."); } } callBackFunction(message.event.err); @@ -208,7 +208,7 @@ global.EVENT_SERVER_CLIENT.createEventHandler(currentProcessKey, 'Process Execution Started') global.EVENT_SERVER_CLIENT.raiseEvent(currentProcessKey, 'Process Execution Started', event) - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> " + currentProcessKey + " Process Execution Started " ); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> " + currentProcessKey + " Process Execution Started "); } callBackFunction(global.DEFAULT_OK_RESPONSE); } @@ -232,7 +232,7 @@ global.EVENT_SERVER_CLIENT.createEventHandler(currentProcessKey, 'Process Execution Finished') global.EVENT_SERVER_CLIENT.raiseEvent(currentProcessKey, 'Process Execution Finished', event) - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] finish -> " + currentProcessKey + " Process Execution Finished " ); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] finish -> " + currentProcessKey + " Process Execution Finished "); } callBackFunction(global.DEFAULT_OK_RESPONSE); diff --git a/ProcessOutput.js b/ProcessOutput.js index 7bbdfff10..2130a7cf6 100644 --- a/ProcessOutput.js +++ b/ProcessOutput.js @@ -30,29 +30,29 @@ /* Some validations to verify that everything is in place. */ if (outputDataset.referenceParent !== undefined) { - if (outputDataset.referenceParent.code.codeName === undefined) { + if (outputDataset.referenceParent.config.codeName === undefined) { logger.write(MODULE_NAME, "[ERROR] raiseEvents -> codeName at Dataset Definition not defined. Dataset Definition = " + JSON.stringify(outputDataset.referenceParent)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return - } + } if (outputDataset.referenceParent.parentNode !== undefined) { - if (outputDataset.referenceParent.parentNode.code.codeName === undefined) { + if (outputDataset.referenceParent.parentNode.config.codeName === undefined) { logger.write(MODULE_NAME, "[ERROR] raiseEvents -> codeName at Product not defined. Product = " + JSON.stringify(outputDataset.referenceParent.parentNode)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return - } + } if (outputDataset.referenceParent.parentNode.parentNode !== undefined) { - if (outputDataset.referenceParent.parentNode.parentNode.code.codeName === undefined) { + if (outputDataset.referenceParent.parentNode.parentNode.config.codeName === undefined) { logger.write(MODULE_NAME, "[ERROR] raiseEvents -> codeName at Bot not defined. Bot = " + JSON.stringify(outputDataset.referenceParent.parentNode.parentNode)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return - } + } if (outputDataset.referenceParent.parentNode.parentNode.parentNode !== undefined) { - if (outputDataset.referenceParent.parentNode.parentNode.parentNode.code.codeName === undefined) { + if (outputDataset.referenceParent.parentNode.parentNode.parentNode.config.codeName === undefined) { logger.write(MODULE_NAME, "[ERROR] raiseEvents -> codeName at Data Mine not defined. Data Mine = " + JSON.stringify(outputDataset.referenceParent.parentNode.parentNode.parentNode)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return - } + } } else { logger.write(MODULE_NAME, "[ERROR] raiseEvents -> Bot not attached to a Data Mine. Bot = " + JSON.stringify(outputDataset.referenceParent.parentNode.parentNode)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); @@ -76,10 +76,10 @@ /* All good, lets emit the event. */ - let dataMine = outputDataset.referenceParent.parentNode.parentNode.parentNode.code.codeName - let botName = outputDataset.referenceParent.parentNode.parentNode.code.codeName - let product = outputDataset.referenceParent.parentNode.code.codeName - let dataset = outputDataset.referenceParent.code.codeName + let dataMine = outputDataset.referenceParent.parentNode.parentNode.parentNode.config.codeName + let botName = outputDataset.referenceParent.parentNode.parentNode.config.codeName + let product = outputDataset.referenceParent.parentNode.config.codeName + let dataset = outputDataset.referenceParent.config.codeName key = dataMine + "-" + botName + "-" + product + "-" + dataset + "-" + bot.exchange + "-" + bot.market.baseAsset + '/' + bot.market.quotedAsset let event = { diff --git a/Root.js b/Root.js index 3a0dec4cd..f4f3910f3 100644 --- a/Root.js +++ b/Root.js @@ -112,7 +112,7 @@ } catch (err) { - console.log(logDisplace + "Root : [ERROR] initialize -> err = " + err.stack); + console.log(logDisplace + "Root : [ERROR] initialize -> err = " + err.stack); return; } } @@ -141,19 +141,19 @@ /* Here we will check if we need to load the configuration and code of the bot from a file or we will take that from the UI. */ if ( - processInstance.referenceParent.code.framework !== undefined && - ( processInstance.referenceParent.code.framework.name === 'Multi-Period-Market' || - processInstance.referenceParent.code.framework.name === 'Multi-Period-Daily' || - processInstance.referenceParent.code.framework.name === 'Multi-Period') - ) { - botConfig = processInstance.referenceParent.parentNode.code + processInstance.referenceParent.config.framework !== undefined && + (processInstance.referenceParent.config.framework.name === 'Multi-Period-Market' || + processInstance.referenceParent.config.framework.name === 'Multi-Period-Daily' || + processInstance.referenceParent.config.framework.name === 'Multi-Period') + ) { + botConfig = processInstance.referenceParent.parentNode.config botConfig.definedByUI = true bootingBot(processIndex) return } else { getBotConfigFromFile(); return - } + } function getBotConfigFromFile() { @@ -162,7 +162,7 @@ const FILE_STORAGE = require('./FileStorage.js'); let fileStorage = FILE_STORAGE.newFileStorage(); - let filePath = global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.code.codeName + '/bots/' + global.TASK_NODE.bot.code.repo + '/this.bot.config.json'; + let filePath = global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.config.codeName + '/bots/' + global.TASK_NODE.bot.config.repo + '/this.bot.config.json'; fileStorage.getTextFile(filePath, onFileReceived); @@ -171,13 +171,13 @@ if (err.result !== global.DEFAULT_OK_RESPONSE.result) { console.log(logDisplace + "Root : [ERROR] start -> getBotConfigFromFile -> onInizialized -> onFileReceived -> err = " + JSON.stringify(err)); console.log(logDisplace + "Root : [ERROR] start -> getBotConfigFromFile -> onInizialized -> onFileReceived -> filePath = " + filePath); - console.log(logDisplace + "Root : [ERROR] start -> getBotConfigFromFile -> onInizialized -> onFileReceived -> dataMine = " + global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.code.codeName); + console.log(logDisplace + "Root : [ERROR] start -> getBotConfigFromFile -> onInizialized -> onFileReceived -> dataMine = " + global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.config.codeName); return; } try { botConfig = JSON.parse(text); - botConfig.repo = global.TASK_NODE.bot.code.repo; + botConfig.repo = global.TASK_NODE.bot.config.repo; bootingBot(processIndex); } catch (err) { console.log(logDisplace + "Root : [ERROR] start -> getBotConfigFromFile -> onInizialized -> onFileReceived -> err = " + JSON.stringify(err)); @@ -195,7 +195,7 @@ try { - botConfig.process = global.TASK_NODE.bot.processes[processIndex].referenceParent.code.codeName + botConfig.process = global.TASK_NODE.bot.processes[processIndex].referenceParent.config.codeName botConfig.debug = {}; botConfig.processNode = global.TASK_NODE.bot.processes[processIndex] @@ -204,15 +204,15 @@ botConfig.DELETE_QUEUE_SIZE = 10 // This number represents how many log files can be at the queue at any point in time, which means how many logs are not still deleted. /* Simplifying the access to basic info */ - botConfig.dataMine = global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.code.codeName + botConfig.dataMine = global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.config.codeName botConfig.exchange = global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent.parentNode.parentNode.name botConfig.exchangeNode = global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent.parentNode.parentNode botConfig.market = { - baseAsset: global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent.baseAsset.referenceParent.code.codeName, - quotedAsset: global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent.quotedAsset.referenceParent.code.codeName + baseAsset: global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent.baseAsset.referenceParent.config.codeName, + quotedAsset: global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent.quotedAsset.referenceParent.config.codeName } - botConfig.uiStartDate = global.TASK_NODE.bot.code.startDate - botConfig.code = global.TASK_NODE.bot.code + botConfig.uiStartDate = global.TASK_NODE.bot.config.startDate + botConfig.config = global.TASK_NODE.bot.config /* This stuff is still hardcoded and unresolved. */ botConfig.version = { @@ -222,10 +222,10 @@ botConfig.dataSetVersion = "dataSet.V1" /* Loop Counter */ - botConfig.loopCounter = 0; + botConfig.loopCounter = 0; /* File Path Root */ - botConfig.filePathRoot = botConfig.exchange + "/" + botConfig.market.baseAsset + "-" + botConfig.market.quotedAsset + "/" + botConfig.dataMine + "/" + botConfig.codeName ; + botConfig.filePathRoot = botConfig.exchange + "/" + botConfig.market.baseAsset + "-" + botConfig.market.quotedAsset + "/" + botConfig.dataMine + "/" + botConfig.codeName; /* Process Key */ botConfig.processKey = global.TASK_NODE.bot.processes[processIndex].name + '-' + global.TASK_NODE.bot.processes[processIndex].type + '-' + global.TASK_NODE.bot.processes[processIndex].id @@ -243,14 +243,14 @@ if (botConfig.processNode.marketReference.keyInstance.referenceParent !== undefined) { let key = botConfig.processNode.marketReference.keyInstance.referenceParent - process.env.KEY = key.code.codeName - process.env.SECRET = key.code.secret + process.env.KEY = key.config.codeName + process.env.SECRET = key.config.secret } } } } - let processConfig = global.TASK_NODE.bot.processes[processIndex].referenceParent.code + let processConfig = global.TASK_NODE.bot.processes[processIndex].referenceParent.config if (processConfig.framework !== undefined) { if (processConfig.framework.name === "Multi-Period-Daily" || processConfig.framework.name === "Multi-Period-Market" || processConfig.framework.name === "Multi-Period") { @@ -283,7 +283,7 @@ if (processConfig.startMode === undefined) { // Default botConfig.hasTheBotJustStarted = true; - + switch (botConfig.type) { case 'Sensor Bot': { runSensorBot(botConfig, processConfig); @@ -475,7 +475,7 @@ pBotConfig.loopCounter = 0; let botId = pBotConfig.dataMine + "." + pBotConfig.codeName + "." + pBotConfig.process; - + if (err.result === global.DEFAULT_OK_RESPONSE.result) { logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully."); diff --git a/Session.js b/Session.js index 8e0c985bd..f8fdc0f1e 100644 --- a/Session.js +++ b/Session.js @@ -24,10 +24,10 @@ } /* Set the folderName for early logging */ - if (bot.processNode.session.code.folderName === undefined) { + if (bot.processNode.session.config.folderName === undefined) { bot.SESSION.folderName = bot.SESSION.id } else { - bot.SESSION.folderName = bot.processNode.session.code.folderName + "-" + bot.SESSION.id + bot.SESSION.folderName = bot.processNode.session.config.folderName + "-" + bot.SESSION.id } /* Check if there is a session */ @@ -59,13 +59,13 @@ bot.RESUME = message.event.resume /* Set the folderName for logging, reports, context and data output */ - let code - if (bot.SESSION.code !== undefined) { - code = bot.SESSION.code - if (code.folderName === undefined) { + let config + if (bot.SESSION.config !== undefined) { + config = bot.SESSION.config + if (config.folderName === undefined) { bot.SESSION.folderName = bot.SESSION.id } else { - bot.SESSION.folderName = code.folderName + "-" + bot.SESSION.id + bot.SESSION.folderName = config.folderName + "-" + bot.SESSION.id } } @@ -173,8 +173,8 @@ let balancePercentage = 1 // This is the default value - if (bot.SESSION.code.balancePercentage !== undefined) { - balancePercentage = bot.SESSION.code.balancePercentage + if (bot.SESSION.config.balancePercentage !== undefined) { + balancePercentage = bot.SESSION.config.balancePercentage } bot.VALUES_TO_USE.initialBalanceA = bot.VALUES_TO_USE.initialBalanceA * balancePercentage / 100 @@ -285,38 +285,38 @@ if (bot.SESSION.parameters.baseAsset.referenceParent !== undefined) { if (bot.SESSION.parameters.baseAsset.referenceParent.referenceParent !== undefined) { - let code = bot.SESSION.parameters.baseAsset.referenceParent.referenceParent.code + let config = bot.SESSION.parameters.baseAsset.referenceParent.referenceParent.config - if (code.codeName !== undefined) { - bot.VALUES_TO_USE.baseAsset = code.codeName; + if (config.codeName !== undefined) { + bot.VALUES_TO_USE.baseAsset = config.codeName; } - code = bot.SESSION.parameters.baseAsset.code + config = bot.SESSION.parameters.baseAsset.config if (bot.VALUES_TO_USE.baseAsset === bot.market.baseAsset) { - if (code.initialBalance !== undefined) { - bot.VALUES_TO_USE.initialBalanceA = code.initialBalance; + if (config.initialBalance !== undefined) { + bot.VALUES_TO_USE.initialBalanceA = config.initialBalance; bot.VALUES_TO_USE.initialBalanceB = 0 } - if (code.minimumBalance !== undefined) { - bot.VALUES_TO_USE.minimumBalanceA = code.minimumBalance; + if (config.minimumBalance !== undefined) { + bot.VALUES_TO_USE.minimumBalanceA = config.minimumBalance; bot.VALUES_TO_USE.minimumBalanceB = 0 } - if (code.maximumBalance !== undefined) { - bot.VALUES_TO_USE.maximumBalanceA = code.maximumBalance; + if (config.maximumBalance !== undefined) { + bot.VALUES_TO_USE.maximumBalanceA = config.maximumBalance; bot.VALUES_TO_USE.maximumBalanceB = 0 } } else { - if (code.initialBalance !== undefined) { - bot.VALUES_TO_USE.initialBalanceB = code.initialBalance; + if (config.initialBalance !== undefined) { + bot.VALUES_TO_USE.initialBalanceB = config.initialBalance; bot.VALUES_TO_USE.initialBalanceA = 0 } - if (code.minimumBalance !== undefined) { - bot.VALUES_TO_USE.minimumBalanceB = code.minimumBalance; + if (config.minimumBalance !== undefined) { + bot.VALUES_TO_USE.minimumBalanceB = config.minimumBalance; bot.VALUES_TO_USE.minimumBalanceA = 0 } - if (code.maximumBalance !== undefined) { - bot.VALUES_TO_USE.maximumBalanceB = code.maximumBalance; + if (config.maximumBalance !== undefined) { + bot.VALUES_TO_USE.maximumBalanceB = config.maximumBalance; bot.VALUES_TO_USE.maximumBalanceA = 0 } } @@ -348,10 +348,10 @@ if (bot.SESSION.parameters.quotedAsset.referenceParent !== undefined) { if (bot.SESSION.parameters.quotedAsset.referenceParent.referenceParent !== undefined) { - let code = bot.SESSION.parameters.quotedAsset.referenceParent.referenceParent.code + let config = bot.SESSION.parameters.quotedAsset.referenceParent.referenceParent.config - if (code.codeName !== undefined) { - bot.VALUES_TO_USE.quotedAsset = code.codeName; + if (config.codeName !== undefined) { + bot.VALUES_TO_USE.quotedAsset = config.codeName; } } } @@ -360,59 +360,59 @@ /* Time Frame */ if (bot.SESSION.parameters.timeFrame !== undefined) { - bot.VALUES_TO_USE.timeFrame = bot.SESSION.parameters.timeFrame.code.value + bot.VALUES_TO_USE.timeFrame = bot.SESSION.parameters.timeFrame.config.value } /* Slippage */ if (bot.SESSION.parameters.slippage !== undefined) { - if (bot.SESSION.parameters.slippage.code !== undefined) { + if (bot.SESSION.parameters.slippage.config !== undefined) { - let code = bot.SESSION.parameters.slippage.code + let config = bot.SESSION.parameters.slippage.config - if (code.positionRate !== undefined) { - bot.VALUES_TO_USE.slippage.positionRate = code.positionRate + if (config.positionRate !== undefined) { + bot.VALUES_TO_USE.slippage.positionRate = config.positionRate } - if (code.stopLoss !== undefined) { - bot.VALUES_TO_USE.slippage.stopLoss = code.stopLoss + if (config.stopLoss !== undefined) { + bot.VALUES_TO_USE.slippage.stopLoss = config.stopLoss } - if (code.takeProfit !== undefined) { - bot.VALUES_TO_USE.slippage.takeProfit = code.takeProfit + if (config.takeProfit !== undefined) { + bot.VALUES_TO_USE.slippage.takeProfit = config.takeProfit } } } /* Fee Structure */ if (bot.SESSION.parameters.feeStructure !== undefined) { - if (bot.SESSION.parameters.feeStructure.code !== undefined) { + if (bot.SESSION.parameters.feeStructure.config !== undefined) { - let code = bot.SESSION.parameters.feeStructure.code + let config = bot.SESSION.parameters.feeStructure.config - if (code.maker !== undefined) { - bot.VALUES_TO_USE.feeStructure.maker = code.maker + if (config.maker !== undefined) { + bot.VALUES_TO_USE.feeStructure.maker = config.maker } - if (code.taker !== undefined) { - bot.VALUES_TO_USE.feeStructure.taker = code.taker + if (config.taker !== undefined) { + bot.VALUES_TO_USE.feeStructure.taker = config.taker } } } /* Time Range */ if (bot.SESSION.parameters.timeRange !== undefined) { - if (bot.SESSION.parameters.timeRange.code !== undefined) { + if (bot.SESSION.parameters.timeRange.config !== undefined) { - let code = bot.SESSION.parameters.timeRange.code - if (code.initialDatetime !== undefined) { - if (isNaN(Date.parse(code.initialDatetime)) === true) { + let config = bot.SESSION.parameters.timeRange.config + if (config.initialDatetime !== undefined) { + if (isNaN(Date.parse(config.initialDatetime)) === true) { parentLogger.write(MODULE_NAME, "[WARN] initialize -> runSession -> setValuesToUse -> Cannot use initialDatatime provided at Session Parameters because it is not a valid Date."); } else { - bot.VALUES_TO_USE.timeRange.initialDatetime = new Date(code.initialDatetime) + bot.VALUES_TO_USE.timeRange.initialDatetime = new Date(config.initialDatetime) } } - if (code.finalDatetime !== undefined) { - if (isNaN(Date.parse(code.finalDatetime)) === true) { + if (config.finalDatetime !== undefined) { + if (isNaN(Date.parse(config.finalDatetime)) === true) { parentLogger.write(MODULE_NAME, "[WARN] initialize -> runSession -> setValuesToUse -> Cannot use finalDatetime provided at Session Parameters because it is not a valid Date."); } else { - bot.VALUES_TO_USE.timeRange.finalDatetime = new Date(code.finalDatetime) + bot.VALUES_TO_USE.timeRange.finalDatetime = new Date(config.finalDatetime) } } } @@ -429,8 +429,8 @@ for (let i = 0; i < bot.SESSION.socialBots.bots.length; i++) { let socialBot = bot.SESSION.socialBots.bots[i] if (socialBot.type === "Telegram Bot") { - let code = socialBot.code - socialBot.botInstance = initializeTelegramBot(code.botToken, code.chatId) + let config = socialBot.config + socialBot.botInstance = initializeTelegramBot(config.botToken, config.chatId) } } } @@ -440,13 +440,13 @@ for (let i = 0; i < bot.SESSION.socialBots.bots.length; i++) { let socialBot = bot.SESSION.socialBots.bots[i] try { - let code = announcement.code + let config = announcement.config if (socialBot.type === "Telegram Bot") { if (announcement.formulaValue !== undefined) { socialBot.botInstance.telegramAPI.sendMessage(socialBot.botInstance.chatId, announcement.formulaValue).catch(err => parentLogger.write(MODULE_NAME, "[WARN] initialize -> initializeSocialBots -> announce -> Telegram API error -> err = " + err)) } else { - socialBot.botInstance.telegramAPI.sendMessage(socialBot.botInstance.chatId, code.text).catch(err => parentLogger.write(MODULE_NAME, "[WARN] initialize -> initializeSocialBots -> announce -> Telegram API error -> err = " + err)) + socialBot.botInstance.telegramAPI.sendMessage(socialBot.botInstance.chatId, config.text).catch(err => parentLogger.write(MODULE_NAME, "[WARN] initialize -> initializeSocialBots -> announce -> Telegram API error -> err = " + err)) } } @@ -467,8 +467,8 @@ for (let i = 0; i < bot.SESSION.socialBots.bots.length; i++) { let socialBot = bot.SESSION.socialBots.bots[i] if (socialBot.type === "Telegram Bot") { - let code = socialBot.code - socialBot.botInstance = finalizeTelegramBot(code.chatId) + let config = socialBot.config + socialBot.botInstance = finalizeTelegramBot(config.chatId) } } } diff --git a/StatusReport.js b/StatusReport.js index 65609aa40..b9865452e 100644 --- a/StatusReport.js +++ b/StatusReport.js @@ -59,7 +59,7 @@ return } - if (statusDependencyNode.referenceParent.parentNode.code.codeName === undefined) { + if (statusDependencyNode.referenceParent.parentNode.config.codeName === undefined) { logger.write(MODULE_NAME, "[ERROR] initialize -> Process Definition witn no codeName defined. Process Definition = " + JSON.stringify(statusDependencyNode.referenceParent.parentNode)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return @@ -71,7 +71,7 @@ return } - if (statusDependencyNode.referenceParent.parentNode.parentNode.code.codeName === undefined) { + if (statusDependencyNode.referenceParent.parentNode.parentNode.config.codeName === undefined) { logger.write(MODULE_NAME, "[ERROR] initialize -> Bot witn no codeName defined. Bot = " + JSON.stringify(statusDependencyNode.referenceParent.parentNode.parentNode)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return @@ -83,22 +83,22 @@ return } - if (statusDependencyNode.referenceParent.parentNode.parentNode.parentNode.code.codeName === undefined) { + if (statusDependencyNode.referenceParent.parentNode.parentNode.parentNode.config.codeName === undefined) { logger.write(MODULE_NAME, "[ERROR] initialize -> Data Mine witn no codeName defined. Data Mine = " + JSON.stringify(statusDependencyNode.referenceParent.parentNode.parentNode.parentNode)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return } /* Simplifying the access to basic info */ - statusDependencyNode.bot = statusDependencyNode.referenceParent.parentNode.parentNode.code.codeName - statusDependencyNode.process = statusDependencyNode.referenceParent.parentNode.code.codeName + statusDependencyNode.bot = statusDependencyNode.referenceParent.parentNode.parentNode.config.codeName + statusDependencyNode.process = statusDependencyNode.referenceParent.parentNode.config.codeName statusDependencyNode.bottype = statusDependencyNode.referenceParent.parentNode.parentNode.type - statusDependencyNode.dataMine = statusDependencyNode.referenceParent.parentNode.parentNode.parentNode.code.codeName + statusDependencyNode.dataMine = statusDependencyNode.referenceParent.parentNode.parentNode.parentNode.config.codeName /* We retrieve the report main utility */ - if (statusDependencyNode.code !== undefined) { - if (statusDependencyNode.code.mainUtility !== undefined) { - thisObject.mainUtility = statusDependencyNode.code.mainUtility + if (statusDependencyNode.config !== undefined) { + if (statusDependencyNode.config.mainUtility !== undefined) { + thisObject.mainUtility = statusDependencyNode.config.mainUtility } } @@ -156,9 +156,9 @@ /* We found where the task that runs the process definition this status report depends on and where it is located on the network. */ thisObject.networkNode = networkNode - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> Retrieving status report from " + networkNode.name + " -> host = " + networkNode.code.host + ' -> port = ' + networkNode.code.webPort + '.'); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> Retrieving status report from " + networkNode.name + " -> host = " + networkNode.config.host + ' -> port = ' + networkNode.config.webPort + '.'); } - fileStorage = FILE_STORAGE.newFileStorage(logger, networkNode.code.host, networkNode.code.webPort); + fileStorage = FILE_STORAGE.newFileStorage(logger, networkNode.config.host, networkNode.config.webPort); callBackFunction(global.DEFAULT_OK_RESPONSE); return true } diff --git a/TradingSimulation.js b/TradingSimulation.js index d55c3db4e..313b2e1e7 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -294,9 +294,9 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, UTILIT for (let k = 0; k < dataDependencies.length; k++) { let dataDependencyNode = dataDependencies[k] - if (dataDependencyNode.referenceParent.code.codeName !== 'Multi-Period-Daily') { continue } - let singularVariableName = dataDependencyNode.referenceParent.parentNode.code.singularVariableName - let pluralVariableName = dataDependencyNode.referenceParent.parentNode.code.pluralVariableName + if (dataDependencyNode.referenceParent.config.codeName !== 'Multi-Period-Daily') { continue } + let singularVariableName = dataDependencyNode.referenceParent.parentNode.config.singularVariableName + let pluralVariableName = dataDependencyNode.referenceParent.parentNode.config.pluralVariableName let currentElement = getElement(thisChart[pluralVariableName], candle, 'Daily' + '-' + mapKey + '-' + pluralVariableName) thisChart[singularVariableName] = currentElement } @@ -311,9 +311,9 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, UTILIT for (let k = 0; k < dataDependencies.length; k++) { let dataDependencyNode = dataDependencies[k] - if (dataDependencyNode.referenceParent.code.codeName !== 'Multi-Period-Market') { continue } - let singularVariableName = dataDependencyNode.referenceParent.parentNode.code.singularVariableName - let pluralVariableName = dataDependencyNode.referenceParent.parentNode.code.pluralVariableName + if (dataDependencyNode.referenceParent.config.codeName !== 'Multi-Period-Market') { continue } + let singularVariableName = dataDependencyNode.referenceParent.parentNode.config.singularVariableName + let pluralVariableName = dataDependencyNode.referenceParent.parentNode.config.pluralVariableName let currentElement = getElement(thisChart[pluralVariableName], candle, 'Market' + '-' + mapKey + '-' + pluralVariableName) thisChart[singularVariableName] = currentElement } @@ -333,9 +333,9 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, UTILIT for (let k = 0; k < dataDependencies.length; k++) { let dataDependencyNode = dataDependencies[k] - if (dataDependencyNode.referenceParent.code.codeName !== 'Single-File') { continue } - let singularVariableName = dataDependencyNode.referenceParent.parentNode.code.singularVariableName - let pluralVariableName = dataDependencyNode.referenceParent.parentNode.code.pluralVariableName + if (dataDependencyNode.referenceParent.config.codeName !== 'Single-File') { continue } + let singularVariableName = dataDependencyNode.referenceParent.parentNode.config.singularVariableName + let pluralVariableName = dataDependencyNode.referenceParent.parentNode.config.pluralVariableName let elementArray = thisChart[pluralVariableName] let currentElement if (elementArray !== undefined) { @@ -2339,8 +2339,8 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, UTILIT /* The Value Variation is what tells us how much the value already announced must change in order to annouce it again. */ let valueVariation - let code = announcement.code - valueVariation = code.valueVariation + let config = announcement.config + valueVariation = config.valueVariation if (newAnnouncementRecord.value !== undefined && valueVariation !== undefined) { let upperLimit = newAnnouncementRecord.value + newAnnouncementRecord.value * valueVariation / 100 diff --git a/server.js b/server.js index 80ac46a62..e2840cc6d 100644 --- a/server.js +++ b/server.js @@ -57,7 +57,7 @@ function finalizeSessions() { } } -process.on('exit', function (code) { +process.on('exit', function (config) { if (global.TASK_NODE !== undefined) { /* We send an event signaling that the Task is being terminated. */ @@ -68,7 +68,7 @@ process.on('exit', function (code) { global.EVENT_SERVER_CLIENT = undefined } - //console.log('[INFO] Task Server -> server -> process.on.exit -> About to exit -> code = ' + code) + //console.log('[INFO] Task Server -> server -> process.on.exit -> About to exit -> config = ' + config) }) /* Here we listen for the message to stop this Task / Process comming from the Task Manager, which is the paret of this node js process. */ @@ -84,7 +84,7 @@ process.on('message', message => { let key = global.TASK_NODE.name + '-' + global.TASK_NODE.type + '-' + global.TASK_NODE.id console.log('[INFO] Task Server -> server -> process.on -> Stopping Task ' + key + '. Nodejs process will be exited in less than 1 minute.') setTimeout(global.EXIT_NODE_PROCESS, 60000); - } + } }); @@ -101,7 +101,7 @@ global.EXIT_NODE_PROCESS = function exitProcess() { clearInterval(global.HEARTBEAT_INTERVAL_HANDLER) for (let i = 0; i < global.TASK_NODE.bot.processes.length; i++) { - let code = global.TASK_NODE.bot.processes[i].code + let config = global.TASK_NODE.bot.processes[i].config let process = global.TASK_NODE.bot.processes[i] key = process.name + '-' + process.type + '-' + process.id @@ -138,7 +138,7 @@ let taskId = process.argv[2] // reading what comes as an argument of the nodejs /* Setting up the global Event Handler */ let EVENT_SERVER_CLIENT = require('./EventServerClient.js'); - + global.EVENT_SERVER_CLIENT = EVENT_SERVER_CLIENT.newEventsServerClient() global.EVENT_SERVER_CLIENT.initialize(preLoader) global.STOP_TASK_GRACEFULLY = false; @@ -162,7 +162,7 @@ function preLoader() { } } else { /* This process was started not by the Task Manager, but independently (most likely for debugging purposes). In this case we listen to an event with the Task Info that should be emitted at the UI */ - try { + try { //console.log('[INFO] Task Server -> server -> preLoader -> Waiting for event to start debugging...') global.EVENT_SERVER_CLIENT.listenToEvent('Task Server', 'Debug Task Started', undefined, 'Task Server', undefined, startDebugging) function startDebugging(message) { @@ -190,15 +190,15 @@ function bootLoader() { function taskHearBeat() { - /* The heartbeat event is raised at the event handler of the instance of this task, created at the UI. */ + /* The heartbeat event is raised at the event handler of the instance of this task, created at the UI. */ let event = { seconds: (new Date()).getSeconds() } - global.EVENT_SERVER_CLIENT.raiseEvent(key, 'Heartbeat', event) + global.EVENT_SERVER_CLIENT.raiseEvent(key, 'Heartbeat', event) } for (let processIndex = 0; processIndex < global.TASK_NODE.bot.processes.length; processIndex++) { - let code = global.TASK_NODE.bot.processes[processIndex].code + let config = global.TASK_NODE.bot.processes[processIndex].config /* Validate that the minimun amount of input required are defined. */ @@ -257,17 +257,17 @@ function bootLoader() { continue } - if (global.TASK_NODE.bot.processes[processIndex].referenceParent.code.codeName === undefined) { + if (global.TASK_NODE.bot.processes[processIndex].referenceParent.config.codeName === undefined) { console.log("[WARN] Task Server -> server -> bootLoader -> Process Definition without a codeName defined. -> Process Definition = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].referenceParent)); continue } - if (global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.code.codeName === undefined) { + if (global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.config.codeName === undefined) { console.log("[WARN] Task Server -> server -> bootLoader -> Bot Definition without a codeName defined. -> Bot Definition = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode)); continue } - if (global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.code.codeName === undefined) { + if (global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.config.codeName === undefined) { console.log("[WARN] Task Server -> server -> bootLoader -> Data Mine without a codeName defined. -> Data Mine Definition = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode)); continue } @@ -278,7 +278,7 @@ function bootLoader() { function startRoot(processIndex) { - // console.log('[INFO] Task Server -> server -> startRoot -> Entering function. ') + // console.log('[INFO] Task Server -> server -> startRoot -> Entering function. ') const ROOT_MODULE = require('./Root') let root = ROOT_MODULE.newRoot() @@ -299,13 +299,13 @@ global.getPercentage = function (fromDate, currentDate, lastDate) { if ((lastDays - fromDays) === 0) { percentage = 100 } - return percentage + return percentage } global.areEqualDates = function (date1, date2) { let day1Days = Math.trunc(date1.valueOf() / ONE_DAY_IN_MILISECONDS) let day2Days = Math.trunc(date2.valueOf() / ONE_DAY_IN_MILISECONDS) - + if (day1Days === day2Days) { return true } else {