function newFileCache() { let fileCache = { getFile: getFile, initialize: initialize } let fileCloud; let files = new Map; let datetime; return fileCache; function initialize(pTeamCodeName, pBotCodeName, pProductCodeName, pLayerCodeName, pExchange, pMarket, callBackFunction) { let product = ecosystem.getProduct(ecosystem.getBot(ecosystem.getTeam(pTeamCodeName), pBotCodeName), pProductCodeName); if (product === undefined) { throw "Product not found at this bot of the ecosystem! - pTeamCodeName = " + pTeamCodeName + ", pBotCodeName = " + pBotCodeName + ", pProductCodeName = " + pProductCodeName; } let exchange = ecosystem.getExchange(product, pExchange); if (exchange === undefined) { throw "Exchange not supoorted by this product of the ecosystem! - pTeamCodeName = " + pTeamCodeName + ", pBotCodeName = " + pBotCodeName + ", pProductCodeName = " + pProductCodeName + ", pExchange = " + pExchange; } let layer = ecosystem.getLayer(product, pLayerCodeName); if (layer === undefined) { throw "Layer not found at this product of the ecosystem! - pTeamCodeName = " + pTeamCodeName + ", pBotCodeName = " + pBotCodeName + ", pProductCodeName = " + pProductCodeName + ", pLayerCodeName = " + pLayerCodeName; } fileCloud = newFileCloud(); fileCloud.initialize(pTeamCodeName, pBotCodeName); /* Now we will get the market files */ for (i = 0; i < marketFilesPeriods.length; i++) { let periodTime = marketFilesPeriods[i][0]; let periodName = marketFilesPeriods[i][1]; if (layer.validPeriods.includes(periodName) === true) { fileCloud.getFile(product, exchange, pMarket, periodName, undefined, onFileReceived); function onFileReceived(file) { files.set(periodTime, file); callBackFunction(); // Note that the call back is called for every file loaded. } } } } function getFile(pPeriod) { return files.get(pPeriod); } }