diff --git a/LowFrequencyTrading/TradingEngine.js b/LowFrequencyTrading/TradingEngine.js index 292b58dfc..5bbce94c2 100644 --- a/LowFrequencyTrading/TradingEngine.js +++ b/LowFrequencyTrading/TradingEngine.js @@ -25,6 +25,8 @@ exports.newTradingEngine = function newTradingEngine(bot, logger) { tradingEngine = bot.simulationState.tradingEngine sessionParameters = bot.SESSION.parameters + initializeNodeMap(tradingEngine) + if (bot.FIRST_EXECUTION === true) { /* Here we will go through all the nodes in the Trading Engine hiriarchy and @@ -98,11 +100,47 @@ exports.newTradingEngine = function newTradingEngine(bot, logger) { } } - function initializeNode(node) { + function initializeNodeMap(node) { if (node === undefined) { return } /* Add to Node Map */ nodesMap.set(node.id, node) + /* Now we go down through all this node children */ + let nodeDefinition = bot.APP_SCHEMA_MAP.get(node.type) + if (nodeDefinition === undefined) { return } + + if (nodeDefinition.properties !== undefined) { + let previousPropertyName // Since there are cases where there are many properties with the same name,because they can hold nodes of different types but only one at the time, we have to avoind counting each property of those as individual children. + for (let i = 0; i < nodeDefinition.properties.length; i++) { + let property = nodeDefinition.properties[i] + + switch (property.type) { + case 'node': { + if (property.name !== previousPropertyName) { + if (node[property.name] !== undefined) { + initializeNodeMap(node[property.name]) + } + previousPropertyName = property.name + } + break + } + case 'array': { + if (node[property.name] !== undefined) { + let nodePropertyArray = node[property.name] + for (let m = 0; m < nodePropertyArray.length; m++) { + initializeNodeMap(nodePropertyArray[m]) + } + } + break + } + } + } + } + } + + function initializeNode(node) { + if (node === undefined) { return } + /* Here we initialize the node value */ if (node.config !== undefined) { if (node.config.initialValue !== undefined) { diff --git a/LowFrequencyTrading/TradingPosition.js b/LowFrequencyTrading/TradingPosition.js index a9d621fd3..076c262e8 100644 --- a/LowFrequencyTrading/TradingPosition.js +++ b/LowFrequencyTrading/TradingPosition.js @@ -238,7 +238,7 @@ exports.newTradingPosition = function newTradingPosition(bot, logger, tradingEng function resetTradingEngineDataStructure() { if (tradingEngine.current.position.status.value === 'Closed') { - tradingEngine.initializeNode(tradingEngine.current.position) + tradingEngineModule.initializeNode(tradingEngine.current.position) } }