Merge pull request #85 from Superalgos/develop

Push to Production
This commit is contained in:
Barry Low authored and GitHub committed 2019-04-23 09:41:50 -07:00
commit 803cce412d
2 files changed
+38 -30

No files matched your search

+14 -20
View File
@@ -4,7 +4,7 @@
const MODULE_NAME = "Context";
/*
/*
This module deals with keeping the context between different executions of the bot. Conceptually this context is divided in 3 main parts:
@@ -69,7 +69,7 @@
let statusDependencies;
let runIndex; // This is the index for this run and depends on the startMode.
let runIndex; // This is the index for this run and depends on the startMode.
let totalAlgobots;
@@ -156,7 +156,7 @@
/* The context is created in 2 situations: 1) when at the bot config is set not to continue using the same context after a new execution. 2) when the status report does not exist. */
if (bot.hasTheBotJustStarted === true || thisObject.statusReport.runs === undefined) {
if (bot.hasTheBotJustStarted === true || thisObject.statusReport.runs === undefined) {
createConext(callBack);
@@ -164,7 +164,7 @@
runIndex = thisObject.statusReport.runs.length - 1;
getExecutionHistory(callBack);
getExecutionHistory(callBack);
}
@@ -216,7 +216,7 @@
/*
It might happen that the file content is corrupt or it does not exist. The bot can not run without an Execution Hitory,
since it is risky to ignore its own history unless it is its first execution in this mode ever.
since it is risky to ignore its own history unless it is its first execution in this mode ever.
*/
@@ -305,16 +305,16 @@
try {
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> createConext -> Entering function."); }
/*
When the bot is executed for the very first time, there are a few files that do not exist and need to be created, and that
content is what we are going to set up now.
*/
if (thisObject.statusReport.runs === undefined) { // This means that the Status Report does not exist.
thisObject.statusReport.runs = [];
}
}
let runContent = {
beginDatetime: bot.processDatetime,
@@ -326,25 +326,19 @@
runIndex = thisObject.statusReport.runs.length - 1;
thisObject.executionHistory = [];
/*
In the current release, the platform is going to be used for the first competition, so we have a few parameters just for that. They will be removed later
once we advance into multiple competitions scheme.
*/
const INITIAL_INVESTMENT_A = 0; // This is just for this release of the platform.
const INITIAL_INVESTMENT_B = truncDecimals(.001 / totalAlgobots); // This is just for this release of the platform.
const INITIAL_INVESTMENT_A = Number(process.env.INITIAL_BALANCE_ASSET_A);
const INITIAL_INVESTMENT_B = Number(process.env.INITIAL_BALANCE_ASSET_B);
thisObject.executionContext = {
investment: { // This is used to calculate profits.
investment: { // This is used to calculate profits.
assetA: INITIAL_INVESTMENT_A,
assetB: INITIAL_INVESTMENT_B
},
balance: { // This is the total balance that includes positions at the order book + funds available to be traded.
balance: { // This is the total balance that includes positions at the order book + funds available to be traded.
assetA: INITIAL_INVESTMENT_A,
assetB: INITIAL_INVESTMENT_B // It starts with the initial investment.
},
availableBalance: { // This is the balance the bot has at any moment in time available to be traded (not in positions at the order book).
availableBalance: { // This is the balance the bot has at any moment in time available to be traded (not in positions at the order book).
assetA: INITIAL_INVESTMENT_A,
assetB: INITIAL_INVESTMENT_B // It starts with the initial investment.
},
@@ -574,4 +568,4 @@
}
};
};
+24 -10
View File
@@ -114,7 +114,7 @@
/* The starting date is fixed, we will start from there. */
contextVariables.dateBeginOfMarket = new Date(processConfig.framework.startDate.fixedDate);
contextVariables.dateBeginOfMarket = new Date(processConfig.framework.startDate.fixedDate);
} else {
@@ -169,7 +169,7 @@
} else {
/*
Here we get the status report from the bot who knows which is the end of the market.
Here we get the status report from the bot who knows which is the end of the market.
*/
let botWhoKnowsTheEndOfTheMarket = statusDependencies.config[processConfig.framework.endDate.takeItFromStatusDependency];
@@ -232,7 +232,7 @@
if (thisReport.lastFile !== undefined) {
if (bot.hasTheBotJustStarted === true && processConfig.framework.startDate.resumeExecution === "false") {
startFromBegining();
return;
}
@@ -308,7 +308,9 @@
bot.processDatetime = new Date(bot.processDatetime.valueOf() + ONE_DAY_IN_MILISECONDS);
previousDay = new Date(bot.processDatetime.valueOf() - ONE_DAY_IN_MILISECONDS);
logger.newInternalLoop(bot.codeName, bot.process);
if(global.FULL_LOG === 'true'){
logger.newInternalLoop(bot.codeName, bot.process);
}
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> advanceTime -> bot.processDatetime = " + bot.processDatetime); }
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> advanceTime -> previousDay = " + previousDay); }
@@ -340,9 +342,9 @@
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoop -> Entering function."); }
/*
We will iterate through all posible periods.
*/
n = 0 // loop Variable representing each possible period as defined at the periods array.
@@ -364,7 +366,19 @@
const timePeriod = global.dailyFilePeriods[n][0];
const outputPeriodLabel = global.dailyFilePeriods[n][1];
if (processConfig.framework.validPeriods !== undefined) {
let validPeriod = false;
for (let i = 0; i < processConfig.framework.validPeriods.length; i++) {
let period = processConfig.framework.validPeriods[i];
if (period === outputPeriodLabel) { validPeriod = true }
}
if (validPeriod === false) {
periodsControlLoop();
return;
}
}
let dependencyIndex = 0;
dataFiles = [];
@@ -387,7 +401,7 @@
} else {
previousFile = [];
getCurrentFile()
}
}
function getPreviousFile() {
@@ -409,7 +423,7 @@
if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> text = " + text); }
if (err.message === "File does not exist." && botNeverRan === true) {
/*
Sometimes one of the dependencies of an indicator for some reasons are not calculated from the begining of the market.
When that happens we can not find those files. What we do in this situation is to move the time fordward until we can find
@@ -422,7 +436,7 @@
advanceTime();
return;
}
if (err.result === "Fail Because" && err.message === "File does not exist.") {
logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> err = " + err.message);