Merge remote-tracking branch 'AAMasters/develop' into develop

This commit is contained in:
Matias committed 2019-05-03 18:50:37 -03:00
commit 3200313c65
4 files changed
+572 -56

No files matched your search

+159 -35
View File
@@ -56,6 +56,8 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) {
async function runSimulation(
recordsArray,
conditionsArray,
strategiesArray,
tradesArray,
lastObjectsArray,
simulationLogic,
timePeriod,
@@ -114,6 +116,30 @@ 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,
status: 0,
number: 0
}
let currentTrade = {
begin: 0,
end: 0,
status: 0,
profit: 0,
exitType: 0,
beginRate: 0,
endRate: 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
@@ -141,7 +167,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;
@@ -154,13 +180,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 +207,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 +234,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 +256,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 +276,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 +293,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;
@@ -380,7 +423,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) {
@@ -423,7 +467,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;
}
}
@@ -458,6 +504,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;
@@ -467,6 +517,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
@@ -489,6 +541,15 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) {
rate = stopLoss;
type = '"Buy@StopLoss"';
strategyPhase = 4;
currentTrade.end = candle.end;
currentTrade.status = 1;
currentTrade.exitType = 1;
currentTrade.endRate = stopLoss;
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. */
@@ -509,10 +570,19 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) {
rate = buyOrder;
type = '"Buy@BuyOrder"';
strategyPhase = 4;
currentTrade.end = candle.end;
currentTrade.status = 1;
currentTrade.exitType = 2;
currentTrade.endRate = buyOrder;
currentStrategy.number = strategyNumber - 1
currentStrategy.end = candle.end;
currentStrategy.endRate = candle.min;
currentStrategy.status = 1;
}
}
/* Strategy Sell Condition */
/* Trade Enter Condition */
if (strategyPhase === 1) {
@@ -544,7 +614,8 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) {
strategyPhase = 2;
stopLossPhase = 1;
buyOrderPhase = 1;
currentTrade.begin = candle.begin;
currentTrade.beginRate = candle.close;
return;
}
}
@@ -602,7 +673,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) {
}
}
/* Buy Order Management */
/* Take Profit Management */
if (strategyPhase === 3) {
@@ -647,7 +718,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) {
}
}
/* Check if we need to sell. */
/* Entering into a Trade */
if (strategyPhase === 2) {
@@ -681,7 +752,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) {
continue;
}
/* Check if we need to buy. */
/* Exiting a Trade */
if (strategyPhase === 4) {
@@ -704,9 +775,10 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) {
lastProfitPercent = lastProfit / previousBalanceAssetA * 100;
if (isNaN(lastProfitPercent)) { lastProfitPercent = 0; }
profit = initialBalanceA - balanceAssetA;
profit = balanceAssetA - initialBalanceA;
currentTrade.lastProfitPercent = lastProfitPercent;
currentTrade.stopRate = stopLoss;
ROI = (initialBalanceA + profit) / initialBalanceA - 1;
//if (isNaN(ROI)) { ROI = 0; }
if (lastProfit > 0) {
@@ -714,7 +786,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) {
if (currentDay !== undefined) {
if (sellInstant < currentDay.valueOf()) {
yesterday.Hits++;
yesterday.hits++;
}
}
@@ -723,14 +795,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;
@@ -741,7 +823,6 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) {
strategyPhase = 0;
stopLossPhase = 0;
buyOrderPhase = 0;
continue;
}
@@ -794,7 +875,8 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) {
0,
"")
} else {
}
else {
orderRecord = createMessage(
messageId,
@@ -855,6 +937,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);
@@ -863,6 +947,46 @@ 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 && lastCandle.end !== lastInstantOfTheDay)
) {
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 && lastCandle.end !== lastInstantOfTheDay)
) {
currentTrade.profit = lastProfit;
tradesArray.push(currentTrade);
currentTrade = {
begin: 0,
end: 0,
status: 0,
lastProfitPercent: 0,
exitType: 0,
beginRate: 0,
endRate: 0
}
}
}
}
@@ -873,23 +997,23 @@ 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;
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;
}
}
@@ -916,7 +1040,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);
}
}
@@ -963,7 +1087,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);
}
}
@@ -1002,7 +1126,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);
}
}
@@ -1041,7 +1165,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);
}
}
@@ -1075,7 +1199,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);
}
}
@@ -1110,7 +1234,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);
}
}
@@ -1156,7 +1280,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);
}
}
+175 -9
View File
@@ -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);
@@ -42,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);
}
}
@@ -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,
@@ -187,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);
@@ -200,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);
}
}
@@ -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 = "";
@@ -268,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);
@@ -277,24 +287,180 @@
}
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.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.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; }
fileContent = fileContent + separator + '[' +
record.begin + "," +
record.end + "," +
record.status + "," +
record.lastProfitPercent + "," +
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.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.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 -> writeConditionsFile -> 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 -> writeConditionsFile -> 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);
}
}
+156 -9
View File
@@ -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);
@@ -42,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);
}
}
@@ -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,
@@ -184,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);
@@ -197,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);
}
}
@@ -259,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);
@@ -268,24 +274,165 @@
}
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];
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.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];
fileContent = fileContent + separator + '[' +
record.begin + "," +
record.end + "," +
record.status + "," +
record.lastProfitPercent + "," +
record.beginRate + "," +
record.endRate + "," +
record.exitType + "," +
record.stopRate + "]";
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.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 -> writeConditionsFile -> 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 -> writeConditionsFile -> 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);
}
}
+82 -3
View File
@@ -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,11 +320,11 @@
{
"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": {
"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"
}
}
@@ -341,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"
}
}
]
}