diff --git a/.vs/AACloudPlatform/v15/.suo b/.vs/AACloudPlatform/v15/.suo index 88ddd4ad7..73b8b3324 100644 Binary files a/.vs/AACloudPlatform/v15/.suo and b/.vs/AACloudPlatform/v15/.suo differ diff --git a/Assistant.js b/Assistant.js index 00584fab5..169a7c3cc 100644 --- a/Assistant.js +++ b/Assistant.js @@ -10,7 +10,7 @@ const MODULE_NAME = "Assistant"; - thisObject = { + let thisObject = { initialize: initialize, putPositionAtExchange: putPositionAtExchange, movePositionAtExchange: movePositionAtExchange @@ -30,7 +30,7 @@ return thisObject; - function initialize(pProcessDatetime, pBotContext, pExchangeAPI, callBackFunction) { + function initialize(pBotContext, pExchangeAPI, callBackFunction) { try { diff --git a/Context.js b/Context.js index fd13398b9..4a5662d24 100644 --- a/Context.js +++ b/Context.js @@ -31,7 +31,7 @@ */ - thisObject = { + let thisObject = { statusReport: undefined, // Here is the information that defines which was the last sucessfull execution and some other details. executionHistory: [], // This is the record of bot execution. executionContext: undefined, // Here is the business information of the last execution of this bot process. @@ -140,7 +140,7 @@ if (FULL_LOG === true) { logger.write("[INFO] initialize -> getStatusReport -> Entering function."); } let fileName = "Status.Report.json" - let filePath = bot.devTeam + "/" + bot.codeName + "/" + bot.version + "/" + bot.dataSetVersion + "/Processes/" + bot.process + "/" + global.EXCHANGE_NAME; + let filePath = bot.devTeam + "/" + bot.codeName + "/" + bot.dataSetVersion + "/Processes/" + bot.process + "/" + global.EXCHANGE_NAME; cloudStorage.getTextFile(filePath, fileName, onFileReceived); @@ -194,7 +194,7 @@ if (FULL_LOG === true) { logger.write("[INFO] initialize -> getExecutionHistory -> Entering function."); } let fileName = "Execution.History.json" - let filePath = bot.devTeam + "/" + bot.codeName + "/" + bot.version + "/" + bot.dataSetVersion + "/Output/" + bot.process + "/" + global.EXCHANGE_NAME; + let filePath = bot.devTeam + "/" + bot.codeName + "/" + bot.dataSetVersion + "/Output/" + bot.process + "/" + global.EXCHANGE_NAME; cloudStorage.getTextFile(filePath, fileName, onFileReceived); @@ -245,7 +245,7 @@ let fileName = "Execution.Context.json" let dateForPath = date.getUTCFullYear() + '/' + utilities.pad(date.getUTCMonth() + 1, 2) + '/' + utilities.pad(date.getUTCDate(), 2) + '/' + utilities.pad(date.getUTCHours(), 2) + '/' + utilities.pad(date.getUTCMinutes(), 2); - let filePath = bot.devTeam + "/" + bot.codeName + "/" + bot.version + "/" + bot.dataSetVersion + "/Output/" + bot.process + "/" + global.EXCHANGE_NAME + "/" + dateForPath; + let filePath = bot.devTeam + "/" + bot.codeName + "/" + bot.dataSetVersion + "/Output/" + bot.process + "/" + global.EXCHANGE_NAME + "/" + dateForPath; cloudStorage.getTextFile(filePath, fileName, onFileReceived); @@ -299,6 +299,8 @@ */ + thisObject.statusReport = {}; + thisObject.executionHistory = []; thisObject.executionContext = { @@ -374,7 +376,7 @@ let fileName = "Execution.Context.json" let dateForPath = global.processDatetime.getUTCFullYear() + '/' + utilities.pad(global.processDatetime.getUTCMonth() + 1, 2) + '/' + utilities.pad(global.processDatetime.getUTCDate(), 2) + '/' + utilities.pad(global.processDatetime.getUTCHours(), 2) + '/' + utilities.pad(global.processDatetime.getUTCMinutes(), 2); - let filePath = bot.devTeam + "/" + bot.codeName + "/" + bot.version + "/" + bot.dataSetVersion + "/Output/" + bot.process + "/" + global.EXCHANGE_NAME + "/" + dateForPath; + let filePath = bot.devTeam + "/" + bot.codeName + "/" + bot.dataSetVersion + "/Output/" + bot.process + "/" + global.EXCHANGE_NAME + "/" + dateForPath; utilities.createFolderIfNeeded(filePath, cloudStorage, onFolderCreated); @@ -429,7 +431,7 @@ try { let fileName = "Execution.History.json" - let filePath = bot.devTeam + "/" + bot.codeName + "/" + bot.version + "/" + bot.dataSetVersion + "/Output/" + bot.process + "/" + global.EXCHANGE_NAME; + let filePath = bot.devTeam + "/" + bot.codeName + "/" + bot.dataSetVersion + "/Output/" + bot.process + "/" + global.EXCHANGE_NAME; utilities.createFolderIfNeeded(filePath, cloudStorage, onFolderCreated); @@ -444,11 +446,11 @@ } let newRecord = [ - newHistoryRecord.date.valueOf(), - newHistoryRecord.rate, - newHistoryRecord.newPositions, - newHistoryRecord.newTrades, - newHistoryRecord.movedPositions + thisObject.newHistoryRecord.date.valueOf(), + thisObject.newHistoryRecord.rate, + thisObject.newHistoryRecord.newPositions, + thisObject.newHistoryRecord.newTrades, + thisObject.newHistoryRecord.movedPositions ]; thisObject.executionHistory.push(newRecord); @@ -494,7 +496,7 @@ try { let fileName = "Status.Report.json" - let filePath = bot.devTeam + "/" + bot.codeName + "/" + bot.version + "/" + bot.dataSetVersion + "/Processes/" + bot.process + "/" + global.EXCHANGE_NAME; + let filePath = bot.devTeam + "/" + bot.codeName + "/" + bot.dataSetVersion + "/Processes/" + bot.process + "/" + global.EXCHANGE_NAME; utilities.createFolderIfNeeded(filePath, cloudStorage, onFolderCreated); diff --git a/Datasource.js b/Datasource.js index 2b1d598f3..015307ec7 100644 --- a/Datasource.js +++ b/Datasource.js @@ -10,7 +10,7 @@ const MODULE_NAME = "Datasource"; - thisObject = { + let thisObject = { initialize: initialize, candlesFiles: new Map, // Complete sets of candles for different Time Periods. For Time Periods < 1hs sets are of current day only, otherwise whole market. candlesMap: new Map, // The last 10 candles for each Time Period will be stored here. @@ -24,35 +24,6 @@ logger.fileName = MODULE_NAME; logger.bot = bot; - let marketFilesPeriods = - '[' + - '[' + 24 * 60 * 60 * 1000 + ',' + '"24-hs"' + ']' + ',' + - '[' + 12 * 60 * 60 * 1000 + ',' + '"12-hs"' + ']' + ',' + - '[' + 8 * 60 * 60 * 1000 + ',' + '"08-hs"' + ']' + ',' + - '[' + 6 * 60 * 60 * 1000 + ',' + '"06-hs"' + ']' + ',' + - '[' + 4 * 60 * 60 * 1000 + ',' + '"04-hs"' + ']' + ',' + - '[' + 3 * 60 * 60 * 1000 + ',' + '"03-hs"' + ']' + ',' + - '[' + 2 * 60 * 60 * 1000 + ',' + '"02-hs"' + ']' + ',' + - '[' + 1 * 60 * 60 * 1000 + ',' + '"01-hs"' + ']' + ']'; - - marketFilesPeriods = JSON.parse(marketFilesPeriods); - - let dailyFilePeriods = - '[' + - '[' + 45 * 60 * 1000 + ',' + '"45-min"' + ']' + ',' + - '[' + 40 * 60 * 1000 + ',' + '"40-min"' + ']' + ',' + - '[' + 30 * 60 * 1000 + ',' + '"30-min"' + ']' + ',' + - '[' + 20 * 60 * 1000 + ',' + '"20-min"' + ']' + ',' + - '[' + 15 * 60 * 1000 + ',' + '"15-min"' + ']' + ',' + - '[' + 10 * 60 * 1000 + ',' + '"10-min"' + ']' + ',' + - '[' + 05 * 60 * 1000 + ',' + '"05-min"' + ']' + ',' + - '[' + 04 * 60 * 1000 + ',' + '"04-min"' + ']' + ',' + - '[' + 03 * 60 * 1000 + ',' + '"03-min"' + ']' + ',' + - '[' + 02 * 60 * 1000 + ',' + '"02-min"' + ']' + ',' + - '[' + 01 * 60 * 1000 + ',' + '"01-min"' + ']' + ']'; - - dailyFilePeriods = JSON.parse(dailyFilePeriods); - let oliviaAzureFileStorage = FILE_STORAGE.newAzureFileStorage(bot); let tomAzureFileStorage = FILE_STORAGE.newAzureFileStorage(bot); @@ -148,10 +119,10 @@ let filesOk = 0; let filesNotOk = 0; - for (i = 0; i < marketFilesPeriods.length; i++) { + for (i = 0; i < global.marketFilesPeriods.length; i++) { - let periodTime = marketFilesPeriods[i][0]; - let periodName = marketFilesPeriods[i][1]; + let periodTime = global.marketFilesPeriods[i][0]; + let periodName = global.marketFilesPeriods[i][1]; getFile(oliviaAzureFileStorage, "@AssetA_@AssetB.json", "@Exchange/Output/Candles/Multi-Period-Market/@Period", periodName, undefined, onFileReceived, callBack); @@ -164,9 +135,9 @@ filesNotOk++; } - if (filesOk + filesNotOk === marketFilesPeriods.length) { + if (filesOk + filesNotOk === global.marketFilesPeriods.length) { - if (filesOk === marketFilesPeriods.length) { + if (filesOk === global.marketFilesPeriods.length) { getDailyFiles(); @@ -192,10 +163,10 @@ let filesOk = 0; let filesNotOk = 0; - for (i = 0; i < dailyFilePeriods.length; i++) { + for (i = 0; i < global.dailyFilePeriods.length; i++) { - let periodTime = dailyFilePeriods[i][0]; - let periodName = dailyFilePeriods[i][1]; + let periodTime = global.dailyFilePeriods[i][0]; + let periodName = global.dailyFilePeriods[i][1]; getFile(oliviaAzureFileStorage, "@AssetA_@AssetB.json", "@Exchange/Output/Candles/Multi-Period-Daily/@Period/@Year/@Month/@Day", periodName, global.processDatetime, onFileReceived, callBack); @@ -208,9 +179,9 @@ filesNotOk++; } - if (filesOk + filesNotOk === dailyFilePeriods.length) { + if (filesOk + filesNotOk === global.dailyFilePeriods.length) { - if (filesOk === dailyFilePeriods.length) { + if (filesOk === global.dailyFilePeriods.length) { getCandlesWeAreIn(); @@ -317,10 +288,10 @@ let filesOk = 0; let filesNotOk = 0; - for (i = 0; i < marketFilesPeriods.length; i++) { + for (i = 0; i < global.marketFilesPeriods.length; i++) { - let periodTime = marketFilesPeriods[i][0]; - let periodName = marketFilesPeriods[i][1]; + let periodTime = global.marketFilesPeriods[i][0]; + let periodName = global.marketFilesPeriods[i][1]; getFile(tomAzureFileStorage, "@AssetA_@AssetB.json", "@Exchange/Tom/dataSet.V1/Output/Candle-Stairs/Multi-Period-Market/@Period", periodName, undefined, onFileReceived, callBack); @@ -333,9 +304,9 @@ filesNotOk++; } - if (filesOk + filesNotOk === marketFilesPeriods.length) { + if (filesOk + filesNotOk === global.marketFilesPeriods.length) { - if (filesOk === marketFilesPeriods.length) { + if (filesOk === global.marketFilesPeriods.length) { getDailyFiles(); @@ -361,10 +332,10 @@ let filesOk = 0; let filesNotOk = 0; - for (i = 0; i < dailyFilePeriods.length; i++) { + for (i = 0; i < global.dailyFilePeriods.length; i++) { - let periodTime = dailyFilePeriods[i][0]; - let periodName = dailyFilePeriods[i][1]; + let periodTime = global.dailyFilePeriods[i][0]; + let periodName = global.dailyFilePeriods[i][1]; getFile(tomAzureFileStorage, "@AssetA_@AssetB.json", "@Exchange/Tom/dataSet.V1/Output/Candle-Stairs/Multi-Period-Daily/@Period/@Year/@Month/@Day", periodName, global.processDatetime, onFileReceived, callBack); @@ -377,9 +348,9 @@ filesNotOk++; } - if (filesOk + filesNotOk === dailyFilePeriods.length) { + if (filesOk + filesNotOk === global.dailyFilePeriods.length) { - if (filesOk === dailyFilePeriods.length) { + if (filesOk === global.dailyFilePeriods.length) { getStairsWeAreIn(); diff --git a/ExchangeAPI.js b/ExchangeAPI.js index 377d1ecc7..b94f505d5 100644 --- a/ExchangeAPI.js +++ b/ExchangeAPI.js @@ -10,7 +10,7 @@ const MODULE_NAME = "Exchange API"; - thisObject = { + let thisObject = { initialize: initialize, getOpenPositions: getOpenPositions, getExecutedTrades: getExecutedTrades, @@ -136,7 +136,7 @@ exchangePositions.push(openPosition); } - callBackFunction(null, exchangePositions); + callBackFunction(global.DEFAULT_OK_RESPONSE, exchangePositions); } } catch (err) { @@ -229,7 +229,7 @@ trades.push(trade); } - callBackFunction(null, trades); + callBackFunction(global.DEFAULT_OK_RESPONSE, trades); } } catch (err) { @@ -316,7 +316,7 @@ */ - callBackFunction(null, exchangeResponse.orderNumber); + callBackFunction(global.DEFAULT_OK_RESPONSE, exchangeResponse.orderNumber); } } catch (err) { @@ -331,7 +331,7 @@ } } - function movePosition(pPosition, pNewRate) { + function movePosition(pPosition, pNewRate, callBackFunction) { try { @@ -397,7 +397,7 @@ */ - callBackFunction(null, exchangeResponse.orderNumber); + callBackFunction(global.DEFAULT_OK_RESPONSE, exchangeResponse.orderNumber); } } catch (err) { diff --git a/Run.js b/Run.js index d6c2a999b..6a05124b2 100644 --- a/Run.js +++ b/Run.js @@ -92,8 +92,41 @@ global.MARKET = { assetB: "BTC", }; +/* Currently only one exchange is supported. */ + global.EXCHANGE_NAME = "Poloniex"; +/* Time Periods Definitions. */ + +global.marketFilesPeriods = + '[' + + '[' + 24 * 60 * 60 * 1000 + ',' + '"24-hs"' + ']' + ',' + + '[' + 12 * 60 * 60 * 1000 + ',' + '"12-hs"' + ']' + ',' + + '[' + 8 * 60 * 60 * 1000 + ',' + '"08-hs"' + ']' + ',' + + '[' + 6 * 60 * 60 * 1000 + ',' + '"06-hs"' + ']' + ',' + + '[' + 4 * 60 * 60 * 1000 + ',' + '"04-hs"' + ']' + ',' + + '[' + 3 * 60 * 60 * 1000 + ',' + '"03-hs"' + ']' + ',' + + '[' + 2 * 60 * 60 * 1000 + ',' + '"02-hs"' + ']' + ',' + + '[' + 1 * 60 * 60 * 1000 + ',' + '"01-hs"' + ']' + ']'; + +global.marketFilesPeriods = JSON.parse(global.marketFilesPeriods); + +global.dailyFilePeriods = + '[' + + '[' + 45 * 60 * 1000 + ',' + '"45-min"' + ']' + ',' + + '[' + 40 * 60 * 1000 + ',' + '"40-min"' + ']' + ',' + + '[' + 30 * 60 * 1000 + ',' + '"30-min"' + ']' + ',' + + '[' + 20 * 60 * 1000 + ',' + '"20-min"' + ']' + ',' + + '[' + 15 * 60 * 1000 + ',' + '"15-min"' + ']' + ',' + + '[' + 10 * 60 * 1000 + ',' + '"10-min"' + ']' + ',' + + '[' + 05 * 60 * 1000 + ',' + '"05-min"' + ']' + ',' + + '[' + 04 * 60 * 1000 + ',' + '"04-min"' + ']' + ',' + + '[' + 03 * 60 * 1000 + ',' + '"03-min"' + ']' + ',' + + '[' + 02 * 60 * 1000 + ',' + '"02-min"' + ']' + ',' + + '[' + 01 * 60 * 1000 + ',' + '"01-min"' + ']' + ']'; + +global.dailyFilePeriods = JSON.parse(global.dailyFilePeriods); + const START_ALL_MONTHS = false; diff --git a/Trading Bot Main Loop.js b/Trading Bot Main Loop.js index eb9d0fd1a..46843cf90 100644 --- a/Trading Bot Main Loop.js +++ b/Trading Bot Main Loop.js @@ -13,7 +13,7 @@ logger.fileName = MODULE_NAME; logger.bot = bot; - thisObject = { + let thisObject = { initialize: initialize, run: run }; @@ -254,7 +254,7 @@ if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> startUserBot -> Entering function."); } - usertBot.run(platform, onFinished); + usertBot.start(onFinished); function onFinished(err) { diff --git a/Utilities.js b/Utilities.js index 2c3dca56b..1f98a896b 100644 --- a/Utilities.js +++ b/Utilities.js @@ -54,7 +54,7 @@ exports.newUtilities = function newUtilities(BOT) { if (i === splittedPath.length) { - callBackFunction(); + callBackFunction(global.DEFAULT_OK_RESPONSE); } else {