From c1c732e4bfa9591180e5586181cd18a350d87491 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 6 Jan 2020 13:47:10 +0100 Subject: [PATCH] Base asset from reference parent --- Session.js | 126 +++++++++++++++++++++++-------------------- TradingSimulation.js | 125 +++++++++++++++++++++--------------------- 2 files changed, 132 insertions(+), 119 deletions(-) diff --git a/Session.js b/Session.js index 22e81f5cf..33fcf1e11 100644 --- a/Session.js +++ b/Session.js @@ -278,37 +278,42 @@ /* Base Asset and Initial Balances. */ { if (tradingSystem.parameters.baseAsset !== undefined) { - let code = tradingSystem.parameters.baseAsset.code + if (tradingSystem.parameters.baseAsset.referenceParent !== undefined) { + if (tradingSystem.parameters.baseAsset.referenceParent.referenceParent !== undefined) { - if (code.name !== undefined) { - bot.VALUES_TO_USE.baseAsset = code.name; - } + let code = tradingSystem.parameters.baseAsset.referenceParent.referenceParent.code - if (bot.VALUES_TO_USE.baseAsset === 'BTC') { - if (code.initialBalance !== undefined) { - bot.VALUES_TO_USE.initialBalanceA = code.initialBalance; - bot.VALUES_TO_USE.initialBalanceB = 0 - } - if (code.minimumBalance !== undefined) { - bot.VALUES_TO_USE.minimumBalanceA = code.minimumBalance; - bot.VALUES_TO_USE.minimumBalanceB = 0 - } - if (code.maximumBalance !== undefined) { - bot.VALUES_TO_USE.maximumBalanceA = code.maximumBalance; - bot.VALUES_TO_USE.maximumBalanceB = 0 - } - } else { - if (code.initialBalance !== undefined) { - bot.VALUES_TO_USE.initialBalanceB = code.initialBalance; - bot.VALUES_TO_USE.initialBalanceA = 0 - } - if (code.minimumBalance !== undefined) { - bot.VALUES_TO_USE.minimumBalanceB = code.minimumBalance; - bot.VALUES_TO_USE.minimumBalanceA = 0 - } - if (code.maximumBalance !== undefined) { - bot.VALUES_TO_USE.maximumBalanceB = code.maximumBalance; - bot.VALUES_TO_USE.maximumBalanceA = 0 + if (code.codeName !== undefined) { + bot.VALUES_TO_USE.baseAsset = code.codeName; + } + + if (bot.VALUES_TO_USE.baseAsset === 'BTC') { + if (code.initialBalance !== undefined) { + bot.VALUES_TO_USE.initialBalanceA = code.initialBalance; + bot.VALUES_TO_USE.initialBalanceB = 0 + } + if (code.minimumBalance !== undefined) { + bot.VALUES_TO_USE.minimumBalanceA = code.minimumBalance; + bot.VALUES_TO_USE.minimumBalanceB = 0 + } + if (code.maximumBalance !== undefined) { + bot.VALUES_TO_USE.maximumBalanceA = code.maximumBalance; + bot.VALUES_TO_USE.maximumBalanceB = 0 + } + } else { + if (code.initialBalance !== undefined) { + bot.VALUES_TO_USE.initialBalanceB = code.initialBalance; + bot.VALUES_TO_USE.initialBalanceA = 0 + } + if (code.minimumBalance !== undefined) { + bot.VALUES_TO_USE.minimumBalanceB = code.minimumBalance; + bot.VALUES_TO_USE.minimumBalanceA = 0 + } + if (code.maximumBalance !== undefined) { + bot.VALUES_TO_USE.maximumBalanceB = code.maximumBalance; + bot.VALUES_TO_USE.maximumBalanceA = 0 + } + } } } } @@ -374,37 +379,42 @@ /* Base Asset and Initial Balances. */ { if (bot.SESSION.parameters.baseAsset !== undefined) { - let code = bot.SESSION.parameters.baseAsset.code + if (tradingSystem.parameters.baseAsset.referenceParent !== undefined) { + if (tradingSystem.parameters.baseAsset.referenceParent.referenceParent !== undefined) { - if (code.name !== undefined) { - bot.VALUES_TO_USE.baseAsset = code.name; - } + let code = tradingSystem.parameters.baseAsset.referenceParent.referenceParent.code - if (bot.VALUES_TO_USE.baseAsset === 'BTC') { - if (code.initialBalance !== undefined) { - bot.VALUES_TO_USE.initialBalanceA = code.initialBalance; - bot.VALUES_TO_USE.initialBalanceB = 0 - } - if (code.minimumBalance !== undefined) { - bot.VALUES_TO_USE.minimumBalanceA = code.minimumBalance; - bot.VALUES_TO_USE.minimumBalanceB = 0 - } - if (code.maximumBalance !== undefined) { - bot.VALUES_TO_USE.maximumBalanceA = code.maximumBalance; - bot.VALUES_TO_USE.maximumBalanceB = 0 - } - } else { - if (code.initialBalance !== undefined) { - bot.VALUES_TO_USE.initialBalanceB = code.initialBalance; - bot.VALUES_TO_USE.initialBalanceA = 0 - } - if (code.minimumBalance !== undefined) { - bot.VALUES_TO_USE.minimumBalanceB = code.minimumBalance; - bot.VALUES_TO_USE.minimumBalanceA = 0 - } - if (code.maximumBalance !== undefined) { - bot.VALUES_TO_USE.maximumBalanceB = code.maximumBalance; - bot.VALUES_TO_USE.maximumBalanceA = 0 + if (code.codeName !== undefined) { + bot.VALUES_TO_USE.baseAsset = code.codeName; + } + + if (bot.VALUES_TO_USE.baseAsset === 'BTC') { + if (code.initialBalance !== undefined) { + bot.VALUES_TO_USE.initialBalanceA = code.initialBalance; + bot.VALUES_TO_USE.initialBalanceB = 0 + } + if (code.minimumBalance !== undefined) { + bot.VALUES_TO_USE.minimumBalanceA = code.minimumBalance; + bot.VALUES_TO_USE.minimumBalanceB = 0 + } + if (code.maximumBalance !== undefined) { + bot.VALUES_TO_USE.maximumBalanceA = code.maximumBalance; + bot.VALUES_TO_USE.maximumBalanceB = 0 + } + } else { + if (code.initialBalance !== undefined) { + bot.VALUES_TO_USE.initialBalanceB = code.initialBalance; + bot.VALUES_TO_USE.initialBalanceA = 0 + } + if (code.minimumBalance !== undefined) { + bot.VALUES_TO_USE.minimumBalanceB = code.minimumBalance; + bot.VALUES_TO_USE.minimumBalanceA = 0 + } + if (code.maximumBalance !== undefined) { + bot.VALUES_TO_USE.maximumBalanceB = code.maximumBalance; + bot.VALUES_TO_USE.maximumBalanceA = 0 + } + } } } } diff --git a/TradingSimulation.js b/TradingSimulation.js index 87ba1a5b2..12e65ef22 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -44,7 +44,6 @@ callBackFunction) { try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> Entering function."); } let processingDailyFiles if (timeFrame > global.dailyFilePeriods[0][0]) { @@ -1361,45 +1360,47 @@ } } - let phase = parentNode.stopLoss.phases[p]; + if (parentNode !== undefined) { + let phase = parentNode.stopLoss.phases[p]; - let nextPhaseEvent = phase.nextPhaseEvent; - if (nextPhaseEvent !== undefined) { + let nextPhaseEvent = phase.nextPhaseEvent; + if (nextPhaseEvent !== undefined) { - for (let k = 0; k < nextPhaseEvent.situations.length; k++) { + for (let k = 0; k < nextPhaseEvent.situations.length; k++) { - let situation = nextPhaseEvent.situations[k]; - let passed = true; + let situation = nextPhaseEvent.situations[k]; + let passed = true; - for (let m = 0; m < situation.conditions.length; m++) { + for (let m = 0; m < situation.conditions.length; m++) { - let condition = situation.conditions[m]; - let key = j + '-' + stageKey + initialDefinitionKey + '-' + 'stopLoss' + '-' + p + '-' + k + '-' + m; + let condition = situation.conditions[m]; + let key = j + '-' + stageKey + initialDefinitionKey + '-' + 'stopLoss' + '-' + p + '-' + k + '-' + m; - let value = false - if (conditions.get(key) !== undefined) { - value = conditions.get(key).value; - } - - if (value === false) { passed = false; } - } - - if (passed) { - - stopLossPhase++; - stopLossStage = 'Manage Stage' - if (takeProfitPhase > 0) { strategyStage = 'Manage Stage' } - - if (processingDailyFiles) { - if (positionedAtYesterday) { - yesterday.stopLossPhase = stopLossPhase; - yesterday.stopLossStage = stopLossStage; - yesterday.strategyStage = strategyStage; + let value = false + if (conditions.get(key) !== undefined) { + value = conditions.get(key).value; } + + if (value === false) { passed = false; } } - checkAnnouncements(nextPhaseEvent) - return; + if (passed) { + + stopLossPhase++; + stopLossStage = 'Manage Stage' + if (takeProfitPhase > 0) { strategyStage = 'Manage Stage' } + + if (processingDailyFiles) { + if (positionedAtYesterday) { + yesterday.stopLossPhase = stopLossPhase; + yesterday.stopLossStage = stopLossStage; + yesterday.strategyStage = strategyStage; + } + } + + checkAnnouncements(nextPhaseEvent) + return; + } } } } @@ -1490,45 +1491,47 @@ } } - let phase = parentNode.takeProfit.phases[p]; + if (parentNode !== undefined) { + let phase = parentNode.takeProfit.phases[p]; - let nextPhaseEvent = phase.nextPhaseEvent; - if (nextPhaseEvent !== undefined) { + let nextPhaseEvent = phase.nextPhaseEvent; + if (nextPhaseEvent !== undefined) { - for (let k = 0; k < nextPhaseEvent.situations.length; k++) { + for (let k = 0; k < nextPhaseEvent.situations.length; k++) { - let situation = nextPhaseEvent.situations[k]; - let passed = true; + let situation = nextPhaseEvent.situations[k]; + let passed = true; - for (let m = 0; m < situation.conditions.length; m++) { + for (let m = 0; m < situation.conditions.length; m++) { - let condition = situation.conditions[m]; - let key = j + '-' + stageKey + initialDefinitionKey + '-' + 'takeProfit' + '-' + p + '-' + k + '-' + m; + let condition = situation.conditions[m]; + let key = j + '-' + stageKey + initialDefinitionKey + '-' + 'takeProfit' + '-' + p + '-' + k + '-' + m; - let value = false - if (conditions.get(key) !== undefined) { - value = conditions.get(key).value; - } - - if (value === false) { passed = false; } - } - - if (passed) { - - takeProfitPhase++; - takeProfitStage = 'Manage Stage' - if (stopLossPhase > 0) { strategyStage = 'Manage Stage' } - - if (processingDailyFiles) { - if (positionedAtYesterday) { - yesterday.takeProfitPhase = takeProfitPhase; - yesterday.takeProfitStage = takeProfitStage; - yesterday.strategyStage = strategyStage; + let value = false + if (conditions.get(key) !== undefined) { + value = conditions.get(key).value; } + + if (value === false) { passed = false; } } - checkAnnouncements(nextPhaseEvent) - return; + if (passed) { + + takeProfitPhase++; + takeProfitStage = 'Manage Stage' + if (stopLossPhase > 0) { strategyStage = 'Manage Stage' } + + if (processingDailyFiles) { + if (positionedAtYesterday) { + yesterday.takeProfitPhase = takeProfitPhase; + yesterday.takeProfitStage = takeProfitStage; + yesterday.strategyStage = strategyStage; + } + } + + checkAnnouncements(nextPhaseEvent) + return; + } } } }