Adding baseline processes
This commit is contained in:
1 parent
b802dd0202
commit
eb34634905
2 files changed
+67
-47
No files matched your search
@@ -104,7 +104,7 @@ LRCIndicator.prototype.calculate = function (price) {
|
||||
}
|
||||
|
||||
exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, BLOB_STORAGE, FILE_STORAGE) {
|
||||
const FULL_LOG = true;
|
||||
const FULL_LOG = false;
|
||||
const LOG_FILE_CONTENT = false;
|
||||
const USE_PARTIAL_LAST_CANDLE = true; // When running live the last candle generated is a partial candle.
|
||||
|
||||
@@ -194,8 +194,8 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, BLOB_S
|
||||
let reportFilePath = EXCHANGE_NAME + "/Processes/" + bot.process;
|
||||
let executionTime;
|
||||
let lastCandles;
|
||||
let dailyFileCache = {};
|
||||
let lrcPointsFileCache = {};
|
||||
let dailyFileCache = new Map();
|
||||
let lrcPointsFileCache = new Map();
|
||||
|
||||
getContextVariables();
|
||||
|
||||
@@ -254,7 +254,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, BLOB_S
|
||||
lastCandles.push(0);
|
||||
}
|
||||
|
||||
lastCandles[10] = new Date(Date.UTC(2018, 5)).valueOf();
|
||||
lastCandles[10] = new Date(Date.UTC(2015, 1, 20)).valueOf();
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> Starting at: " + new Date(lastCandles[10]).toISOString()); }
|
||||
|
||||
@@ -304,11 +304,12 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, BLOB_S
|
||||
let candleBeginIndex = 4;
|
||||
let lastDayIndex = 10 + '/' + executionTime.getUTCFullYear() + "/" + utilities.pad(executionTime.getUTCMonth() + 1, 2) + "/" + utilities.pad(executionTime.getUTCDate(), 2);
|
||||
|
||||
if (dailyFileCache[lastDayIndex] === undefined) {
|
||||
if (!dailyFileCache.has(lastDayIndex)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let lastCandlePeriodOnCache = dailyFileCache[lastDayIndex][dailyFileCache[lastDayIndex].length - 1][candleBeginIndex];
|
||||
let currentFile = dailyFileCache.get(lastDayIndex);
|
||||
let lastCandlePeriodOnCache = currentFile[currentFile.length - 1][candleBeginIndex];
|
||||
|
||||
return (executionTime.valueOf() >= lastCandlePeriodOnCache.valueOf());
|
||||
}
|
||||
@@ -398,7 +399,11 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, BLOB_S
|
||||
backwardsCount++;
|
||||
} else {
|
||||
logger.write(MODULE_NAME, "[WARN] start -> getLRCPoints -> Not enough history to calculate LRC. Moving to Next Period.");
|
||||
// Move to the next period without writing report
|
||||
|
||||
// If the control candle is not ready, advance the execution.
|
||||
if (n === 10) {
|
||||
lastCandles[10] += ONE_MIN_IN_MILISECONDS;
|
||||
}
|
||||
setTimeout(function () { controlLoop(); }, 0);
|
||||
}
|
||||
}
|
||||
@@ -417,10 +422,10 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, BLOB_S
|
||||
let datePath = dateTime.getUTCFullYear() + "/" + utilities.pad(dateTime.getUTCMonth() + 1, 2) + "/" + utilities.pad(dateTime.getUTCDate(), 2);
|
||||
let cachePosition = n + '/' + datePath;
|
||||
|
||||
if (dailyFileCache[cachePosition] !== undefined) {
|
||||
if (dailyFileCache.has(cachePosition)) {
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getLRCPoints -> getDailyFile -> Getting the file from local cache."); }
|
||||
|
||||
let cache = dailyFileCache[cachePosition];
|
||||
let cache = dailyFileCache.get(cachePosition);
|
||||
onDailyFileReceived(global.DEFAULT_OK_RESPONSE, cache);
|
||||
|
||||
} else {
|
||||
@@ -436,11 +441,16 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, BLOB_S
|
||||
|
||||
let candleFile = JSON.parse(text);
|
||||
|
||||
dailyFileCache[cachePosition] = candleFile;
|
||||
dailyFileCache.set(cachePosition, candleFile);
|
||||
onDailyFileReceived(global.DEFAULT_OK_RESPONSE, candleFile);
|
||||
} else {
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> getLRCPoints -> getDailyFile -> onFileReceived -> Failed to get the file. Will abort the process and request a retry.");
|
||||
callBackFunction(global.DEFAULT_RETRY_RESPONSE);
|
||||
logger.write(MODULE_NAME, "[WARN] start -> getLRCPoints -> getDailyFile -> onFileReceived -> Failed to get the file. Dependency not ready.");
|
||||
|
||||
// If the control candle is not ready, advance the execution.
|
||||
if (n === 10) {
|
||||
lastCandles[10] += ONE_MIN_IN_MILISECONDS;
|
||||
}
|
||||
setTimeout(function () { controlLoop(); }, 0);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
@@ -534,11 +544,11 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, BLOB_S
|
||||
|
||||
let cachePosition = n + '/' + datePath;
|
||||
|
||||
if (lrcPointsFileCache[cachePosition] === undefined) {
|
||||
lrcPointsFileCache[cachePosition] = [];
|
||||
if (!lrcPointsFileCache.has(cachePosition)) {
|
||||
lrcPointsFileCache.set(cachePosition, []);
|
||||
}
|
||||
|
||||
lrcPointsFileCache[cachePosition].push(lrcPoint);
|
||||
lrcPointsFileCache.get(cachePosition).push(lrcPoint);
|
||||
|
||||
lastCandles[n] = lrcPoint[0];
|
||||
|
||||
@@ -581,7 +591,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, BLOB_S
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> savePoint -> createFile -> Entering function."); }
|
||||
|
||||
let fileContent = JSON.stringify(lrcPointsFileCache[cachePosition]);
|
||||
let fileContent = JSON.stringify(lrcPointsFileCache.get(cachePosition));
|
||||
|
||||
gaussStorage.createTextFile(filePath, fileName, fileContent, onFileCreated);
|
||||
|
||||
@@ -629,10 +639,10 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, BLOB_S
|
||||
|
||||
function appendLRCPoints(existingLRCPoints) {
|
||||
if (existingLRCPoints === undefined)
|
||||
return lrcPointsFileCache[cachePosition];
|
||||
return lrcPointsFileCache.get(cachePosition);
|
||||
|
||||
for (i = 0; i < lrcPointsFileCache[cachePosition].length; i++) {
|
||||
let lrcPoint = lrcPointsFileCache[cachePosition][i];
|
||||
for (i = 0; i < lrcPointsFileCache.get(cachePosition).length; i++) {
|
||||
let lrcPoint = lrcPointsFileCache.get(cachePosition)[i];
|
||||
let lastCandleOnFile = existingLRCPoints[existingLRCPoints.length - 1];
|
||||
|
||||
if (lastCandleOnFile[0] < lrcPoint[0]) {
|
||||
@@ -657,8 +667,8 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, BLOB_S
|
||||
let cachePosition = n + '/' + datePath;
|
||||
|
||||
// Remove and go back one day
|
||||
if (fileCache[cachePosition] !== undefined) {
|
||||
fileCache[cachePosition] = undefined;
|
||||
if (fileCache.has(cachePosition)) {
|
||||
fileCache.delete(cachePosition);
|
||||
date.setDate(date.getDate() - 1);
|
||||
cleanUpCache(fileCache, date);
|
||||
}
|
||||
@@ -675,11 +685,11 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, BLOB_S
|
||||
let candleBeginIndex = 4;
|
||||
let lastDayIndex = n + '/' + executionTime.getUTCFullYear() + "/" + utilities.pad(executionTime.getUTCMonth() + 1, 2) + "/" + utilities.pad(executionTime.getUTCDate(), 2);
|
||||
|
||||
if (dailyFileCache[lastDayIndex] === undefined) {
|
||||
if (!dailyFileCache.has(lastDayIndex)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let lastCandlePeriodOnCache = dailyFileCache[lastDayIndex][dailyFileCache[lastDayIndex].length - 1][candleBeginIndex];
|
||||
let currentFile = dailyFileCache.get(lastDayIndex);
|
||||
let lastCandlePeriodOnCache = currentFile[currentFile.length - 1][candleBeginIndex];
|
||||
|
||||
if (FULL_LOG === true) {
|
||||
logger.write(MODULE_NAME, "[INFO] start -> buildLRCPoints -> savePoint -> Execution: " + new Date(timeToValidate).toISOString() + ". lastCandlePeriodOnCache: " + new Date(lastCandlePeriodOnCache).toISOString() + ". lastDayIndex: " + lastDayIndex);
|
||||
@@ -739,7 +749,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, BLOB_S
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeDataRange -> Entering function."); }
|
||||
|
||||
let dataRange = {
|
||||
begin: 1522540800000,//TODO: 1424373300000,
|
||||
begin: 1424373300000,
|
||||
end: lastOneMinuteCandle.valueOf()
|
||||
};
|
||||
|
||||
|
||||
@@ -193,8 +193,8 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, BLOB_S
|
||||
let reportFilePath = EXCHANGE_NAME + "/Processes/" + bot.process;
|
||||
let executionTime;
|
||||
let lastCandles;
|
||||
let marketFileCache = {};
|
||||
let lrcPointsFileCache = {};
|
||||
let marketFileCache = new Map();
|
||||
let lrcPointsFileCache = new Map();
|
||||
|
||||
getContextVariables();
|
||||
|
||||
@@ -253,7 +253,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, BLOB_S
|
||||
lastCandles.push(0);
|
||||
}
|
||||
|
||||
lastCandles[7] = new Date(Date.UTC(2018, 5)).valueOf();
|
||||
lastCandles[7] = new Date(Date.UTC(2015, 1, 20)).valueOf();
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> Starting at: " + new Date(lastCandles[7]).toISOString()); }
|
||||
|
||||
@@ -275,7 +275,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, BLOB_S
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> buildLRCPoints -> Entering function."); }
|
||||
|
||||
let writeReport = false;
|
||||
let writeReport = false;
|
||||
|
||||
advanceTime();
|
||||
|
||||
@@ -301,11 +301,12 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, BLOB_S
|
||||
|
||||
function isExecutionOnHeadOfMarket() {
|
||||
let candleBeginIndex = 4;
|
||||
if (marketFileCache[7] === undefined) {
|
||||
if (!marketFileCache.has(7)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let lastCandlePeriodOnCache = marketFileCache[7][marketFileCache[7].length - 1][candleBeginIndex];
|
||||
let currentFile = marketFileCache.get(7);
|
||||
let lastCandlePeriodOnCache = currentFile[currentFile.length - 1][candleBeginIndex];
|
||||
|
||||
return (executionTime.valueOf() >= lastCandlePeriodOnCache.valueOf());
|
||||
}
|
||||
@@ -388,7 +389,11 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, BLOB_S
|
||||
|
||||
} else {
|
||||
logger.write(MODULE_NAME, "[WARN] start -> getLRCPoints -> Not enough history to calculate LRC. Moving to Next Period.");
|
||||
// Move to the next period without writing report
|
||||
|
||||
// If the control candle is not ready, advance the execution.
|
||||
if (n === 7) {
|
||||
lastCandles[7] += ONE_HOUR_IN_MILISECONDS;
|
||||
}
|
||||
setTimeout(function () { controlLoop(); }, 0);
|
||||
}
|
||||
}
|
||||
@@ -404,10 +409,10 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, BLOB_S
|
||||
*
|
||||
*/
|
||||
|
||||
if (marketFileCache[n] !== undefined) {
|
||||
if (marketFileCache.has(n)) {
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getLRCPoints -> getMarketFile -> Getting the file from local cache."); }
|
||||
|
||||
onMarketFileReceived(global.DEFAULT_OK_RESPONSE, marketFileCache[n]);
|
||||
onMarketFileReceived(global.DEFAULT_OK_RESPONSE, marketFileCache.get(7));
|
||||
} else {
|
||||
let filePath = "AAMasters/AAOlivia.1.0/AACloud.1.1/Poloniex/dataSet.V1/Output/Candles/Multi-Period-Market/" + folderName;
|
||||
let fileName = market.assetA + '_' + market.assetB + ".json"
|
||||
@@ -420,11 +425,16 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, BLOB_S
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getLRCPoints -> getMarketFile -> onFileReceived > Entering Function."); }
|
||||
|
||||
let candleFile = JSON.parse(text);
|
||||
marketFileCache[n] = candleFile; // We keep a copy of the results for local use
|
||||
marketFileCache.set(n, candleFile); // We keep a copy of the results for local use
|
||||
onMarketFileReceived(global.DEFAULT_OK_RESPONSE, candleFile);
|
||||
} else {
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> getLRCPoints -> getMarketFile -> onFileReceived -> Failed to get the file. Will abort the process and request a retry.");
|
||||
callBackFunction(global.DEFAULT_RETRY_RESPONSE);
|
||||
logger.write(MODULE_NAME, "[WARN] start -> getLRCPoints -> getMarketFile -> onFileReceived -> Failed to get the file. Dependency not ready.");
|
||||
|
||||
// if the dependency is not ready advance the control candle one period.
|
||||
if (n === 7) {
|
||||
lastCandles[7] += ONE_HOUR_IN_MILISECONDS;
|
||||
}
|
||||
setTimeout(function () { controlLoop(); }, 0);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
@@ -510,11 +520,11 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, BLOB_S
|
||||
let filePath = bot.filePathRoot + "/Output/LRC-Points/Multi-Period-Market/" + folderName;
|
||||
let fileName = market.assetA + '_' + market.assetB + ".json"
|
||||
|
||||
if (lrcPointsFileCache[n] === undefined) {
|
||||
lrcPointsFileCache[n] = [];
|
||||
if (!lrcPointsFileCache.has(n)) {
|
||||
lrcPointsFileCache.set(n, []);
|
||||
}
|
||||
|
||||
lrcPointsFileCache[n].push(lrcPoint);
|
||||
lrcPointsFileCache.get(n).push(lrcPoint);
|
||||
|
||||
lastCandles[n] = lrcPoint[0];
|
||||
|
||||
@@ -557,7 +567,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, BLOB_S
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> savePoint -> createFile -> Entering function."); }
|
||||
|
||||
let fileContent = JSON.stringify(lrcPointsFileCache[n]);
|
||||
let fileContent = JSON.stringify(lrcPointsFileCache.get(n));
|
||||
|
||||
gaussStorage.createTextFile(filePath, fileName, fileContent, onFileCreated);
|
||||
|
||||
@@ -607,10 +617,10 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, BLOB_S
|
||||
|
||||
function appendLRCPoints(existingLRCPoints) {
|
||||
if (existingLRCPoints === undefined)
|
||||
return lrcPointsFileCache[n];
|
||||
return lrcPointsFileCache.get(n);
|
||||
|
||||
for (i = 0; i < lrcPointsFileCache[n].length; i++) {
|
||||
let lrcPoint = lrcPointsFileCache[n][i];
|
||||
for (i = 0; i < lrcPointsFileCache.get(n).length; i++) {
|
||||
let lrcPoint = lrcPointsFileCache.get(n)[i];
|
||||
let lastCandleOnFile = existingLRCPoints[existingLRCPoints.length - 1];
|
||||
|
||||
if (lastCandleOnFile[0] < lrcPoint[0]) {
|
||||
@@ -632,11 +642,11 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, BLOB_S
|
||||
function isPeriodOnHeadOfMarket(timeToValidate) {
|
||||
let candleBeginIndex = 4
|
||||
|
||||
if (marketFileCache[n] === undefined) {
|
||||
if (!marketFileCache.has(n)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let lastCandlePeriodOnCache = marketFileCache[n][marketFileCache[n].length - 1][candleBeginIndex];
|
||||
let currentFile = marketFileCache.get(n);
|
||||
let lastCandlePeriodOnCache = currentFile[currentFile.length - 1][candleBeginIndex];
|
||||
|
||||
if (FULL_LOG === true) {
|
||||
logger.write(MODULE_NAME, "[INFO] start -> buildLRCPoints -> savePoint -> Execution: " + new Date(timeToValidate).toISOString() + ". lastCandlePeriodOnCache: " + new Date(lastCandlePeriodOnCache).toISOString());
|
||||
|
||||
Reference in new issue
Block a user