Merge pull request #22 from AAMasters/develop

Clone appearing on Pannel.
This commit is contained in:
benme authored and GitHub committed 2019-03-24 20:06:19 +01:00
commit fba7a3447a
28 files changed
+164 -2211

No files matched your search

+1 -1
View File
@@ -263,7 +263,7 @@ function newDeleteTradingHistory () {
if (canDrawIcon === false) { return }
let breakpointsHeight = 14
let breakpointsHeight = 0
let imageHeight = 15
let imageWidth = 15
+4 -3
View File
@@ -107,7 +107,7 @@ function newCanvas () {
}
}
function initialize (callBackFunction) {
async function initialize (callBackFunction) {
try {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') }
@@ -118,7 +118,7 @@ function newCanvas () {
/* Instantiate all the children spaces of Canvas object */
thisObject.topSpace = newTopSpace()
thisObject.topSpace.initialize()
await thisObject.topSpace.initialize()
thisObject.bottomSpace = newBottomSpace()
thisObject.bottomSpace.initialize()
@@ -230,6 +230,8 @@ function newCanvas () {
if (INFO_LOG === true) { logger.write('[INFO] initializeBrowserCanvas -> Entering function.') }
browserCanvasContext = browserCanvas.getContext('2d')
// browserCanvasContext.font = 'italic small-caps bold 12px Saira'
browserCanvasContext.font = 'Saira'
viewPort.initialize()
} catch (err) {
@@ -679,4 +681,3 @@ function newCanvas () {
}
}
}
-49
View File
@@ -1,49 +0,0 @@
function newCloudRequire (bot, logger) {
const INFO_LOG = true
const LOG_FILE_CONTENT = false
const MODULE_NAME = 'Cloud Require'
let thisObject = {
downloadBot: downloadBot,
downloadCommons: downloadCommons
}
return thisObject
function downloadBot (pCloudStorage, pFilePath, callBackFunction) {
try {
if (INFO_LOG === true) { logger.write(MODULE_NAME, '[INFO] downloadBot -> Entering function.') }
let filePath = window.canvasApp.urlPrefix + 'Bots' + '/' + pFilePath + '/' + 'User.Bot.js'
downloadModule(filePath, onDownloaded)
function onDownloaded (pModule) {
callBackFunction(window.DEFAULT_OK_RESPONSE, pModule)
return
}
} catch (err) {
logger.write(MODULE_NAME, '[ERROR] downloadBot -> err = ' + err.message)
callBackFunction(window.DEFAULT_FAIL_RESPONSE)
}
}
function downloadCommons (pCloudStorage, pFilePath, callBackFunction) {
try {
if (INFO_LOG === true) { logger.write(MODULE_NAME, '[INFO] downloadCommons -> Entering function.') }
let filePath = window.canvasApp.urlPrefix + 'Bots' + '/' + pFilePath + '/' + 'Commons.js'
downloadModule(filePath, onDownloaded)
function onDownloaded (pModule) {
callBackFunction(window.DEFAULT_OK_RESPONSE, pModule)
return
}
} catch (err) {
logger.write(MODULE_NAME, '[ERROR] downloadCommons -> err = ' + err.message)
callBackFunction(window.DEFAULT_FAIL_RESPONSE)
}
}
};
-121
View File
@@ -1,121 +0,0 @@

/*
This module is for enabling the AACloud to run at the browser.
When running at the clode on NodeJS some things work diffently that at the browser. That gap will be fixed by the functions at this module.
*/
function webRequire (pModulePath) {
switch (pModulePath) {
case './AzureStorage': {
let MODULE = {}
MODULE.newAzureStorage = newAzureStorage
return MODULE
function newAzureStorage () {
return AzureStorage.Blob
}
}
case './EventHandler': {
let MODULE = {}
MODULE.newEventHandler = newEventHandler
return MODULE
}
case './BlobStorage': {
let MODULE = {}
MODULE.newBlobStorage = newBlobStorage
return MODULE
}
case './DebugLog': {
let MODULE = {}
MODULE.newDebugLog = newDebugLog
return MODULE
}
case './TradingBotProcessMainLoop': {
let MODULE = {}
MODULE.newTradingBotProcessMainLoop = newTradingBotProcessMainLoop
return MODULE
}
case './ExtractionBotProcessMainLoop': {
let MODULE = {}
MODULE.newExtractionBotProcessMainLoop = newExtractionBotProcessMainLoop
return MODULE
}
case './IndicatorBotProcessMainLoop': {
let MODULE = {}
MODULE.newIndicatorBotProcessMainLoop = newIndicatorBotProcessMainLoop
return MODULE
}
case './CloudUtilities': {
let MODULE = {}
MODULE.newCloudUtilities = newCloudUtilities
return MODULE
}
case './PoloniexAPIClient': {
let MODULE = {}
MODULE.newPoloniexAPIClient = newPoloniexAPIClient
return MODULE
}
case './Exchange/ExchangeAPI': {
let MODULE = {}
MODULE.newExchangeAPI = newExchangeAPI
return MODULE
}
case './Context': {
let MODULE = {}
MODULE.newContext = newContext
return MODULE
}
case './Assistant': {
let MODULE = {}
MODULE.newAssistant = newAssistant
return MODULE
}
case './StatusReport': {
let MODULE = {}
MODULE.newStatusReport = newStatusReport
return MODULE
}
case './DataSet': {
let MODULE = {}
MODULE.newDataSet = newDataSet
return MODULE
}
case './StatusDependencies': {
let MODULE = {}
MODULE.newStatusDependencies = newStatusDependencies
return MODULE
}
case './DataDependencies': {
let MODULE = {}
MODULE.newDataDependencies = newDataDependencies
return MODULE
}
case './CloudRequire': {
let MODULE = {}
MODULE.newCloudRequire = newCloudRequire
return MODULE
}
default: {
console.log(pModulePath + ' not found. ')
}
}
}
function downloadModule (pPath, callBackFunction) {
/* We will need this to load individual bots modules. */
REQUIREJS([pPath], onRequired)
function onRequired (pModule) {
console.log('CloudVM ' + pPath + ' downloaded.')
let MODULE = {}
MODULE.newUserBot = newUserBot
callBackFunction(MODULE)
}
}
-129
View File
@@ -1,129 +0,0 @@

function newCloudVM () {
const MODULE_NAME = 'CloudVM'
const INFO_LOG = false
const ERROR_LOG = true
const logger = newWebDebugLog()
logger.fileName = MODULE_NAME
var thisObject = {
onBotPlayPressed: onBotPlayPressed,
onBotStopPressed: onBotStopPressed
}
let root = newRoot()
let intervalHandler
let previousBotCode = ''
let errorsCheckingForBotCodeChanges = 0
return thisObject
function onBotPlayPressed (pUI_COMMANDS) {
try {
if (INFO_LOG === true) { logger.write('[INFO] onBotPlayPressed -> Entering function.') }
window.SHALL_BOT_STOP = false
errorsCheckingForBotCodeChanges = 0
window.CURRENT_ENVIRONMENT = 'Develop'
window.CURRENT_EXECUTION_AT = 'Browser'
window.STORAGE_PERMISSIONS = ecosystem.getStoragePermissions()
window.EXCHANGE_NAME = 'Poloniex'
window.MARKET = {
assetA: 'USDT',
assetB: 'BTC'
}
/*
When running at the browser, the AACloud VM will look for this data, in this case it does not contain any key or secret, since the browser only know the
session token the user received when he logged in.
*/
window.EXCHANGE_KEYS = {
Poloniex: {
Key: '',
Secret: ''
}
}
root.initialize(pUI_COMMANDS, onInitialized)
function onInitialized () {
try {
if (INFO_LOG === true) { logger.write('[INFO] onBotPlayPressed -> Entering function.') }
root.start()
intervalHandler = setInterval(checkForChangesInBotCode, 10000)
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] onBotPlayPressed -> onInitialized -> err.message = ' + err.message) }
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] onBotPlayPressed -> err.message = ' + err.message) }
}
}
function onBotStopPressed () {
if (INFO_LOG === true) { logger.write('[INFO] onBotStopPressed -> Entering function.') }
window.SHALL_BOT_STOP = true
errorsCheckingForBotCodeChanges = 0
}
function checkForChangesInBotCode () {
try {
if (INFO_LOG === true) { logger.write('[INFO] checkForChangesInBotCode -> Entering function.') }
let botFunction = newUserBot
if (botFunction !== undefined) {
let currentBotCode = botFunction.toString()
if (previousBotCode !== '') {
if (currentBotCode !== previousBotCode) {
console.log('CloudVM -> Bot code changes detected.')
let path = window.canvasApp.urlPrefix
+ 'AABrowserAPI' + '/'
+ 'saveBotCode' + '/'
+ window.DEV_TEAM + '/'
+ 'members' + '/'
+ window.USER_LOGGED_IN + '/'
+ window.CURRENT_BOT_REPO + '/'
+ window.CURRENT_PROCESS + '/'
+ 'User.Bot.js'
callServer(currentBotCode, path, onServerResponse)
function onServerResponse (err) {
err = JSON.parse(err)
if (INFO_LOG === true) { logger.write('[INFO] checkForChangesInBotCode -> onServerResponse -> Entering function.') }
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
if (ERROR_LOG === true) { logger.write('[ERROR] checkForChangesInBotCode -> onServerResponse -> err.message = ' + err.message) }
console.log('CloudVM -> Changes in code NOT saved. Plase check the error log and try again.')
return
}
console.log('CloudVM -> Changes in code saved.')
}
}
}
previousBotCode = currentBotCode
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] checkForChangesInBotCode -> err.message = ' + err.message) }
errorsCheckingForBotCodeChanges++
if (errorsCheckingForBotCodeChanges > 2) {
if (ERROR_LOG === true) { logger.write('[ERROR] checkForChangesInBotCode -> Giving up.') }
clearInterval(intervalHandler)
}
}
}
}
-64
View File
@@ -1,64 +0,0 @@
function newWebFS () {
const MODULE_NAME = 'Web FS'
const INFO_LOG = false
const ERROR_LOG = true
const logger = newWebDebugLog()
logger.fileName = MODULE_NAME
/*
This is the module emulates the NodeJS 'fs'.
*/
var thisObject = {
readFileSync: readFileSync,
appendFileSync: appendFileSync,
mkdirSync: mkdirSync,
statSync: statSync,
readdir: readdir,
readdirSync: readdirSync,
readFile: readFile
}
return thisObject
function readFileSync (pPath, pEncoding) {
switch (pPath) {
case '': {
break
}
}
}
function appendFileSync (pPath, pText) {
/* We will ignore this since we can not and dont want to really write something on disk while we are at the browser. */
}
function readdir (pPath, callBackFunction) {
/* We will return an empty array of files. */
callBackFunction([])
}
function readdirSync (pPath, callBackFunction) {
}
function mkdirSync (pPath) {
/* Again we do nothing. */
}
function readFile (pPath) {
/* Again we do nothing. */
}
function statSync (pPath) {
let stats
stats.size = 0
return stats
}
}
+2 -2
View File
@@ -55,7 +55,7 @@ function newCompetitionStorage (pName) {
for (let j = 0; j < pCompetition.participants.length; j++) {
let devTeam = ecosystem.getTeam(pCompetition.participants[j].devTeam)
let bot = ecosystem.getBot(devTeam, pCompetition.participants[j].bot)
let pOperationsId = pCompetition.participants[j].pOperationsId
bot.cloneId = pCompetition.participants[j].clonesId
let product = ecosystem.getProduct(bot, 'Competition Trading History')
if (INFO_LOG === true) { logger.write('[INFO] initialize -> key = ' + devTeam.codeName + '-' + bot.codeName + '-' + product.codeName) }
@@ -68,7 +68,7 @@ function newCompetitionStorage (pName) {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> File Sequence -> key = ' + pHost.codeName + '-' + pCompetition.codeName + '-' + devTeam.codeName + '-' + bot.codeName + '-' + product.codeName) }
let fileSequence = newFileSequence()
fileSequence.initialize(devTeam, bot, product, thisSet, pExchange, pMarket, onFileSequenceReady, pOperationsId)
fileSequence.initialize(devTeam, bot, product, thisSet, pExchange, pMarket, onFileSequenceReady)
fileSequences.push(fileSequence)
dataSetsToLoad++
}
-327
View File
@@ -1,327 +0,0 @@

function newDailyFiles () {
const MODULE_NAME = 'Daily Files'
const INFO_LOG = false
const ERROR_LOG = true
const logger = newWebDebugLog()
logger.fileName = MODULE_NAME
let thisObject = {
getFileCursor: getFileCursor,
setDatetime: setDatetime,
setTimePeriod: setTimePeriod,
getExpectedFiles: getExpectedFiles,
getFilesLoaded: getFilesLoaded,
initialize: initialize,
finalize: finalize
}
let filesLoaded = 0
let expectedFiles = 0
let fileCloud
let fileCursors = new Map()
let callBackWhenFileReceived
return thisObject
function finalize () {
try {
if (INFO_LOG === true) { logger.write('[INFO] finalize -> Entering function.') }
filesLoaded = undefined
expectedFiles = undefined
fileCloud = undefined
fileCursors.forEach(finalizeEach)
function finalizeEach (item, key, mapObj) {
if (INFO_LOG === true) { logger.write('[INFO] finalize -> finalizeEach -> Entering function.') }
item.finalize()
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] finalize -> err = ' + err) }
}
}
function initialize (pDevTeam, pBot, pProduct, pSet, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) {
try {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> key = ' + pDevTeam.codeName + '-' + pBot.codeName + '-' + pProduct.codeName) }
callBackWhenFileReceived = callBackFunction
let exchange = ecosystem.getExchange(pProduct, pExchange)
if (exchange === undefined) {
throw 'Exchange not supoorted by this product of the ecosystem! - pDevTeam.codeName = ' + pDevTeam.codeName + ', pBot.codeName = ' + pBot.codeName + ', pProduct.codeName = ' + pProduct.codeName + ', pExchange = ' + pExchange
}
fileCloud = newFileCloud()
fileCloud.initialize(pBot)
/* First we will get the Data Range */
fileCloud.getFile(pDevTeam, pBot, pSet, exchange, pMarket, undefined, undefined, undefined, true, onDataRangeReceived)
function onDataRangeReceived (err, pFile) {
try {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileReceived -> Entering function.') }
let beginDateRange
let endDateRange
switch (err.result) {
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileReceived -> Received OK Response.') }
beginDateRange = new Date(pFile.begin)
endDateRange = new Date(pFile.end)
break
}
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileReceived -> Received FAIL Response.') }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
return
}
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileReceived -> Received CUSTOM FAIL Response.') }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileReceived -> err.message = ' + err.message) }
if (err.message === 'File does not exist.') {
if (INFO_LOG === true) { logger.write('[WARN] initialize -> onFileReceived -> No Date Range file found. maxDate will be set to current datetime. ') }
endDateRange = new Date()
break
}
if (err.message === 'Missing Configuration.') {
if (ERROR_LOG === true) { logger.write('[WARN] initialize -> onFileReceived -> The needed configuration for the dateRange at the dataSet of the product was not found.') }
if (ERROR_LOG === true) { logger.write('[WARN] initialize -> onFileReceived -> maxDate will be set to current datetime.') }
endDateRange = new Date()
break
}
/* If none of the previous conditions are met, the we return the err to the caller. */
callBackFunction(err)
return
}
default: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileReceived -> Received Unexpected Response.') }
callBackFunction(err)
return
}
}
/* Now we will get the daily files */
for (i = 0; i < dailyFilePeriods.length; i++) {
let periodTime = dailyFilePeriods[i][0]
let periodName = dailyFilePeriods[i][1]
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileReceived -> periodTime = ' + periodTime) }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileReceived -> periodName = ' + periodName) }
if (pSet.validPeriods.includes(periodName) === true) {
let fileCursor = newFileCursor()
fileCursor.initialize(fileCloud, pDevTeam, pBot, pSet, exchange, pMarket, periodName, periodTime, pDatetime, pTimePeriod, beginDateRange, endDateRange, onInitialized)
function onInitialized (err) {
try {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileReceived -> onInitialized -> Entering function.') }
switch (err.result) {
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileReceived -> onInitialized -> Received OK Response.') }
break
}
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileReceived -> onInitialized -> Received FAIL Response.') }
callBackWhenFileReceived(GLOBAL.DEFAULT_FAIL_RESPONSE)
return
}
default: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileReceived -> onInitialized -> Received Unexpected Response.') }
callBackWhenFileReceived(err)
return
}
}
fileCursors.set(periodTime, fileCursor)
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileReceived -> onInitialized -> expectedFiles = ' + expectedFiles) }
expectedFiles = expectedFiles + fileCursor.getExpectedFiles()
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileReceived -> onInitialized -> expectedFiles = ' + expectedFiles) }
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onFileReceived -> onInitialized -> err = ' + err) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
}
}
loadThemAll()
function loadThemAll () {
try {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileReceived -> loadThemAll -> Entering function.') }
for (i = 0; i < dailyFilePeriods.length; i++) {
let periodTime = dailyFilePeriods[i][0]
let periodName = dailyFilePeriods[i][1]
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileReceived -> loadThemAll -> periodTime = ' + periodTime) }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileReceived -> loadThemAll -> periodName = ' + periodName) }
if (pSet.validPeriods.includes(periodName) === true) {
let fileCursor = fileCursors.get(periodTime)
fileCursor.reload(onFileReceived)
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onFileReceived -> loadThemAll -> err = ' + err) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onFileReceived -> err = ' + err) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err = ' + err) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
function onFileReceived (err) {
try {
if (INFO_LOG === true) { logger.write('[INFO] onFileReceived -> Entering function.') }
switch (err.result) {
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] onFileReceived -> Received OK Response.') }
break
}
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] onFileReceived -> Received FAIL Response.') }
callBackWhenFileReceived(GLOBAL.DEFAULT_FAIL_RESPONSE)
return
}
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] onFileReceived -> Received CUSTOM FAIL Response.') }
if (INFO_LOG === true) { logger.write('[INFO] onFileReceived -> err.message = ' + err.message) }
callBackWhenFileReceived(err)
return
}
default: {
if (INFO_LOG === true) { logger.write('[INFO] onFileReceived -> Received Unexpected Response.') }
callBackWhenFileReceived(err)
return
}
}
filesLoaded++
if (INFO_LOG === true) { logger.write('[INFO] onFileReceived -> filesLoaded = ' + filesLoaded) }
callBackWhenFileReceived(GLOBAL.DEFAULT_OK_RESPONSE, thisObject) // Note that the call back is called for every file loaded at each cursor.
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] onFileReceived -> err = ' + err) }
callBackWhenFileReceived(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
function getFileCursor (pPeriod) {
try {
if (INFO_LOG === true) { logger.write('[INFO] getFileCursor -> Entering function.') }
return fileCursors.get(pPeriod)
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] getFileCursor -> err = ' + err) }
}
}
function setDatetime (pDatetime) {
try {
if (INFO_LOG === true) { logger.write('[INFO] setDatetime -> Entering function.') }
filesLoaded = 0
expectedFiles = 0
fileCursors.forEach(setDatetimeToEach)
function setDatetimeToEach (fileCursor, key, map) {
fileCursor.setDatetime(pDatetime)
if (INFO_LOG === true) { logger.write('[INFO] setDatetime -> expectedFiles = ' + expectedFiles) }
expectedFiles = expectedFiles + fileCursor.getExpectedFiles()
if (INFO_LOG === true) { logger.write('[INFO] setDatetime -> expectedFiles = ' + expectedFiles) }
fileCursor.reload(onFileReceived)
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] setDatetime -> err = ' + err) }
}
}
function setTimePeriod (pTimePeriod, pDatetime) {
try {
if (INFO_LOG === true) { logger.write('[INFO] setTimePeriod -> Entering function.') }
filesLoaded = 0
expectedFiles = 0
fileCursors.forEach(setTimePeriodToEach)
function setTimePeriodToEach (fileCursor, key, map) {
fileCursor.setTimePeriod(pTimePeriod, pDatetime)
if (INFO_LOG === true) { logger.write('[INFO] setTimePeriod -> expectedFiles = ' + expectedFiles) }
expectedFiles = expectedFiles + fileCursor.getExpectedFiles()
if (INFO_LOG === true) { logger.write('[INFO] setTimePeriod -> expectedFiles = ' + expectedFiles) }
fileCursor.reload(onFileReceived)
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] setTimePeriod -> err = ' + err) }
}
}
function getExpectedFiles () {
if (INFO_LOG === true) { logger.write('[INFO] getExpectedFiles -> Entering function.') }
if (INFO_LOG === true) { logger.write('[INFO] getExpectedFiles -> expectedFiles = ' + expectedFiles) }
return expectedFiles
}
function getFilesLoaded () {
if (INFO_LOG === true) { logger.write('[INFO] getFilesLoaded -> Entering function.') }
if (INFO_LOG === true) { logger.write('[INFO] getFilesLoaded -> filesLoaded = ' + filesLoaded) }
return filesLoaded
}
}
-216
View File
@@ -1,216 +0,0 @@
function newFileCloud () {
const MODULE_NAME = 'File Cloud'
const INFO_LOG = false
const ERROR_LOG = true
const logger = newWebDebugLog()
logger.fileName = MODULE_NAME
/*
This is the module in the system that actually connects to the cloud storage and grabs from there the needed files.
*/
var thisObject = {
getFile: getFile,
initialize: initialize
}
let blobService
return thisObject
function initialize (pBot) {
try {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> pBot = ' + pBot.codeName) }
blobService = AzureStorage.Blob.createBlobServiceWithSas(pBot.storage.fileUri, pBot.storage.sas)
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err = ' + err) }
// callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE); TODO> Handle this callback.
}
}
function getFile (pDevTeam, pBot, pSet, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction, pOperationsId) {
try {
if (INFO_LOG === true) { logger.write('[INFO] getFile -> Entering function.') }
const MAX_RETRIES = 3
if (pOperationsId !== undefined) {
getFileRecursively(0, pDevTeam, pBot, pSet, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction, pOperationsId)
} else {
getFileRecursively(0, pDevTeam, pBot, pSet, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction)
}
function getFileRecursively (pRetryCounter, pDevTeam, pBot, pSet, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction, pOperationsId) {
try {
if (INFO_LOG === true) { logger.write('[INFO] getFile -> getFileRecursively -> Entering function.') }
if (INFO_LOG === true) { logger.write('[INFO] getFile -> getFileRecursively -> key = ' + pDevTeam.codeName + '-' + pBot.codeName + '-' + pSet.filePath + '-' + pSet.fileName) }
let fileName
let filePath
if (pDataRange === undefined) {
fileName = pSet.fileName
filePath = pSet.filePath
} else {
if (pSet.dataRange !== undefined) {
fileName = pSet.dataRange.fileName
filePath = pSet.dataRange.filePath
} else {
let customErr = {
result: GLOBAL.CUSTOM_FAIL_RESPONSE.result,
message: 'Missing Configuration.'
}
if (ERROR_LOG === true) { logger.write('[WARN] getFile -> getFileRecursively -> onFileReceived -> customErr.message = ' + customErr.message) }
if (ERROR_LOG === true) { logger.write('[WARN] getFile -> getFileRecursively -> onFileReceived -> Data Range configuration could not be found. ') }
callBackFunction(customErr)
return
}
}
if (fileName === undefined) {
logger.write('[ERROR] getFile -> getFileRecursively -> Inconsistant data. Check the following: ')
logger.write('[ERROR] getFile -> getFileRecursively -> pDevTeam = ' + JSON.stringify(pDevTeam))
logger.write('[ERROR] getFile -> getFileRecursively -> pBot = ' + JSON.stringify(pBot))
logger.write('[ERROR] getFile -> getFileRecursively -> pSet = ' + JSON.stringify(pSet))
logger.write('[ERROR] getFile -> getFileRecursively -> pExchange = ' + JSON.stringify(pExchange))
logger.write('[ERROR] getFile -> getFileRecursively -> pMarket = ' + JSON.stringify(pMarket))
logger.write('[ERROR] getFile -> getFileRecursively -> pPeriodName = ' + JSON.stringify(pPeriodName))
throw ('Inconsistant data received.')
}
if (pMarket !== undefined) {
fileName = fileName.replace('@AssetA', pMarket.assetA)
fileName = fileName.replace('@AssetB', pMarket.assetB)
}
if (pDevTeam !== undefined) {
filePath = filePath.replace('@DevTeam', pDevTeam.codeName)
}
if (pBot !== undefined) {
if (pOperationsId !== undefined) {
filePath = filePath.replace('@Bot', pBot.codeName + '-' + pOperationsId)
} else {
filePath = filePath.replace('@Bot', pBot.codeName)
}
}
if (pExchange !== undefined) {
filePath = filePath.replace('@Exchange', pExchange.name)
}
filePath = filePath.replace('@Period', pPeriodName)
if (pDatetime !== undefined) {
filePath = filePath.replace('@Year', pDatetime.getUTCFullYear())
filePath = filePath.replace('@Month', pad(pDatetime.getUTCMonth() + 1, 2))
filePath = filePath.replace('@Day', pad(pDatetime.getUTCDate(), 2))
filePath = filePath.replace('@Hour', pad(pDatetime.getUTCHours(), 2))
filePath = filePath.replace('@Minute', pad(pDatetime.getUTCMinutes(), 2))
}
if (pSequence !== undefined) {
fileName = fileName.replace('@Sequence', pSequence)
}
if (INFO_LOG === true) { logger.write('[INFO] getFile -> getFileRecursively -> filePath = ' + filePath) }
if (INFO_LOG === true) { logger.write('[INFO] getFile -> getFileRecursively -> fileName = ' + fileName) }
let containerName
containerName = pDevTeam.codeName.toLowerCase()
blobService.getBlobToText(containerName, filePath + '/' + fileName, onFileReceived)
function onFileReceived (err, text, response) {
try {
if (INFO_LOG === true) { logger.write('[INFO] getFile -> getFileRecursively -> onFileReceived -> Entering function.') }
if (INFO_LOG === true) { logger.write('[INFO] getFile -> getFileRecursively -> onFileReceived -> filePath = ' + filePath) }
if (INFO_LOG === true) { logger.write('[INFO] getFile -> getFileRecursively -> onFileReceived -> fileName = ' + fileName) }
let data
if (err) {
if (err.code === 'BlobNotFound' | err.code === 'FileNotFound' | err.code === 'ParentNotFound') {
let customErr = {
result: GLOBAL.CUSTOM_FAIL_RESPONSE.result,
message: 'File does not exist.'
}
if (INFO_LOG === true) { logger.write('[WARN] getFile -> getFileRecursively -> onFileReceived -> customErr.message = ' + customErr.message) }
callBackFunction(customErr)
return
}
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> containerName = ' + containerName) }
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> filePath = ' + filePath) }
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> fileName = ' + fileName) }
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> Unexpected Error Ocurred.') }
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> err = ' + err) }
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> text = ' + text) }
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> response = ' + response) }
if (err.message === 'XHR error') {
if (pRetryCounter < MAX_RETRIES) {
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> Retrying to get this file. ') }
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> MAX_RETRIES = ' + MAX_RETRIES) }
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> pRetryCounter = ' + pRetryCounter) }
getFileRecursively(pRetryCounter + 1, pDevTeam, pBot, pSet, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction)
return
} else {
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> Could not get this file from storage. ') }
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> MAX_RETRIES = ' + MAX_RETRIES) }
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> pRetryCounter = ' + pRetryCounter) }
}
}
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
return
} else {
try {
data = JSON.parse(text)
if (INFO_LOG === true) { logger.write('[INFO] getFile -> getFileRecursively -> onFileReceived -> Data received is valid JSON.') }
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, data)
return
} catch (err) {
if (INFO_LOG === true) { logger.write('[WARN] getFile -> getFileRecursively -> onFileReceived -> err = ' + err) }
let customErr = {
result: GLOBAL.CUSTOM_OK_RESPONSE.result,
message: 'Data not in JSON Format.'
}
if (INFO_LOG === true) { logger.write('[WARN] getFile -> getFileRecursively -> onFileReceived -> customErr.message = ' + customErr.message) }
callBackFunction(customErr, text)
return
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> err = ' + err) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> err = ' + err) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> err = ' + err) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
}
-586
View File
@@ -1,586 +0,0 @@

function newFileCursor () {
const MODULE_NAME = 'File Cursor'
const INFO_LOG = false
const ERROR_LOG = true
const logger = newWebDebugLog()
logger.fileName = MODULE_NAME
let cursorDate
let thisObject = {
reload: reload,
setDatetime: setDatetime,
setTimePeriod: setTimePeriod,
files: new Map(),
getExpectedFiles: getExpectedFiles,
initialize: initialize,
finalize: finalize
}
let minCursorSize = 10
let maxCursorSize = 30
let market
let exchange
let fileCloud
let devTeam
let bot
let thisSet
let periodName
let timePeriod
let beginDateRange
let endDateRange
let intervalHandle
return thisObject
function finalize () {
try {
if (INFO_LOG === true) { logger.write('[INFO] finalize -> Entering function.') }
clearInterval(intervalHandle)
thisObject.files = undefined
cursorDate = undefined
fileCloud = undefined
periodName = undefined
timePeriod = undefined
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] finalize -> err = ' + err) }
}
}
function initialize (pFileCloud, pDevTeam, pBot, pSet, pExchange, pMarket, pPeriodName, pTimePeriod, pCursorDate, pCurrentTimePeriod, pBeginDateRange, pEndDateRange, callBackFunction) {
try {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> key = ' + pDevTeam.codeName + '-' + pBot.codeName + '-' + pSet.codeName + '-' + pPeriodName) }
market = pMarket
exchange = pExchange
fileCloud = pFileCloud
devTeam = pDevTeam
bot = pBot
thisSet = pSet
periodName = pPeriodName
cursorDate = pCursorDate
timePeriod = pTimePeriod
beginDateRange = pBeginDateRange
endDateRange = pEndDateRange
if (INFO_LOG === true) { logger.write('[INFO] initialize -> market = ' + market) }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> periodName = ' + periodName) }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> cursorDate = ' + cursorDate) }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> beginDateRange = ' + beginDateRange) }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> endDateRange = ' + endDateRange) }
setTimePeriod(pCurrentTimePeriod, pCursorDate)
intervalHandle = setInterval(updateFiles, timePeriod)
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE)
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err = ' + err) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
function updateFiles () {
try {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> Entering function.') }
/*
In order to know if we need to update any file we follow this logic:
1. If the current date is already a file in the cursor, we need to update it.
2. If the current date is one day ahead of a file in the cursor, we need to add this one to the cursor.
*/
let targetDate
let dateString
let file
/* Situation 1 */
targetDate = new Date()
dateString = targetDate.getUTCFullYear() + '-' + pad(targetDate.getUTCMonth() + 1, 2) + '-' + pad(targetDate.getUTCDate(), 2)
file = thisObject.files.get(dateString)
if (file !== undefined) {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> File found at the cursor, proceeding to update.') }
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, periodName, targetDate, undefined, undefined, onFileReceived)
return
}
/* Situation 2 */
targetDate = new Date((new Date()).valueOf() - ONE_DAY_IN_MILISECONDS)
dateString = targetDate.getUTCFullYear() + '-' + pad(targetDate.getUTCMonth() + 1, 2) + '-' + pad(targetDate.getUTCDate(), 2)
file = thisObject.files.get(dateString) // This is from yesterday
targetDate = new Date()
dateString = targetDate.getUTCFullYear() + '-' + pad(targetDate.getUTCMonth() + 1, 2) + '-' + pad(targetDate.getUTCDate(), 2)
if (file !== undefined) {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> Previous day file found at the cursor, proceeding to add current date.') }
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, periodName, targetDate, undefined, undefined, onFileReceived)
return
}
function onFileReceived (err, file) {
try {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onFileReceived -> Entering function.') }
switch (err.result) {
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onFileReceived -> Received OK Response.') }
break
}
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onFileReceived -> Received FAIL Response.') }
return
}
default: {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onFileReceived -> Received Unexpected Response.') }
return
}
}
thisObject.files.set(dateString, file)
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onFileReceived -> File updated.') }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onFileReceived -> devTeam = ' + devTeam.codeName) }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onFileReceived -> bot = ' + bot.codeName) }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onFileReceived -> thisSet = ' + thisSet.codeName) }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onFileReceived -> dateString = ' + dateString) }
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] updateFiles -> onFileReceived -> err = ' + err) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] updateFiles -> err = ' + err) }
}
}
function setTimePeriod (pTimePeriod, pDatetime) {
try {
if (INFO_LOG === true) { logger.write('[INFO] setTimePeriod -> Entering function.') }
/*
We are implementing here an algorithm designed to save bandwidth, memory and processing power at the browser.
We say there is a saving mode where the cursor is running at a minimum size. When the end user aproaches the time period the cursor
is set, then it should exit the saving mode and go to its actual size.
To do this we are going to measure the distance from the Time Period received to the one the cursors was initialized with.
If these periods are consecutive, it means that the cursor should exit saving mode and load its full size.
*/
cursorDate = pDatetime // Adjust the cursor date to the one received.
let positionA
for (let i = 0; i < dailyFilePeriods.length; i++) {
let period = dailyFilePeriods[i]
if (period[0] === pTimePeriod) {
positionA = i
}
if (period[0] === timePeriod) {
positionB = i
}
}
if (Math.abs(positionB - positionA) <= 1) {
if (INFO_LOG === true) { logger.write('[INFO] setTimePeriod -> Will EXIT Saving Mode.') }
if (INFO_LOG === true) { logger.write('[INFO] setTimePeriod -> pTimePeriod = ' + convertTimePeriodToName(pTimePeriod)) }
if (INFO_LOG === true) { logger.write('[INFO] setTimePeriod -> timePeriod = ' + convertTimePeriodToName(timePeriod)) }
exitSavingMode()
} else {
if (INFO_LOG === true) { logger.write('[INFO] setTimePeriod -> Will ENTER Saving Mode.') }
if (INFO_LOG === true) { logger.write('[INFO] setTimePeriod -> pTimePeriod = ' + convertTimePeriodToName(pTimePeriod)) }
if (INFO_LOG === true) { logger.write('[INFO] setTimePeriod -> timePeriod = ' + convertTimePeriodToName(timePeriod)) }
enterSavingMode()
}
function enterSavingMode () {
try {
if (INFO_LOG === true) { logger.write('[INFO] setTimePeriod -> enterSavingMode -> Entering function.') }
switch (timePeriod) {
case _45_MINUTES_IN_MILISECONDS:
{
minCursorSize = 3
maxCursorSize = 30
}
break
case _40_MINUTES_IN_MILISECONDS:
{
minCursorSize = 3
maxCursorSize = 20
}
break
case _30_MINUTES_IN_MILISECONDS:
{
minCursorSize = 3
maxCursorSize = 15
}
break
case _20_MINUTES_IN_MILISECONDS:
{
minCursorSize = 3
maxCursorSize = 15
}
break
case _15_MINUTES_IN_MILISECONDS:
{
minCursorSize = 3
maxCursorSize = 15
}
break
case _10_MINUTES_IN_MILISECONDS:
{
minCursorSize = 3
maxCursorSize = 15
}
break
case _5_MINUTES_IN_MILISECONDS:
{
minCursorSize = 3
maxCursorSize = 15
}
break
case _4_MINUTES_IN_MILISECONDS:
{
minCursorSize = 3
maxCursorSize = 15
}
break
case _3_MINUTES_IN_MILISECONDS:
{
minCursorSize = 3
maxCursorSize = 15
}
break
case _2_MINUTES_IN_MILISECONDS:
{
minCursorSize = 3
maxCursorSize = 15
}
break
case _1_MINUTE_IN_MILISECONDS:
{
minCursorSize = 3
maxCursorSize = 15
}
break
default:
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] setTimePeriod -> enterSavingMode -> err = ' + err) }
}
}
function exitSavingMode () {
try {
if (INFO_LOG === true) { logger.write('[INFO] setTimePeriod -> exitSavingMode -> Entering function.') }
switch (timePeriod) {
case _45_MINUTES_IN_MILISECONDS:
{
minCursorSize = 15
maxCursorSize = 30
}
break
case _40_MINUTES_IN_MILISECONDS:
{
minCursorSize = 13
maxCursorSize = 20
}
break
case _30_MINUTES_IN_MILISECONDS:
{
minCursorSize = 11
maxCursorSize = 15
}
break
case _20_MINUTES_IN_MILISECONDS:
{
minCursorSize = 9
maxCursorSize = 15
}
break
case _15_MINUTES_IN_MILISECONDS:
{
minCursorSize = 7
maxCursorSize = 15
}
break
case _10_MINUTES_IN_MILISECONDS:
{
minCursorSize = 7
maxCursorSize = 15
}
break
case _5_MINUTES_IN_MILISECONDS:
{
minCursorSize = 5
maxCursorSize = 15
}
break
case _4_MINUTES_IN_MILISECONDS:
{
minCursorSize = 5
maxCursorSize = 15
}
break
case _3_MINUTES_IN_MILISECONDS:
{
minCursorSize = 5
maxCursorSize = 15
}
break
case _2_MINUTES_IN_MILISECONDS:
{
minCursorSize = 5
maxCursorSize = 15
}
break
case _1_MINUTE_IN_MILISECONDS:
{
minCursorSize = 5
maxCursorSize = 15
}
break
default:
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] setTimePeriod -> exitSavingMode -> err = ' + err) }
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] setTimePeriod -> err = ' + err) }
}
}
function setDatetime (pDatetime) {
try {
if (INFO_LOG === true) { logger.write('[INFO] setDatetime -> Entering function.') }
if (pDatetime === undefined) {
if (ERROR_LOG === true) { logger.write('[ERROR] setDatetime -> Received undefined datetime.') }
return
}
cursorDate = pDatetime
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] setDatetime -> err = ' + err) }
}
}
function reload (callBackFunction) {
try {
if (INFO_LOG === true) { logger.write('[INFO] reload -> Entering function.') }
getFiles(callBackFunction)
collectGarbage(callBackFunction)
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] reload -> err = ' + err) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
function getFiles (callBackFunction) {
try {
if (INFO_LOG === true) { logger.write('[INFO] getFiles -> Entering function.') }
let i = 0
let j = 0
let dateString
getNextFile()
function getNextFile () {
try {
if (INFO_LOG === true) { logger.write('[INFO] getFiles -> getNextFile -> Entering function.') }
let targetDate = new Date(cursorDate)
targetDate.setUTCDate(targetDate.getUTCDate() + j)
/* Small algorith to allow load first the current date, then alternate between the most forwad and the most backwards ones. */
if (j === 0) { j++ } else {
if (j < 0) {
j = -j
j++
} else {
j = -j
}
}
let compareTargetDate = new Date(targetDate.toDateString())
if (beginDateRange !== undefined) {
let compareBeginDate = new Date(beginDateRange.toDateString())
if (compareTargetDate.valueOf() < compareBeginDate.valueOf()) {
if (INFO_LOG === true) { logger.write('[INFO] getFiles -> getNextFile -> compareTargetDate < compareBeginDate -> Not loading the file for this date.') }
if (INFO_LOG === true) { logger.write('[INFO] getFiles -> getNextFile -> compareTargetDate < compareBeginDate -> compareTargetDate = ' + compareTargetDate) }
if (INFO_LOG === true) { logger.write('[INFO] getFiles -> getNextFile -> compareTargetDate < compareBeginDate -> compareBeginDate = ' + compareBeginDate) }
controlLoop()
return
}
}
if (endDateRange !== undefined) {
let compareEndDate = new Date(endDateRange.toDateString())
if (compareTargetDate.valueOf() > compareEndDate.valueOf()) {
if (INFO_LOG === true) { logger.write('[INFO] getFiles -> getNextFile -> compareTargetDate > compareEndDate -> Not loading the file for this date.') }
if (INFO_LOG === true) { logger.write('[INFO] getFiles -> getNextFile -> compareTargetDate > compareEndDate -> compareTargetDate = ' + compareTargetDate) }
if (INFO_LOG === true) { logger.write('[INFO] getFiles -> getNextFile -> compareTargetDate > compareEndDate -> compareEndDate = ' + compareEndDate) }
controlLoop()
return
}
}
dateString = targetDate.getUTCFullYear() + '-' + pad(targetDate.getUTCMonth() + 1, 2) + '-' + pad(targetDate.getUTCDate(), 2)
let currentDay = Math.trunc((new Date()).valueOf() / (24 * 60 * 60 * 1000))
let targetDay = Math.trunc(targetDate.valueOf() / (24 * 60 * 60 * 1000))
if (targetDay > currentDay) {
controlLoop()
} else {
if (thisObject.files.get(dateString) === undefined) {
// We dont reload files we already have.
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, periodName, targetDate, undefined, undefined, onFileReceived)
} else {
controlLoop()
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] getFiles -> getNextFile -> err = ' + err) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
function onFileReceived (err, file) {
try {
if (INFO_LOG === true) { logger.write('[INFO] getFiles -> onFileReceived -> Entering function.') }
switch (err.result) {
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] getFiles -> onFileReceived -> Received OK Response.') }
break
}
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] getFiles -> onFileReceived -> Received FAIL Response.') }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
return
}
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] getFiles -> onFileReceived -> Received CUSTOM FAIL Response.') }
if (INFO_LOG === true) { logger.write('[INFO] getFiles -> onFileReceived -> err.message = ' + err.message) }
if (err.message === 'File does not exist.') {
controlLoop()
return
} else {
callBackFunction(err)
return
}
}
default: {
if (INFO_LOG === true) { logger.write('[INFO] getFiles -> onFileReceived -> Received Unexpected Response.') }
callBackFunction(err)
return
}
}
thisObject.files.set(dateString, file)
controlLoop()
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] getFiles -> onFileReceived -> err = ' + err) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
function controlLoop () {
try {
if (INFO_LOG === true) { logger.write('[INFO] getFiles -> controlLoop -> Entering function.') }
if (callBackFunction !== undefined) {
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE)
}
i++
if (i < minCursorSize) {
getNextFile()
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] getFiles -> controlLoop -> err = ' + err) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] getFiles -> err = ' + err) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
function collectGarbage (callBackFunction) {
try {
if (INFO_LOG === true) { logger.write('[INFO] collectGarbage -> Entering function.') }
date = removeTime(cursorDate)
let minDate = date.valueOf() - maxCursorSize * ONE_DAY_IN_MILISECONDS / 2
let maxDate = date.valueOf() + maxCursorSize * ONE_DAY_IN_MILISECONDS / 2
for (let key of thisObject.files.keys()) {
let keyDate = new Date(key)
if (keyDate.valueOf() < minDate || keyDate.valueOf() > maxDate) {
thisObject.files.delete(key)
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] collectGarbage -> err = ' + err) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
function getExpectedFiles () {
if (INFO_LOG === true) { logger.write('[INFO] getExpectedFiles -> Entering function.') }
return minCursorSize
}
}
-347
View File
@@ -1,347 +0,0 @@
function newFileSequence () {
const MODULE_NAME = 'File Sequence'
const INFO_LOG = false
const ERROR_LOG = true
const logger = newWebDebugLog()
logger.fileName = MODULE_NAME
let thisObject = {
eventHandler: undefined,
getFile: getFile,
getExpectedFiles: getExpectedFiles,
getFilesLoaded: getFilesLoaded,
initialize: initialize,
finalize: finalize
}
let filesLoaded = 0
let fileCloud
let files = new Map()
let maxSequence = -1 // This is replaced by the content of the sequence file, which contains an index that starts on zero. In the case that the sequence file is not found the default value is -1 so when you add 1 it gives you the amount of files in the sequence, zero.
let market
let devTeam
let bot
let thisSet
let product
thisObject.eventHandler = newEventHandler()
let intervalHandle
return thisObject
function finalize () {
try {
if (INFO_LOG === true) { logger.write('[INFO] finalize -> Entering function.') }
if (INFO_LOG === true) { logger.write('[INFO] finalize -> devTeam = ' + devTeam.codeName) }
if (INFO_LOG === true) { logger.write('[INFO] finalize -> bot = ' + bot.codeName) }
if (INFO_LOG === true) { logger.write('[INFO] finalize -> thisSet = ' + thisSet.codeName) }
if (INFO_LOG === true) { logger.write('[INFO] finalize -> intervalHandle = ' + intervalHandle) }
clearInterval(intervalHandle)
filesLoaded = undefined
fileCloud = undefined
files = undefined
maxSequence = undefined
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] finalize -> err = ' + err) }
}
}
function initialize (pDevTeam, pBot, pProduct, pSet, pExchange, pMarket, callBackFunction, pOperationsId) {
try {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> key = ' + pDevTeam.codeName + '-' + pBot.codeName + '-' + pProduct.codeName) }
exchange = ecosystem.getExchange(pProduct, pExchange)
if (exchange === undefined) {
throw 'Exchange not supoorted by this pProduct of the ecosystem! - pDevTeam.codeName = ' + pDevTeam.codeName + ', pBot.codeName = ' + pBot.codeName + ', pProduct.codeName = ' + pProduct.codeName + ', pExchange = ' + pExchange
}
if (pOperationsId !== undefined) {
intervalHandle = setInterval(function () { updateFiles(pOperationsId) }, _1_MINUTE_IN_MILISECONDS)
} else {
intervalHandle = setInterval(updateFiles, _1_MINUTE_IN_MILISECONDS)
}
if (INFO_LOG === true) { logger.write('[INFO] initialize -> intervalHandle = ' + intervalHandle) }
market = pMarket
devTeam = pDevTeam
bot = pBot
thisSet = pSet
product = pProduct
fileCloud = newFileCloud()
fileCloud.initialize(bot)
/* First we will get the sequence max number */
if (pOperationsId !== undefined) {
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, 'Sequence', undefined, onSequenceFileReceived, pOperationsId)
} else {
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, 'Sequence', undefined, onSequenceFileReceived)
}
function onSequenceFileReceived (err, file) {
try {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> Entering function.') }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> key = ' + devTeam.codeName + '-' + bot.codeName + '-' + product.codeName) }
switch (err.result) {
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> Received OK Response.') }
break
}
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> Received FAIL Response.') }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
return
}
case GLOBAL.CUSTOM_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> Received CUSTOM OK Response.') }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> err.message = ' + err.message) }
callBackFunction(err)
return
}
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> Received CUSTOM FAIL Response.') }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> err.message = ' + err.message) }
callBackFunction(err, thisObject)
return
}
default: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> Received Unexpected Response.') }
callBackFunction(err)
return
}
}
maxSequence = Number(file)
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> maxSequence = ' + maxSequence) }
/* Now we will get the sequence of files */
for (let i = 0; i <= maxSequence; i++) {
if (pOperationsId !== undefined) {
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, i, undefined, onFileReceived, pOperationsId)
} else {
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, i, undefined, onFileReceived)
}
function onFileReceived (err, file) {
try {
switch (err.result) {
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> Received OK Response.') }
break
}
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> Received FAIL Response.') }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
return
}
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> Received CUSTOM FAIL Response.') }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> err.message = ' + err.message) }
callBackFunction(err)
return
}
default: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> Received Unexpected Response.') }
callBackFunction(err)
return
}
}
files.set(i, file)
filesLoaded++
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, thisObject) // Note that the callback is called for every file loaded.
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onSequenceFileReceived -> onFileReceived -> err = ' + err) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onSequenceFileReceived -> err = ' + err) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err = ' + err) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
function updateFiles (pOperationsId) {
try {
let updateFiles = 0
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> Entering function.') }
/*
To keep this data structure up-to-date we need to:
1. Re-read the sequence file.
2. Re-load the current last file.
3. Re-load all new files after our last one.
*/
let currentMaxSequence = maxSequence
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> currentMaxSequence = ' + currentMaxSequence) }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> intervalHandle = ' + intervalHandle) }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> devTeam = ' + devTeam.codeName) }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> bot = ' + bot.codeName) }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> thisSet = ' + thisSet.codeName) }
if (pOperationsId !== undefined) {
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, 'Sequence', undefined, onSequenceFileReceived, pOperationsId)
} else {
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, 'Sequence', undefined, onSequenceFileReceived)
}
function onSequenceFileReceived (err, file) {
try {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> Entering function.') }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> key = ' + devTeam.codeName + '-' + bot.codeName + '-' + product.codeName) }
switch (err.result) {
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> Received OK Response.') }
break
}
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> Received FAIL Response.') }
return
}
case GLOBAL.CUSTOM_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> Received CUSTOM OK Response.') }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> err.message = ' + err.message) }
return
}
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> Received CUSTOM FAIL Response.') }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> err.message = ' + err.message) }
return
}
default: {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> Received Unexpected Response.') }
return
}
}
maxSequence = Number(file)
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> maxSequence = ' + maxSequence) }
/* Now we will get the sequence of files, but in this case only from the currentMaxSequence and above. */
for (let i = currentMaxSequence; i <= maxSequence; i++) {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> i = ' + i) }
if (pOperationsId !== undefined) {
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, i, undefined, onFileReceived, pOperationsId)
} else {
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, i, undefined, onFileReceived)
}
function onFileReceived (err, file) {
try {
switch (err.result) {
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> Received OK Response.') }
break
}
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> Received FAIL Response.') }
return
}
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> Received CUSTOM FAIL Response.') }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> err.message = ' + err.message) }
return
}
default: {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> Received Unexpected Response.') }
return
}
}
files.set(i, file)
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> File Updated.') }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> i = ' + i) }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> file.length = ' + file.length) }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> filesLoaded = ' + filesLoaded) }
if (i !== currentMaxSequence) {
filesLoaded++
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> filesLoaded = ' + filesLoaded) }
}
if (filesLoaded === maxSequence + 1) {
thisObject.eventHandler.raiseEvent('Files Updated', undefined)
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> Files Updated event Raised.') }
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] updateFiles -> onSequenceFileReceived -> onFileReceived -> err = ' + err) }
}
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] updateFiles -> onSequenceFileReceived -> err = ' + err) }
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] updateFiles -> err = ' + err) }
}
}
function getFile (pSequence) {
if (INFO_LOG === true) { logger.write('[INFO] getFile -> Entering function.') }
if (INFO_LOG === true) { logger.write('[INFO] getFile -> pSequence = ' + pSequence) }
return files.get(pSequence)
}
function getExpectedFiles () {
if (INFO_LOG === true) { logger.write('[INFO] getExpectedFiles -> Entering function.') }
return maxSequence + 1
}
function getFilesLoaded () {
if (INFO_LOG === true) { logger.write('[INFO] getFilesLoaded -> Entering function.') }
return filesLoaded
}
}
-210
View File
@@ -1,210 +0,0 @@

