diff --git a/src/DailyFiles.js b/src/DailyFiles.js index faf199ce8..55cb27de9 100644 --- a/src/DailyFiles.js +++ b/src/DailyFiles.js @@ -45,14 +45,14 @@ function newDailyFiles () { } } - function initialize (pDataMine, pBot, pSession, pProduct, pDataset, pExchange, pMarket, pDatetime, pTimeFrame, callBackFunction) { + function initialize (pDataMine, pBot, pSession, pProduct, pDataset, pExchange, pMarket, pDatetime, pTimeFrame, pHost, pPort, pEventsServerClient, callBackFunction) { try { callBackWhenFileReceived = callBackFunction let exchange = pExchange fileCloud = newFileCloud() - fileCloud.initialize(pBot) + fileCloud.initialize(pBot, pHost, pPort) /* Some Validations */ if (pDataset.code.validTimeFrames === undefined) { @@ -114,7 +114,7 @@ function newDailyFiles () { if (pDataset.code.validTimeFrames.includes(periodName) === true) { let fileCursor = newFileCursor() fileCursor.eventHandler = thisObject.eventHandler // We share our event handler with each file cursor, so that they can raise events there when files are changed.s - fileCursor.initialize(fileCloud, pDataMine, pBot, pSession, pProduct, pDataset, exchange, pMarket, periodName, periodTime, pDatetime, pTimeFrame, beginDateRange, endDateRange, onInitialized) + fileCursor.initialize(fileCloud, pDataMine, pBot, pSession, pProduct, pDataset, exchange, pMarket, periodName, periodTime, pDatetime, pTimeFrame, beginDateRange, endDateRange, pEventsServerClient, onInitialized) function onInitialized (err) { try { switch (err.result) { diff --git a/src/FileCloud.js b/src/FileCloud.js index 4ee129964..051705797 100644 --- a/src/FileCloud.js +++ b/src/FileCloud.js @@ -17,12 +17,12 @@ function newFileCloud () { initialize: initialize } - let blobService + let fileStorage return thisObject - function initialize (pBot) { - blobService = newFileStorage() + function initialize (pBot, pHost, pPort) { + fileStorage = newFileStorage(pHost, pPort) } function getFile (pDataMine, pBot, pSession, pProduct, pDataset, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction) { @@ -121,7 +121,7 @@ function newFileCloud () { if (INFO_LOG === true) { logger.write('[INFO] getFile -> getFileRecursively -> filePath = ' + filePath) } if (INFO_LOG === true) { logger.write('[INFO] getFile -> getFileRecursively -> fileName = ' + fileName) } - blobService.getBlobToText(filePath + '/' + fileName, undefined, onFileReceived) + fileStorage.getFileFromHost(filePath + '/' + fileName, onFileReceived) function onFileReceived (err, text, response) { try { diff --git a/src/FileCursor.js b/src/FileCursor.js index 88c1463e1..29ddb900e 100644 --- a/src/FileCursor.js +++ b/src/FileCursor.js @@ -34,6 +34,7 @@ function newFileCursor () { let timeFrame let beginDateRange let endDateRange + let eventsServerClient let finalized = false @@ -61,6 +62,7 @@ function newFileCursor () { timeFrame = undefined beginDateRange = undefined endDateRange = undefined + eventsServerClient = undefined thisObject.files = undefined cursorDate = undefined @@ -73,7 +75,23 @@ function newFileCursor () { } } - function initialize (pFileCloud, pDataMine, pBot, pSession, pProduct, pDataset, pExchange, pMarket, pPeriodName, pTimeFrame, pCursorDate, pCurrentTimeFrame, pBeginDateRange, pEndDateRange, callBackFunction) { + function initialize ( + pFileCloud, + pDataMine, + pBot, + pSession, + pProduct, + pDataset, + pExchange, + pMarket, + pPeriodName, + pTimeFrame, + pCursorDate, + pCurrentTimeFrame, + pBeginDateRange, + pEndDateRange, + pEventsServerClient, + callBackFunction) { try { market = pMarket exchange = pExchange @@ -88,6 +106,7 @@ function newFileCursor () { timeFrame = pTimeFrame beginDateRange = pBeginDateRange endDateRange = pEndDateRange + eventsServerClient = pEventsServerClient let key = dataMine.code.codeName + '-' + bot.code.codeName + '-' + product.code.codeName + '-' + dataset.code.codeName + '-' + exchange.name + '-' + market.baseAsset + '/' + market.quotedAsset let callerId = key + '-' + periodName + newUniqueId() diff --git a/src/FileSequence.js b/src/FileSequence.js index feedf0b32..f14de19f4 100644 --- a/src/FileSequence.js +++ b/src/FileSequence.js @@ -32,6 +32,7 @@ function newFileSequence () { let eventSubscriptionIdDatasetUpdated let callerId + let eventsServerClient return thisObject @@ -52,6 +53,7 @@ function newFileSequence () { session = undefined dataset = undefined product = undefined + eventsServerClient = undefined finalized = true } catch (err) { @@ -59,7 +61,18 @@ function newFileSequence () { } } - function initialize (pDataMine, pBot, pSession, pProduct, pDataset, pExchange, pMarket, callBackFunction) { + function initialize ( + pDataMine, + pBot, + pSession, + pProduct, + pDataset, + pExchange, + pMarket, + pHost, + pPort, + pEventsServerClient, + callBackFunction) { try { exchange = pExchange market = pMarket @@ -68,9 +81,10 @@ function newFileSequence () { session = pSession dataset = pDataset product = pProduct + eventsServerClient = pEventsServerClient fileCloud = newFileCloud() - fileCloud.initialize(bot) + fileCloud.initialize(bot, pHost, pPort) callerId = newUniqueId() diff --git a/src/FileStorage.js b/src/FileStorage.js index bdd833546..ee85468b0 100644 --- a/src/FileStorage.js +++ b/src/FileStorage.js @@ -1,4 +1,4 @@ -function newFileStorage () { +function newFileStorage (host, port) { const MODULE_NAME = 'File Storage' const INFO_LOG = false const logger = newWebDebugLog() @@ -24,20 +24,28 @@ function newFileStorage () { ] let thisObject = { - getBlobToText: getBlobToText + getFileFromHost: getFileFromHost } + if (host === '' || host === undefined) { host = 'localhost' } + if (port === '' || port === undefined) { port = '34247' } + return thisObject - async function getBlobToText (filePath, host, callBackFunction, pathComplete) { + async function getFileFromHost (filePath, callBackFunction, pathComplete) { try { - if (INFO_LOG === true) { logger.write('[INFO] getBlobToText -> Entering function.') } + if (INFO_LOG === true) { logger.write('[INFO] getFileFromHost -> Entering function.') } let folder = '' if (pathComplete === false || pathComplete === undefined) { folder = 'Storage/' } - callServer(undefined, folder + filePath, (response, fileContent) => { + let url = folder + filePath + if (host !== undefined) { + url = 'http://' + host + ':' + port + '/' + folder + filePath + } + + callServer(undefined, url, (response, fileContent) => { if (response.result === GLOBAL.DEFAULT_OK_RESPONSE.result) { callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, fileContent) } else { @@ -48,7 +56,7 @@ function newFileStorage () { if (verifyRetry(err.code) && currentRetry < MAX_RETRY) { currentRetry++ if (INFO_LOG === true) { console.log('[INFO] getTextFile -> Retrying connection to the server because received error: ' + err.code + '. Retry #: ' + currentRetry) } - getBlobToText(filePath, host, callBackFunction) + getFileFromHost(filePath, callBackFunction) } else if (err.message === 'Request aborted') { let err = { code: 'The specified key does not exist.' } callBackFunction(err) diff --git a/src/MarketFiles.js b/src/MarketFiles.js index ec1a45ee2..666389d08 100644 --- a/src/MarketFiles.js +++ b/src/MarketFiles.js @@ -37,6 +37,7 @@ function newMarketFiles () { let finalized = false let eventSubscriptionIdDatasetUpdated = [] + let eventsServerClient return thisObject @@ -60,6 +61,7 @@ function newMarketFiles () { dataset = undefined product = undefined periodName = undefined + eventsServerClient = undefined finalized = true } catch (err) { @@ -67,7 +69,18 @@ function newMarketFiles () { } } - function initialize (pDataMine, pBot, pSession, pProduct, pDataset, pExchange, pMarket, callBackFunction) { + function initialize ( + pDataMine, + pBot, + pSession, + pProduct, + pDataset, + pExchange, + pMarket, + pHost, + pPort, + pEventsServerClient, + callBackFunction) { try { exchange = pExchange market = pMarket @@ -76,9 +89,10 @@ function newMarketFiles () { session = pSession dataset = pDataset product = pProduct + eventsServerClient = pEventsServerClient fileCloud = newFileCloud() - fileCloud.initialize(pBot) + fileCloud.initialize(pBot, pHost, pPort) /* Some Validations */ if (dataset.code.validTimeFrames === undefined) { diff --git a/src/SingleFile.js b/src/SingleFile.js index ba9971e6f..17d2542de 100644 --- a/src/SingleFile.js +++ b/src/SingleFile.js @@ -16,7 +16,18 @@ function newSingleFile () { return thisObject - function initialize (pDataMine, pBot, pSession, pProduct, pDataset, pExchange, pMarket, callBackFunction) { + function initialize ( + pDataMine, + pBot, + pSession, + pProduct, + pDataset, + pExchange, + pMarket, + pHost, + pPort, + pEventsServerClient, + callBackFunction) { try { if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') } if (INFO_LOG === true) { logger.write('[INFO] initialize -> key = ' + pDataMine.code.codeName + '-' + pBot.code.codeName + '-' + pProduct.code.codeName) } @@ -24,7 +35,7 @@ function newSingleFile () { let exchange = pExchange fileCloud = newFileCloud() - fileCloud.initialize(pBot) + fileCloud.initialize(pBot, pHost, pPort) /* Now we will get the file */