Merge pull request #433 from Superalgos/develop

Hot Fix to fix bug with Exchange Raw data during Live Trading
This commit is contained in:
Luis Fernando Molina authored and GitHub committed 2021-01-21 14:15:13 +01:00
commit e91610dc34
13 files changed
+642 -168

No files matched your search

+103 -21
View File
@@ -590,21 +590,49 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
switch (requestParameters[2]) { // switch by command
case 'Contribute': {
try {
const commitMessage = unescape(requestParameters[3])
let commitMessage = unescape(requestParameters[3])
const username = unescape(requestParameters[4])
const token = unescape(requestParameters[5])
const currentBranch = unescape(requestParameters[6])
const contributionsBranch = unescape(requestParameters[7])
let error
/* Unsavping # */
for (let i = 0; i < 10; i++) {
commitMessage = commitMessage.replace('HASHTAG', '#')
}
contribute()
async function contribute() {
if (await doGit() === false) {
respondWithContent(JSON.stringify(global.DEFAULT_FAIL_RESPONSE), httpResponse)
await doGit()
if (error !== undefined) {
let docs = {
project: 'Superalgos',
category: 'Topic',
type: 'App Error - Contribution Not Sent',
anchor: undefined,
placeholder: {}
}
respondWithDocsObject(docs, error)
return
}
if (await doGithub() === false) {
respondWithContent(JSON.stringify(global.DEFAULT_FAIL_RESPONSE), httpResponse)
await doGithub()
if (error !== undefined) {
let docs = {
project: 'Superalgos',
category: 'Topic',
type: 'App Error - Contribution Not Sent',
anchor: undefined,
placeholder: {}
}
console.log('respond with docs ')
respondWithDocsObject(docs, error)
return
}
respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse)
@@ -623,14 +651,13 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
await git.add('./*')
await git.commit(commitMessage)
await git.push('origin', currentBranch)
return true
} catch (err) {
console.log('[ERROR] httpInterface -> App -> Contribute -> doGit -> Method call produced an error.')
console.log('[ERROR] httpInterface -> App -> Contribute -> doGit -> err.stack = ' + err.stack)
console.log('[ERROR] httpInterface -> App -> Contribute -> doGit -> commitMessage = ' + commitMessage)
console.log('[ERROR] httpInterface -> App -> Contribute -> doGit -> currentBranch = ' + currentBranch)
console.log('[ERROR] httpInterface -> App -> Contribute -> doGit -> contributionsBranch = ' + contributionsBranch)
return false
error = err
}
}
@@ -657,20 +684,19 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
head,
base,
});
return true
} catch (err) {
if (err.stack.indexOf('A pull request already exists') >= 0) {
return true
return
} else {
console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> Method call produced an error.')
console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> err.stack = ' + err.stack)
console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> commitMessage = ' + commitMessage)
console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> username = ' + username)
console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> token starts with = ' + token.substring(0, 10) + '...')
console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> token starts with = ' + token.substring(0, 10) + '...')
console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> token ends with = ' + '...' + token.substring(token.length - 10))
console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> currentBranch = ' + currentBranch)
console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> contributionsBranch = ' + contributionsBranch)
return false
error = err
}
}
}
@@ -693,22 +719,33 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
}
break
}
case 'Update': {
try {
const currentBranch = unescape(requestParameters[3])
update()
async function update() {
let message = await doGit()
let result = await doGit()
if (message !== undefined) {
if (result.error === undefined) {
let customResponse = {
result: global.CUSTOM_OK_RESPONSE.result,
message: message
message: result.message
}
respondWithContent(JSON.stringify(customResponse), httpResponse)
} else {
respondWithContent(JSON.stringify(global.DEFAULT_FAIL_RESPONSE), httpResponse)
let docs = {
project: 'Superalgos',
category: 'Topic',
type: 'App Error - Update Failed',
anchor: undefined,
placeholder: {}
}
respondWithDocsObject(docs, result.error)
}
}
@@ -724,10 +761,11 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
let message
try {
message = await git.pull('https://github.com/Superalgos/Superalgos', currentBranch)
return message
return { message: message }
} catch (err) {
console.log('[ERROR] Error updating ' + currentBranch)
console.log(err.stack)
return { error: err }
}
}
@@ -751,15 +789,25 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
case 'Checkout': {
try {
const currentBranch = unescape(requestParameters[3])
let error
checkout()
async function checkout() {
let result = await doGit()
await doGit()
if (result === true) {
if (error === undefined) {
respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse)
} else {
respondWithContent(JSON.stringify(global.DEFAULT_FAIL_RESPONSE), httpResponse)
let docs = {
project: 'Superalgos',
category: 'Topic',
type: 'Switching Branches - Current Branch Not Changed',
anchor: undefined,
placeholder: {}
}
respondWithDocsObject(docs, error)
}
}
@@ -776,9 +824,8 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
} catch (err) {
console.log('[ERROR] Error changing current branch to ' + currentBranch)
console.log(err.stack)
return false
error = err
}
return true
}
} catch (err) {
@@ -798,6 +845,41 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
break
}
}
function respondWithDocsObject(docs, error) {
if (error.message !== undefined) {
docs.placeholder.errorMessage = {
style: 'Error',
text: error.message
}
}
if (error.stack !== undefined) {
docs.placeholder.errorStack = {
style: 'Javascript',
text: error.stack
}
}
if (error.code !== undefined) {
docs.placeholder.errorCode = {
style: 'Json',
text: error.code
}
}
docs.placeholder.errorDetails = {
style: 'Json',
text: JSON.stringify(error, undefined, 4)
}
let customResponse = {
result: global.CUSTOM_FAIL_RESPONSE.result,
docs: docs
}
respondWithContent(JSON.stringify(customResponse), httpResponse)
}
}
break
@@ -9,8 +9,77 @@
"paragraphs": [
{
"style": "Text",
"text": "Check for the Client's console for details on what may have happened. After you fix the issue that prevented the App Contribute Command to run, you may try again.",
"updated": 1611129009743
"text": "Check the following section for details on what may have happened. After you fix the issue that prevented the App Contribute Command to run, you may try again.",
"updated": 1611152997869
},
{
"style": "Title",
"text": "Error Info",
"updated": 1611154606702
},
{
"style": "Text",
"text": "In the following section you will find the specific information received when this error occured."
},
{
"style": "Note",
"text": "You will only see it if you opened this page as a result of the error actually happening.",
"updated": 1611153032408
},
{
"style": "Subtitle",
"text": "Error Message"
},
{
"style": "Text",
"text": "The following is the Error Message of the Exception that occured at the Client:"
},
{
"style": "Placeholder",
"text": "errorMessage"
},
{
"style": "Subtitle",
"text": "Error Stack"
},
{
"style": "Text",
"text": "The following is the Error Stack of the Exception that occured at the Client:"
},
{
"style": "Placeholder",
"text": "errorStack"
},
{
"style": "Subtitle",
"text": "Error Code"
},
{
"style": "Text",
"text": "The follwing is the Error Code of the Exception that occured at the Client:"
},
{
"style": "Placeholder",
"text": "errorCode"
},
{
"style": "Subtitle",
"text": "Error Details",
"updated": 1611154543778
},
{
"style": "Text",
"text": "The follwing are all the Error details of the Exception that occured at the Client:",
"updated": 1611154675224
},
{
"style": "Placeholder",
"text": "errorDetails",
"updated": 1611154555419
},
{
"style": "Text",
"text": ""
}
]
}
@@ -9,8 +9,77 @@
"paragraphs": [
{
"style": "Success",
"text": "Check for the Client's console for details on what may have happened. After you fix the issue, you may try again.",
"updated": 1611129360143
"text": "Check for the following section for details on what may have happened. After you fix the issue, you may try again.",
"updated": 1611152967185
},
{
"style": "Title",
"text": "Error Info",
"updated": 1611154641024
},
{
"style": "Text",
"text": "In the following section you will find the specific information received when this error occured."
},
{
"style": "Note",
"text": "You will only see it if you opened this page as a result of the error actually happening.",
"updated": 1611151375974
},
{
"style": "Subtitle",
"text": "Error Message"
},
{
"style": "Text",
"text": "The following is the Error Message of the Exception that occured at the Client:",
"updated": 1611151299633
},
{
"style": "Placeholder",
"text": "errorMessage"
},
{
"style": "Subtitle",
"text": "Error Stack"
},
{
"style": "Text",
"text": "The following is the Error Stack of the Exception that occured at the Client:",
"updated": 1611151427220
},
{
"style": "Placeholder",
"text": "errorStack"
},
{
"style": "Subtitle",
"text": "Error Code"
},
{
"style": "Text",
"text": "The follwing is the Error Code of the Exception that occured at the Client:",
"updated": 1611151443562
},
{
"style": "Placeholder",
"text": "errorCode"
},
{
"style": "Subtitle",
"text": "Error Details"
},
{
"style": "Text",
"text": "The follwing are all the Error details of the Exception that occured at the Client:"
},
{
"style": "Placeholder",
"text": "errorDetails"
},
{
"style": "Text",
"text": ""
}
]
}
@@ -9,8 +9,12 @@
"paragraphs": [
{
"style": "Success",
"text": "You now have the latest version of Superalgos. Just remeber to restart the Client and the UI.",
"updated": 1610454408134
"text": "You now have the latest version of Superalgos. Just remeber to restart the Client and the UI. If you have Tasks running, you should first stop the tasks, and then restart the Client, so that you can run those task again using the updated codebase.",
"updated": 1611160648343
},
{
"style": "Note",
"text": "The update you made, only afffects the Client which you are connected to via http using your browser. If you have more Clients running as part of a Network, you will need to update them too, etither manually using Git or by navigating with your browser to their URL and doing running the App Update Command there."
}
]
}
@@ -7,10 +7,75 @@
"updated": 1610543788194
},
"paragraphs": [
{
"style": "Text",
"text": "More detailed info of what caused this failure to switch can be found below.",
"updated": 1611155878425
},
{
"style": "Title",
"text": "Error Info"
},
{
"style": "Text",
"text": "In the following section you will find the specific information received when this error occured."
},
{
"style": "Note",
"text": "More detailed info of what caused this failure to switch can be find at the Client's Console.",
"updated": 1610543823314
"text": "You will only see it if you opened this page as a result of the error actually happening.",
"updated": 1611155956953
},
{
"style": "Subtitle",
"text": "Error Message"
},
{
"style": "Text",
"text": "The following is the Error Message of the Exception that occured at the Client:"
},
{
"style": "Placeholder",
"text": "errorMessage"
},
{
"style": "Subtitle",
"text": "Error Stack"
},
{
"style": "Text",
"text": "The following is the Error Stack of the Exception that occured at the Client:"
},
{
"style": "Placeholder",
"text": "errorStack"
},
{
"style": "Subtitle",
"text": "Error Code"
},
{
"style": "Text",
"text": "The follwing is the Error Code of the Exception that occured at the Client:"
},
{
"style": "Placeholder",
"text": "errorCode"
},
{
"style": "Subtitle",
"text": "Error Details"
},
{
"style": "Text",
"text": "The follwing are all the Error details of the Exception that occured at the Client:"
},
{
"style": "Placeholder",
"text": "errorDetails"
},
{
"style": "Text",
"text": ""
}
]
}
@@ -3,25 +3,60 @@
"pageNumber": "4",
"type": "Docs In Italian",
"definition": {
"text": "The Docs articles are fully written in English. The system allow users to search / browse articles in other languages as well, as long as other users contribute translations."
"text": "The Docs articles are fully written in English. The system allow users to search / browse articles in other languages as well, as long as other users contribute translations.",
"translations": [
{
"language": "IT",
"text": "La guida di Superalgos è scritta interamente in inglese ma anche tu puoi aiutare a tradurre nella tua lingua preferita. Il sistema attualmente consente agli utenti di cercare o sfogliare la guida anche in altre lingue purché altri utenti contribuiscano alle traduzioni.",
"updated": 1610794887971
}
]
},
"paragraphs": [
{
"style": "Text",
"text": "Superalgos and any other integrated project are written in English, since English is considered the default language. Node types, variable names, etc., all is originally in English language. "
"text": "Superalgos and any other integrated project are written in English, since English is considered the default language. Node types, variable names, etc., all is originally in English language. ",
"translations": [
{
"language": "IT",
"text": "Superalgos e gli altri progetti integrati sono scritti in inglese perchè considerata la lingua predefinita. Tipi di nodi, nomi di variabili, ecc., Tutto è originariamente in lingua inglese.",
"updated": 1610806159263
}
]
},
{
"style": "Text",
"text": "The Docs content can be translated by anyone willing to contribute some time doing so. That helps users to read the contents of the Docs in their native language. "
"text": "The Docs content can be translated by anyone willing to contribute some time doing so. That helps users to read the contents of the Docs in their native language. ",
"translations": [
{
"language": "IT",
"text": "Il contenuto della guida può essere tradotto da chiunque desideri contribuire! Così facendo aiuterai gli utenti a leggere i contenuti della guida nella loro lingua madre e tu potrai dare il tuo contributo.",
"updated": 1610806232380
}
]
},
{
"style": "Success",
"text": " Users can switch between languages using the links provided at the footer of every page at the Docs. ",
"updated": 1609085068937
"updated": 1609085068937,
"translations": [
{
"language": "IT",
"text": "Gli utenti possono passare da una lingua all'altra utilizzando i collegamenti che si trovano nel footer di ogni pagina in questa guida.",
"updated": 1610806272356
}
]
},
{
"style": "Note",
"text": "You can only add or delete pages to the Docs if you are navigating it in English, because English is the default language, and from there pages are later translated. "
"text": "You can only add or delete pages to the Docs if you are navigating it in English, because English is the default language, and from there pages are later translated. ",
"translations": [
{
"language": "IT",
"text": "Puoi aggiungere o eliminare le pagine della guida solo se stai navigando in inglese perché è la lingua predefinita e da lì le pagine possono essere tradotte in seguito.",
"updated": 1610806324698
}
]
}
]
}
@@ -16,8 +16,20 @@
},
{
"style": "Title",
"text": "Error Message",
"updated": 1610971316249
"text": "Error Details",
"updated": 1611151211050
},
{
"style": "Text",
"text": "In the following section you will find the specific information received when this error occured."
},
{
"style": "Note",
"text": "You will only see it if you opened this page as a result of the error actually happening."
},
{
"style": "Subtitle",
"text": "Error Message"
},
{
"style": "Text",
@@ -30,7 +42,7 @@
"updated": 1610971337737
},
{
"style": "Title",
"style": "Subtitle",
"text": "Error Stack",
"updated": 1610968600444
},
@@ -45,7 +57,7 @@
"updated": 1610968640796
},
{
"style": "Title",
"style": "Subtitle",
"text": "Error Code"
},
{
@@ -20,7 +20,6 @@ exports.newSuperalgosBotModulesHistoricOHLCVs = function (processIndex) {
let fetchType = "by Time"
let lastId
let firstId
let allOHLCVs = []
let thisReport;
let since
let initialProcessTimestamp
@@ -119,6 +118,11 @@ exports.newSuperalgosBotModulesHistoricOHLCVs = function (processIndex) {
function start(callBackFunction) {
try {
/*
Initialize the array where we are going to receive the
data from the exchange.
*/
let rawDataArray = []
if (TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING === true) {
callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE);
@@ -252,7 +256,7 @@ exports.newSuperalgosBotModulesHistoricOHLCVs = function (processIndex) {
processingDate = processingDate.getUTCFullYear() + '-' + TS.projects.superalgos.utilities.miscellaneousFunctions.pad(processingDate.getUTCMonth() + 1, 2) + '-' + TS.projects.superalgos.utilities.miscellaneousFunctions.pad(processingDate.getUTCDate(), 2);
TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME,
"[INFO] start -> getOHLCVs -> Fetching OHLCVs @ " + processingDate + "-> exchange = " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.parentNode.parentNode.name + " -> symbol = " + symbol + " -> since = " + since + " -> limit = " + limit)
let heartBeatText = "Fetching " + allOHLCVs.length.toFixed(0) + " OHLCVs from " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.parentNode.parentNode.name + " " + symbol + " @ " + processingDate
let heartBeatText = "Fetching " + rawDataArray.length.toFixed(0) + " OHLCVs from " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.parentNode.parentNode.name + " " + symbol + " @ " + processingDate
let currentDate = new Date(since)
let percentage = TS.projects.superalgos.utilities.dateTimeFunctions.getPercentage(fromDate, currentDate, lastDate)
TS.projects.superalgos.functionLibraries.processFunctions.processHeartBeat(processIndex, heartBeatText, percentage) // tell the world we are alive and doing well
@@ -332,7 +336,7 @@ exports.newSuperalgosBotModulesHistoricOHLCVs = function (processIndex) {
let OHLCVKey = OHLCV[0] + '-' + OHLCV[1].toFixed(16) + '-' + OHLCV[2].toFixed(16) + '-' + OHLCV[3].toFixed(16) + '-' + OHLCV[4].toFixed(16) + '-' + OHLCV[5].toFixed(16)
if (OHLCVKey !== lastOHLCVKey) {
allOHLCVs.push(OHLCV)
rawDataArray.push(OHLCV)
}
lastOHLCVKey = OHLCVKey
}
@@ -343,7 +347,7 @@ exports.newSuperalgosBotModulesHistoricOHLCVs = function (processIndex) {
if (
OHLCVs.length < limit - 1 ||
TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING === true ||
allOHLCVs.length >= MAX_OHLCVs_PER_EXECUTION
rawDataArray.length >= MAX_OHLCVs_PER_EXECUTION
) {
break
}
@@ -376,18 +380,27 @@ exports.newSuperalgosBotModulesHistoricOHLCVs = function (processIndex) {
}
async function saveOHLCVs() {
/*
What we are going to do in this function is to save all the candles
received from the exchage. We need to partition the batch of candles
into 1 day files. At the same time we need to take care of the situation
that some exchanges send inconsitent data. We have detected some cases
where candles do not begin at second 0 of the minute but are a little
bit shifted. We will try to detectthis and fix it as we go.
We have the data received from the exchage at the arrary rawDataArray
*/
try {
let candlesFileContent = '['
let volumesFileContent = '['
let previousDay = Math.trunc((initialProcessTimestamp - TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS) / TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS)
let currentDay = Math.trunc((initialProcessTimestamp - TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS) / TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS)
let needSeparator = false
let error
let separator
let heartBeatCounter = 0
let headOfTheMarketReached = false
let savingProcedureFinished = false
let endOfTheOHLCVArrayReached = false
let currentDay = Math.trunc((initialProcessTimestamp - TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS) / TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS)
let lastCandle = {
begin: 0,
@@ -405,55 +418,104 @@ exports.newSuperalgosBotModulesHistoricOHLCVs = function (processIndex) {
sell: 0
}
let i = 0
let ohlcvArrayIndex = 0
lastId = undefined
if (lastCandleOfTheDay !== undefined) {
lastCandle = JSON.parse(JSON.stringify(lastCandleOfTheDay))
}
/*
At a macro level, we will be creating one file per day, so we will
run into a loop that each run will represent one day.
*/
controlLoop()
function loop() {
/*
Here we will try to match the OHLCVs received with each possible
candle of a single day.
*/
let filesToCreate = 0
let filesCreated = 0
/* Go through all possible 1 min candles of a day. */
for (let j = 0; j < 60 * 24; j++) {
/*
We will loop aroud all the possible 1 minute candles that be found
on a single day. For each minute of the day, we will try to find
the matching OHLCV. This would be an easy task if the exchanges
would allways return consistent data, but that is not the case.
Sometimes, some candles are missing. We have seen also candles that
do not start at an UTC minute, they are shifted in time some seconds.
In order to address all these inconsistencies the process gets a little
bit complicated.
*/
for (let minuteOfTheDay = 0; minuteOfTheDay < 60 * 24; minuteOfTheDay++) {
/*
We initialize our candle and volume objecs positioning them
at the current minute of the day of the current day. We also
initialize them with the last candle and volume property values.
The reason we do this last thing is because we don't knwo if
we are going to find or not a matching OHLCV. If we do find one
these property values will be overwritten, and if not, they will
hold at least the last know value.
*/
let candle = {
begin: currentDay * TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS + TS.projects.superalgos.globals.timeConstants.ONE_MIN_IN_MILISECONDS * j,
end: currentDay * TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS + TS.projects.superalgos.globals.timeConstants.ONE_MIN_IN_MILISECONDS * j + TS.projects.superalgos.globals.timeConstants.ONE_MIN_IN_MILISECONDS - 1,
begin: currentDay * TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS + TS.projects.superalgos.globals.timeConstants.ONE_MIN_IN_MILISECONDS * minuteOfTheDay,
end: currentDay * TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS + TS.projects.superalgos.globals.timeConstants.ONE_MIN_IN_MILISECONDS * minuteOfTheDay + TS.projects.superalgos.globals.timeConstants.ONE_MIN_IN_MILISECONDS - 1,
open: lastCandle.close,
close: lastCandle.close,
min: lastCandle.close,
max: lastCandle.close
}
let volume = {
begin: currentDay * TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS + TS.projects.superalgos.globals.timeConstants.ONE_MIN_IN_MILISECONDS * j,
end: currentDay * TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS + TS.projects.superalgos.globals.timeConstants.ONE_MIN_IN_MILISECONDS * j + TS.projects.superalgos.globals.timeConstants.ONE_MIN_IN_MILISECONDS - 1,
begin: currentDay * TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS + TS.projects.superalgos.globals.timeConstants.ONE_MIN_IN_MILISECONDS * minuteOfTheDay,
end: currentDay * TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS + TS.projects.superalgos.globals.timeConstants.ONE_MIN_IN_MILISECONDS * minuteOfTheDay + TS.projects.superalgos.globals.timeConstants.ONE_MIN_IN_MILISECONDS - 1,
buy: lastVolume.buy,
sell: lastVolume.sell
}
let processingDate = new Date(candle.begin)
processingDate = processingDate.getUTCFullYear() + '-' + TS.projects.superalgos.utilities.miscellaneousFunctions.pad(processingDate.getUTCMonth() + 1, 2) + '-' + TS.projects.superalgos.utilities.miscellaneousFunctions.pad(processingDate.getUTCDate(), 2);
/*
Here we will check that the current candle is not going into the future.
Remember we are looping around all possible minutes of a day, and when
that day is the current actual day, and the current minute is in the future,
it manke no more sense to continue inside this loop since we are not going
to find more OHLCVs matchings.
if (candle.begin > (new Date()).valueOf()) {
At the same time, we are going to check that we haven't processed the whole
OHLCV array. Once we reached the end of it, it makes no sense to continue
inside this loop.
*/
if (
candle.begin > (new Date()).valueOf() ||
endOfTheOHLCVArrayReached === true
) {
/* We stop when the current candle is pointing to a time in the future.*/
headOfTheMarketReached = true
savingProcedureFinished = true
/*
This will be our last file saved.
*/
saveFile(currentDay)
TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME,
"[INFO] start -> saveOHLCVs -> Before Fetch -> Saving OHLCVs @ " + processingDate + " -> i = " + i + " -> total = " + allOHLCVs.length)
TS.projects.superalgos.functionLibraries.processFunctions.processHeartBeat(processIndex, "Saving " + i.toFixed(0) + " / " + allOHLCVs.length + " OHLCVs from " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.parentNode.parentNode.name + " " + symbol + " @ " + processingDate) // tell the world we are alive and doing well
/*
We will produce our last log and heartbeat, since we have just
reached the head of the market.
*/
logAndHeartBeat()
/* We exit the loop and we aint comming back*/
return
}
let OHLCV = { // these values should be overrided unless there are no OHLVCs fetched from the exchange.
/*
We initialize here the OHLCV object. These initial
values should be overrided unless there are no
OHLVCs fetched from the exchange. We need the
timestamp in order to calculate OHLCVMinute.
*/
let OHLCV = {
timestamp: (new Date()).valueOf() + TS.projects.superalgos.globals.timeConstants.ONE_MIN_IN_MILISECONDS,
open: 0,
hight: 0,
@@ -462,9 +524,16 @@ exports.newSuperalgosBotModulesHistoricOHLCVs = function (processIndex) {
volume: 0
}
let record = allOHLCVs[i]
let record = rawDataArray[ohlcvArrayIndex]
if (record !== undefined) { // can be undefined if there is no candle fetched from the exchange
/*
We will check that we can have a record to
analize. It might happen that we don't have one
in the situation that we could not get a single
record from the exchange. We still want to be
here so that everything is properly logged.
*/
if (record !== undefined) {
OHLCV = {
timestamp: record[0],
open: record[1],
@@ -477,48 +546,73 @@ exports.newSuperalgosBotModulesHistoricOHLCVs = function (processIndex) {
let candleMinute = Math.trunc(candle.begin / TS.projects.superalgos.globals.timeConstants.ONE_MIN_IN_MILISECONDS)
let OHLCVMinute
/*
Some exchanges return inconsistent data. It is not guaranteed
that each candle will have a timeStamp exactly at the begining of an
UTC minute. It is also not guaranteed that the distance
between timestamps will be the same. To fix this, we will do this.
*/
checkOHLCVMinute()
OHLCVMinute = Math.trunc(OHLCV.timestamp / TS.projects.superalgos.globals.timeConstants.ONE_MIN_IN_MILISECONDS)
function checkOHLCVMinute() {
/*
Some exchanges return inconsistent data. It is not guaranteed that each candle will have a timeStamp exactly at the begining of an
UTC minute. It is also not guaranteed that the distance between timestamps will be the same. To fix this, we will do this.
*/
/*
If the minute of the record item received from the exchange is
less than the minute of the current minute in our loop,
that means that we need to reposition the inded at the rawDataArray
array, moving it one record fordward, and that is what we are
doing here.
*/
while (OHLCVMinute < candleMinute) {
OHLCVMinute = Math.trunc(OHLCV.timestamp / TS.projects.superalgos.globals.timeConstants.ONE_MIN_IN_MILISECONDS)
/* Move fordward at the rawDataArray array. */
ohlcvArrayIndex++
if (OHLCVMinute < candleMinute) {
if (i >= allOHLCVs.length - 1) {
/* We run out of OHLCVs, we can not move to the next OHLCV, we leave this function. */
return
}
i++
record = allOHLCVs[i]
OHLCV = {
timestamp: record[0],
open: record[1],
hight: record[2],
low: record[3],
close: record[4],
volume: record[5],
id: record[6]
}
setImmediate (checkOHLCVMinute)
/* Check that we have not passed the end of the array */
if (ohlcvArrayIndex > rawDataArray.length - 1) {
/*
We run out of OHLCVs, we can not move to the next OHLCV,
we need to leave this loop.
*/
break
}
record = rawDataArray[ohlcvArrayIndex]
/*
Once this loop is broken, this is the OHLCV that needs
to be considered. All the ones in the past are ignored.
*/
OHLCV = {
timestamp: record[0],
open: record[1],
hight: record[2],
low: record[3],
close: record[4],
volume: record[5],
id: record[6]
}
/* Recalculate this to see if we need to break the loop*/
OHLCVMinute = Math.trunc(OHLCV.timestamp / TS.projects.superalgos.globals.timeConstants.ONE_MIN_IN_MILISECONDS)
}
/* Reporting we are doing well */
heartBeatCounter--
if (heartBeatCounter <= 0) {
heartBeatCounter = 1440
TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME,
"[INFO] start -> saveOHLCVs -> After Fetch -> Saving OHLCVs @ " + processingDate + " -> i = " + i + " -> total = " + allOHLCVs.length)
TS.projects.superalgos.functionLibraries.processFunctions.processHeartBeat(processIndex, "Saving " + i.toFixed(0) + " / " + allOHLCVs.length + " OHLCVs from " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.parentNode.parentNode.name + " " + symbol + " @ " + processingDate) // tell the world we are alive and doing well
}
/* End Reporting */
/*
If the candleMinute and the OHLCVMinute matches, then
we transfer the properties of the OHLCV into the
candle object and the volume object. Two things to
consider here:
1. If they do not match, at this point it could only means
that the OHLCVMinute is in the future, in which case the
candle and volume will keep their initialization values
which in turn are equal to the latest candle and volumes.
2. They might be equal even though the OHLCV timestamp
did not match exactly the UTC minute, but since we are
comparing truncated values, then we force the matching
and we correct the shifting in time that sometimes happens
with exchange data.
*/
if (candleMinute === OHLCVMinute) {
candle.open = OHLCV.open
candle.close = OHLCV.close
@@ -527,14 +621,25 @@ exports.newSuperalgosBotModulesHistoricOHLCVs = function (processIndex) {
volume.buy = OHLCV.volume / 2
volume.sell = OHLCV.volume / 2
if (i < allOHLCVs.length - 1) {
i++
/*
Since we extracted this OHLCV value, we move
fordward our array index.
*/
if (ohlcvArrayIndex < rawDataArray.length - 1) {
ohlcvArrayIndex++
} else {
endOfTheOHLCVArrayReached = true
}
lastId = OHLCV.id
}
/*
Here we remeber the last candle and volumen, in case
we need it.
*/
lastCandle = candle
lastVolume = volume
if (needSeparator === false) {
needSeparator = true;
@@ -548,14 +653,40 @@ exports.newSuperalgosBotModulesHistoricOHLCVs = function (processIndex) {
volumesFileContent = volumesFileContent + separator + '[' + volume.buy + "," + volume.sell + "," + volume.begin + "," + volume.end + "]";
/* We store the last candle of the day in order to have a previous candles during next execution. */
if (j === 1440 - 1) {
if (minuteOfTheDay === 1440 - 1) {
lastCandleOfTheDay = JSON.parse(JSON.stringify(candle))
}
/* Reporting we are doing well */
heartBeatCounter--
if (heartBeatCounter <= 0) {
heartBeatCounter = 1440
logAndHeartBeat()
}
function logAndHeartBeat() {
/* We need thi processing date for logging purposes only */
let processingDate = new Date(candle.begin)
processingDate =
processingDate.getUTCFullYear() + '-' +
TS.projects.superalgos.utilities.miscellaneousFunctions.pad(processingDate.getUTCMonth() + 1, 2) + '-' +
TS.projects.superalgos.utilities.miscellaneousFunctions.pad(processingDate.getUTCDate(), 2);
TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME,
"[INFO] start -> saveOHLCVs -> Before Fetch -> Saving OHLCVs @ " + processingDate + " -> ohlcvArrayIndex = " + ohlcvArrayIndex + " -> total = " + rawDataArray.length)
TS.projects.superalgos.functionLibraries.processFunctions.processHeartBeat(processIndex, "Saving " + (ohlcvArrayIndex + 1).toFixed(0) + " / " + rawDataArray.length + " OHLCVs from " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.parentNode.parentNode.name + " " + symbol + " @ " + processingDate) // tell the world we are alive and doing well
}
}
previousDay = currentDay
if (i > 0) { // Only start saving at the day of the first candle.
/*
When the bot is processing historical information, it
happens that during the whole processing of one day
it did not reach either the head of the market (a future time)
nor the end of the Raw Data Array. In this situation
we still need to save the full day of content, and
we do it only if at least one candle has been processed.
*/
if (ohlcvArrayIndex > 0) {
saveFile(currentDay)
return
}
@@ -565,7 +696,7 @@ exports.newSuperalgosBotModulesHistoricOHLCVs = function (processIndex) {
function saveFile(day) {
candlesFileContent = candlesFileContent + ']'
volumesFileContent = volumesFileContent + ']'
let fileName = 'Data.json'
filesToCreate++
@@ -577,7 +708,6 @@ exports.newSuperalgosBotModulesHistoricOHLCVs = function (processIndex) {
candlesFileContent = '['
volumesFileContent = '['
needSeparator = false
}
function onFileCreated(err) {
@@ -605,39 +735,60 @@ exports.newSuperalgosBotModulesHistoricOHLCVs = function (processIndex) {
}
function controlLoop() {
/*
This loop advances one day, and if it does not need to stop
for any reason, it will execute the loop function so as to process
the next day.
*/
currentDay++
/*
It might have happened that the User is stopping the Task. If that
is the case, we need to stop this processing here.
*/
if (TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING === true) {
callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE);
return
}
/*
If we had any problem saving the latest file, we will also abort
this process here, so that we can record our progress until it stopped
working.
*/
if (error) {
callBackFunction(error);
return;
}
currentDay++
/*
One possible exit is when we reached the amount of candles downloaded. This not necesary happens at the end of the market
if the process was canceled for any reason at the middle.
One possible exit is when we reached the amount of candles downloaded.
This does not necesary happens at the end of the market
if the process was canceled for any reason at the middle,
or the exchange became unavailable.
*/
if (i >= allOHLCVs.length - 1) {
if (ohlcvArrayIndex >= rawDataArray.length - 1) {
writeStatusReport()
TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME,
"[INFO] start -> saveOHLCVs -> controlLoop -> Exit because i reached the end of the candles array. ")
"[INFO] start -> saveOHLCVs -> controlLoop -> Exit because i reached the end of the rawDataArray array. ")
return
}
/* The natural exit is at the end of the market */
if (headOfTheMarketReached === false) {
setImmediate(loop)
} else {
/*
The most common exit is at the end of the market. There is
nothing else to save, so we finish here.
*/
if (savingProcedureFinished === true) {
writeStatusReport()
TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME,
"[INFO] start -> saveOHLCVs -> controlLoop -> Exit because we reached the end of the market. ")
writeStatusReport()
return
}
/*
If there is no reson to exit, we will process the next day.
*/
setImmediate(loop)
}
} catch (err) {
@@ -65,7 +65,7 @@ function newSuperalgosDocsCommmandInterface() {
httpRequest(
undefined,
'App/Contribute/' +
message + '/' +
message.replaceAll('#', 'HASHTAG') + '/' +
config.username + '/' +
config.token + '/' +
UI.projects.superalgos.spaces.docsSpace.currentBranch + '/' +
@@ -82,7 +82,14 @@ function newSuperalgosDocsCommmandInterface() {
if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result && data.result === GLOBAL.DEFAULT_OK_RESPONSE.result) {
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Message - Contribution Done')
} else {
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Error - Contribution Not Sent', 'Anchor Contribution Not Sent')
UI.projects.superalgos.spaces.docsSpace.navigateTo(
data.docs.project,
data.docs.category,
data.docs.type,
data.docs.anchor,
undefined,
data.docs.placeholder
)
}
}
}
@@ -94,33 +101,6 @@ function newSuperalgosDocsCommmandInterface() {
}
if (UI.projects.superalgos.spaces.docsSpace.commandInterface.command.indexOf('App.Update') !== 0 && UI.projects.superalgos.spaces.docsSpace.commandInterface.command.indexOf('app.update') !== 0) { return 'Not Update Commands' }
/* Set up the commit message */
let message = UI.projects.superalgos.spaces.docsSpace.commandInterface.command.trim().substring(UI.projects.superalgos.spaces.docsSpace.commandInterface.command.indexOf(' ') + 1, UI.projects.superalgos.spaces.docsSpace.commandInterface.command.length)
if (message.toLowerCase() === 'app.update') {
message = 'Updating my Superalgos Fork and local Repository'
}
/* Find the Username and Password */
let apisNode = UI.projects.superalgos.spaces.designSpace.workspace.getHierarchyHeadsByType('APIs')
if (apisNode === undefined) {
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Error - Github Credentials Missing', 'Anchor Hierarchy APIs Not Found')
return
}
if (apisNode.githubAPI === undefined) {
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Error - Github Credentials Missing', 'Anchor Github API Node Not Found')
return
}
let config = JSON.parse(apisNode.githubAPI.config)
if (config.username === undefined || config.username === "") {
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Error - Github Credentials Missing', 'Anchor Config Property Username Not Found')
return
}
if (config.token === undefined || config.token === "") {
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Error - Github Credentials Missing', 'Anchor Config Property Token Not Found')
return
}
httpRequest(undefined, 'App/Update/' + UI.projects.superalgos.spaces.docsSpace.currentBranch, onResponse)
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Message - Updating Your Local App')
@@ -136,7 +116,14 @@ function newSuperalgosDocsCommmandInterface() {
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Message - Update Done - Already Up-To-Date')
}
} else {
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Error - Update Failed', 'Anchor Update Failed')
UI.projects.superalgos.spaces.docsSpace.navigateTo(
data.docs.project,
data.docs.category,
data.docs.type,
data.docs.anchor,
undefined,
data.docs.placeholder
)
}
}
}
@@ -21,7 +21,7 @@ function newSuperalgosDocSpace() {
paragraphMap: undefined, // Here we will store a map of paragraphs from the Docs Node, Concept, Topics, Tutorials, Reviews or Books Schema in order to find it when we need to update them.
textArea: undefined,
changeLanguage: changeLanguage,
changeActiveBranch: changeActiveBranch,
changeCurrentBranch: changeCurrentBranch,
changeContributionsBranch: changeContributionsBranch,
enterEditMode: enterEditMode,
exitEditMode: exitEditMode,
@@ -183,7 +183,7 @@ function newSuperalgosDocSpace() {
initialize()
}
function changeActiveBranch(branch) {
function changeCurrentBranch(branch) {
httpRequest(undefined, 'App/Checkout/' + branch, onResponse)
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Switching Branches - Changing Current Branch')
@@ -195,7 +195,14 @@ function newSuperalgosDocSpace() {
window.localStorage.setItem('Current Branch', branch)
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Switching Branches - Current Branch Changed')
} else {
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Switching Branches - Current Branch Not Changed')
UI.projects.superalgos.spaces.docsSpace.navigateTo(
data.docs.project,
data.docs.category,
data.docs.type,
data.docs.anchor,
undefined,
data.docs.placeholder
)
}
}
}
@@ -476,13 +476,13 @@ function newSuperalgosDocsDocumentPage() {
case "Placeholder": {
renderParagraph(paragraph, key)
editableParagraphIndex++
let error = addPlaceholdedParagraph(paragraph.text)
if (error !== undefined) {
let result = addPlaceholdedParagraph(paragraph.text)
if (result !== undefined) {
paragraph = {
style: "Error",
text: error
style: "Note",
text: result
}
key = 'error-paragraph-' + autoGeneratedParagraphIndex
key = 'note-paragraph-' + autoGeneratedParagraphIndex
renderParagraph(paragraph, key)
autoGeneratedParagraphIndex++
}
@@ -622,14 +622,7 @@ function newSuperalgosDocsDocumentPage() {
autoGeneratedParagraphIndex++
return
} else {
let paragraph = {
type: "Json",
text: JSON.stringify(UI.projects.superalgos.spaces.docsSpace.currentDocumentBeingRendered.placeholder, undefined, 4)
}
let key = 'placeholded-paragraph-' + autoGeneratedParagraphIndex
renderParagraph(paragraph, key)
autoGeneratedParagraphIndex++
return 'Property ' + propertyName + ' not found at the placeholder object.'
return 'Property ' + propertyName + ' not found at the placeholder object. This means that within the info recieved, this information is not available.'
}
}
}
@@ -98,8 +98,8 @@ function newSuperalgosDocsFooter() {
HTML = HTML + '<h4>Choose the Current Branch</h4>'
HTML = HTML + 'You are currently running on the <code class="docs-footer-code">' + UI.projects.superalgos.utilities.gitBranches.getBranchLabel(UI.projects.superalgos.spaces.docsSpace.currentBranch) + '</code> branch. Switch to:'
HTML = HTML + '<ul>'
HTML = HTML + '<li><a href="#" onClick="UI.projects.superalgos.spaces.docsSpace.changeActiveBranch(\'master\')">Master</a></li>'
HTML = HTML + '<li><a href="#" onClick="UI.projects.superalgos.spaces.docsSpace.changeActiveBranch(\'develop\')">Develop</a></li>'
HTML = HTML + '<li><a href="#" onClick="UI.projects.superalgos.spaces.docsSpace.changeCurrentBranch(\'master\')">Master</a></li>'
HTML = HTML + '<li><a href="#" onClick="UI.projects.superalgos.spaces.docsSpace.changeCurrentBranch(\'develop\')">Develop</a></li>'
HTML = HTML + '</ul>'
HTML = HTML + '</div>'
+2 -2
View File
@@ -48,7 +48,7 @@ Before you begin, it is recommended that you set up Chrome/Safari as your defaul
# Superalgos Client Installation
**1.** Scroll the page all the way to the top. Find and click the **Fork** button to create your fork/copy of this repository. To fork Superalgos you need a GitHub account. If you don't have one, go ahead and create it. A Fork is required for your contributions to the project and to stay up to date with the latest version of the software (more on this later).
**1.** Scroll the page all the way to the top. Find and click the **Fork** button to create your fork/copy of this repository. To fork Superalgos you need a GitHub account. If you don't have one, go ahead and create it. A Fork is required for your contributions to the project (more on this later).
**2.** Once the fork is created, you will land on the page of your fork. Copy the URL from your browser's address bar.
@@ -74,7 +74,7 @@ git clone https://github.com/John/Superalgos
**1.** You need to make a fork so that you may contribute work. Superalgos is a Community project and you are expected to contribute, like everyone else. You don't need to be a technical person to contribute. Fixing a typo in the docs or translating a paragraph into your native language are valuable contributions too. Superalgos has built-in features that make contributing easy. Help make Superalgos better and Superalgos will better serve you! [Free-riding is not cool](https://en.wikipedia.org/wiki/Free-rider_problem), particularly on free, open-source, Community-driven projects.
**2.** You also need a fork to use the in-app self-update feature. It will help you stay up-to-date with the latest version of the software. Updates are on-demand, so don't worry about undesired updates. The project moves very fast and new features become available regularly, particularly if you choose to run the software in the ```develop``` branch (you may switch branches from within the app).
**2.** The software includes an in-app self-update command / feature. It will help you stay up-to-date with the latest version of the software. Updates are on-demand, so don't worry about undesired updates. The project moves very fast and new features become available regularly, particularly if you choose to run the software in the ```develop``` branch (you may switch branches from within the app).
**3.** You are better off running the git clone command as an administrator to avoid permission issues while creating the Superalgos folder and downloading the repository. It may work without admin powers depending on your setup, particularly if you are running the command on a folder where you've got write permissions.