From 843f0ce046985dc0e1c53c2005471c47f10fe938 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 5 Jun 2019 21:13:34 +0200 Subject: [PATCH] Sending Formula and Condition Values to the Plotter --- Commons.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Commons.js b/Commons.js index fb9b46702..10fc39b22 100644 --- a/Commons.js +++ b/Commons.js @@ -345,7 +345,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { let key = j + '-' + 'triggerStage' + '-' + 'triggerOn' + '-' + k + '-' + m; if (condition.code !== undefined) { - newCondition(key, condition.code.code); + newCondition(key, condition.code); } } } @@ -363,7 +363,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { let key = j + '-' + 'triggerStage' + '-' + 'triggerOff' + '-' + k + '-' + m; if (condition.code !== undefined) { - newCondition(key, condition.code.code); + newCondition(key, condition.code); } } } @@ -381,7 +381,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { let key = j + '-' + 'triggerStage' + '-' + 'takePosition' + '-' + k + '-' + m; if (condition.code !== undefined) { - newCondition(key, condition.code.code); + newCondition(key, condition.code); } } } @@ -415,7 +415,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { let key = j + '-' + 'openStage' + '-' + 'initialDefinition' + '-' + 'stopLoss' + '-' + p + '-' + k + '-' + m; if (condition.code !== undefined) { - newCondition(key, condition.code.code); + newCondition(key, condition.code); } } } @@ -442,7 +442,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { let key = j + '-' + 'openStage' + '-' + 'initialDefinition' + '-' + 'takeProfit' + '-' + p + '-' + k + '-' + m; if (condition.code !== undefined) { - newCondition(key, condition.code.code); + newCondition(key, condition.code); } } } @@ -475,7 +475,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { let key = j + '-' + 'manageStage' + '-' + 'stopLoss' + '-' + p + '-' + k + '-' + m; if (condition.code !== undefined) { - newCondition(key, condition.code.code); + newCondition(key, condition.code); } } } @@ -502,7 +502,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { let key = j + '-' + 'manageStage' + '-' + 'takeProfit' + '-' + p + '-' + k + '-' + m; if (condition.code !== undefined) { - newCondition(key, condition.code.code); + newCondition(key, condition.code); } } } @@ -512,27 +512,25 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { } } - function newCondition(key, code) { + function newCondition(key, node) { let condition; - let value = false; let error = '' try { - value = eval(code); + node.value = eval(node.code); } catch (err) { /* One possible error is that the conditions references a .previous that is undefined. For this reason and others, we will simply set the value to false. */ - value = false - error = err.message + node.value = false + node.error = err.message } condition = { key: key, - value: value, - error: error + value: node.value }; conditions.set(condition.key, condition); @@ -863,7 +861,8 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { if (phase.formula !== undefined) { try { - stopLoss = eval(phase.formula.code); // Here is where we apply the formula given for the stop loss. + phase.formula.value = eval(phase.formula.code); // Here is where we apply the formula given for the stop loss. + stopLoss = phase.formula.value } catch (err) { phase.formula.error = err.message } @@ -971,7 +970,8 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { if (phase.formula !== undefined) { try { - takeProfit = eval(phase.formula.code); // Here is where we apply the formula given for the stop loss. + phase.formula.value = eval(phase.formula.code); // Here is where we apply the formula given for the stop loss. + takeProfit = phase.formula.value } catch (err) { phase.formula.error = err.message }