Dates at Trading Engine Loop

This commit is contained in:
Luis Fernando Molina committed 2019-09-11 22:15:50 +02:00
1 parent 3dd9e954c5
commit e8165368fd
5 files changed
+54 -104

No files matched your search

-10
View File
@@ -372,16 +372,6 @@
}
}
let timePeriodFilter = global.EXECUTION_CONFIG.timePeriodFilter
if (timePeriodFilter !== undefined) {
if (timePeriodFilter.indexOf(outputPeriodLabel) === -1) {
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoopBody -> Discarding period for being filtered out. -> outputPeriodLabel = " + outputPeriodLabel); }
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoopBody -> Discarding period for being filtered out. -> timePeriodFilter = " + timePeriodFilter); }
periodsControlLoop();
return;
}
}
let dependencyIndex = 0;
dataFiles = [];
-8
View File
@@ -143,14 +143,6 @@
let dependencyIndex = 0;
dataFiles = [];
let timePeriodFilter = global.EXECUTION_CONFIG.timePeriodFilter
if (timePeriodFilter !== undefined) {
if (timePeriodFilter.indexOf(outputPeriodLabel) === -1) {
periodsControlLoop();
return;
}
}
dependencyLoopBody();
function dependencyLoopBody() {
+9 -42
View File
@@ -217,19 +217,11 @@
}
}
}
if (processConfig.startMode.live !== undefined) {
if (processConfig.startMode.live.run === "true") {
if (processConfig.startMode.live.beginDatetime !== undefined) {
processConfig.framework.startDate.fixedDate = processConfig.startMode.live.beginDatetime;
processConfig.framework.startDate.resumeExecution = processConfig.startMode.live.resumeExecution;
}
}
}
if (processConfig.startMode.backtest !== undefined) {
if (processConfig.startMode.backtest.run === "true") {
if (processConfig.startMode.backtest.beginDatetime !== undefined) {
processConfig.framework.startDate.fixedDate = processConfig.startMode.backtest.beginDatetime;
processConfig.framework.startDate.resumeExecution = processConfig.startMode.backtest.resumeExecution;
if (processConfig.startMode.userDefined !== undefined) {
if (processConfig.startMode.userDefined.run === "true") {
if (processConfig.startMode.userDefined.beginDatetime !== undefined) {
processConfig.framework.startDate.fixedDate = processConfig.startMode.userDefined.beginDatetime;
processConfig.framework.startDate.resumeExecution = processConfig.startMode.userDefined.resumeExecution;
}
}
}
@@ -377,17 +369,17 @@
}
}
if (processConfig.startMode.live !== undefined) {
if (processConfig.startMode.userDefined !== undefined) {
if (processConfig.startMode.live.run === "true") {
if (processConfig.startMode.userDefined.run === "true") {
botConfig.startMode = "Live";
botConfig.startMode = "User Defined";
console.log(logDisplace + "Root : [INFO] start -> findProcess -> Process found at the bot configuration file. -> Start Mode = " + botConfig.startMode);
let month = pad((new Date()).getUTCMonth() + 1, 2);
let year = (new Date()).getUTCFullYear();
if (processConfig.startMode.live.resumeExecution === true) {
if (processConfig.startMode.userDefined.resumeExecution === true) {
botConfig.hasTheBotJustStarted = false;
} else {
botConfig.hasTheBotJustStarted = true;
@@ -405,31 +397,6 @@
}
}
if (processConfig.startMode.backtest !== undefined) {
if (processConfig.startMode.backtest.run === "true") {
botConfig.startMode = "Backtest";
console.log(logDisplace + "Root : [INFO] start -> findProcess -> Process found at the bot configuration file. -> Start Mode = " + botConfig.startMode);
botConfig.backtest = processConfig.startMode.backtest
/* Backtest Mode does not support Resume Execution, so this is the only way. */
botConfig.hasTheBotJustStarted = true;
switch (botConfig.type) {
case 'Trading-Engine': {
runTradingEngine(botConfig, processConfig);
break;
}
default: {
console.log(logDisplace + "Root : [ERROR] start -> findProcess -> Unexpected bot type. -> botConfig.type = " + botConfig.type);
}
}
}
}
} catch (err) {
console.log(logDisplace + "Root : [ERROR] start -> findProcess -> Unexpected exception. -> err.message = " + err.message);
}
+42 -9
View File
@@ -107,14 +107,47 @@
stopRequestedEventListenerSubscriptionId = global.SYSTEM_EVENT_HANDLER.listenToEvent('Cockpit-Restart-Button', 'Stop Requested', undefined, undefined, undefined, stopRequested)
function startBackTesting() {
/* Reload the definition in case something changed. */
global.DEFINITION = require(process.env.INTER_PROCESS_FILES_PATH + '/Definition');
bot.startMode = "Backtest"
processConfig.framework.startDate.resumeExecution = false;
skipProcessing = false
bot.hasTheBotJustStarted = true
/* We exctact the initial and final date for the backtest from the Definition */
processConfig.framework.startDate.fixedDate = new Date() // If we can not get for any reason the initial date of the backtest, we will start at present time.
if (global.DEFINITION.tradingSystem !== undefined) {
if (global.DEFINITION.tradingSystem.parameters !== undefined) {
if (global.DEFINITION.tradingSystem.parameters.timeRange !== undefined) {
if (global.DEFINITION.tradingSystem.parameters.timeRange.code !== undefined) {
try {
let code = JSON.parse(global.DEFINITION.tradingSystem.parameters.timeRange.code)
if (code.initialDatetime !== undefined) {
processConfig.framework.startDate.fixedDate = code.initialDatetime /* The second override occurs here, with the date explicitelly defined by the user */
}
if (code.finalDatetime !== undefined) {
processConfig.framework.endDate.fixedDate = code.finalDatetime
}
} catch (err) {
global.DEFINITION.tradingSystem.parameters.timeRange.error = err.message
}
}
}
}
}
}
function startLiveTrading() {
/* Reload the definition in case something changed. */
global.DEFINITION = require(process.env.INTER_PROCESS_FILES_PATH + '/Definition');
bot.startMode = "Live"
processConfig.framework.startDate.fixedDate = new Date()
processConfig.framework.startDate.resumeExecution = false;
skipProcessing = false
bot.hasTheBotJustStarted = true
}
function stopRequested() {
@@ -146,15 +179,6 @@
let nextWaitTime;
/* Checking if we should process this loop or not.*/
if (skipProcessing === true) {
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> We are going to skip this Loop bacause we were requested to stop or never asked to start."); }
console.log("[INFO] run -> loop -> We are going to skip this Loop bacause we were requested to stop or never asked to start.")
nextWaitTime = 'Normal';
loopControl(nextWaitTime);
return
}
/* Loop Heartbeat sent to the UI */
hearBeat()
@@ -178,6 +202,15 @@
console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30)
+ " Entered into Main Loop # " + pad(Number(bot.loopCounter), 8));
/* Checking if we should process this loop or not.*/
if (skipProcessing === true) {
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> We are going to skip this Loop bacause we were requested to stop or never asked to start."); }
console.log("[INFO] run -> loop -> We are going to skip this Loop bacause we were requested to stop or never asked to start.")
nextWaitTime = 'Normal';
loopControl(nextWaitTime);
return
}
/* We will prepare first the infraestructure needed for the bot to run. There are 3 modules we need to sucessfullly initialize first. */
let userBot;
+3 -35
View File
@@ -66,7 +66,7 @@ if (global.USER_DEFINITION !== undefined) {
}
else { // I use this section to debug in standalone mode.
let argument = '{"type":"Task","name":"Brings Trades Records from the Exchange","bot":{"type":"Sensor","name":"Charly","processes":[{"type":"Process","name":"Live Trades","code":{"devTeam":"AAMasters","bot":"AACharly","mode":"noTime","resumeExecution":true,"type":"Sensor","exchangeName":"Poloniex","process":"Live-Trades"},"id":"3aae75f5-67ae-4ae5-9586-ec5640f79b18"}]},"id":"54444b07-eee2-4fa8-9183-8fea3b5ff9de"}'
let argument = ' {"type":"Task","name":"Runs Backtests, Fordwardtests & Live Trades ","bot":{"type":"Trading Engine","processes":[{"type":"Process","name":"Multi Period","code":{"devTeam":"AAMasters","bot":"AAJason","mode":"live","resumeExecution":true,"type":"Trading-Engine","exchangeName":"Poloniex","process":"Multi-Period-Daily","beginDatetime":"2019-08-01T08:00:00.000Z","timePeriod":"05-min"},"id":"1bfce24d-8c05-4be9-bd25-328f07c85265"}]},"id":"cbb13086-608d-4bb4-960a-17a81038877b"}'
try {
global.USER_DEFINITION = JSON.parse(argument)
} catch (err) {
@@ -186,7 +186,6 @@ function startSequence() {
process.env.STOP_GRACEFULLY = false;
execution.devTeam ? process.env.DEV_TEAM = execution.devTeam : undefined;
execution.bot ? process.env.BOT = execution.bot : undefined;
execution.mode ? process.env.START_MODE = execution.mode : undefined;
execution.resumeExecution = true;
execution.type ? process.env.TYPE = execution.type : undefined;
execution.process ? process.env.PROCESS = execution.process : undefined;
@@ -234,10 +233,6 @@ async function readExecutionConfiguration(execution, processIndex) {
let timePeriodFilter
let botProcess
/* 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 finalDatetime = process.env.END_DATE_TIME
if (execution.type === 'Trading-Engine') {
/* The Trading Engine only resumes its execution after the first sequence was completed. */
@@ -245,18 +240,9 @@ async function readExecutionConfiguration(execution, processIndex) {
execution.resumeExecution = false
}
/* We set the START MODE of the Trading Engine */
if (process.env.KEY === undefined || process.env.SECRET === undefined) {
process.env.START_MODE = "backtest" // if we dont have keys, we swtich to backtest mode to avoid exchange errors.
} else {
process.env.START_MODE = "live" // If we have keys, then we are in live mode.
}
if (global.DEFINITION !== undefined) {
if (global.DEFINITION.simulationParams !== undefined) {
if (global.DEFINITION.simulationParams.beginDatetime !== undefined) {
initialDatetime = new Date(global.DEFINITION.simulationParams.beginDatetime) /* The first override occurs here, with the simulation parameters */
}
/* Here we only look for one timePeriod, in the future we will be able to process the whole array, but not for now. */
if (global.DEFINITION.simulationParams.timePeriodDailyArray !== undefined) {
if (global.DEFINITION.simulationParams.timePeriodDailyArray.length === 1) {
@@ -271,25 +257,7 @@ async function readExecutionConfiguration(execution, processIndex) {
}
}
}
if (global.DEFINITION.tradingSystem !== undefined) {
if (global.DEFINITION.tradingSystem.parameters !== undefined) {
if (global.DEFINITION.tradingSystem.parameters.timeRange !== undefined) {
if (global.DEFINITION.tradingSystem.parameters.timeRange.code !== undefined) {
try {
let code = JSON.parse(global.DEFINITION.tradingSystem.parameters.timeRange.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
}
} catch (err) {
global.DEFINITION.tradingSystem.parameters.timeRange.error = err.message
}
}
}
}
}
/* Get the initial balance from the global.DEFINITION */
let tradingSystem = global.DEFINITION.tradingSystem