Bug Fixes + Folders
This commit is contained in:
1 parent
17fe6ca50f
commit
cb61cc1ef0
39 files changed
+1333
-299
No files matched your search
+13
-8
@@ -95,26 +95,31 @@
|
||||
return
|
||||
}
|
||||
|
||||
if (outputDatasetNode.referenceParent.parentNode.parentNode === undefined) {
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> Product Definition not attached to a Bot. Product Definition = " + JSON.stringify(outputDatasetNode.referenceParent.parentNode));
|
||||
let botNode = global.FIND_NODE_IN_NODE_MESH(outputDatasetNode, 'Indicator Bot')
|
||||
if (botNode === undefined) {
|
||||
botNode = global.FIND_NODE_IN_NODE_MESH(outputDatasetNode, 'Trading Bot')
|
||||
}
|
||||
if (botNode === undefined) {
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> Product Definition not attached to a Bot. Product Definition = " );
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return
|
||||
}
|
||||
|
||||
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));
|
||||
if (botNode.config.codeName === undefined) {
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> Bot witn no codeName defined." );
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return
|
||||
}
|
||||
|
||||
if (outputDatasetNode.referenceParent.parentNode.parentNode.parentNode === undefined) {
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> Bot not attached to a Data Mine. Bot = " + JSON.stringify(outputDatasetNode.referenceParent.parentNode.parentNode));
|
||||
let dataMineNode = global.FIND_NODE_IN_NODE_MESH(outputDatasetNode, 'Data Mine')
|
||||
if (dataMineNode === undefined) {
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> Bot not attached to a Data Mine.");
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return
|
||||
}
|
||||
|
||||
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));
|
||||
if (dataMineNode.config.codeName === undefined) {
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> Data Mine witn no codeName defined." );
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return
|
||||
}
|
||||
|
||||
+12
-67
@@ -79,77 +79,22 @@ exports.newDataSet = function newDataSet(BOT, logger) {
|
||||
let network = global.TASK_NETWORK
|
||||
let datasetProductDefinition = thisObject.node.parentNode
|
||||
|
||||
for (let i = 0; i < network.networkNodes.length; i++) {
|
||||
let networkNode = network.networkNodes[i]
|
||||
if (networkNode.dataStorage !== undefined) {
|
||||
if (networkNode.dataStorage.sessionIndependentData !== undefined) {
|
||||
for (let j = 0; j < networkNode.dataStorage.sessionIndependentData.exchangeDataProducts.length; j++) {
|
||||
let exchangeDataProduct = networkNode.dataStorage.sessionIndependentData.exchangeDataProducts[j]
|
||||
for (let k = 0; k < exchangeDataProduct.singleMarketData.length; k++) {
|
||||
let singleMarketData = exchangeDataProduct.singleMarketData[k]
|
||||
if (singleMarketData.referenceParent !== undefined) {
|
||||
let market = singleMarketData.referenceParent
|
||||
let currentProcessMarket = bot.processNode.marketReference.referenceParent
|
||||
let nodeArray = global.NODE_MESH_TO_PATH_ARRAY(network, datasetProductDefinition.id)
|
||||
let networkNode = global.FIND_NODE_IN_NODE_ARRAY(nodeArray, 'Network Node')
|
||||
|
||||
if (currentProcessMarket.id === market.id) {
|
||||
for (let m = 0; m < singleMarketData.dataProducts.length; m++) {
|
||||
let dataProduct = singleMarketData.dataProducts[m]
|
||||
if (dataProduct.referenceParent !== undefined) {
|
||||
let productDefinition = dataProduct.referenceParent
|
||||
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.config.host + ' -> port = ' + networkNode.config.webPort + '.'); }
|
||||
|
||||
fileStorage = FILE_STORAGE.newFileStorage(logger, networkNode.config.host, networkNode.config.webPort);
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (networkNode.dataStorage.sessionBasedData !== undefined) {
|
||||
for (let j = 0; j < networkNode.dataStorage.sessionBasedData.exchangeDataProducts.length; j++) {
|
||||
let exchangeDataProduct = networkNode.dataStorage.sessionBasedData.exchangeDataProducts[j]
|
||||
for (let s = 0; s < exchangeDataProduct.sessionReferences.length; s++) {
|
||||
let sessionReference = exchangeDataProduct.sessionReferences[s]
|
||||
let singleMarketData = sessionReference.singleMarketData
|
||||
if (singleMarketData.referenceParent !== undefined) {
|
||||
let market = singleMarketData.referenceParent
|
||||
let currentProcessMarket = bot.processNode.marketReference.referenceParent
|
||||
|
||||
if (currentProcessMarket.id === market.id) {
|
||||
for (let m = 0; m < singleMarketData.dataProducts.length; m++) {
|
||||
let dataProduct = singleMarketData.dataProducts[m]
|
||||
if (dataProduct.referenceParent !== undefined) {
|
||||
let productDefinition = dataProduct.referenceParent
|
||||
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.config.host + ' -> port = ' + networkNode.config.webPort + '.'); }
|
||||
|
||||
fileStorage = FILE_STORAGE.newFileStorage(logger, networkNode.config.host, networkNode.config.webPort);
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (networkNode === undefined) {
|
||||
logger.write(MODULE_NAME, "[ERROR] initialize -> Network Node not found.")
|
||||
logger.write(MODULE_NAME, "[ERROR] initialize -> Initialization Failed because we could not find where the data of this dataset is located within the network. Check the logs for more info.");
|
||||
logger.write(MODULE_NAME, "[ERROR] initialize -> Could not find where " + datasetProductDefinition.name + " for " + bot.exchange + " " + bot.market.baseAsset + "/" + bot.market.quotedAsset + " is stored within the network.");
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return
|
||||
}
|
||||
|
||||
logger.write(MODULE_NAME, "[ERROR] initialize -> Initialization Failed because we could not find where the data of this dataset is located within the network. Check the logs for more info.");
|
||||
logger.write(MODULE_NAME, "[ERROR] initialize -> Could not find where " + datasetProductDefinition.name + " for " + bot.exchange + " " + bot.market.baseAsset + "/" + bot.market.quotedAsset + " is stored within the network.");
|
||||
/* 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.config.host + ' -> port = ' + networkNode.config.webPort + '.'); }
|
||||
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
fileStorage = FILE_STORAGE.newFileStorage(logger, networkNode.config.host, networkNode.config.webPort);
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
|
||||
} catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] initialize -> err = " + err.stack);
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
let dataDependencies = bot.processNode.referenceParent.processDependencies.dataDependencies
|
||||
if (commons.validateDataDependencies(dataDependencies, callBackFunction) !== true) { return }
|
||||
|
||||
let outputDatasets = bot.processNode.referenceParent.processOutput.outputDatasets
|
||||
let outputDatasets = global.NODE_BRANCH_TO_ARRAY (bot.processNode.referenceParent.processOutput, 'Output Dataset')
|
||||
if (commons.validateOutputDatasets(outputDatasets, callBackFunction) !== true) { return }
|
||||
|
||||
/* The second phase is about transforming the inputs into a format that can be used to apply the user defined code. */
|
||||
@@ -130,8 +130,11 @@
|
||||
|
||||
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
|
||||
|
||||
let botNode = global.FIND_NODE_IN_NODE_MESH(outputDatasetNode, 'Indicator Bot')
|
||||
contextSummary.bot = botNode.config.codeName
|
||||
let dataMineNode = global.FIND_NODE_IN_NODE_MESH(outputDatasetNode, 'Data Mine')
|
||||
contextSummary.dataMine = dataMineNode.config.codeName
|
||||
|
||||
let fileContent = commons.generateFileContent(outputData, outputDatasetNode.referenceParent.parentNode.record, resultsWithIrregularPeriods, processingDailyFiles, currentDay, callBackFunction)
|
||||
commons.writeFile(contextSummary, fileContent, anotherFileWritten, processingDailyFiles, timeFrameLabel, currentDay, callBackFunction)
|
||||
|
||||
@@ -124,7 +124,7 @@ exports.newSnapshots = function newSnapshots(bot, logger) {
|
||||
}
|
||||
|
||||
/* Now we go down through all this node children */
|
||||
let nodeDefinition = bot.APP_SCHEMA_MAP.get(node.type)
|
||||
let nodeDefinition = global.APP_SCHEMA_MAP.get(node.type)
|
||||
if (nodeDefinition === undefined) { return }
|
||||
|
||||
if (nodeDefinition.properties !== undefined) {
|
||||
|
||||
@@ -99,7 +99,7 @@ exports.newTradingEngine = function newTradingEngine(bot, logger) {
|
||||
destinationNode.value = originNode.value
|
||||
|
||||
/* Now we go down through all the children of the origin node, assuming the destination node has the same children structure*/
|
||||
let nodeDefinition = bot.APP_SCHEMA_MAP.get(originNode.type)
|
||||
let nodeDefinition = global.APP_SCHEMA_MAP.get(originNode.type)
|
||||
if (nodeDefinition === undefined) { return }
|
||||
|
||||
if (nodeDefinition.properties !== undefined) {
|
||||
@@ -138,7 +138,7 @@ exports.newTradingEngine = function newTradingEngine(bot, logger) {
|
||||
nodesMap.set(node.id, node)
|
||||
|
||||
/* Now we go down through all this node children */
|
||||
let nodeDefinition = bot.APP_SCHEMA_MAP.get(node.type)
|
||||
let nodeDefinition = global.APP_SCHEMA_MAP.get(node.type)
|
||||
if (nodeDefinition === undefined) { return }
|
||||
|
||||
if (nodeDefinition.properties !== undefined) {
|
||||
@@ -181,7 +181,7 @@ exports.newTradingEngine = function newTradingEngine(bot, logger) {
|
||||
}
|
||||
|
||||
/* Now we go down through all this node children */
|
||||
let nodeDefinition = bot.APP_SCHEMA_MAP.get(node.type)
|
||||
let nodeDefinition = global.APP_SCHEMA_MAP.get(node.type)
|
||||
if (nodeDefinition === undefined) { return }
|
||||
|
||||
if (nodeDefinition.properties !== undefined) {
|
||||
|
||||
@@ -503,7 +503,7 @@ exports.newTradingOrders = function newTradingOrders(bot, logger, tradingEngineM
|
||||
tradingEngineOrder.orderQuotedAsset.size.value = global.PRECISE(tradingEngineOrder.orderQuotedAsset.size.value, 10)
|
||||
}
|
||||
|
||||
function recalculateSizePlaced(){
|
||||
function recalculateSizePlaced() {
|
||||
/*
|
||||
Recaulculate the Size Placed Based on the newly calculated Quoted Asset Size.
|
||||
*/
|
||||
@@ -723,12 +723,14 @@ exports.newTradingOrders = function newTradingOrders(bot, logger, tradingEngineM
|
||||
|
||||
function syncWithExchange(tradingEngineStage, tradingSystemOrder, tradingEngineOrder, order) {
|
||||
|
||||
let previousBaseAssetSize = tradingEngineOrder.orderBaseAsset.size.value
|
||||
let previousQuotedAssetSize = tradingEngineOrder.orderQuotedAsset.size.value
|
||||
let previousBaseAssetSizeFilled = tradingEngineOrder.orderBaseAsset.sizeFilled.value
|
||||
let previousQuotedAssetSizeFilled = tradingEngineOrder.orderQuotedAsset.sizeFilled.value
|
||||
let previousBaseAssetFeesPaid = tradingEngineOrder.orderBaseAsset.feesPaid.value
|
||||
let previousQuotedAssetFeesPaid = tradingEngineOrder.orderQuotedAsset.feesPaid.value
|
||||
|
||||
actualSizeCalculation()
|
||||
actualRateCalculation()
|
||||
percentageFilledCalculation()
|
||||
feesPaidCalculation()
|
||||
@@ -746,6 +748,51 @@ exports.newTradingOrders = function newTradingOrders(bot, logger, tradingEngineM
|
||||
|
||||
return
|
||||
|
||||
function actualSizeCalculation() {
|
||||
/*
|
||||
When we submit the order to the exchange, we do it specifying the order size
|
||||
in Base Asset. The exchange might take that size or might change it a little
|
||||
bit if for example, it does not accept as many decimals as we are sending.
|
||||
If we identify the situation in which the size accepted is different than the
|
||||
size we have accounted for, we need to make several adjustments so that the
|
||||
accounting syncronizes with reality.
|
||||
*/
|
||||
if (tradingEngineOrder.orderBaseAsset.size.value === order.amount) { return }
|
||||
/*
|
||||
We will sync the Base Asset size, and recalculate the Quoted Asset size too.
|
||||
*/
|
||||
tradingEngineOrder.orderBaseAsset.size.value = order.amount
|
||||
tradingEngineOrder.orderQuotedAsset.size.value = tradingEngineOrder.orderBaseAsset.size.value * tradingEngineOrder.rate.value
|
||||
|
||||
tradingEngineOrder.orderBaseAsset.size.value = global.PRECISE(tradingEngineOrder.orderBaseAsset.size.value, 10)
|
||||
tradingEngineOrder.orderQuotedAsset.size.value = global.PRECISE(tradingEngineOrder.orderQuotedAsset.size.value, 10)
|
||||
/*
|
||||
Finaly we need to unaccount the previous size placed and correctly account
|
||||
for the the new sizes we know have.
|
||||
*/
|
||||
tradingEngineStage.stageBaseAsset.sizePlaced.value =
|
||||
tradingEngineStage.stageBaseAsset.sizePlaced.value -
|
||||
previousBaseAssetSize
|
||||
|
||||
tradingEngineStage.stageBaseAsset.sizePlaced.value =
|
||||
tradingEngineStage.stageBaseAsset.sizePlaced.value +
|
||||
tradingEngineOrder.orderBaseAsset.size.value
|
||||
|
||||
tradingEngineStage.stageQuotedAsset.sizePlaced.value =
|
||||
tradingEngineStage.stageQuotedAsset.sizePlaced.value -
|
||||
previousQuotedAssetSize
|
||||
|
||||
tradingEngineStage.stageQuotedAsset.sizePlaced.value =
|
||||
tradingEngineStage.stageQuotedAsset.sizePlaced.value +
|
||||
tradingEngineOrder.orderQuotedAsset.size.value
|
||||
|
||||
tradingEngineStage.stageBaseAsset.sizePlaced.value = global.PRECISE(tradingEngineStage.stageBaseAsset.sizePlaced.value, 10)
|
||||
tradingEngineStage.stageQuotedAsset.sizePlaced.value = global.PRECISE(tradingEngineStage.stageQuotedAsset.sizePlaced.value, 10)
|
||||
|
||||
previousBaseAssetSize = tradingEngineOrder.orderBaseAsset.size.value
|
||||
previousQuotedAssetSize = tradingEngineOrder.orderQuotedAsset.size.value
|
||||
}
|
||||
|
||||
function actualRateCalculation() {
|
||||
/*
|
||||
Actual Rate Calculation: Let's remember that the exchange may not take the rate
|
||||
@@ -772,9 +819,11 @@ exports.newTradingOrders = function newTradingOrders(bot, logger, tradingEngineM
|
||||
}
|
||||
|
||||
tradingEngineOrder.orderStatistics.actualRate.value = global.PRECISE(tradingEngineOrder.orderStatistics.actualRate.value, 10)
|
||||
|
||||
if (tradingEngineOrder.orderStatistics.actualRate.value === tradingEngineOrder.rate.value) {return}
|
||||
/*
|
||||
Now we know the Actual Rate at which the order was filled. Since the actual rate
|
||||
might not be the same as the Rate we defined for the order, we need to syncronize
|
||||
is not the same as the Rate we defined for the order, we need to syncronize
|
||||
the Order Size for Quoted Asset since it was calculated with the Order Size that we
|
||||
now know it is not the once really used at the exchange. We will recalculate the
|
||||
Order Size in Quoted Asset and not in Base Asset, since the Order Size in Base Asset
|
||||
|
||||
@@ -40,7 +40,7 @@ exports.newTradingOutput = function newTradingOutput(bot, logger, tradingEngineM
|
||||
const TRADING_SIMULATION = require('./TradingSimulation.js')
|
||||
let tradingSimulation = TRADING_SIMULATION.newTradingSimulation(bot, logger, tradingEngineModule, UTILITIES)
|
||||
|
||||
let outputDatasets = bot.processNode.referenceParent.processOutput.outputDatasets
|
||||
let outputDatasets = global.NODE_BRANCH_TO_ARRAY(bot.processNode.referenceParent.processOutput, 'Output Dataset')
|
||||
let outputDatasetsMap = new Map()
|
||||
|
||||
if (bot.processingDailyFiles === true) {
|
||||
|
||||
@@ -507,7 +507,7 @@
|
||||
let dataDependencies = bot.processNode.referenceParent.processDependencies.dataDependencies
|
||||
if (commons.validateDataDependencies(dataDependencies, callBackFunction) !== true) { return }
|
||||
|
||||
let outputDatasets = bot.processNode.referenceParent.processOutput.outputDatasets
|
||||
let outputDatasets = global.NODE_BRANCH_TO_ARRAY(bot.processNode.referenceParent.processOutput, 'Output Dataset')
|
||||
if (commons.validateOutputDatasets(outputDatasets, callBackFunction) !== true) { return }
|
||||
|
||||
/* The second phase is about transforming the inputs into a format that can be used to apply the user defined code. */
|
||||
@@ -566,6 +566,7 @@
|
||||
}
|
||||
|
||||
async function writeProcessFiles() {
|
||||
let outputDatasets = global.NODE_BRANCH_TO_ARRAY(bot.processNode.referenceParent.processOutput, 'Output Dataset')
|
||||
|
||||
await writeTimeFramesFiles(currentTimeFrame, currentTimeFrameLabel)
|
||||
await writeDataRanges()
|
||||
@@ -579,10 +580,10 @@
|
||||
async function writeDataRanges() {
|
||||
for (
|
||||
let outputDatasetIndex = 0;
|
||||
outputDatasetIndex < bot.processNode.referenceParent.processOutput.outputDatasets.length;
|
||||
outputDatasetIndex < outputDatasets.length;
|
||||
outputDatasetIndex++
|
||||
) {
|
||||
let productCodeName = bot.processNode.referenceParent.processOutput.outputDatasets[outputDatasetIndex].referenceParent.parentNode.config.codeName;
|
||||
let productCodeName = outputDatasets[outputDatasetIndex].referenceParent.parentNode.config.codeName;
|
||||
await writeDataRange(productCodeName);
|
||||
}
|
||||
|
||||
@@ -618,10 +619,10 @@
|
||||
|
||||
for (
|
||||
let outputDatasetIndex = 0;
|
||||
outputDatasetIndex < bot.processNode.referenceParent.processOutput.outputDatasets.length;
|
||||
outputDatasetIndex < outputDatasets.length;
|
||||
outputDatasetIndex++
|
||||
) {
|
||||
let productCodeName = bot.processNode.referenceParent.processOutput.outputDatasets[outputDatasetIndex].referenceParent.parentNode.config.codeName;
|
||||
let productCodeName = outputDatasets[outputDatasetIndex].referenceParent.parentNode.config.codeName;
|
||||
await writeTimeFramesFile( currentTimeFrameLabel, productCodeName, 'Multi-Period-Daily')
|
||||
await writeTimeFramesFile( currentTimeFrameLabel, productCodeName, 'Multi-Period-Market')
|
||||
|
||||
|
||||
@@ -37,7 +37,8 @@ exports.newTradingRecords = function newTradingRecords(bot, logger) {
|
||||
we have a pointer to the node that have the information we need to extract.
|
||||
Later, based on the product record definition we will extract each individual value.
|
||||
*/
|
||||
let outputDatasets = bot.processNode.referenceParent.processOutput.outputDatasets
|
||||
let outputDatasets = global.NODE_BRANCH_TO_ARRAY(bot.processNode.referenceParent.processOutput, 'Output Dataset')
|
||||
|
||||
for (let i = 0; i < outputDatasets.length; i++) {
|
||||
let outputDatasetNode = outputDatasets[i]
|
||||
let dataset = outputDatasetNode.referenceParent
|
||||
|
||||
@@ -182,7 +182,7 @@ exports.newTradingSystem = function newTradingSystem(bot, logger, tradingEngineM
|
||||
}
|
||||
|
||||
/* Now we go down through all this node children */
|
||||
let nodeDefinition = bot.APP_SCHEMA_MAP.get(node.type)
|
||||
let nodeDefinition = global.APP_SCHEMA_MAP.get(node.type)
|
||||
if (nodeDefinition === undefined) { return }
|
||||
|
||||
if (nodeDefinition.properties !== undefined) {
|
||||
|
||||
@@ -469,17 +469,18 @@
|
||||
}
|
||||
|
||||
function writeDataRanges(callBack) {
|
||||
let outputDatasets = global.NODE_BRANCH_TO_ARRAY (bot.processNode.referenceParent.processOutput, 'Output Dataset')
|
||||
let outputDatasetIndex = -1;
|
||||
controlLoop()
|
||||
|
||||
function productLoopBody() {
|
||||
let productCodeName = bot.processNode.referenceParent.processOutput.outputDatasets[outputDatasetIndex].referenceParent.parentNode.config.codeName;
|
||||
let productCodeName = outputDatasets[outputDatasetIndex].referenceParent.parentNode.config.codeName;
|
||||
writeDataRange(contextVariables.dateBeginOfMarket, bot.multiPeriodDailyProcessDatetime, productCodeName, controlLoop)
|
||||
}
|
||||
|
||||
function controlLoop() {
|
||||
outputDatasetIndex++
|
||||
if (outputDatasetIndex < bot.processNode.referenceParent.processOutput.outputDatasets.length) {
|
||||
if (outputDatasetIndex < outputDatasets.length) {
|
||||
productLoopBody()
|
||||
} else {
|
||||
callBack(global.DEFAULT_OK_RESPONSE)
|
||||
|
||||
@@ -141,17 +141,18 @@
|
||||
}
|
||||
|
||||
function writeTimeFramesFiles(callBack) {
|
||||
let outputDatasets = global.NODE_BRANCH_TO_ARRAY (bot.processNode.referenceParent.processOutput, 'Output Dataset')
|
||||
let outputDatasetIndex = -1;
|
||||
controlLoop()
|
||||
|
||||
function productLoopBody() {
|
||||
let productCodeName = bot.processNode.referenceParent.processOutput.outputDatasets[outputDatasetIndex].referenceParent.parentNode.config.codeName;
|
||||
let productCodeName = outputDatasets[outputDatasetIndex].referenceParent.parentNode.config.codeName;
|
||||
writeTimeFramesFile(productCodeName, controlLoop)
|
||||
}
|
||||
|
||||
function controlLoop() {
|
||||
outputDatasetIndex++
|
||||
if (outputDatasetIndex < bot.processNode.referenceParent.processOutput.outputDatasets.length) {
|
||||
if (outputDatasetIndex < outputDatasets.length) {
|
||||
productLoopBody()
|
||||
} else {
|
||||
callBack()
|
||||
|
||||
+102
-93
@@ -16,80 +16,83 @@
|
||||
return thisObject;
|
||||
|
||||
function raiseEvents(lastFile, timeFrames, callBackFunction) {
|
||||
|
||||
try {
|
||||
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] raiseEvents -> Entering function."); }
|
||||
|
||||
/* We will reaise the events for the datasets impacted by the process that just finished. */
|
||||
|
||||
if (bot.processNode.referenceParent.processOutput !== undefined) {
|
||||
if (bot.processNode.referenceParent.processOutput.outputDatasets !== undefined) {
|
||||
let outputDatasets = bot.processNode.referenceParent.processOutput.outputDatasets
|
||||
let outputDatasets = global.NODE_BRANCH_TO_ARRAY(bot.processNode.referenceParent.processOutput, 'Output Dataset')
|
||||
|
||||
for (let j = 0; j < outputDatasets.length; j++) {
|
||||
let outputDataset = outputDatasets[j]
|
||||
for (let j = 0; j < outputDatasets.length; j++) {
|
||||
let outputDataset = outputDatasets[j]
|
||||
|
||||
/* Some validations to verify that everything is in place. */
|
||||
if (outputDataset.referenceParent !== 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));
|
||||
let botNode = global.FIND_NODE_IN_NODE_MESH(outputDataset, 'Indicator Bot')
|
||||
if (botNode === undefined) {
|
||||
botNode = global.FIND_NODE_IN_NODE_MESH(outputDataset, 'Trading Bot')
|
||||
}
|
||||
if (botNode === undefined) {
|
||||
botNode = global.FIND_NODE_IN_NODE_MESH(outputDataset, 'Sensor Bot')
|
||||
}
|
||||
|
||||
/* Some validations to verify that everything is in place. */
|
||||
if (outputDataset.referenceParent !== 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.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 !== 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));
|
||||
if (botNode !== undefined) {
|
||||
if (botNode.config.codeName === undefined) {
|
||||
logger.write(MODULE_NAME, "[ERROR] raiseEvents -> codeName at Bot not defined. Bot = " + JSON.stringify(botNode));
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return
|
||||
}
|
||||
if (outputDataset.referenceParent.parentNode.parentNode !== 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.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));
|
||||
if (botNode.parentNode !== undefined) {
|
||||
if (botNode.parentNode.config.codeName === undefined) {
|
||||
logger.write(MODULE_NAME, "[ERROR] raiseEvents -> codeName at Data Mine not defined. Data Mine = " + JSON.stringify(botNode.parentNode));
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return
|
||||
}
|
||||
} else {
|
||||
logger.write(MODULE_NAME, "[ERROR] raiseEvents -> Product not attached to a Bot. Product = " + JSON.stringify(outputDataset.referenceParent.parentNode));
|
||||
logger.write(MODULE_NAME, "[ERROR] raiseEvents -> Bot not attached to a Data Mine. Bot = " + JSON.stringify(botNode));
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return
|
||||
}
|
||||
} else {
|
||||
logger.write(MODULE_NAME, "[ERROR] raiseEvents -> Dataset Definition not attached to a Product. Dataset Definition = " + JSON.stringify(outputDataset.referenceParent));
|
||||
logger.write(MODULE_NAME, "[ERROR] raiseEvents -> Product not attached to a Bot. Product = " + JSON.stringify(outputDataset.referenceParent.parentNode));
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return
|
||||
}
|
||||
} else {
|
||||
logger.write(MODULE_NAME, "[ERROR] raiseEvents -> Output Dataset with no reference to a Dataset Definition. Output Dataset = " + JSON.stringify(outputDataset));
|
||||
logger.write(MODULE_NAME, "[ERROR] raiseEvents -> Dataset Definition not attached to a Product. Dataset Definition = " + JSON.stringify(outputDataset.referenceParent));
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return
|
||||
}
|
||||
|
||||
/* All good, lets emit the event. */
|
||||
|
||||
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 = {
|
||||
lastFile: lastFile,
|
||||
timeFrames: timeFrames
|
||||
}
|
||||
global.EVENT_SERVER_CLIENT.createEventHandler(key, 'Dataset Updated')
|
||||
global.EVENT_SERVER_CLIENT.raiseEvent(key, 'Dataset Updated', event)
|
||||
} else {
|
||||
logger.write(MODULE_NAME, "[ERROR] raiseEvents -> Output Dataset with no reference to a Dataset Definition. Output Dataset = " + JSON.stringify(outputDataset));
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return
|
||||
}
|
||||
|
||||
/* All good, lets emit the event. */
|
||||
|
||||
let dataMine = botNode.parentNode.config.codeName
|
||||
let botName = botNode.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 = {
|
||||
lastFile: lastFile,
|
||||
timeFrames: timeFrames
|
||||
}
|
||||
global.EVENT_SERVER_CLIENT.createEventHandler(key, 'Dataset Updated')
|
||||
global.EVENT_SERVER_CLIENT.raiseEvent(key, 'Dataset Updated', event)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,65 +107,71 @@
|
||||
function asyncRaiseEvents(lastFile, timeFrames) {
|
||||
|
||||
if (bot.processNode.referenceParent.processOutput !== undefined) {
|
||||
if (bot.processNode.referenceParent.processOutput.outputDatasets !== undefined) {
|
||||
let outputDatasets = bot.processNode.referenceParent.processOutput.outputDatasets
|
||||
let outputDatasets = global.NODE_BRANCH_TO_ARRAY(bot.processNode.referenceParent.processOutput, 'Output Dataset')
|
||||
|
||||
for (let j = 0; j < outputDatasets.length; j++) {
|
||||
let outputDataset = outputDatasets[j]
|
||||
for (let j = 0; j < outputDatasets.length; j++) {
|
||||
let outputDataset = outputDatasets[j]
|
||||
|
||||
/* Some validations to verify that everything is in place. */
|
||||
if (outputDataset.referenceParent !== 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));
|
||||
throw(global.DEFAULT_FAIL_RESPONSE);
|
||||
let botNode = global.FIND_NODE_IN_NODE_MESH(outputDataset, 'Indicator Bot')
|
||||
if (botNode === undefined) {
|
||||
botNode = global.FIND_NODE_IN_NODE_MESH(outputDataset, 'Trading Bot')
|
||||
}
|
||||
if (botNode === undefined) {
|
||||
botNode = global.FIND_NODE_IN_NODE_MESH(outputDataset, 'Sensor Bot')
|
||||
}
|
||||
|
||||
/* Some validations to verify that everything is in place. */
|
||||
if (outputDataset.referenceParent !== 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));
|
||||
throw (global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
if (outputDataset.referenceParent.parentNode !== 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));
|
||||
throw (global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
if (outputDataset.referenceParent.parentNode !== 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));
|
||||
throw(global.DEFAULT_FAIL_RESPONSE);
|
||||
if (botNode !== undefined) {
|
||||
if (botNode.config.codeName === undefined) {
|
||||
logger.write(MODULE_NAME, "[ERROR] raiseEvents -> codeName at Bot not defined. Bot = " + JSON.stringify(botNode));
|
||||
throw (global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
if (outputDataset.referenceParent.parentNode.parentNode !== 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));
|
||||
throw(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
if (outputDataset.referenceParent.parentNode.parentNode.parentNode !== 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));
|
||||
throw(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
} else {
|
||||
logger.write(MODULE_NAME, "[ERROR] raiseEvents -> Bot not attached to a Data Mine. Bot = " + JSON.stringify(outputDataset.referenceParent.parentNode.parentNode));
|
||||
throw(global.DEFAULT_FAIL_RESPONSE);
|
||||
if (botNode.parentNode !== undefined) {
|
||||
if (botNode.parentNode.config.codeName === undefined) {
|
||||
logger.write(MODULE_NAME, "[ERROR] raiseEvents -> codeName at Data Mine not defined. Data Mine = " + JSON.stringify(botNode.parentNode));
|
||||
throw (global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
} else {
|
||||
logger.write(MODULE_NAME, "[ERROR] raiseEvents -> Product not attached to a Bot. Product = " + JSON.stringify(outputDataset.referenceParent.parentNode));
|
||||
throw(global.DEFAULT_FAIL_RESPONSE);
|
||||
logger.write(MODULE_NAME, "[ERROR] raiseEvents -> Bot not attached to a Data Mine. Bot = " + JSON.stringify(botNode));
|
||||
throw (global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
} else {
|
||||
logger.write(MODULE_NAME, "[ERROR] raiseEvents -> Dataset Definition not attached to a Product. Dataset Definition = " + JSON.stringify(outputDataset.referenceParent));
|
||||
throw(global.DEFAULT_FAIL_RESPONSE);
|
||||
logger.write(MODULE_NAME, "[ERROR] raiseEvents -> Product not attached to a Bot. Product = " + JSON.stringify(outputDataset.referenceParent.parentNode));
|
||||
throw (global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
} else {
|
||||
logger.write(MODULE_NAME, "[ERROR] raiseEvents -> Output Dataset with no reference to a Dataset Definition. Output Dataset = " + JSON.stringify(outputDataset));
|
||||
throw(global.DEFAULT_FAIL_RESPONSE);
|
||||
logger.write(MODULE_NAME, "[ERROR] raiseEvents -> Dataset Definition not attached to a Product. Dataset Definition = " + JSON.stringify(outputDataset.referenceParent));
|
||||
throw (global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
|
||||
/* All good, lets emit the event. */
|
||||
|
||||
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 = {
|
||||
lastFile: lastFile,
|
||||
timeFrames: timeFrames
|
||||
}
|
||||
global.EVENT_SERVER_CLIENT.createEventHandler(key, 'Dataset Updated')
|
||||
global.EVENT_SERVER_CLIENT.raiseEvent(key, 'Dataset Updated', event)
|
||||
} else {
|
||||
logger.write(MODULE_NAME, "[ERROR] raiseEvents -> Output Dataset with no reference to a Dataset Definition. Output Dataset = " + JSON.stringify(outputDataset));
|
||||
throw (global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
|
||||
/* All good, lets emit the event. */
|
||||
|
||||
let dataMine = botNode.parentNode.config.codeName
|
||||
let botName = botNode.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 = {
|
||||
lastFile: lastFile,
|
||||
timeFrames: timeFrames
|
||||
}
|
||||
global.EVENT_SERVER_CLIENT.createEventHandler(key, 'Dataset Updated')
|
||||
global.EVENT_SERVER_CLIENT.raiseEvent(key, 'Dataset Updated', event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,6 @@
|
||||
if (bot.SESSION_STATUS === 'Idle' || bot.SESSION_STATUS === 'Running') { return } // This happens when the UI is reloaded, the session was running and tries to run it again.
|
||||
|
||||
/* We are going to run the Definition comming at the event. */
|
||||
bot.APP_SCHEMA_ARRAY = JSON.parse(message.event.appSchema)
|
||||
bot.TRADING_SYSTEM = JSON.parse(message.event.tradingSystem)
|
||||
bot.TRADING_ENGINE = JSON.parse(message.event.tradingEngine)
|
||||
bot.SESSION = JSON.parse(message.event.session)
|
||||
@@ -66,7 +65,6 @@
|
||||
bot.FIRST_EXECUTION = true
|
||||
bot.SESSION.stop = stopSession // stop function
|
||||
|
||||
setUpAppSchema()
|
||||
setUpSessionFolderName()
|
||||
|
||||
/* We validate all parameters received and complete some that might be missing if needed. */
|
||||
@@ -118,16 +116,6 @@
|
||||
sessionInfo(bot.SESSION, commandOrigin)
|
||||
}
|
||||
|
||||
function setUpAppSchema() {
|
||||
/* Setup the APP_SCHEMA_MAP based on the APP_SCHEMA_ARRAY */
|
||||
bot.APP_SCHEMA_MAP = new Map()
|
||||
for (let i = 0; i < bot.APP_SCHEMA_ARRAY.length; i++) {
|
||||
let nodeDefinition = bot.APP_SCHEMA_ARRAY[i]
|
||||
let key = nodeDefinition.type
|
||||
bot.APP_SCHEMA_MAP.set(key, nodeDefinition)
|
||||
}
|
||||
}
|
||||
|
||||
function setUpSessionFolderName() {
|
||||
/*
|
||||
The session object is overwritten when the session is run. For that reason we
|
||||
|
||||
@@ -83,7 +83,7 @@
|
||||
function validationFailed(errorInNode, errorMessage) {
|
||||
let nodeString = JSON.stringify(errorInNode)
|
||||
logger.write(MODULE_NAME, "[ERROR] initialize -> " + errorMessage + ' -> nodeString = ' + nodeString)
|
||||
bot.global.PROCESS_ERROR(bot.processKey, errorInNode, errorMessage)
|
||||
global.PROCESS_ERROR(bot.processKey, errorInNode, errorMessage)
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
|
||||
|
||||
+185
-2
@@ -102,6 +102,177 @@ global.PROCESS_INFO = function (processKey, node, infoMessage) {
|
||||
global.EVENT_SERVER_CLIENT.raiseEvent(processKey, 'Info', event)
|
||||
}
|
||||
|
||||
global.NODE_BRANCH_TO_ARRAY = function (node, nodeType) {
|
||||
let resultArray = []
|
||||
scanNodeBranch(node, nodeType)
|
||||
return resultArray
|
||||
|
||||
function scanNodeBranch(startingNode) {
|
||||
let nodeDefinition = global.APP_SCHEMA_MAP.get(startingNode.type)
|
||||
if (nodeDefinition === undefined) { return }
|
||||
|
||||
if (startingNode.type === nodeType) {
|
||||
resultArray.push(startingNode)
|
||||
return
|
||||
}
|
||||
|
||||
if (nodeDefinition.properties === undefined) { return }
|
||||
for (let i = 0; i < nodeDefinition.properties.length; i++) {
|
||||
let property = nodeDefinition.properties[i]
|
||||
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
scanNodeBranch(startingNode[property.name])
|
||||
}
|
||||
break
|
||||
case 'array': {
|
||||
let startingNodePropertyArray = startingNode[property.name]
|
||||
if (startingNodePropertyArray !== undefined) {
|
||||
for (let m = 0; m < startingNodePropertyArray.length; m++) {
|
||||
scanNodeBranch(startingNodePropertyArray[m])
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
global.FIND_NODE_IN_NODE_MESH = function (node, nodeType) {
|
||||
/*
|
||||
This function scans a node mesh for a certain node type and
|
||||
returns the first instance found.
|
||||
*/
|
||||
let nodeFound
|
||||
scanNodeMesh(node, nodeType)
|
||||
return nodeFound
|
||||
|
||||
function scanNodeMesh(startingNode) {
|
||||
if (startingNode === undefined) { return }
|
||||
if (nodeFound !== undefined) { return }
|
||||
|
||||
let nodeDefinition = APP_SCHEMA_MAP.get(startingNode.type)
|
||||
if (nodeDefinition === undefined) { return }
|
||||
|
||||
if (startingNode.type === nodeType) {
|
||||
nodeFound = startingNode
|
||||
return
|
||||
}
|
||||
|
||||
/* We scan through this node children */
|
||||
if (nodeDefinition.properties !== undefined) {
|
||||
for (let i = 0; i < nodeDefinition.properties.length; i++) {
|
||||
let property = nodeDefinition.properties[i]
|
||||
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
scanNodeMesh(startingNode[property.name])
|
||||
}
|
||||
break
|
||||
case 'array': {
|
||||
let startingNodePropertyArray = startingNode[property.name]
|
||||
if (startingNodePropertyArray !== undefined) {
|
||||
for (let m = 0; m < startingNodePropertyArray.length; m++) {
|
||||
scanNodeMesh(startingNodePropertyArray[m])
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* We scan parents nodes. */
|
||||
if (startingNode.parentNode !== undefined) {
|
||||
scanNodeMesh(startingNode.parentNode)
|
||||
}
|
||||
/* We scan reference parents too. */
|
||||
if (startingNode.referenceParent !== undefined) {
|
||||
scanNodeMesh(startingNode.referenceParent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
global.NODE_MESH_TO_PATH_ARRAY = function (node, nodeId) {
|
||||
/*
|
||||
This function scans a node mesh for a certain node if and
|
||||
returns an array with the path within that mesh to the
|
||||
requested node.
|
||||
*/
|
||||
let nodeArray = []
|
||||
scanNodeMesh(node)
|
||||
return nodeArray
|
||||
|
||||
function scanNodeMesh(startingNode) {
|
||||
if (startingNode === undefined) { return }
|
||||
|
||||
let nodeDefinition = APP_SCHEMA_MAP.get(startingNode.type)
|
||||
if (nodeDefinition === undefined) { return }
|
||||
|
||||
if (startingNode.id === nodeId) {
|
||||
nodeArray.push(startingNode)
|
||||
return
|
||||
}
|
||||
|
||||
/* We scan through this node children */
|
||||
if (nodeDefinition.properties !== undefined) {
|
||||
for (let i = 0; i < nodeDefinition.properties.length; i++) {
|
||||
let property = nodeDefinition.properties[i]
|
||||
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
scanNodeMesh(startingNode[property.name])
|
||||
if (nodeArray.length > 0) {
|
||||
nodeArray.unshift(startingNode)
|
||||
return
|
||||
}
|
||||
}
|
||||
break
|
||||
case 'array': {
|
||||
let startingNodePropertyArray = startingNode[property.name]
|
||||
if (startingNodePropertyArray !== undefined) {
|
||||
for (let m = 0; m < startingNodePropertyArray.length; m++) {
|
||||
scanNodeMesh(startingNodePropertyArray[m])
|
||||
if (nodeArray.length > 0) {
|
||||
nodeArray.unshift(startingNode)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* We scan parents nodes. */
|
||||
if (startingNode.parentNode !== undefined) {
|
||||
scanNodeMesh(startingNode.parentNode)
|
||||
if (nodeArray.length > 0) {
|
||||
nodeArray.unshift(startingNode)
|
||||
return
|
||||
}
|
||||
}
|
||||
/* We scan reference parents too. */
|
||||
if (startingNode.referenceParent !== undefined) {
|
||||
scanNodeMesh(startingNode.referenceParent)
|
||||
if (nodeArray.length > 0) {
|
||||
nodeArray.unshift(startingNode)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
global.FIND_NODE_IN_NODE_ARRAY = function (nodeArray, nodeType) {
|
||||
for (let i=0; i < nodeArray.length; i++) {
|
||||
let node = nodeArray[i]
|
||||
if (node.type === nodeType) {
|
||||
return node
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
process.on('uncaughtException', function (err) {
|
||||
console.log('[ERROR] Task Server -> server -> uncaughtException -> err.message = ' + err.message)
|
||||
console.log('[ERROR] Task Server -> server -> uncaughtException -> err.stack = ' + err.stack)
|
||||
@@ -230,7 +401,8 @@ function preLoader() {
|
||||
global.EVENT_SERVER_CLIENT.listenToEvent('Task Server - ' + taskId, 'Run Task', undefined, 'Task Server - ' + taskId, undefined, eventReceived)
|
||||
global.EVENT_SERVER_CLIENT.raiseEvent('Task Manager - ' + taskId, 'Nodejs Process Ready for Task')
|
||||
function eventReceived(message) {
|
||||
global.TASK_NODE = message
|
||||
global.APP_SCHEMA_ARRAY = JSON.parse(message.event.appSchema)
|
||||
setUpAppSchema()
|
||||
global.TASK_NODE = JSON.parse(message.event.taskDefinition)
|
||||
global.TASK_NETWORK = JSON.parse(message.event.networkDefinition)
|
||||
bootLoader()
|
||||
@@ -245,7 +417,8 @@ function preLoader() {
|
||||
//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) {
|
||||
global.TASK_NODE = message
|
||||
global.APP_SCHEMA_ARRAY = JSON.parse(message.event.appSchema)
|
||||
setUpAppSchema()
|
||||
global.TASK_NODE = JSON.parse(message.event.taskDefinition)
|
||||
global.TASK_NETWORK = JSON.parse(message.event.networkDefinition)
|
||||
bootLoader()
|
||||
@@ -255,6 +428,16 @@ function preLoader() {
|
||||
console.log('[ERROR] Task Server -> server -> preLoader -> global.TASK_NODE = ' + JSON.stringify(global.TASK_NODE).substring(0, 1000))
|
||||
}
|
||||
}
|
||||
|
||||
function setUpAppSchema() {
|
||||
/* Setup the APP_SCHEMA_MAP based on the APP_SCHEMA_ARRAY */
|
||||
global.APP_SCHEMA_MAP = new Map()
|
||||
for (let i = 0; i < global.APP_SCHEMA_ARRAY.length; i++) {
|
||||
let nodeDefinition = global.APP_SCHEMA_ARRAY[i]
|
||||
let key = nodeDefinition.type
|
||||
global.APP_SCHEMA_MAP.set(key, nodeDefinition)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function bootLoader() {
|
||||
|
||||
Reference in new issue
Block a user