Mechanics to Resent Begining of Market date implemented

This commit is contained in:
Luis Fernando Molina committed 2020-02-08 14:34:33 +01:00
1 parent 0c71439e38
commit 9e49479e87
1 file changed
+24 -18
+24 -18
View File
@@ -17,7 +17,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt
let statusDependencies
const ONE_MINUTE = 60000
const MAX_TRADES_PER_EXECUTION = 10000
const MAX_TRADES_PER_EXECUTION = 100000
const symbol = bot.market.baseAsset + '/' + bot.market.quotedAsset
const ccxt = require('ccxt')
@@ -33,6 +33,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt
let lastId
let firstId
let exchange
let uiStartDate = new Date(bot.uiStartDate)
const limit = 1000
@@ -110,8 +111,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt
async function begin() {
getContextVariables()
defineSince()
await getFirstId()
await getTrades()
if (global.STOP_TASK_GRACEFULLY === true) {
@@ -144,6 +144,25 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt
} else { // This means this is the first time this process run.
beginingOfMarket = new Date()
}
defineSince()
function defineSince() {
if (thisReport.file.uiStartDate === undefined) {
thisReport.file.uiStartDate = uiStartDate
} else {
thisReport.file.uiStartDate = new Date(thisReport.file.uiStartDate)
}
if (uiStartDate.valueOf() !== thisReport.file.uiStartDate.valueOf()) {
since = uiStartDate.valueOf()
initialProcessTimestamp = since
beginingOfMarket = new Date(uiStartDate.valueOf())
} else {
since = lastFileSaved.valueOf()
initialProcessTimestamp = lastFileSaved.valueOf()
}
}
} catch (err) {
logger.write(MODULE_NAME, "[ERROR] start -> getContextVariables -> err = " + err.stack);
if (err.message === "Cannot read property 'file' of undefined") {
@@ -154,20 +173,6 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt
}
}
function defineSince() {
let uiStartDate = new Date(bot.uiStartDate)
if (uiStartDate.valueOf() < beginingOfMarket.valueOf()) {
since = (new Date(bot.uiStartDate)).valueOf()
initialProcessTimestamp = since
beginingOfMarket = new Date(uiStartDate.valueOf())
} else {
since = lastFileSaved.valueOf()
initialProcessTimestamp = lastFileSaved.valueOf()
}
}
async function getFirstId() {
try {
/* We need the first id only when we are going to fetch trades based on id and it is the first time the process runs*/
@@ -446,7 +451,8 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt
days: beginingOfMarket.getUTCDate(),
hours: beginingOfMarket.getUTCHours(),
minutes: beginingOfMarket.getUTCMinutes()
}
},
uiStartDate: uiStartDate.toUTCString()
};
if (fetchType === "by Id") {