Interval Executor concept added

This commit is contained in:
Luis Fernando Molina committed 2018-02-10 09:43:19 +01:00
1 parent 8673b0ae47
commit 2300f76d46
8 files changed
+1372 -20

No files matched your search

Binary file not shown.
+10 -6
View File
@@ -6,8 +6,8 @@
<ProjectGuid>{045bbaef-3c35-4017-8458-e46aef438790}</ProjectGuid>
<ProjectHome />
<ProjectView>ShowAllFiles</ProjectView>
<StartupFile>One-Min-Daily-Candles\run.js</StartupFile>
<WorkingDirectory>C:\Users\Luis\source\repos\AABruce\One-Min-Daily-Candles\</WorkingDirectory>
<StartupFile>Multi-Period-Daily-Candles-Volumes\run.js</StartupFile>
<WorkingDirectory>C:\Users\Luis\source\repos\AABruce\Multi-Period-Daily-Candles-Volumes\</WorkingDirectory>
<OutputPath>.</OutputPath>
<ProjectTypeGuids>{3AF33F2E-1136-4D97-BBB7-1795711AC8B8};{349c5851-65df-11da-9384-00065b846f21};{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
@@ -23,12 +23,15 @@
<Compile Include="Azure Web Job Shutdown.js" />
<Compile Include="Debug Log.js" />
<Compile Include="Markets.js" />
<Compile Include="One-Min-Daily-Candles\Interval.js" />
<Compile Include="Multi-Period-Daily-Candles-Volumes\Interval.js" />
<Compile Include="Multi-Period-Daily-Candles-Volumes\Interval Executor.js" />
<Compile Include="Multi-Period-Daily-Candles-Volumes\run.js" />
<Compile Include="One-Min-Daily-Candles-Volumes\Interval.js" />
<Compile Include="Poloniex API Client.js" />
<Compile Include="Utilities.js" />
<Content Include="logs\Dummy File.txt" />
<Compile Include="One-Min-Daily-Candles\One Min Daily Candles Volumes.js" />
<Compile Include="One-Min-Daily-Candles\run.js" />
<Compile Include="One-Min-Daily-Candles-Volumes\Interval Executor.js" />
<Compile Include="One-Min-Daily-Candles-Volumes\run.js" />
<Content Include="obj\Debug\AACarol.njsproj.FileListAbsolute.txt" />
<Content Include="obj\Debug\AACharly.njsproj.FileListAbsolute.txt" />
</ItemGroup>
@@ -40,9 +43,10 @@
<Folder Include="logs\AA Masters\Connectivity\Carol" />
<Folder Include="logs\AA Masters\Connectivity\Carol\1.0.0" />
<Folder Include="logs\AA Masters\Connectivity\Carol\1.0.0\Order-Books" />
<Folder Include="Multi-Period-Daily-Candles-Volumes\" />
<Folder Include="obj" />
<Folder Include="obj\Debug" />
<Folder Include="One-Min-Daily-Candles" />
<Folder Include="One-Min-Daily-Candles-Volumes\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.Common.targets" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<!--Do not delete the following Import Project. While this appears to do nothing it is a marker for setting TypeScript properties before our import that depends on them.-->
@@ -1,11 +1,11 @@
exports.newPloniexHoleFixing = function newPloniexHoleFixing(BOT) {
exports.newIntervalExecutor = function newIntervalExecutor(BOT) {
let bot = BOT;
const ROOT_DIR = '../';
const INTERVAL_LAPSE = 10 * 1000;
const MODULE_NAME = "One Min Daily Candles Volumes";
const MODULE_NAME = "Interval Executor";
const LOG_INFO = true;
const INTERVAL_MODULE = require('./Interval');
+97
View File
@@ -0,0 +1,97 @@
let bot = {
name: "Bruce",
process: "Multi-Period-Daily-Candles-Volumes",
type: "Indicator",
version: "1.0.0",
devTeam: "AA Masters"
};
const ROOT_DIR = '../';
const MODULE_NAME = "run";
const START_ALL_MONTHS = false;
const START_ONE_MONTH = true;
const INTERVAL_EXECUTOR_MODULE = require('./Interval Executor');
const DEBUG_MODULE = require(ROOT_DIR + 'Debug Log');
const logger = DEBUG_MODULE.newDebugLog();
logger.fileName = MODULE_NAME;
logger.bot = bot;
process.on('uncaughtException', function (err) {
logger.write('uncaughtException - ' + err.message);
});
process.on('unhandledRejection', (reason, p) => {
logger.write("Unhandled Rejection at: Promise " + JSON.stringify(p) + " reason: " + reason);
});
process.on('exit', function (code) {
logger.write('About to exit with code:' + code);
});
try {
if (START_ALL_MONTHS === true) {
for (let year = 2018; year > 2014; year--) {
for (let month = 12; month > 0; month--) {
let timeDelay = Math.random() * 10 * 1000; // We introduce a short delay so as to not overload the machine.
setTimeout(startProcess, timeDelay);
function startProcess() {
const newIntervalExecutor = INTERVAL_EXECUTOR_MODULE.newIntervalExecutor(bot);
newIntervalExecutor.initialize(year, month, onInitializeReady);
function onInitializeReady() {
newIntervalExecutor.start();
}
}
}
}
}
if (START_ONE_MONTH === true) {
startProcess();
function startProcess() {
const newIntervalExecutor = INTERVAL_EXECUTOR_MODULE.newIntervalExecutor(bot);
let month = 2;
let year = 2018;
newIntervalExecutor.initialize(year, month, onInitializeReady);
function onInitializeReady() {
newIntervalExecutor.start();
}
}
}
} catch (err) {
console.log(err.message);
logger.write(err.message);
}
@@ -0,0 +1,169 @@
exports.newIntervalExecutor = function newIntervalExecutor(BOT) {
let bot = BOT;
const ROOT_DIR = '../';
const INTERVAL_LAPSE = 10 * 1000;
const MODULE_NAME = "Interval Executor";
const LOG_INFO = true;
const INTERVAL_MODULE = require('./Interval');
const DEBUG_MODULE = require(ROOT_DIR + 'Debug Log');
const logger = DEBUG_MODULE.newDebugLog();
logger.fileName = MODULE_NAME;
logger.bot = bot;
const INTERVAL_MAX_LOOPS = -1; // -1 for infinite loop.
poloniexHoleFixing = {
initialize: initialize,
start: start
};
const SHUTDOWN_EVENT = require(ROOT_DIR + 'Azure Web Job Shutdown');
let shutdownEvent = SHUTDOWN_EVENT.newShutdownEvent(bot);
const UTILITIES = require(ROOT_DIR + 'Utilities');
let utilities = UTILITIES.newUtilities(bot);
let year;
let month;
return poloniexHoleFixing;
function initialize(yearAssigend, monthAssigned, callBackFunction) {
try {
year = yearAssigend;
month = monthAssigned;
month = utilities.pad(month, 2); // Adding a left zero when needed.
logger.fileName = MODULE_NAME + "-" + year + "-" + month;
const logText = "[INFO] initialize - Entering function 'initialize' " + " @ " + year + "-" + month;
console.log(logText);
logger.write(logText);
callBackFunction();
} catch (err) {
const logText = "[ERROR] initialize - ' ERROR : " + err.message;
console.log(logText);
logger.write(logText);
}
}
function start() {
try {
if (LOG_INFO === true) {
logger.write("[INFO] Entering function 'start', with year = " + year + " and month = " + month);
}
let intervalId;
if (INTERVAL_MAX_LOOPS === 0) {
intervalId = setInterval(startNewInterval, INTERVAL_LAPSE);
}
let intervalLoopCounter = 0;
startNewInterval(); // First, inmadiate run.
function startNewInterval() {
try {
if (LOG_INFO === true) {
if (INTERVAL_MAX_LOOPS !== 0) {
logger.write("[INFO] Entering function 'startNewInterval', next execution inmediately after the current Interval finishes.");
} else {
logger.write("[INFO] Entering function 'startNewInterval', next execution in " + INTERVAL_LAPSE / 1000 / 60 + " minutes.");
}
}
if (shutdownEvent.isShuttingDown() === false) {
let fileProcessingInterval = INTERVAL_MODULE.newInterval(bot);
fileProcessingInterval.initialize(year, month, onReadyToStart);
function onReadyToStart() {
fileProcessingInterval.start(loopControl);
}
}
else {
clearInterval(intervalId);
const logText = "[INFO] requestNewData - Terminating Set Interval - About to exit gracefully the process. ";
console.log(logText);
logger.write(logText);
}
}
catch (err) {
const logText = "[ERROR] 'startNewInterval' - ERROR : " + err.message;
logger.write(logText);
}
}
function loopControl(moreIntervalExecutionsNeeded) {
if (moreIntervalExecutionsNeeded === true) {
intervalLoopCounter++;
if (intervalLoopCounter === INTERVAL_MAX_LOOPS) {
const logText = "[WARN] 'INTERVAL_MAX_LOOPS' reached. Stopping execution. ";
logger.write(logText);
} else {
const logText = "[WARN] 'loopControl'. Staring new Interval. ";
logger.write(logText);
setTimeout(startNewInterval, INTERVAL_LAPSE);// Looped Execution.
}
} else {
logger.write("[WARN] Received the signal from last Interval execution to not call it anymore. Stopping execution. ");
}
}
}
catch (err) {
const logText = "[ERROR] 'Start' - ERROR : " + err.message;
logger.write(logText);
}
}
};
File diff suppressed because it is too large. Load diff
@@ -4,17 +4,17 @@ let bot = {
process: "One-Min-Daily-Candles-Volumes",
type: "Indicator",
version: "1.0.0",
devTeam: "AA Masters"
devTeam: "AA Masters"
};
const ROOT_DIR = '../';
const MODULE_NAME = "run";
const START_ONE_MIN_DAILY_CANDLES_VOLUMES = false;
const START_ONE_MIN_DAILY_CANDLES_VOLUMES_AT_ONE_MONTH = true;
const START_ALL_MONTHS = false;
const START_ONE_MONTH = true;
const ONE_MIN_DAILY_CANDLES_MODULE = require('./One Min Daily Candles Volumes');
const INTERVAL_EXECUTOR_MODULE = require('./Interval Executor');
const DEBUG_MODULE = require(ROOT_DIR + 'Debug Log');
const logger = DEBUG_MODULE.newDebugLog();
@@ -37,7 +37,7 @@ process.on('exit', function (code) {
try {
if (START_ONE_MIN_DAILY_CANDLES_VOLUMES === true) {
if (START_ALL_MONTHS === true) {
for (let year = 2018; year > 2014; year--) {
@@ -49,13 +49,13 @@ try {
function startProcess() {
const newPloniexHoleFixing = ONE_MIN_DAILY_CANDLES_MODULE.newPloniexHoleFixing(bot);
const newIntervalExecutor = INTERVAL_EXECUTOR_MODULE.newIntervalExecutor(bot);
newPloniexHoleFixing.initialize(year, month, onInitializeReady);
newIntervalExecutor.initialize(year, month, onInitializeReady);
function onInitializeReady() {
newPloniexHoleFixing.start();
newIntervalExecutor.start();
}
@@ -68,22 +68,22 @@ try {
}
if (START_ONE_MIN_DAILY_CANDLES_VOLUMES_AT_ONE_MONTH === true) {
if (START_ONE_MONTH === true) {
startProcess();
function startProcess() {
const newPloniexHoleFixing = ONE_MIN_DAILY_CANDLES_MODULE.newPloniexHoleFixing(bot);
const newIntervalExecutor = INTERVAL_EXECUTOR_MODULE.newIntervalExecutor(bot);
let month = 2;
let year = 2018;
newPloniexHoleFixing.initialize(year, month, onInitializeReady);
newIntervalExecutor.initialize(year, month, onInitializeReady);
function onInitializeReady() {
newPloniexHoleFixing.start();
newIntervalExecutor.start();
}
}