function newMarketFiles () {
const MODULE_NAME = 'Market Files'
const INFO_LOG = false
const ERROR_LOG = true
const logger = newWebDebugLog()
logger.fileName = MODULE_NAME
let thisObject = {
eventHandler: undefined,
getFile: getFile,
getExpectedFiles: getExpectedFiles,
getFilesLoaded: getFilesLoaded,
initialize: initialize,
finalize: finalize
}
let filesLoaded = 0
let fileCloud
let files = new Map()
let market
let exchange
let devTeam
let bot
let thisSet
let periodName
thisObject.eventHandler = newEventHandler()
let intervalHandle
return thisObject
function finalize () {
try {
if (INFO_LOG === true) { logger.write('[INFO] finalize -> Entering function.') }
clearInterval(intervalHandle)
filesLoaded = undefined
files = undefined
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] finalize -> err = ' + err) }
}
}
function initialize (pDevTeam, pBot, pProduct, pSet, pExchange, pMarket, callBackFunction) {
try {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> key = ' + pDevTeam.codeName + '-' + pBot.codeName + '-' + pProduct.codeName) }
exchange = ecosystem.getExchange(pProduct, pExchange)
if (exchange === undefined) {
throw 'Exchange not supoorted by this pProduct of the ecosystem! - pDevTeam.codeName = ' + pDevTeam.codeName + ', pBot.codeName = ' + pBot.codeName + ', pProduct.codeName = ' + pProduct.codeName + ', pExchange = ' + pExchange
}
intervalHandle = setInterval(updateFiles, _10_MINUTES_IN_MILISECONDS)
market = pMarket
devTeam = pDevTeam
bot = pBot
thisSet = pSet
fileCloud = newFileCloud()
fileCloud.initialize(pBot)
/* Now we will get the market files */
for (let i = 0; i < marketFilesPeriods.length; i++) {
let periodTime = marketFilesPeriods[i][0]
let periodName = marketFilesPeriods[i][1]
if (thisSet.validPeriods.includes(periodName) === true) {
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, periodName, undefined, undefined, undefined, onFileReceived)
function onFileReceived (err, file) {
try {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileReceived -> Entering function.') }
switch (err.result) {
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileReceived -> Received OK Response.') }
break
}
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileReceived -> Received FAIL Response.') }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
return
}
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileReceived -> Received CUSTOM FAIL Response.') }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileReceived -> err.message = ' + err.message) }
callBackFunction(err)
return
}
default: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileReceived -> Received Unexpected Response.') }
callBackFunction(err)
return
}
}
files.set(periodTime, file)
filesLoaded++
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, thisObject) // Note that the callback is called for every file loaded.
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onFileReceived -> err = ' + err) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err = ' + err) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
function updateFiles () {
try {
let updateFiles = 0
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> Entering function.') }
/* Now we will get the market files */
for (let i = 0; i < marketFilesPeriods.length; i++) {
let periodTime = marketFilesPeriods[i][0]
let periodName = marketFilesPeriods[i][1]
if (thisSet.validPeriods.includes(periodName) === true) {
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, periodName, undefined, undefined, undefined, onFileReceived)
function onFileReceived (err, file) {
try {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onFileReceived -> Entering function.') }
switch (err.result) {
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onFileReceived -> Received OK Response.') }
break
}
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onFileReceived -> Received FAIL Response.') }
return
}
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onFileReceived -> Received CUSTOM FAIL Response.') }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onFileReceived -> err.message = ' + err.message) }
return
}
default: {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onFileReceived -> Received Unexpected Response.') }
return
}
}
files.set(periodTime, file)
updateFiles++
if (updateFiles === marketFilesPeriods.length) {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onFileReceived -> All files received. ') }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onFileReceived -> devTeam = ' + devTeam.codeName) }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onFileReceived -> bot = ' + bot.codeName) }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onFileReceived -> thisSet = ' + thisSet.codeName) }
thisObject.eventHandler.raiseEvent('Files Updated', undefined)
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] updateFiles -> onFileReceived -> err = ' + err) }
}
}
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] updateFiles -> err = ' + err) }
}
}
function getFile (pPeriod) {
if (INFO_LOG === true) { logger.write('[INFO] getFile -> Entering function.') }
return files.get(pPeriod)
}
function getExpectedFiles () {
if (INFO_LOG === true) { logger.write('[INFO] getExpectedFiles -> Entering function.') }
return marketFilesPeriods.length
}
function getFilesLoaded () {
if (INFO_LOG === true) { logger.write('[INFO] getFilesLoaded -> Entering function.') }
return filesLoaded
}
}
-89
View File
@@ -1,89 +0,0 @@

