Merge pull request #126 from AAMasters/develop

timePeriod and beginDate coming at simulationParams
This commit is contained in:
benme authored and GitHub committed 2019-08-10 09:08:25 -03:00
commit 2fbd01dc2f
10 files changed
+68 -2943

No files matched your search

-2349
View File
File diff suppressed because it is too large. Load diff
+1 -1
View File
@@ -131,7 +131,7 @@
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> getStatusReport -> Entering function."); } if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> getStatusReport -> Entering function."); }
let key = bot.devTeam + "-" + bot.codeName + "-" + bot.process + "-" + bot.dataSetVersion; let key = bot.devTeam + "-" + bot.codeName + "-" + "Context" + "-" + bot.dataSetVersion;
statusReportModule = statusDependencies.statusReports.get(key); statusReportModule = statusDependencies.statusReports.get(key);
thisObject.statusReport = statusReportModule.file; thisObject.statusReport = statusReportModule.file;
+1 -1
View File
@@ -370,7 +370,7 @@
} }
} }
let timePeriodFilter = process.env.TIME_PERIOD let timePeriodFilter = global.EXECUTION_CONFIG.timePeriodFileStorage
if (timePeriodFilter !== undefined) { if (timePeriodFilter !== undefined) {
if (timePeriodFilter.indexOf(outputPeriodLabel) === -1) { if (timePeriodFilter.indexOf(outputPeriodLabel) === -1) {
periodsControlLoop(); periodsControlLoop();
+1 -1
View File
@@ -141,7 +141,7 @@
let dependencyIndex = 0; let dependencyIndex = 0;
dataFiles = []; dataFiles = [];
let timePeriodFilter = process.env.TIME_PERIOD let timePeriodFilter = global.EXECUTION_CONFIG.timePeriodFileStorage
if (timePeriodFilter !== undefined) { if (timePeriodFilter !== undefined) {
if (timePeriodFilter.indexOf(outputPeriodLabel) === -1) { if (timePeriodFilter.indexOf(outputPeriodLabel) === -1) {
periodsControlLoop(); periodsControlLoop();
-2
View File
@@ -24,7 +24,6 @@
<Compile Include="Assistant.js"> <Compile Include="Assistant.js">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Commons.js" />
<Compile Include="Integrations\Ecosystem.js" /> <Compile Include="Integrations\Ecosystem.js" />
<Compile Include="Integrations\FileStorage.js" /> <Compile Include="Integrations\FileStorage.js" />
<Compile Include="Integrations\Strategy.js" /> <Compile Include="Integrations\Strategy.js" />
@@ -37,7 +36,6 @@
<Compile Include="TradingEngineProcessMainLoop.js"> <Compile Include="TradingEngineProcessMainLoop.js">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="User.Bot.js" />
<Compile Include="utils\logger.js"> <Compile Include="utils\logger.js">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
+3 -3
View File
@@ -345,7 +345,7 @@
let month = pad((new Date()).getUTCMonth() + 1, 2); let month = pad((new Date()).getUTCMonth() + 1, 2);
let year = (new Date()).getUTCFullYear(); let year = (new Date()).getUTCFullYear();
if (processConfig.startMode.noTime.resumeExecution === "true") { if (processConfig.startMode.noTime.resumeExecution === true) {
botConfig.hasTheBotJustStarted = false; botConfig.hasTheBotJustStarted = false;
} else { } else {
botConfig.hasTheBotJustStarted = true; botConfig.hasTheBotJustStarted = true;
@@ -403,7 +403,7 @@
let month = pad((new Date()).getUTCMonth() + 1, 2); let month = pad((new Date()).getUTCMonth() + 1, 2);
let year = (new Date()).getUTCFullYear(); let year = (new Date()).getUTCFullYear();
if (processConfig.startMode.live.resumeExecution === "true") { if (processConfig.startMode.live.resumeExecution === true) {
botConfig.hasTheBotJustStarted = false; botConfig.hasTheBotJustStarted = false;
} else { } else {
botConfig.hasTheBotJustStarted = true; botConfig.hasTheBotJustStarted = true;
@@ -459,7 +459,7 @@
botConfig.competition = processConfig.startMode.competition; botConfig.competition = processConfig.startMode.competition;
if (processConfig.startMode.competition.resumeExecution === "false") { if (processConfig.startMode.competition.resumeExecution === false) {
botConfig.hasTheBotJustStarted = true; botConfig.hasTheBotJustStarted = true;
} else { } else {
botConfig.hasTheBotJustStarted = false; botConfig.hasTheBotJustStarted = false;
+56 -24
View File
@@ -35,18 +35,19 @@ if (process.env.RUN_SEQUENCE !== undefined) {
} }
if (isRunSequence) { if (isRunSequence) {
sequenceExecution(sequenceStep) sequenceExecution(sequenceStep, false)
} else { } else {
readExecutionConfiguration() readExecutionConfiguration()
} }
function sequenceExecution(currentStep) { function sequenceExecution(currentStep, notFirstSequence) {
let execution = sequenceList[currentStep]; let execution = sequenceList[currentStep];
process.env.STOP_GRACEFULLY = true; process.env.STOP_GRACEFULLY = true;
execution.devTeam ? process.env.DEV_TEAM = execution.devTeam : undefined; execution.devTeam ? process.env.DEV_TEAM = execution.devTeam : undefined;
execution.bot ? process.env.BOT = execution.bot : undefined; execution.bot ? process.env.BOT = execution.bot : undefined;
execution.mode ? process.env.START_MODE = execution.mode : undefined; execution.mode ? process.env.START_MODE = execution.mode : undefined;
execution.resumeExecution ? process.env.RESUME_EXECUTION = execution.resumeExecution : undefined; execution.resumeExecution = notFirstSequence
execution.type ? process.env.TYPE = execution.type : undefined; execution.type ? process.env.TYPE = execution.type : undefined;
execution.process ? process.env.PROCESS = execution.process : undefined; execution.process ? process.env.PROCESS = execution.process : undefined;
execution.startYear ? process.env.MIN_YEAR = execution.startYear : undefined; execution.startYear ? process.env.MIN_YEAR = execution.startYear : undefined;
@@ -69,7 +70,7 @@ function sequenceExecution(currentStep) {
processedSteps.set(stepKey, 0); processedSteps.set(stepKey, 0);
} }
console.log("Sequence Execution Parameters: " + JSON.stringify(execution)) console.log("Sequence Execution Parameters: " + JSON.stringify(execution))
readExecutionConfiguration(); readExecutionConfiguration(execution);
sequenceStep++; sequenceStep++;
} }
@@ -79,17 +80,17 @@ function onExecutionFinish (result, finishStepKey) {
console.log('[INFO] onExecutionFinish -> Step already processed.') console.log('[INFO] onExecutionFinish -> Step already processed.')
} else { } else {
if (sequenceStep < sequenceList.length) { if (sequenceStep < sequenceList.length) {
sequenceExecution(sequenceStep) sequenceExecution(sequenceStep, true)
} else { } else {
if (sequenceStep < sequenceList.length) { if (sequenceStep < sequenceList.length) {
sequenceExecution(sequenceStep); sequenceExecution(sequenceStep, true);
} else { } else {
setTimeout(function () { setTimeout(function () {
console.log("[INFO] onExecutionFinish -> New round for sequence execution started."); console.log("[INFO] onExecutionFinish -> New round for sequence execution started.");
sequenceList = require('./sequence'); // We read again the sequence after every loop sequenceList = require('./sequence'); // We read again the sequence after every loop
sequenceStep = 0; sequenceStep = 0;
processedSteps = new Map(); processedSteps = new Map();
sequenceExecution(sequenceStep); sequenceExecution(sequenceStep, true);
}, process.env.EXECUTION_LOOP_DELAY); }, process.env.EXECUTION_LOOP_DELAY);
} }
} }
@@ -97,24 +98,53 @@ function onExecutionFinish (result, finishStepKey) {
} }
async function readExecutionConfiguration() { async function readExecutionConfiguration(execution) {
try { try {
console.log("[INFO] Run -> readExecutionConfiguration -> Entering function. "); console.log("[INFO] Run -> readExecutionConfiguration -> Entering function. ");
let timePeriod
let botProcess
/* Try to get the begin and end dates from the Definition */ /* Try to get the begin and end dates from the Definition */
let definition = await strategy.getStrategy() let definition = await strategy.getStrategy()
/* Dates are taken initially from .env, but can be overwritten if they are defined by the user */
let initialDatetime = process.env.BEGIN_DATE_TIME let initialDatetime = process.env.BEGIN_DATE_TIME
let finalDatetime = process.env.END_DATE_TIME let finalDatetime = process.env.END_DATE_TIME
if (definition !== undefined) { if (execution.type === 'Trading-Engine') {
if (definition.tradingSystem !== undefined) { if (definition !== undefined) {
if (definition.tradingSystem.parameters !== undefined) { if (definition.simulationParams !== undefined) {
if (definition.tradingSystem.parameters.baseAsset !== undefined) { if (definition.simulationParams.beginDatetime !== undefined) {
if (definition.tradingSystem.parameters.baseAsset.formula !== undefined) { initialDatetime = new Date(definition.simulationParams.beginDatetime) /* The first override occurs here, with the simulation parameters */
if (definition.tradingSystem.parameters.baseAsset.formula.code !== undefined) { }
let code = JSON.parse(definition.tradingSystem.parameters.baseAsset.formula.code) /* Here we only look for one timePeriod, in the future we will be able to process the whole array, but not for now. */
initialDatetime = code.initialDatetime if (definition.simulationParams.timePeriodDailyArray !== undefined) {
finalDatetime = code.finalDatetime if (definition.simulationParams.timePeriodDailyArray.length > 0) {
timePeriod = definition.simulationParams.timePeriodDailyArray[0]
botProcess = "Multi-Period-Daily"
}
}
if (definition.simulationParams.timePeriodMarketArray !== undefined) {
if (definition.simulationParams.timePeriodMarketArray.length > 0) {
timePeriod = definition.simulationParams.timePeriodMarketArray[0]
botProcess = "Multi-Period-Market"
}
}
}
if (definition.tradingSystem !== undefined) {
if (definition.tradingSystem.parameters !== undefined) {
if (definition.tradingSystem.parameters.baseAsset !== undefined) {
if (definition.tradingSystem.parameters.baseAsset.formula !== undefined) {
if (definition.tradingSystem.parameters.baseAsset.formula.code !== undefined) {
let code = JSON.parse(definition.tradingSystem.parameters.baseAsset.formula.code)
if (code.initialDatetime !== undefined) {
initialDatetime = code.initialDatetime /* The second override occurs here, with the date explicitelly defined by the user */
}
if (code.finalDatetime !== undefined) {
finalDatetime = code.finalDatetime
}
}
} }
} }
} }
@@ -131,21 +161,21 @@ async function readExecutionConfiguration() {
if (process.env.TYPE === 'Trading' || process.env.TYPE === 'Trading-Engine') { if (process.env.TYPE === 'Trading' || process.env.TYPE === 'Trading-Engine') {
let live = { let live = {
run: 'false', run: 'false',
resumeExecution: process.env.RESUME_EXECUTION, resumeExecution: execution.resumeExecution,
beginDatetime: initialDatetime, beginDatetime: initialDatetime,
endDatetime: finalDatetime endDatetime: finalDatetime
} }
let backtest = { let backtest = {
run: 'false', run: 'false',
resumeExecution: process.env.RESUME_EXECUTION, resumeExecution: execution.resumeExecution,
beginDatetime: initialDatetime, beginDatetime: initialDatetime,
endDatetime: finalDatetime endDatetime: finalDatetime
} }
let competition = { let competition = {
run: 'false', run: 'false',
resumeExecution: process.env.RESUME_EXECUTION, resumeExecution: execution.resumeExecution,
beginDatetime: initialDatetime, beginDatetime: initialDatetime,
endDatetime: finalDatetime endDatetime: finalDatetime
} }
@@ -169,7 +199,7 @@ async function readExecutionConfiguration() {
let noTime = { let noTime = {
run: "false", run: "false",
beginDatetime: process.env.BEGIN_DATE_TIME, beginDatetime: process.env.BEGIN_DATE_TIME,
resumeExecution: process.env.RESUME_EXECUTION resumeExecution: execution.resumeExecution
} }
let fixedInterval = { let fixedInterval = {
run: "false", run: "false",
@@ -189,19 +219,21 @@ async function readExecutionConfiguration() {
startMode[process.env.START_MODE].run = "true" startMode[process.env.START_MODE].run = "true"
if (botProcess === undefined) { botProcess = process.env.PROCESS } // Only use the .env when nothing comes at Definition.json
let cloneToExecute = { let cloneToExecute = {
enabled: "true", enabled: "true",
devTeam: process.env.DEV_TEAM, devTeam: process.env.DEV_TEAM,
bot: process.env.BOT, bot: process.env.BOT,
process: process.env.PROCESS, process: botProcess,
repo: global.CURRENT_BOT_REPO repo: global.CURRENT_BOT_REPO
} }
if (timePeriod === undefined) { timePeriod = process.env.TIME_PERIOD} // Only use the .env when nothing comes at Definition.json
global.EXECUTION_CONFIG = { global.EXECUTION_CONFIG = {
cloneToExecute: cloneToExecute, cloneToExecute: cloneToExecute,
startMode: startMode, startMode: startMode,
timePeriod: getTimePeriod(process.env.TIME_PERIOD), timePeriod: getTimePeriod(timePeriod),
timePeriodFileStorage: process.env.TIME_PERIOD, timePeriodFileStorage: timePeriod,
dataSet: process.env.DATA_SET dataSet: process.env.DATA_SET
}; };
+2 -2
View File
@@ -162,7 +162,7 @@
let ownerId = owner.devTeam + "-" + owner.bot + "-" + owner.botVersion.major + "-" + owner.botVersion.minor + "-" + owner.process + "-" + owner.dataSetVersion; let ownerId = owner.devTeam + "-" + owner.bot + "-" + owner.botVersion.major + "-" + owner.botVersion.minor + "-" + owner.process + "-" + owner.dataSetVersion;
let botId = bot.devTeam + "-" + bot.codeName + "-" + bot.version.major + "-" + bot.version.minor + "-" + bot.process + "-" + bot.dataSetVersion; let botId = bot.devTeam + "-" + bot.codeName + "-" + bot.version.major + "-" + bot.version.minor + "-" + bot.process + "-" + bot.dataSetVersion;
if (ownerId !== botId) { if (ownerId !== botId && owner.process !== "Context") { // Context is a special case where the report is created by the Context.js module itself.
let customErr = { let customErr = {
result: global.CUSTOM_FAIL_RESPONSE.result, result: global.CUSTOM_FAIL_RESPONSE.result,
@@ -176,7 +176,7 @@
let fileName = "Status.Report." + global.MARKET.assetA + '_' + global.MARKET.assetB + ".json"; let fileName = "Status.Report." + global.MARKET.assetA + '_' + global.MARKET.assetB + ".json";
let filePath = bot.filePathRoot + "/Reports/" + owner.process + timePath; let filePath = bot.filePathRoot + "/Reports/" + owner.process + timePath;
if (bot.type === 'Trading') { if (bot.type === 'Trading' ) {
fileName = bot.startMode + "." + fileName; fileName = bot.startMode + "." + fileName;
} }
+4 -4
View File
@@ -56,8 +56,8 @@
} }
USER_BOT_MODULE = {} USER_BOT_MODULE = {}
USER_BOT_MODULE.newUserBot = require(ROOT_DIR + 'User.Bot').newUserBot // Use this for a better debugging experience. You need to bring this js module to this folder in order to work. //USER_BOT_MODULE.newUserBot = require(ROOT_DIR + 'User.Bot').newUserBot // Use this for a better debugging experience. You need to bring this js module to this folder in order to work.
//USER_BOT_MODULE.newUserBot = eval(text); // Use this for production USER_BOT_MODULE.newUserBot = eval(text); // Use this for production
filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo; filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo;
filePath += "/Commons.js" filePath += "/Commons.js"
@@ -72,8 +72,8 @@
return; return;
} }
COMMONS_MODULE = {} COMMONS_MODULE = {}
COMMONS_MODULE.newCommons = require(ROOT_DIR + 'Commons').newCommons // Use this for a better debugging experience. You need to bring this js module to this folder in order to work. //COMMONS_MODULE.newCommons = require(ROOT_DIR + 'Commons').newCommons // Use this for a better debugging experience. You need to bring this js module to this folder in order to work.
//COMMONS_MODULE.newCommons = eval(text); // Use this for production COMMONS_MODULE.newCommons = eval(text); // Use this for production
callBackFunction(global.DEFAULT_OK_RESPONSE); callBackFunction(global.DEFAULT_OK_RESPONSE);
} }
-556
View File
@@ -1,556 +0,0 @@
exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileStorage) {
const FULL_LOG = true;
const LOG_FILE_CONTENT = false;
const MODULE_NAME = "User Bot";
const EXECUTION_FOLDER_NAME = "Trading-Execution";
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);
thisObject = {
initialize: initialize,
start: start
};
let utilities = UTILITIES.newCloudUtilities(bot, logger);
let dataDependencies;
let assistant;
return thisObject;
function initialize(pDataDependencies, callBackFunction, pAssistant) {
try {
logger.fileName = MODULE_NAME;
logger.initialize();
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] initialize -> Entering function."); }
dataDependencies = pDataDependencies;
assistant = pAssistant;
callBackFunction(global.DEFAULT_OK_RESPONSE);
} catch (err) {
logger.write(MODULE_NAME, "[ERROR] initialize -> err = " + err.stack);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
function start(dataFiles, timePeriod, outputPeriodLabel, currentDay, startDate, endDate, interExecutionMemory, callBackFunction) {
try {
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> Entering function."); }
let market = global.MARKET;
let dataFile;
let recordsArray
let conditionsArray
let strategiesArray
let tradesArray
let lastObjectsArray
let tradingSystem = {};
commons.initializeData();
for (let i = 0; i < dataDependencies.config.length; i++) {
let dependency = dataDependencies.config[i];
dataFile = dataFiles[i];
switch (i) {
/*
case 0: {
commons.buildLRC(dataFile, callBackFunction);
break;
}*/
case 0: {
commons.buildPercentageBandwidthMap(dataFile, callBackFunction);
break;
}
case 1: {
commons.buildBollingerBandsMap(dataFile, callBackFunction);
break;
}
case 2: {
commons.buildBollingerChannelsArray(dataFile, callBackFunction);
break;
}
case 3: {
commons.buildBollingerSubChannelsArray(dataFile, callBackFunction);
break;
}
case 4: {
commons.buildCandles(dataFile, callBackFunction);
break;
}
}
}
commons.runSimulation(
timePeriod,
currentDay,
startDate,
endDate,
interExecutionMemory,
assistant,
writeFiles,
callBackFunction)
function writeFiles(pTradingSystem, pExecutionArray, pRecordsArray, pConditionsArray, pStrategiesArray, pTradesArray, pLastObjectsArray) {
tradingSystem = pTradingSystem
executionArray = pExecutionArray
recordsArray = pRecordsArray
conditionsArray = pConditionsArray
strategiesArray = pStrategiesArray
tradesArray = pTradesArray
lastObjectsArray = pLastObjectsArray
writeExecutionFile()
}
function writeExecutionFile() {
try {
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeExecutionFile -> Entering function."); }
let separator = "";
let fileRecordCounter = 0;
let fileContent = "";
for (let i = 0; i < executionArray.length; i++) {
let record = executionArray[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 + "," +
JSON.stringify(record.executionRecord) + "]";
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.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion;
let filePath = filePathRoot + "/Output/" + EXECUTION_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + outputPeriodLabel + "/" + dateForPath;
filePath += '/' + fileName
fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated);
function onFileCreated(err) {
try {
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeExecutionFile -> onFileCreated -> Entering function."); }
if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> writeExecutionFile -> onFileCreated -> fileContent = " + fileContent); }
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
logger.write(MODULE_NAME, "[ERROR] start -> writeExecutionFile -> onFileCreated -> err = " + err.stack);
logger.write(MODULE_NAME, "[ERROR] start -> writeExecutionFile -> onFileCreated -> filePath = " + filePath);
logger.write(MODULE_NAME, "[ERROR] start -> writeExecutionFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB);
callBackFunction(err);
return;
}
writeRecordsFile();
}
catch (err) {
logger.write(MODULE_NAME, "[ERROR] start -> writeExecutionFile -> onFileCreated -> err = " + err.stack);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
}
catch (err) {
logger.write(MODULE_NAME, "[ERROR] start -> writeExecutionFile -> err = " + err.stack);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
function writeRecordsFile() {
try {
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeRecordsFile -> Entering function."); }
let separator = "";
let fileRecordCounter = 0;
let fileContent = "";
for (let i = 0; i < recordsArray.length; i++) {
let record = recordsArray[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.type + "," +
record.marketRate + "," +
record.amount + "," +
record.balanceA + "," +
record.balanceB + "," +
record.profit + "," +
record.lastTradeProfitLoss + "," +
record.stopLoss + "," +
record.roundtrips + "," +
record.hits + "," +
record.fails + "," +
record.hitRatio + "," +
record.ROI + "," +
record.periods + "," +
record.days + "," +
record.anualizedRateOfReturn + "," +
record.positionRate + "," +
record.lastTradeROI + "," +
record.strategy + "," +
record.strategyStageNumber + "," +
record.takeProfit + "," +
record.stopLossPhase + "," +
record.takeProfitPhase + "," +
JSON.stringify(record.executionRecord) + "," +
record.positionSize + "," +
record.initialBalanceA + "," +
record.minimumBalanceA + "," +
record.maximumBalanceA + "," +
record.initialBalanceB + "," +
record.minimumBalanceB + "," +
record.maximumBalanceB + "," +
record.baseAsset + "]";
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.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion;
let filePath = filePathRoot + "/Output/" + SIMULATED_RECORDS_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + outputPeriodLabel + "/" + dateForPath;
filePath += '/' + fileName
fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated);
function onFileCreated(err) {
try {
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeRecordsFile -> onFileCreated -> Entering function."); }
if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> writeRecordsFile -> onFileCreated -> fileContent = " + fileContent); }
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
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);
callBackFunction(err);
return;
}
writeConditionsFile();
}
catch (err) {
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.stack);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
function writeConditionsFile() {
try {
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeConditionsFile -> Entering function."); }
let separator = "";
let fileRecordCounter = 0;
let fileContent = "";
for (let i = 0; i < conditionsArray.length; i++) {
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 = "";
/* Will only add to the file the records of the current day */
if (record.begin < currentDay.valueOf()) { continue; }
for (let j = 0; j < record.length - 3; j++) {
conditions = conditions + conditionsSeparator + record[j];
if (conditionsSeparator === "") { conditionsSeparator = ","; }
}
conditions = conditions + conditionsSeparator + '[' + record[record.length - 3] + ']'; // The last item contains an Array of condition values.
conditions = conditions + conditionsSeparator + '[' + record[record.length - 2] + ']'; // The last item contains an Array of formulaErrors.
conditions = conditions + conditionsSeparator + '[' + record[record.length - 1] + ']'; // The last item contains an Array of formulaValues.
fileContent = fileContent + separator + '[' + conditions + ']';
if (separator === "") { separator = ","; }
fileRecordCounter++;
}
fileContent = "[" + fileContent + "]";
fileContent = "[" + JSON.stringify(tradingSystem) + "," + JSON.stringify(lastObjectsArray) + "," + 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.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion;
let filePath = filePathRoot + "/Output/" + CONDITIONS_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + outputPeriodLabel + "/" + dateForPath;
filePath += '/' + fileName
fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated);
function onFileCreated(err) {
try {
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeConditionsFile -> onFileCreated -> Entering function."); }
if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> writeConditionsFile -> onFileCreated -> fileContent = " + fileContent); }
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
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);
callBackFunction(err);
return;
}
writeStrategiesFile();
}
catch (err) {
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.stack);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
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. 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.end < 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.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion;
let filePath = filePathRoot + "/Output/" + STRATEGIES_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + outputPeriodLabel + "/" + dateForPath;
filePath += '/' + fileName
fileStorage.createTextFile(bot.devTeam, filePath, 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.stack);
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.stack);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
}
catch (err) {
logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> err = " + err.stack);
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. 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.end < currentDay.valueOf()) { continue; }
if (record.stopRate === undefined) { record.stopRate = 0}
fileContent = fileContent + separator + '[' +
record.begin + "," +
record.end + "," +
record.status + "," +
record.lastTradeROI + "," +
record.beginRate + "," +
record.endRate + "," +
record.exitType + "," +
record.stopRate + "]";
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.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion;
let filePath = filePathRoot + "/Output/" + TRADES_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + outputPeriodLabel + "/" + dateForPath;
filePath += '/' + fileName
fileStorage.createTextFile(bot.devTeam, filePath, 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.stack);
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.stack);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
}
catch (err) {
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.stack);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
};