From 2feae2c8539a1e681af7c03eaf00591c0645ea70 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 20 Apr 2019 12:00:29 +0200 Subject: [PATCH 1/5] Only Calculates and show some time periods --- this.bot.config.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/this.bot.config.json b/this.bot.config.json index 6290a1b0b..9b033db43 100644 --- a/this.bot.config.json +++ b/this.bot.config.json @@ -154,6 +154,7 @@ "comaWaitTime": 86400000, "framework": { "name": "Multi-Period-Daily", + "validPeriods": [ "15-min", "10-min", "05-min"], "startDate": { "fixedDate": "2018-07-01" }, @@ -280,7 +281,7 @@ { "codeName": "Multi-Period-Daily", "type": "Daily Files", - "validPeriods": [ "45-min", "40-min", "30-min", "20-min", "15-min", "10-min", "05-min", "04-min", "03-min", "02-min", "01-min" ], + "validPeriods": ["15-min", "10-min", "05-min"], "filePath": "AAMasters/AAJason.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Trading-Simulation/Multi-Period-Daily/@Period/@Year/@Month/@Day", "fileName": "@AssetA_@AssetB.json", "dataRange": { @@ -319,7 +320,7 @@ { "codeName": "Multi-Period-Daily", "type": "Daily Files", - "validPeriods": [ "45-min", "40-min", "30-min", "20-min", "15-min", "10-min", "05-min", "04-min", "03-min", "02-min", "01-min" ], + "validPeriods": ["15-min", "10-min", "05-min"], "filePath": "AAMasters/AAJason.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Conditions/Multi-Period-Daily/@Period/@Year/@Month/@Day", "fileName": "@AssetA_@AssetB.json", "dataRange": { From e53ed7845ac85ac81cd73251f052704d90ef169c Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 23 Apr 2019 21:44:36 +0200 Subject: [PATCH 2/5] Bug on ROI calculation --- Commons.js | 57 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/Commons.js b/Commons.js index f797e9bed..779995fe5 100644 --- a/Commons.js +++ b/Commons.js @@ -154,13 +154,17 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { yesterday.lastProfit = 0; yesterday.Roundtrips = 0; - yesterday.Fails = 0; - yesterday.Hits = 0; + yesterday.fails = 0; + yesterday.hits = 0; yesterday.Periods = 0; yesterday.orderId = 0; yesterday.messageId = 0; + yesterday.hitRatio = 0; + yesterday.ROI = 0; + yesterday.anualizedRateOfReturn = 0; + if (interExecutionMemory.roundtrips === undefined) { /* Initialize the data structure we will use inter execution. */ @@ -177,6 +181,10 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { interExecutionMemory.orderId = 0; interExecutionMemory.messageId = 0; + interExecutionMemory.hitRatio = 0; + interExecutionMemory.ROI = 0; + interExecutionMemory.anualizedRateOfReturn = 0; + } else { /* We get the initial values from the day previous to the candles we receive at the current execution */ @@ -200,6 +208,15 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { orderId = interExecutionMemory.orderId; messageId = interExecutionMemory.messageId; + + hitRatio = interExecutionMemory.hitRatio; + ROI = interExecutionMemory.ROI; + anualizedRateOfReturn = interExecutionMemory.anualizedRateOfReturn; + + yesterday.hitRatio = hitRatio; + yesterday.ROI = ROI; + yesterday.anualizedRateOfReturn = anualizedRateOfReturn; + } simulationLogic.strategies = await getStrategy(); @@ -213,9 +230,9 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { let candle = candles[i]; let percentageBandwidth = percentageBandwidthMap.get(candle.begin); let bollingerBand = bollingerBandsMap.get(candle.begin); - let LRC = LRCMap.get(candle.begin); + //let LRC = LRCMap.get(candle.begin); - if (LRC === undefined) { continue; } + //if (LRC === undefined) { continue; } if (percentageBandwidth === undefined) { continue; } // percentageBandwidth might start after the first few candles. if (candle.begin < initialDate.valueOf()) { continue; } @@ -233,7 +250,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { let lastObjects = { candle: clone(candle), - LRC: clone(LRC), + //LRC: clone(LRC), bollingerBand: clone(bollingerBand), percentageBandwidth: clone(percentageBandwidth), channel: clone(channel), @@ -250,7 +267,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { } lastObjects.candle.previous = undefined; - lastObjects.LRC.previous = undefined; + //lastObjects.LRC.previous = undefined; lastObjects.bollingerBand.previous = undefined; lastObjects.percentageBandwidth.previous = undefined; lastObjects.channel.previous = undefined; @@ -704,9 +721,9 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { lastProfitPercent = lastProfit / previousBalanceAssetA * 100; if (isNaN(lastProfitPercent)) { lastProfitPercent = 0; } - profit = initialBalanceA - balanceAssetA; + profit = balanceAssetA - initialBalanceA; + - ROI = (initialBalanceA + profit) / initialBalanceA - 1; //if (isNaN(ROI)) { ROI = 0; } if (lastProfit > 0) { @@ -714,7 +731,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { if (currentDay !== undefined) { if (sellInstant < currentDay.valueOf()) { - yesterday.Hits++; + yesterday.hits++; } } @@ -723,14 +740,24 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { if (currentDay !== undefined) { if (sellInstant < currentDay.valueOf()) { - yesterday.Fails++; + yesterday.fails++; } } } - hitRatio = hits / roundtrips; + ROI = (initialBalanceA + profit) / initialBalanceA - 1; + hitRatio = hits / roundtrips; anualizedRateOfReturn = ROI / days * 365; + if (currentDay !== undefined) { + if (sellInstant < currentDay.valueOf()) { + yesterday.ROI = ROI; + yesterday.hitRatio = hitRatio; + yesterday.anualizedRateOfReturn = anualizedRateOfReturn; + } + } + + addRecord(); strategyNumber = 0; @@ -884,12 +911,16 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { interExecutionMemory.lastProfit = yesterday.lastProfit; interExecutionMemory.roundtrips = interExecutionMemory.roundtrips + yesterday.Roundtrips; - interExecutionMemory.fails = interExecutionMemory.fails + yesterday.Fails; - interExecutionMemory.hits = interExecutionMemory.hits + yesterday.Hits; + interExecutionMemory.fails = interExecutionMemory.fails + yesterday.fails; + interExecutionMemory.hits = interExecutionMemory.hits + yesterday.hits; interExecutionMemory.periods = interExecutionMemory.periods + yesterday.Periods; interExecutionMemory.messageId = interExecutionMemory.messageId + yesterday.messageId; interExecutionMemory.orderId = interExecutionMemory.orderId + yesterday.orderId; + + interExecutionMemory.hitRatio = yesterday.hitRatio; + interExecutionMemory.ROI = yesterday.ROI; + interExecutionMemory.anualizedRateOfReturn = yesterday.anualizedRateOfReturn; } } From 9592176ce2b7aec07a2898bf5b88d5232d2f91a9 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 29 Apr 2019 08:52:15 +0200 Subject: [PATCH 3/5] Current Strategy and Trade files generated --- Commons.js | 96 +++++++++++++++++-- Multi-Period-Daily/User.Bot.js | 162 +++++++++++++++++++++++++++++++- Multi-Period-Market/User.Bot.js | 145 +++++++++++++++++++++++++++- this.bot.config.json | 84 ++++++++++++++++- 4 files changed, 473 insertions(+), 14 deletions(-) diff --git a/Commons.js b/Commons.js index 779995fe5..191e0905b 100644 --- a/Commons.js +++ b/Commons.js @@ -56,6 +56,8 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { async function runSimulation( recordsArray, conditionsArray, + strategiesArray, + tradesArray, lastObjectsArray, simulationLogic, timePeriod, @@ -114,6 +116,20 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { let rate = 0; let newStopLoss; + let currentStrategy = { + begin: 0, + end: 0, + status: 0, + number: 0 + } + + let currentTrade = { + begin: 0, + end: 0, + status: 0, + profit: 0 + } + /* The following counters need to survive multiple executions of the similator and keep themselves reliable. This is challenging when the simulation is executed using Daily Files, since each execution means a new @@ -397,7 +413,8 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { } } - /* While we are outside all strategies, we evaluate whether it is time to enter one or not. */ + + /* Strategy Enter Condition */ if (strategyNumber === 0 && balanceAssetA > minimunBalanceA) { @@ -440,7 +457,9 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { strategyPhase = 1; strategyNumber = j + 1; - + currentStrategy.begin = candle.begin; + currentStrategy.beginRate = candle.min; + currentStrategy.endRate = candle.min; // In case the strategy does not get exited return; } } @@ -475,6 +494,10 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { if (passed) { + currentStrategy.number = strategyNumber - 1 + currentStrategy.end = candle.end; + currentStrategy.endRate = candle.min; + currentStrategy.status = 1; strategyPhase = 0; strategyNumber = 0; @@ -484,6 +507,8 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { } } + /* Checking if Stop or Take Profit were hit */ + if (strategyPhase === 3) { /* Checking what happened since the last execution. We need to know if the Stop Loss @@ -506,6 +531,13 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { rate = stopLoss; type = '"Buy@StopLoss"'; strategyPhase = 4; + currentTrade.end = candle.end; + currentTrade.status = 1; + + currentStrategy.number = strategyNumber - 1 + currentStrategy.end = candle.end; + currentStrategy.endRate = candle.min; + currentStrategy.status = 1; } /* Buy Order condition: Here we verify if the Buy Order was filled or not. */ @@ -526,10 +558,17 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { rate = buyOrder; type = '"Buy@BuyOrder"'; strategyPhase = 4; + currentTrade.end = candle.end; + currentTrade.status = 1; + + currentStrategy.number = strategyNumber - 1 + currentStrategy.end = candle.end; + currentStrategy.endRate = candle.min; + currentStrategy.status = 1; } } - /* Strategy Sell Condition */ + /* Trade Enter Condition */ if (strategyPhase === 1) { @@ -561,7 +600,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { strategyPhase = 2; stopLossPhase = 1; buyOrderPhase = 1; - + currentTrade.begin = candle.begin; return; } } @@ -619,7 +658,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { } } - /* Buy Order Management */ + /* Take Profit Management */ if (strategyPhase === 3) { @@ -664,7 +703,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { } } - /* Check if we need to sell. */ + /* Entering into a Trade */ if (strategyPhase === 2) { @@ -698,7 +737,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { continue; } - /* Check if we need to buy. */ + /* Exiting a Trade */ if (strategyPhase === 4) { @@ -768,7 +807,6 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { strategyPhase = 0; stopLossPhase = 0; buyOrderPhase = 0; - continue; } @@ -821,7 +859,8 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { 0, "") - } else { + } + else { orderRecord = createMessage( messageId, @@ -882,6 +921,8 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { type = '""'; + /* Prepare the information for the Conditions File */ + conditionsArrayRecord.push(strategyNumber); conditionsArrayRecord.push(strategyPhase); conditionsArrayRecord.push(stopLossPhase); @@ -890,6 +931,43 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { conditionsArray.push(conditionsArrayRecord); + /* Prepare the information for the Strategies File*/ + + if ( + (currentStrategy.begin !== 0 && currentStrategy.end !== 0) || + (currentStrategy.begin !== 0 && i === candles.length - 1) + ) { + + strategiesArray.push(currentStrategy); + + currentStrategy = { + begin: 0, + end: 0, + status: 0, + number: 0, + beginRate: 0, + endRate: 0 + } + } + + /* Prepare the information for the Trades File */ + + if ( + (currentTrade.begin !== 0 && currentTrade.end !== 0) || + (currentTrade.begin !== 0 && i === candles.length - 1) + ) { + + currentTrade.profit = lastProfit; + + tradesArray.push(currentTrade); + + currentTrade = { + begin: 0, + end: 0, + status: 0, + profit: 0 + } + } } } diff --git a/Multi-Period-Daily/User.Bot.js b/Multi-Period-Daily/User.Bot.js index b155229ca..29a9c2552 100644 --- a/Multi-Period-Daily/User.Bot.js +++ b/Multi-Period-Daily/User.Bot.js @@ -7,6 +7,8 @@ const SIMULATED_RECORDS_FOLDER_NAME = "Trading-Simulation"; const CONDITIONS_FOLDER_NAME = "Simulation-Conditions"; + const STRATEGIES_FOLDER_NAME = "Simulation-Strategies"; + const TRADES_FOLDER_NAME = "Simulation-Trades"; const commons = COMMONS.newCommons(bot, logger, UTILITIES); @@ -63,6 +65,8 @@ let recordsArray = []; let conditionsArray = []; + let strategiesArray = []; + let tradesArray = []; let simulationLogic = {}; let lastObjectsArray = []; @@ -106,6 +110,8 @@ commons.runSimulation( recordsArray, conditionsArray, + strategiesArray, + tradesArray, lastObjectsArray, simulationLogic, timePeriod, @@ -226,6 +232,10 @@ let record = conditionsArray[i]; + /* Will only add to the file the records of the current day */ + + if (record.begin < currentDay.valueOf()) { continue; } + let conditions = ""; let conditionsSeparator = ""; @@ -277,7 +287,7 @@ } - callBackFunction(global.DEFAULT_OK_RESPONSE); + writeStrategiesFile(); } catch (err) { @@ -292,6 +302,156 @@ } } + function writeStrategiesFile() { + + try { + + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeStrategiesFile -> Entering function."); } + + let separator = ""; + let fileRecordCounter = 0; + + let fileContent = ""; + + for (let i = 0; i < strategiesArray.length; i++) { + let record = strategiesArray[i]; + + /* Will only add to the file the records of the current day */ + + if (record.begin < currentDay.valueOf()) { continue; } + + fileContent = fileContent + separator + '[' + + record.begin + "," + + record.end + "," + + record.status + "," + + record.number + "," + + record.beginRate + "," + + record.endRate + "]"; + + if (separator === "") { separator = ","; } + + fileRecordCounter++; + + } + + fileContent = "[" + fileContent + "]"; + + let dateForPath = currentDay.getUTCFullYear() + '/' + utilities.pad(currentDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(currentDay.getUTCDate(), 2); + let fileName = '' + market.assetA + '_' + market.assetB + '.json'; + + let filePathRoot = bot.devTeam + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.PLATFORM_CONFIG.codeName + "." + global.PLATFORM_CONFIG.version.major + "." + global.PLATFORM_CONFIG.version.minor + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; + let filePath = filePathRoot + "/Output/" + STRATEGIES_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + outputPeriodLabel + "/" + dateForPath; + + thisBotStorage.createTextFile(filePath, fileName, fileContent + '\n', onFileCreated); + + function onFileCreated(err) { + + try { + + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeStrategiesFile -> onFileCreated -> Entering function."); } + if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> writeStrategiesFile -> onFileCreated -> fileContent = " + fileContent); } + + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { + + logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> onFileCreated -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> onFileCreated -> filePath = " + filePath); + logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB); + + callBackFunction(err); + return; + + } + + writeTradesFile(); + + } + catch (err) { + logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> onFileCreated -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + } + } + } + catch (err) { + logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + } + } + + function writeTradesFile() { + + try { + + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeTradesFile -> Entering function."); } + + let separator = ""; + let fileRecordCounter = 0; + + let fileContent = ""; + + for (let i = 0; i < tradesArray.length; i++) { + + let record = tradesArray[i]; + + /* Will only add to the file the records of the current day */ + + if (record.begin < currentDay.valueOf()) { continue; } + + fileContent = fileContent + separator + '[' + + record.begin + "," + + record.end + "," + + record.status + "," + + record.profit + "]"; + + if (separator === "") { separator = ","; } + + fileRecordCounter++; + + } + + fileContent = "[" + fileContent + "]"; + + let dateForPath = currentDay.getUTCFullYear() + '/' + utilities.pad(currentDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(currentDay.getUTCDate(), 2); + let fileName = '' + market.assetA + '_' + market.assetB + '.json'; + + let filePathRoot = bot.devTeam + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.PLATFORM_CONFIG.codeName + "." + global.PLATFORM_CONFIG.version.major + "." + global.PLATFORM_CONFIG.version.minor + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; + let filePath = filePathRoot + "/Output/" + TRADES_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + outputPeriodLabel + "/" + dateForPath; + + thisBotStorage.createTextFile(filePath, fileName, fileContent + '\n', onFileCreated); + + function onFileCreated(err) { + + try { + + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeTradesFile -> onFileCreated -> Entering function."); } + if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> writeTradesFile -> onFileCreated -> fileContent = " + fileContent); } + + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { + + logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> onFileCreated -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> onFileCreated -> filePath = " + filePath); + logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB); + + callBackFunction(err); + return; + + } + + callBackFunction(global.DEFAULT_OK_RESPONSE); + + } + catch (err) { + logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> onFileCreated -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + } + } + } + catch (err) { + logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + } + } + + } catch (err) { logger.write(MODULE_NAME, "[ERROR] start -> err = " + err.message); diff --git a/Multi-Period-Market/User.Bot.js b/Multi-Period-Market/User.Bot.js index c9090cc63..acc354cdd 100644 --- a/Multi-Period-Market/User.Bot.js +++ b/Multi-Period-Market/User.Bot.js @@ -7,6 +7,8 @@ const SIMULATED_RECORDS_FOLDER_NAME = "Trading-Simulation"; const CONDITIONS_FOLDER_NAME = "Simulation-Conditions"; + const STRATEGIES_FOLDER_NAME = "Simulation-Strategies"; + const TRADES_FOLDER_NAME = "Simulation-Trades"; const commons = COMMONS.newCommons(bot, logger, UTILITIES); @@ -63,6 +65,8 @@ let recordsArray = []; let conditionsArray = []; + let strategiesArray = []; + let tradesArray = []; let lastObjectsArray = []; let simulationLogic = {}; @@ -108,6 +112,8 @@ commons.runSimulation( recordsArray, conditionsArray, + strategiesArray, + tradesArray, lastObjectsArray, simulationLogic, timePeriod, @@ -268,7 +274,7 @@ } - callBackFunction(global.DEFAULT_OK_RESPONSE); + writeStrategiesFile(); } catch (err) { @@ -283,6 +289,143 @@ } } + function writeStrategiesFile() { + + try { + + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeStrategiesFile -> Entering function."); } + + let separator = ""; + let fileRecordCounter = 0; + + let fileContent = ""; + + for (let i = 0; i < strategiesArray.length; i++) { + let record = strategiesArray[i]; + + fileContent = fileContent + separator + '[' + + record.begin + "," + + record.end + "," + + record.status + "," + + record.number + "," + + record.beginRate + "," + + record.endRate + "]"; + + if (separator === "") { separator = ","; } + + fileRecordCounter++; + + } + + fileContent = "[" + fileContent + "]"; + let fileName = '' + market.assetA + '_' + market.assetB + '.json'; + + let filePathRoot = bot.devTeam + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.PLATFORM_CONFIG.codeName + "." + global.PLATFORM_CONFIG.version.major + "." + global.PLATFORM_CONFIG.version.minor + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; + let filePath = filePathRoot + "/Output/" + STRATEGIES_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + outputPeriodLabel; + + thisBotStorage.createTextFile(filePath, fileName, fileContent + '\n', onFileCreated); + + function onFileCreated(err) { + + try { + + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeStrategiesFile -> onFileCreated -> Entering function."); } + if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> writeStrategiesFile -> onFileCreated -> fileContent = " + fileContent); } + + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { + + logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> onFileCreated -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> onFileCreated -> filePath = " + filePath); + logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB); + + callBackFunction(err); + return; + + } + + writeTradesFile(); + + } + catch (err) { + logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> onFileCreated -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + } + } + } + catch (err) { + logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + } + } + + function writeTradesFile() { + + try { + + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeTradesFile -> Entering function."); } + + let separator = ""; + let fileRecordCounter = 0; + + let fileContent = ""; + + for (let i = 0; i < tradesArray.length; i++) { + + let record = tradesArray[i]; + + fileContent = fileContent + separator + '[' + + record.begin + "," + + record.end + "," + + record.status + "," + + record.profit + "]"; + + if (separator === "") { separator = ","; } + + fileRecordCounter++; + + } + + fileContent = "[" + fileContent + "]"; + let fileName = '' + market.assetA + '_' + market.assetB + '.json'; + + let filePathRoot = bot.devTeam + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.PLATFORM_CONFIG.codeName + "." + global.PLATFORM_CONFIG.version.major + "." + global.PLATFORM_CONFIG.version.minor + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; + let filePath = filePathRoot + "/Output/" + TRADES_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + outputPeriodLabel; + + thisBotStorage.createTextFile(filePath, fileName, fileContent + '\n', onFileCreated); + + function onFileCreated(err) { + + try { + + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeTradesFile -> onFileCreated -> Entering function."); } + if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> writeTradesFile -> onFileCreated -> fileContent = " + fileContent); } + + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { + + logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> onFileCreated -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> onFileCreated -> filePath = " + filePath); + logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB); + + callBackFunction(err); + return; + + } + + callBackFunction(global.DEFAULT_OK_RESPONSE); + + } + catch (err) { + logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> onFileCreated -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + } + } + } + catch (err) { + logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + } + } + } catch (err) { logger.write(MODULE_NAME, "[ERROR] start -> err = " + err.message); diff --git a/this.bot.config.json b/this.bot.config.json index 9b033db43..1bf3db7cc 100644 --- a/this.bot.config.json +++ b/this.bot.config.json @@ -281,7 +281,7 @@ { "codeName": "Multi-Period-Daily", "type": "Daily Files", - "validPeriods": ["15-min", "10-min", "05-min"], + "validPeriods": [ "15-min", "10-min", "05-min" ], "filePath": "AAMasters/AAJason.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Trading-Simulation/Multi-Period-Daily/@Period/@Year/@Month/@Day", "fileName": "@AssetA_@AssetB.json", "dataRange": { @@ -320,11 +320,11 @@ { "codeName": "Multi-Period-Daily", "type": "Daily Files", - "validPeriods": ["15-min", "10-min", "05-min"], + "validPeriods": [ "15-min", "10-min", "05-min" ], "filePath": "AAMasters/AAJason.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Conditions/Multi-Period-Daily/@Period/@Year/@Month/@Day", "fileName": "@AssetA_@AssetB.json", "dataRange": { - "filePath": "AAMasters/AAJason.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Trading-Simulation/Multi-Period-Daily", + "filePath": "AAMasters/AAJason.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Conditions/Multi-Period-Daily", "fileName": "Data.Range.@AssetA_@AssetB.json" } } @@ -342,6 +342,84 @@ "codeName": "PlottersTradingSimulation", "moduleName": "Conditions" } + }, + { + "codeName": "Simulation-Strategies", + "displayName": "Simulation Strategies", + "description": "Simulation Strategies", + "storageAccount": "aajason", + "dataSets": [ + { + "codeName": "Multi-Period-Market", + "type": "Market Files", + "validPeriods": [ "24-hs", "12-hs", "08-hs", "06-hs", "04-hs", "03-hs", "02-hs", "01-hs" ], + "filePath": "AAMasters/AAJason.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Strategies/Multi-Period-Market/@Period", + "fileName": "@AssetA_@AssetB.json" + }, + { + "codeName": "Multi-Period-Daily", + "type": "Daily Files", + "validPeriods": [ "15-min", "10-min", "05-min" ], + "filePath": "AAMasters/AAJason.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Strategies/Multi-Period-Daily/@Period/@Year/@Month/@Day", + "fileName": "@AssetA_@AssetB.json", + "dataRange": { + "filePath": "AAMasters/AAJason.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Strategies/Multi-Period-Daily", + "fileName": "Data.Range.@AssetA_@AssetB.json" + } + } + ], + "exchangeList": [ + { + "name": "Poloniex" + }, + { + "name": "Coss" + } + ], + "plotter": { + "devTeam": "AAMasters", + "codeName": "PlottersTradingSimulation", + "moduleName": "Strategies" + } + }, + { + "codeName": "Simulation-Trades", + "displayName": "Simulation Trades", + "description": "Simulation Trades", + "storageAccount": "aajason", + "dataSets": [ + { + "codeName": "Multi-Period-Market", + "type": "Market Files", + "validPeriods": [ "24-hs", "12-hs", "08-hs", "06-hs", "04-hs", "03-hs", "02-hs", "01-hs" ], + "filePath": "AAMasters/AAJason.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Trades/Multi-Period-Market/@Period", + "fileName": "@AssetA_@AssetB.json" + }, + { + "codeName": "Multi-Period-Daily", + "type": "Daily Files", + "validPeriods": [ "15-min", "10-min", "05-min" ], + "filePath": "AAMasters/AAJason.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Trades/Multi-Period-Daily/@Period/@Year/@Month/@Day", + "fileName": "@AssetA_@AssetB.json", + "dataRange": { + "filePath": "AAMasters/AAJason.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Trades/Multi-Period-Daily", + "fileName": "Data.Range.@AssetA_@AssetB.json" + } + } + ], + "exchangeList": [ + { + "name": "Poloniex" + }, + { + "name": "Coss" + } + ], + "plotter": { + "devTeam": "AAMasters", + "codeName": "PlottersTradingSimulation", + "moduleName": "Trades" + } } ] } From 2b280530b0022cda3a4a38a894262b263b170dc2 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 29 Apr 2019 10:49:24 +0200 Subject: [PATCH 4/5] Bugs corrected at Daily, when an object is spanning more than one day --- Commons.js | 33 ++++++++++++++------------- Multi-Period-Daily/User.Bot.js | 40 +++++++++++++++++---------------- Multi-Period-Market/User.Bot.js | 30 ++++++++++++------------- 3 files changed, 54 insertions(+), 49 deletions(-) diff --git a/Commons.js b/Commons.js index 191e0905b..761a18652 100644 --- a/Commons.js +++ b/Commons.js @@ -116,6 +116,13 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { let rate = 0; let newStopLoss; + /* In some cases we need to know if we are positioned at the last candle of the calendar day, for that we need thse variables. */ + + let lastInstantOfTheDay = currentDay.valueOf() + ONE_DAY_IN_MILISECONDS - 1; + let lastCandle = candles[candles.length - 1]; + + /* These 2 objects will allow us to create separate files for each one of them. */ + let currentStrategy = { begin: 0, end: 0, @@ -157,7 +164,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { let hits = 0; let periods = 0; - /* Message to Su=Simulation Executor */ + /* Message to the Simulation Executor */ let orderId = 0; let messageId = 0; @@ -935,7 +942,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { if ( (currentStrategy.begin !== 0 && currentStrategy.end !== 0) || - (currentStrategy.begin !== 0 && i === candles.length - 1) + (currentStrategy.begin !== 0 && i === candles.length - 1 && lastCandle.end !== lastInstantOfTheDay) ) { strategiesArray.push(currentStrategy); @@ -954,7 +961,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { if ( (currentTrade.begin !== 0 && currentTrade.end !== 0) || - (currentTrade.begin !== 0 && i === candles.length - 1) + (currentTrade.begin !== 0 && i === candles.length - 1 && lastCandle.end !== lastInstantOfTheDay) ) { currentTrade.profit = lastProfit; @@ -978,11 +985,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { if (currentDay !== undefined) { - let lastInstantOdDay = currentDay.valueOf() + ONE_DAY_IN_MILISECONDS - 1; - - lastCandle = candles[candles.length - 1]; - - if (lastCandle.end === lastInstantOdDay) { + if (lastCandle.end === lastInstantOfTheDay) { interExecutionMemory.balanceAssetA = yesterday.balanceAssetA; interExecutionMemory.balanceAssetB = yesterday.balanceAssetB; @@ -1025,7 +1028,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] runSimulation -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] runSimulation -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -1072,7 +1075,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] buildLRC -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] buildLRC -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -1111,7 +1114,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] buildPercentageBandwidthMap -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] buildPercentageBandwidthMap -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -1150,7 +1153,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] buildBollingerBandsMap -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] buildBollingerBandsMap -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -1184,7 +1187,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] buildBollingerChannelsArray -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] buildBollingerChannelsArray -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -1219,7 +1222,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] buildBollingerSubChannelsArray -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] buildBollingerSubChannelsArray -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -1265,7 +1268,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] buildCandles -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] buildCandles -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } diff --git a/Multi-Period-Daily/User.Bot.js b/Multi-Period-Daily/User.Bot.js index 29a9c2552..e700da9de 100644 --- a/Multi-Period-Daily/User.Bot.js +++ b/Multi-Period-Daily/User.Bot.js @@ -44,12 +44,12 @@ callBackFunction(global.DEFAULT_OK_RESPONSE); } else { - logger.write(MODULE_NAME, "[ERROR] initializeStorage -> onStorageInizialized -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] initializeStorage -> onStorageInizialized -> err = " + err.stack); callBackFunction(err); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] initialize -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] initialize -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -193,7 +193,7 @@ if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write(MODULE_NAME, "[ERROR] start -> writeRecordsFile -> onFileCreated -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeRecordsFile -> onFileCreated -> err = " + err.stack); logger.write(MODULE_NAME, "[ERROR] start -> writeRecordsFile -> onFileCreated -> filePath = " + filePath); logger.write(MODULE_NAME, "[ERROR] start -> writeRecordsFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB); @@ -206,13 +206,13 @@ } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> writeRecordsFile -> onFileCreated -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeRecordsFile -> onFileCreated -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> writeRecordsFile -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeRecordsFile -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -278,7 +278,7 @@ if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write(MODULE_NAME, "[ERROR] start -> writeConditionsFile -> onFileCreated -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeConditionsFile -> onFileCreated -> err = " + err.stack); logger.write(MODULE_NAME, "[ERROR] start -> writeConditionsFile -> onFileCreated -> filePath = " + filePath); logger.write(MODULE_NAME, "[ERROR] start -> writeConditionsFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB); @@ -291,13 +291,13 @@ } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> writeConditionsFile -> onFileCreated -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeConditionsFile -> onFileCreated -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> writeConditionsFile -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeConditionsFile -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -316,9 +316,10 @@ for (let i = 0; i < strategiesArray.length; i++) { let record = strategiesArray[i]; - /* Will only add to the file the records of the current day */ + /* Will only add to the file the records of the current day. In this case since objects can span more than one day, we add all of the objects that ends + at the current date. */ - if (record.begin < currentDay.valueOf()) { continue; } + if (record.end < currentDay.valueOf()) { continue; } fileContent = fileContent + separator + '[' + record.begin + "," + @@ -353,7 +354,7 @@ if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> onFileCreated -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> onFileCreated -> err = " + err.stack); logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> onFileCreated -> filePath = " + filePath); logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB); @@ -366,13 +367,13 @@ } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> onFileCreated -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> onFileCreated -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -392,9 +393,10 @@ let record = tradesArray[i]; - /* Will only add to the file the records of the current day */ + /* Will only add to the file the records of the current day. In this case since objects can span more than one day, we add all of the objects that ends + at the current date. */ - if (record.begin < currentDay.valueOf()) { continue; } + if (record.end < currentDay.valueOf()) { continue; } fileContent = fileContent + separator + '[' + record.begin + "," + @@ -427,7 +429,7 @@ if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> onFileCreated -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> onFileCreated -> err = " + err.stack); logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> onFileCreated -> filePath = " + filePath); logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB); @@ -440,13 +442,13 @@ } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> onFileCreated -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> onFileCreated -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -454,7 +456,7 @@ } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } diff --git a/Multi-Period-Market/User.Bot.js b/Multi-Period-Market/User.Bot.js index acc354cdd..629cb1067 100644 --- a/Multi-Period-Market/User.Bot.js +++ b/Multi-Period-Market/User.Bot.js @@ -44,12 +44,12 @@ callBackFunction(global.DEFAULT_OK_RESPONSE); } else { - logger.write(MODULE_NAME, "[ERROR] initializeStorage -> onStorageInizialized -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] initializeStorage -> onStorageInizialized -> err = " + err.stack); callBackFunction(err); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] initialize -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] initialize -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -190,7 +190,7 @@ if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write(MODULE_NAME, "[ERROR] start -> writeRecordsFile -> onFileCreated -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeRecordsFile -> onFileCreated -> err = " + err.stack); logger.write(MODULE_NAME, "[ERROR] start -> writeRecordsFile -> onFileCreated -> filePath = " + filePath); logger.write(MODULE_NAME, "[ERROR] start -> writeRecordsFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB); @@ -203,13 +203,13 @@ } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> writeRecordsFile -> onFileCreated -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeRecordsFile -> onFileCreated -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> writeRecordsFile -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeRecordsFile -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -265,7 +265,7 @@ if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write(MODULE_NAME, "[ERROR] start -> writeConditionsFile -> onFileCreated -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeConditionsFile -> onFileCreated -> err = " + err.stack); logger.write(MODULE_NAME, "[ERROR] start -> writeConditionsFile -> onFileCreated -> filePath = " + filePath); logger.write(MODULE_NAME, "[ERROR] start -> writeConditionsFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB); @@ -278,13 +278,13 @@ } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> writeConditionsFile -> onFileCreated -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeConditionsFile -> onFileCreated -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> writeConditionsFile -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeConditionsFile -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -334,7 +334,7 @@ if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> onFileCreated -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> onFileCreated -> err = " + err.stack); logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> onFileCreated -> filePath = " + filePath); logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB); @@ -347,13 +347,13 @@ } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> onFileCreated -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> onFileCreated -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -402,7 +402,7 @@ if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> onFileCreated -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> onFileCreated -> err = " + err.stack); logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> onFileCreated -> filePath = " + filePath); logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB); @@ -415,20 +415,20 @@ } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> onFileCreated -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> onFileCreated -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } From 053664d2193be027af4c17767b0ec22200c56622 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 29 Apr 2019 16:31:17 +0200 Subject: [PATCH 5/5] All working, with individual files for Trades and Strategies --- Commons.js | 20 ++++++++++++++++---- Multi-Period-Daily/User.Bot.js | 6 +++++- Multi-Period-Market/User.Bot.js | 6 +++++- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Commons.js b/Commons.js index 761a18652..635d32736 100644 --- a/Commons.js +++ b/Commons.js @@ -134,7 +134,10 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { begin: 0, end: 0, status: 0, - profit: 0 + profit: 0, + exitType: 0, + beginRate: 0, + endRate: 0 } /* @@ -540,6 +543,8 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { strategyPhase = 4; currentTrade.end = candle.end; currentTrade.status = 1; + currentTrade.exitType = 1; + currentTrade.endRate = stopLoss; currentStrategy.number = strategyNumber - 1 currentStrategy.end = candle.end; @@ -566,7 +571,9 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { type = '"Buy@BuyOrder"'; strategyPhase = 4; currentTrade.end = candle.end; - currentTrade.status = 1; + currentTrade.status = 1; + currentTrade.exitType = 2; + currentTrade.endRate = buyOrder; currentStrategy.number = strategyNumber - 1 currentStrategy.end = candle.end; @@ -608,6 +615,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { stopLossPhase = 1; buyOrderPhase = 1; currentTrade.begin = candle.begin; + currentTrade.beginRate = candle.close; return; } } @@ -768,7 +776,8 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { if (isNaN(lastProfitPercent)) { lastProfitPercent = 0; } profit = balanceAssetA - initialBalanceA; - + currentTrade.lastProfitPercent = lastProfitPercent; + currentTrade.stopRate = stopLoss; //if (isNaN(ROI)) { ROI = 0; } @@ -972,7 +981,10 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { begin: 0, end: 0, status: 0, - profit: 0 + lastProfitPercent: 0, + exitType: 0, + beginRate: 0, + endRate: 0 } } } diff --git a/Multi-Period-Daily/User.Bot.js b/Multi-Period-Daily/User.Bot.js index e700da9de..952e51922 100644 --- a/Multi-Period-Daily/User.Bot.js +++ b/Multi-Period-Daily/User.Bot.js @@ -402,7 +402,11 @@ record.begin + "," + record.end + "," + record.status + "," + - record.profit + "]"; + record.lastProfitPercent + "," + + record.beginRate + "," + + record.endRate + "," + + record.exitType + "," + + record.stopRate + "]"; if (separator === "") { separator = ","; } diff --git a/Multi-Period-Market/User.Bot.js b/Multi-Period-Market/User.Bot.js index 629cb1067..1faeca81d 100644 --- a/Multi-Period-Market/User.Bot.js +++ b/Multi-Period-Market/User.Bot.js @@ -377,7 +377,11 @@ record.begin + "," + record.end + "," + record.status + "," + - record.profit + "]"; + record.lastProfitPercent + "," + + record.beginRate + "," + + record.endRate + "," + + record.exitType + "," + + record.stopRate + "]"; if (separator === "") { separator = ","; }