function newSingleFile () {
const MODULE_NAME = 'Single File'
const INFO_LOG = false
const ERROR_LOG = true
const logger = newWebDebugLog()
logger.fileName = MODULE_NAME
let thisObject = {
getFile: getFile,
initialize: initialize
}
let fileCloud
let file
return thisObject
function initialize (pDevTeam, pBot, pProduct, pSet, pExchange, pMarket, callBackFunction) {
try {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> key = ' + pDevTeam.codeName + '-' + pBot.codeName + '-' + pProduct.codeName) }
let exchange = ecosystem.getExchange(pProduct, pExchange)
if (pExchange !== undefined && exchange === undefined) {
// We support no exchange as a parameter, but if provided, then it must be at the list of exchanges of that product.
throw 'Exchange not supoorted by this pProduct of the ecosystem! - pDevTeam.codeName = ' + pDevTeam.codeName + ', pBot.codeName = ' + pBot.codeName + ', pProduct.codeName = ' + pProduct.codeName + ', pExchange = ' + pExchange
}
fileCloud = newFileCloud()
fileCloud.initialize(pBot)
/* Now we will get the file */
fileCloud.getFile(pDevTeam, pBot, pSet, exchange, pMarket, undefined, undefined, undefined, undefined, onFileReceived)
function onFileReceived (err, pFile) {
try {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileReceived -> Entering function.') }
switch (err.result) {
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileReceived -> Received OK Response.') }
break
}
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileReceived -> Received FAIL Response.') }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
return
}
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileReceived -> Received CUSTOM FAIL Response.') }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileReceived -> err.message = ' + err.message) }
callBackFunction(err)
return
}
default: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileReceived -> Received Unexpected Response.') }
callBackFunction(err)
return
}
}
file = pFile
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE)
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onFileReceived -> err = ' + err) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err = ' + err) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
function getFile () {
if (INFO_LOG === true) { logger.write('[INFO] getFile -> Entering function.') }
return file
}
}
+2 -2
View File
@@ -214,7 +214,7 @@ function newNote () {
if (label !== undefined) {
if (SIZE_PERCENTAGE > 0.9) {
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + ' Saira'
let xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO
let yOffset = (TITLE_BAR_HEIGHT - fontSize) / 2 + 2
@@ -292,7 +292,7 @@ function newNote () {
y: startingPosition.y + (i + 1) * (fontSize * FONT_ASPECT_RATIO + 10)
}
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + ' Saira'
browserCanvasContext.fillStyle = 'rgba(60, 60, 60, ' + ALPHA + ')'
browserCanvasContext.fillText(labelRow, labelPoint.x, labelPoint.y)
}
+3 -3
View File
@@ -278,7 +278,7 @@ function newProfileBall () {
let labelPoint
let fontSize = pFloatingObject.currentFontSize
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + ' Saira'
let label
@@ -290,7 +290,7 @@ function newProfileBall () {
y: pFloatingObject.currentPosition.y - pFloatingObject.currentImageSize / 2 - fontSize * FONT_ASPECT_RATIO - 10
}
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + ' Saira'
browserCanvasContext.fillStyle = pFloatingObject.labelStrokeStyle
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y)
}
@@ -303,7 +303,7 @@ function newProfileBall () {
y: pFloatingObject.currentPosition.y + pFloatingObject.currentImageSize / 2 + fontSize * FONT_ASPECT_RATIO + 15
}
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + ' Saira'
browserCanvasContext.fillStyle = pFloatingObject.labelStrokeStyle
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y)
}
+1 -1
View File
@@ -375,7 +375,7 @@ function newFrame () {
let labelPoint
let fontSize = 10
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + ' Saira'
let label = frame.containerName
+2 -2
View File
@@ -84,7 +84,7 @@ function newPanelTabButton () {
if (tabStatus === 'going down') {
if (transitionPosition.y < hiddenPosition.y) {
transitionPosition.y = transitionPosition.y + 25
transitionPosition.y = transitionPosition.y + 50
thisObject.parentContainer.frame.position.y = transitionPosition.y
} else {
thisObject.parentContainer.frame.position.y = hiddenPosition.y
@@ -93,7 +93,7 @@ function newPanelTabButton () {
}
if (tabStatus === 'going up') {
if (transitionPosition.y > visiblePosition.y) {
transitionPosition.y = transitionPosition.y - 25
transitionPosition.y = transitionPosition.y - 50
thisObject.parentContainer.frame.position.y = transitionPosition.y
} else {
thisObject.parentContainer.frame.position.y = visiblePosition.y
+2
View File
@@ -59,6 +59,8 @@
for (let j = 0; j < devTeam.bots.length; j++) {
let bot = devTeam.bots[j]
if (bot.type !== 'Indicator' && bot.cloneId === undefined) { continue }
if (bot.products !== undefined) {
for (let k = 0; k < bot.products.length; k++) {
let product = bot.products[k]
+3 -10
View File
@@ -37,13 +37,6 @@ function newTimeControlPanel () {
panelTabButton.container.frame.parentFrame = thisObject.container.frame
panelTabButton.initialize()
/* The code from here down might be out of date. */
let buttonPosition
let buttonNames = ['Fast Backwards', 'Play Backwards', 'Step Backwards', 'Pause', 'Step Forward', 'Play Forward', 'Fast Forward']
let lastX = 0
let datetime = INITIAL_DATE
let datetimeDisplay = {
@@ -127,7 +120,7 @@ function newTimeControlPanel () {
labelPoint = thisObject.container.frame.frameThisPoint(labelPoint)
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + ' Saira'
browserCanvasContext.fillStyle = 'rgba(60, 60, 60, 0.50)'
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y)
@@ -144,7 +137,7 @@ function newTimeControlPanel () {
labelPoint = thisObject.container.frame.frameThisPoint(labelPoint)
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + ' Saira'
browserCanvasContext.fillStyle = 'rgba(60, 60, 60, 0.50)'
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y)
@@ -163,7 +156,7 @@ function newTimeControlPanel () {
labelPoint = thisObject.container.frame.frameThisPoint(labelPoint)
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + ' Saira'
browserCanvasContext.fillStyle = 'rgba(60, 60, 60, 0.50)'
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y)
}
+4 -4
View File
@@ -587,7 +587,7 @@
let labelPoint
let fontSize = 10
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + ' Saira'
let label
@@ -602,7 +602,7 @@
labelPoint = thisObject.container.frame.frameThisPoint(labelPoint)
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + ' Saira'
browserCanvasContext.fillStyle = 'rgba(60, 60, 60, 0.50)'
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y)
@@ -617,7 +617,7 @@
labelPoint = thisObject.container.frame.frameThisPoint(labelPoint)
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + ' Saira'
browserCanvasContext.fillStyle = 'rgba(60, 60, 60, 0.50)'
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y)
@@ -639,7 +639,7 @@
labelPoint = thisObject.container.frame.frameThisPoint(labelPoint)
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + ' Saira'
browserCanvasContext.fillStyle = 'rgba(60, 60, 60, 0.50)'
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y)
+16 -13
View File
@@ -25,7 +25,7 @@ function newTopSpace () {
return thisObject
function initialize () {
async function initialize () {
let sharedStatus = {
currentDevTeamIndex: 0,
currentEventIndex: 0,
@@ -36,8 +36,9 @@ function newTopSpace () {
}
thisObject.login = newLogin()
thisObject.login.initialize(sharedStatus, onLoginInitialized)
await thisObject.login.initialize(sharedStatus)
/*
thisObject.companyLogo = newCompanyLogo()
thisObject.endUser = newEndUser()
thisObject.currentBot = newCurrentBot()
@@ -45,18 +46,17 @@ function newTopSpace () {
thisObject.currentStartMode = newCurrentStartMode()
thisObject.currentEvent = newCurrentEvent()
thisObject.devTeam = newDevTeam()
*/
window.canvasApp.eventHandler.listenToEvent('Browser Resized', resize)
function onLoginInitialized () {
thisObject.companyLogo.initialize()
thisObject.endUser.initialize()
thisObject.currentBot.initialize(sharedStatus)
thisObject.currentProcess.initialize(sharedStatus)
thisObject.currentStartMode.initialize(sharedStatus)
thisObject.currentEvent.initialize(sharedStatus)
thisObject.devTeam.initialize(sharedStatus)
}
/*
thisObject.companyLogo.initialize()
thisObject.endUser.initialize()
thisObject.currentBot.initialize(sharedStatus)
thisObject.currentProcess.initialize(sharedStatus)
thisObject.currentStartMode.initialize(sharedStatus)
thisObject.currentEvent.initialize(sharedStatus)
thisObject.devTeam.initialize(sharedStatus)
*/
}
function resize () {
@@ -69,6 +69,7 @@ function newTopSpace () {
function getContainer (point) {
let container
return
container = thisObject.companyLogo.getContainer(point)
if (container !== undefined) { return container }
@@ -103,6 +104,8 @@ function newTopSpace () {
thisObject.container.frame.draw(false, false)
drawBackground()
return
thisObject.companyLogo.draw()
thisObject.endUser.draw()
thisObject.devTeam.draw()
+1
View File
@@ -133,6 +133,7 @@ function newSplashScreen () {
}
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY
browserCanvasContext.font = 'Saira'
browserCanvasContext.fillStyle = 'rgba(0, 0, 0, ' + opacity + ')'
browserCanvasContext.fillText(title, titlePoint.x, titlePoint.y)
}
+3 -1
View File
@@ -28,6 +28,8 @@ function newCurrentBot () {
function initialize (pSharedStatus) {
sharedStatus = pSharedStatus
if (window.USER_PROFILE === undefined) { return }
if (window.USER_PROFILE.devTeams.length === 0) {
window.CURRENT_BOT_DISPLAY_NAME = NOT_FOUND
} else {
@@ -119,7 +121,7 @@ function newCurrentBot () {
thisObject.container.frame.draw(false, false)
let breakpointsHeight = 14
let breakpointsHeight = 0
let fontSize = 12
let label = window.CURRENT_BOT_DISPLAY_NAME
if (label === undefined) { label = '' };
+2 -2
View File
@@ -52,7 +52,7 @@ function newCurrentEvent () {
hackedEcosystem[0].competitions[0].participants.push({
devTeam: participant.clone.team.slug,
bot: participant.clone.bot.slug,
pOperationsId: participant.clone.id,
cloneId: participant.clone.id,
release: '1.0.0'
})
})
@@ -178,7 +178,7 @@ function newCurrentEvent () {
thisObject.container.frame.draw(false, false)
let breakpointsHeight = 14
let breakpointsHeight = 0
let fontSize = 12
let point = {
+1 -1
View File
@@ -111,7 +111,7 @@ function newCurrentProcess () {
thisObject.container.frame.draw(false, false)
let breakpointsHeight = 14
let breakpointsHeight = 0
let fontSize = 12
let label = window.CURRENT_PROCESS
if (label === undefined) { label = '' };
+1 -1
View File
@@ -91,7 +91,7 @@ function newCurrentStartMode () {
thisObject.container.frame.draw(false, false)
let breakpointsHeight = 14
let breakpointsHeight = 0
let fontSize = 12
let label = window.CURRENT_START_MODE + ' Mode'
if (label === 'undefined Mode') { label = '' };
+1 -1
View File
@@ -108,7 +108,7 @@ function newDevTeam () {
thisObject.container.frame.draw(false, false)
let breakpointsHeight = 14
let breakpointsHeight = 0
let fontSize = 12
let point = {
+115 -26
View File
@@ -26,7 +26,7 @@ function newLogin () {
return thisObject
function initialize (pSharedStatus, callBackFunction) {
async function initialize (pSharedStatus) {
const accessToken = window.localStorage.getItem('access_token')
let user = window.localStorage.getItem('user')
@@ -54,7 +54,7 @@ function newLogin () {
connectToDevTools: true
})
const QUERY = Apollo.gql`
const USERS_QUERY = Apollo.gql`
query($authId: String){
users_UserByAuthId (authId: $authId){
id
@@ -81,7 +81,7 @@ function newLogin () {
const getUser = () => {
return new Promise((resolve, reject) => {
apolloClient.query({
query: QUERY,
query: USERS_QUERY,
variables: {
authId: authId
}
@@ -99,6 +99,8 @@ function newLogin () {
})
}
/* Getting all Teams */
const networkInterfaceTeams = Apollo.lib.createNetworkInterface({
uri: window.canvasApp.graphQL.masterAppApiUrl
})
@@ -167,7 +169,7 @@ function newLogin () {
})
}
// Gettings events
/* Gettings All Events */
const networkInterfaceEvents = Apollo.lib.createNetworkInterface({
uri: window.canvasApp.graphQL.masterAppApiUrl
@@ -179,7 +181,7 @@ function newLogin () {
addTypename: false
})
const EVENTS = Apollo.gql`
const EVENTS_QUERY = Apollo.gql`
query events($maxStartDate: Int, $minEndDate: Int){
events_Events(maxStartDate: $maxStartDate, minEndDate: $minEndDate){
id
@@ -207,7 +209,7 @@ function newLogin () {
var twoWeeksAgoSeconds = nowSeconds - 1209600
return new Promise((resolve, reject) => {
apolloClientEvents.query({
query: EVENTS,
query: EVENTS_QUERY,
variables: { maxStartDate: nowSeconds, minEndDate: twoWeeksAgoSeconds }
})
.then(response => {
@@ -230,45 +232,132 @@ function newLogin () {
})
}
/* Getting all Clones */
const networkInterfaceClones = Apollo.lib.createNetworkInterface({
uri: window.canvasApp.graphQL.masterAppApiUrl
})
networkInterfaceClones.use([{
applyMiddleware (req, next) {
req.options.headers = {
authorization: `Bearer ${accessToken}`
}
next()
}
}])
const apolloClientClones = new Apollo.lib.ApolloClient({
networkInterface: networkInterfaceClones,
connectToDevTools: true
})
const CLONES_QUERY = Apollo.gql`
query Operations_Clones{
operations_Clones {
id
authId
teamId
botId
mode
resumeExecution
beginDatetime
endDatetime
waitTime
state
stateDatetime
createDatetime
lastLogs
runAsTeam
summaryDate
buyAverage
sellAverage
marketRate
combinedProfitsA
combinedProfitsB
assetA
assetB
botType
teamName
botName
botAvatar
teamAvatar
processName
keyId
botSlug
}
}
`
const getClones = () => {
return new Promise((resolve, reject) => {
apolloClientClones.query({
query: CLONES_QUERY
})
.then(response => {
window.localStorage.setItem('userClones', JSON.stringify(response.data.operations_Clones))
let clones = response.data.operations_Clones
for (let i = 0; i < clones.length; i++) {
let clone = clones[i]
if (clone.botType === 'Trading') {
let teamSlug = clone.teamName.toLowerCase()
teamSlug = teamSlug.replace(' ', '-')
let devTeam = ecosystem.getTeam(teamSlug)
let bot = ecosystem.getBot(devTeam, clone.botSlug)
if (bot !== undefined) {
bot.cloneId = clone.id
}
}
}
resolve({ clones: response.data.operations_Clones})
})
.catch(error => {
console.log('apolloClient error getting user clones', error)
reject(error)
})
})
}
// To avoid race conditions, add asynchronous fetches to array
let fetchDataPromises = []
fetchDataPromises.push(getUser(), getTeamByOwner(), getCurrentEvents())
fetchDataPromises.push(getUser(), getTeamByOwner(), getCurrentEvents(), getClones(), authenticateUser())
// When all asynchronous fetches resolve, authenticate user or throw error.
Promise.all(fetchDataPromises).then(result => {
/* this is the time to authenticate the user at AAWeb */
await Promise.all(fetchDataPromises).then(result => {
authenticateUser()
}, err => {
console.error('fetchData error', err)
console.error('[ERROR] Login -> GraphQL Fetch Error -> err = ', err)
})
thisObject.container.eventHandler.listenToEvent('onMouseClick', onClick)
function authenticateUser () {
async function authenticateUser () {
if (sessionToken === undefined) { sessionToken = '' }
let path = window.canvasApp.urlPrefix + 'AABrowserAPI/authenticateUser/' + sessionToken
callServer(undefined, path, onServerReponded)
return new Promise(
function (resolve, reject) {
callServer(undefined, path, (result) => {
let responseFromServer = JSON.parse(result)
function onServerReponded (pResponseFromServer) {
let responseFromServer = JSON.parse(pResponseFromServer)
err = responseFromServer.err
err = responseFromServer.err
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
console.log('Please make sure you create a new team!')
reject(err)
}
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
console.log('Please make sure you create a new team!')
return
}
window.USER_PROFILE = responseFromServer.userProfile
window.localStorage.setItem('sessionToken', sessionToken)
window.USER_PROFILE = responseFromServer.userProfile
window.localStorage.setItem('sessionToken', sessionToken)
currentLabel = 'Logged In'
callBackFunction()
}
currentLabel = 'Logged In'
resolve()
})
}
)
}
}