Bug Fixes, related to Limit Orders

This commit is contained in:
Luis Fernando Molina committed 2020-08-10 13:50:25 +02:00
1 parent d4af4a3865
commit 666e37bc6a
24 files changed
+209 -141

No files matched your search

@@ -9,6 +9,7 @@ exports.newTradingEngine = function newTradingEngine(bot, logger) {
getNodeById: getNodeById,
cloneValues: cloneValues,
setCurrentCandle: setCurrentCandle,
initializeNode: initializeNode,
initialize: initialize,
finalize: finalize
}
@@ -24,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
@@ -97,18 +100,53 @@ 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) {
node.value = node.config.initialValue
}
}
node.initialize = initializeNode // This will allow anyone to initialize this node and its children.
/* Now we go down through all this node children */
let nodeDefinition = bot.APP_SCHEMA_MAP.get(node.type)