From 0f61eb0320a3ef7a3a16d3e21a12e13d5376cd11 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 16 Feb 2018 12:44:43 +0100 Subject: [PATCH] Ready to run from the AACloudPlatform --- .vs/AACharly/v15/.suo | Bin 37888 -> 52736 bytes AACharly.njsproj | 16 +- AACharly.sln | 2 +- Azure File Storage.js | 247 ----------- Azure Web Job Shutdown.js | 41 -- Debug Log.js | 144 ------- Markets.js | 252 ----------- Poloniex API Client.js | 406 ------------------ Poloniex-Historic-Trades/Interval.js | 11 +- .../Poloniex Historic Trades.js | 169 -------- Poloniex-Historic-Trades/run.js | 97 ----- Poloniex-Hole-Fixing/Interval.js | 9 +- Poloniex-Hole-Fixing/Poloniex Hole Fixing.js | 169 -------- Poloniex-Hole-Fixing/run.js | 97 ----- Poloniex-Live-Trades/Interval.js | 13 +- Poloniex-Live-Trades/Poloniex Live Trades.js | 106 ----- Poloniex-Live-Trades/run.js | 57 --- Utilities.js | 81 ---- logs/Dummy File.txt | 0 this.bot.config.json | 76 ++++ 20 files changed, 86 insertions(+), 1907 deletions(-) delete mode 100644 Azure File Storage.js delete mode 100644 Azure Web Job Shutdown.js delete mode 100644 Debug Log.js delete mode 100644 Markets.js delete mode 100644 Poloniex API Client.js delete mode 100644 Poloniex-Historic-Trades/Poloniex Historic Trades.js delete mode 100644 Poloniex-Historic-Trades/run.js delete mode 100644 Poloniex-Hole-Fixing/Poloniex Hole Fixing.js delete mode 100644 Poloniex-Hole-Fixing/run.js delete mode 100644 Poloniex-Live-Trades/Poloniex Live Trades.js delete mode 100644 Poloniex-Live-Trades/run.js delete mode 100644 Utilities.js delete mode 100644 logs/Dummy File.txt create mode 100644 this.bot.config.json diff --git a/.vs/AACharly/v15/.suo b/.vs/AACharly/v15/.suo index 93e438b644617c88ae67c15b7859de0c9fa5e948..a1a83b56e3e57d5c91f69f980736ecbdaf6f4ab8 100644 GIT binary patch literal 52736 zcmeHQ37i~NnXgF#B%BfOtRND$IJ-P3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v;W09aQz%@#uCufuiLC1U*>F(Zb=dOY zKU+2#TP2_5m!6Pn>GYZ$3am||w6*yZURz?(E?|)ssY!YRdClJdYLW{&*JcxX{Ca|I zVJbOXO$8mc(EevW5{a2ul2>J{q7oTXZ99nbxLxsFUf~(NelNdn!G!X)wKc#fVcY zJGHXY<`wkj_5!9+%~$r&=u|_X1KZM4v?#_tfJ4r8?YlD4uk?Iz)9P9}_FN7xV7}H3 zSB~JswyG&z9IM*$!~0_+&MsCb8cpoY9(WK8_{`)Svd7>51)tm!ecF{xt-WRnciE}+ zEwe}^(fuCDy_*i@R|=zGIjh1$_L5JPvz4sQ*A?yDkEZmOee>z$OU3w%+xaqyAe}q% z5Y=~E>BLsE(9x9LD}rX1T2ECes~-;9x55}H->qme9;eEfgG88{cW2WtM;=t2)*eVA zXTL&A4y+_s{}yr`^csEAQt39yEBPr>;EKv#tJiUraIhmPd(PfbvaeO^fTm7yD{4UW zVCSQV1$z@8=UmM(y;Qztl(;g5tq*V?db`Rb7iR;_keqZh8AV|Fz?6yE3*w0QgNH|Ue4 z{!e1EWM0;ItlGsQMj^PL3&HG>clz5et37%n@5IGJ`|jiP?FF6&Mi-Cl?jqVXXy95x zy9aaW7goeiG-1fg^&!-D zbeTA`$SLBRuQ+z8zacGZI+tC0mduIzu TRu+4q;Gr5)4tv>yTr2$num+&v diff --git a/AACharly.njsproj b/AACharly.njsproj index 16da68313..6d6b72fc1 100644 --- a/AACharly.njsproj +++ b/AACharly.njsproj @@ -6,7 +6,8 @@ {ae0a3fe2-7021-4cc2-9922-a887ca5cdd7c} ShowAllFiles - Poloniex-Hole-Fixing\run.js + + c:\users\luis\source\repos\AACharly\Poloniex-Hole-Fixing . {3AF33F2E-1136-4D97-BBB7-1795711AC8B8};{349c5851-65df-11da-9384-00065b846f21};{9092AA53-FB77-4645-B42D-1CCCA6BD08BD} @@ -17,21 +18,10 @@ - - - - - - - - - - - - + diff --git a/AACharly.sln b/AACharly.sln index 9ebd7e1df..48a43c66f 100644 --- a/AACharly.sln +++ b/AACharly.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26730.10 +VisualStudioVersion = 15.0.27130.2027 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}") = "AACharly", "AACharly.njsproj", "{AE0A3FE2-7021-4CC2-9922-A887CA5CDD7C}" EndProject diff --git a/Azure File Storage.js b/Azure File Storage.js deleted file mode 100644 index dcb2f6c89..000000000 --- a/Azure File Storage.js +++ /dev/null @@ -1,247 +0,0 @@ - -exports.newAzureFileStorage = function newAzureFileStorage(BOT) { - - let bot = BOT; - const ROOT_DIR = '../'; - - const MODULE_NAME = "Azure File Storage"; - - var fs = require('fs'); - var util = require('util'); - var guid = require('node-uuid'); - var crypto = require('crypto'); - var storage = require('azure-storage'); - - const DEBUG_MODULE = require('./Debug Log'); - const logger = DEBUG_MODULE.newDebugLog(); - logger.fileName = MODULE_NAME; - logger.bot = bot; - - const shareName = 'data'; - let dataOwner; - - let azureFileStorage = { - initialize: initialize, - createFolder: createFolder, - createTextFile: createTextFile, - getTextFile: getTextFile, - listFilesAndFolders: listFilesAndFolders - }; - - let fileService; - - return azureFileStorage; - - - function initialize(dataOwnerBotName) { - - try { - - if (dataOwnerBotName === undefined) { - - dataOwner = bot.name; - - } else { - - dataOwner = dataOwnerBotName; - - } - - fileService = storage.createFileService(readConfig().connectionString); - - } - catch (err) { - const logText = "[ERROR] 'initialize' - ERROR : " + err.message; - logger.write(logText); - } - } - - function readConfig() { - - try { - - return JSON.parse(fs.readFileSync(ROOT_DIR + dataOwner + '.azure.storage.connstring', 'utf8')); - - } - catch (err) { - const logText = "[ERROR] 'readConfig' - ERROR : " + err.message; - logger.write(logText); - } - - } - - function createFolder(folderPath, callBackFunction) { - - try { - - fileService.createDirectoryIfNotExists(shareName, folderPath, onFolderCreated); - - function onFolderCreated(err) { - - if (err) { - - const logText = "[ERROR] createFolder - onFolderCreated ' ERROR = " + err.message + " SHARE NAME = " + shareName + " FOLDER PATH = " + folderPath; - console.log(logText); - logger.write(logText); - - } - - callBackFunction(); - - } - - } - catch (err) { - const logText = "[ERROR] 'createFolder' - ERROR : " + err.message; - logger.write(logText); - } - - } - - function createTextFile(folderPath, fileName, fileContent, callBackFunction) { - - try { - - fileService.createFileFromText(shareName, folderPath, fileName, fileContent, onFileCreated); - - function onFileCreated(err, result, response) { - - if (err) { - - const logText = "[WARN] createTextFile - onFileCreated ' ERROR = " + err.message + " SHARE NAME = " + shareName + " FOLDER PATH = " + folderPath + " FILE NAME = " + fileName; - console.log(logText); - logger.write(logText); - - if (err.message.indexOf("The server is busy") > 0) { - - fileService.createFileFromText(shareName, folderPath, fileName, fileContent, onFileCreatedSecondTry); - - function onFileCreatedSecondTry(err) { - - if (err) { - - const logText = "[ERROR] createTextFile - onFileCreated - onFileCreatedSecondTry : File not created. Giving Up.' ERROR = " + err.message + " SHARE NAME = " + shareName + " FOLDER PATH = " + folderPath + " FILE NAME = " + fileName; - console.log(logText); - logger.write(logText); - - } else { - - const logText = "[INFO] createTextFile - onFileCreated - onFileCreatedSecondTry ' : File succesfully created on second try. SHARE NAME = " + shareName + " FOLDER PATH = " + folderPath + " FILE NAME = " + fileName; - console.log(logText); - logger.write(logText); - - } - } - } - } - - callBackFunction(); - } - - } - catch (err) { - const logText = "[ERROR] 'createTextFile' - ERROR : " + err.message; - logger.write(logText); - } - - } - - function getTextFile(folderPath, fileName, callBackFunction, ignoreNotFound) { - - try { - - fileService.getFileToText(shareName, folderPath, fileName, undefined, onFileReceived); - - function onFileReceived(err, text, response) { - - if (err) { - - if (ignoreNotFound === undefined) { - - const logText = "[ERROR] getTextFile - onFileReceived ' ERROR = " + err.message + " SHARE NAME = " + shareName + " FOLDER PATH = " + folderPath + " FILE NAME = " + fileName; - console.log(logText); - logger.write(logText); - - } - - text = undefined; - - } - - callBackFunction(text); - } - - } - catch (err) { - const logText = "[ERROR] 'getTextFile' - ERROR : " + err.message; - logger.write(logText); - } - - } - - function listFilesAndFolders(folderPath, callBackFunction) { - - try { - - let items = { - files: [], - folders: [] - }; - - /* - * @param { object } [options] The request options. - * @param { int } [options.maxResults] Specifies the maximum number of folders to return per call to Azure ServiceClient. - * This does NOT affect list size returned by this function. (maximum: 5000) - * @param { LocationMode } [options.locationMode] Specifies the location mode used to decide which location the request should be sent to. - * Please see StorageUtilities.LocationMode for the possible values. - * @param { int } [options.timeoutIntervalInMs] The server timeout interval, in milliseconds, to use for the request. - * @param { int } [options.maximumExecutionTimeInMs] The maximum execution time, in milliseconds, across all potential retries, to use when making this request. - * The maximum execution time interval begins at the time that the client begins building the request.The maximum - * execution time is checked intermittently while performing requests, and before executing retries. - * @param { string } [options.clientRequestId] A string that represents the client request ID with a 1KB character limit. - * @param { bool } [options.useNagleAlgorithm] Determines whether the Nagle al - */ - - let options = { - maxResults: 500 - }; - - fileService.listFilesAndDirectoriesSegmented(shareName, folderPath, null, options, onFilesAndFoldersReceived); - - - function onFilesAndFoldersReceived(error, result) { - - try { - - if (error) { - - const logText = "[ERROR] 'listFilesAndFolders - onFilesAndFoldersReceived' - ERROR RECEIVED : " + error; - logger.write(logText); - - callBackFunction(items); - - } else { - - items.files.push.apply(items.files, result.entries.files); - items.folders.push.apply(items.folders, result.entries.directories); - - callBackFunction(items); - - } - - } - catch (err) { - const logText = "[ERROR] 'listFilesAndFolders - onFilesAndFoldersReceived' - ERROR : " + err.message; - logger.write(logText); - } - - } - - } - catch (err) { - const logText = "[ERROR] 'listFilesAndFolders' - ERROR : " + err.message; - logger.write(logText); - } - } - -}; \ No newline at end of file diff --git a/Azure Web Job Shutdown.js b/Azure Web Job Shutdown.js deleted file mode 100644 index 22ed305de..000000000 --- a/Azure Web Job Shutdown.js +++ /dev/null @@ -1,41 +0,0 @@ - -exports.newShutdownEvent = function newShutdownEvent(BOT) { - - let bot = BOT; - const ROOT_DIR = '../'; - - const MODULE_NAME = "Azure Web Job Shutdown"; - - - const DEBUG_MODULE = require('./Debug Log'); - const logger = DEBUG_MODULE.newDebugLog(); - logger.fileName = MODULE_NAME; - logger.bot = bot; - - let shutdownEvent = { - isShuttingDown: isShuttingDown - }; - - return shutdownEvent; - - - function isShuttingDown() { - - let filePath = process.env.WEBJOBS_SHUTDOWN_FILE; - - let fs = require('fs'); - - if (fs.existsSync(filePath)) { - return true; - } - else - { - return false; - } - - } - - - - -} \ No newline at end of file diff --git a/Debug Log.js b/Debug Log.js deleted file mode 100644 index fc543e5d7..000000000 --- a/Debug Log.js +++ /dev/null @@ -1,144 +0,0 @@ - - - -exports.newDebugLog = function newDebugLog() { - - - const MODULE_NAME = "Debug Log"; - const fileSystem = require('fs'); - - const currentDate = new Date(); - const dateString = currentDate.getUTCFullYear() + '-' + pad(currentDate.getUTCMonth() + 1, 2) + '-' + pad(currentDate.getUTCDate(), 2) + '-' + pad(currentDate.getUTCHours(), 2) + '-' + pad(currentDate.getUTCMinutes(), 2); - const randomId = parseInt(Math.random() * 1000000); - - let fileNumber = 1; - let messageId = 0; - let firstCall = true; - let folderPath; - - debugLog = { - bot: undefined, - fileName: undefined, - write: write - }; - - - - return debugLog; - - - function createFolders() { - - try { - - folderPath = debugLog.bot.devTeam; - - createFolderSync(folderPath); - - folderPath = debugLog.bot.devTeam + "/" + debugLog.bot.type; - - createFolderSync(folderPath); - - folderPath = debugLog.bot.devTeam + "/" + debugLog.bot.type + "/" + debugLog.bot.name; - - createFolderSync(folderPath); - - folderPath = debugLog.bot.devTeam + "/" + debugLog.bot.type + "/" + debugLog.bot.name + "/" + debugLog.bot.version; - - createFolderSync(folderPath); - - folderPath = debugLog.bot.devTeam + "/" + debugLog.bot.type + "/" + debugLog.bot.name + "/" + debugLog.bot.version + "/" + debugLog.bot.process; - - createFolderSync(folderPath); - - firstCall = false; - - } - catch (err) { - console.log("Error trying to create the folders needed. Error: " + err); - } - - - } - - - function write(Message) { - - if (firstCall === true) { - - createFolders(); - - } - - let filePath = getCurrentLogFile(folderPath + "/" + dateString + "---" + randomId + "---", this.fileName); - - let newDate = new Date(); - newDate = newDate.toISOString(); - - messageId++; - - try { - - fileSystem.appendFileSync(filePath, '\r\n' + newDate + " " + messageId + " " + Message); - - } - catch (err) { - console.log("Error trying to log info into a file. File: " + filePath + " Error:" + err); - } - } - - - function createFolderSync(name) { - try { - fileSystem.mkdirSync( '../logs/' + name) - } catch (err) { - if (err.code !== 'EEXIST') throw err - } - } - - function getCurrentLogFile(relativePath, fileName) { - - let filePath; - let stats; - let i; - - try { - for (i = 1; i < 1000000; i++) { - - filePath = '../logs/' + relativePath + i + "." + fileName + '.log'; - stats = fileSystem.statSync(filePath); - } - } - catch (err) { - - if (i > 1) { - - filePath = '../logs/' + relativePath + (i - 1) + "." + fileName + '.log'; - - stats = fileSystem.statSync(filePath); - const fileSizeInBytes = stats.size; - - if (fileSizeInBytes > 10240000) { - - filePath = '../logs/' + relativePath + i + "." + fileName + '.log'; - } - - return filePath; - - } else { - - return filePath; - - } - - } - - } - - function pad(str, max) { - str = str.toString(); - return str.length < max ? pad("0" + str, max) : str; - } - -}; - diff --git a/Markets.js b/Markets.js deleted file mode 100644 index 54ba5512d..000000000 --- a/Markets.js +++ /dev/null @@ -1,252 +0,0 @@ -/* This business logic module is responsible for Markets and Assets. */ - - -exports.newMarkets = function newMarkets(BOT) { - - let bot = BOT; - const ROOT_DIR = '../'; - - const MODULE_NAME = "Markets"; - - const FOLDER_PATHS = 'data'; - const MARKETS_FOLDER_NAME = "other-files"; - - const DEBUG_MODULE = require('./Debug Log'); - const logger = DEBUG_MODULE.newDebugLog(); - logger.fileName = MODULE_NAME; - logger.bot = bot; - - const EXCHANGE_ID = 1; - const fileName = "Markets_" + EXCHANGE_ID + ".json"; - - const DATA_OWNER_BOT_NAME = "Carol" - - const markets = { - DISABLED: 0, - ENABLED: 1, - getMarketsByExchange: getMarketsByExchange, - getExistingOrNewMarketId: getExistingOrNewMarketId, - createNewAsset: createNewAsset, - createNewMarket: createNewMarket, - disableMarket: disableMarket, - initialize: initialize - }; - - //const dataLayer = DATA_LAYER_MODULE.newDataLayer(); - - let marketsArray; - - const AZURE_FILE_STORAGE = require('./Azure File Storage'); - let azureFileStorage = AZURE_FILE_STORAGE.newAzureFileStorage(bot); - - return markets; - - - function initialize(callBackFunction) { - - azureFileStorage.initialize(DATA_OWNER_BOT_NAME); - - try { - - azureFileStorage.getTextFile(MARKETS_FOLDER_NAME, fileName, onFileRead); - - function onFileRead(text) { - - try { - - var fileString = text; - let cleanString = fileString; - - /* Dont know why but sometimes files comes with a first characater that is not supposed to be there and you can not see it at the file opened with notepad */ - - if (fileString[0] !== "[") { - - cleanString = ''; - - for (let i = 1; i < fileString.length; i++) { - cleanString = cleanString + fileString[i]; - } - } - - marketsArray = JSON.parse(cleanString); - callBackFunction(); - - } - catch (err) { - const logText = "[ERROR] initialize - onFileRead ' ERROR : " + err.message + " File: " + fileName; - console.log(logText); - logger.write(logText); - } - - } - } - catch (err) { - const logText = "[ERROR] initialize - ' ERROR : " + err.message + " File Not Found: " + fileName; - console.log(logText); - logger.write(logText); - } - - - } - - - - function getMarketsByExchange(exchangeId, callBackFunction) { - - try { - - // TODO: Currently the exchange Id is ignored as the class is still working with only one exchange. We must fix this. - - callBackFunction(JSON.stringify(marketsArray)); - - - } catch (err) { - - const logText = "[ERROR] getMarketsByExchange - ' ERROR : " + err.message; - console.log(logText); - logger.write(logText); - - } - - } - - - function getExistingOrNewMarketId(marketName, market, exchangeId, callBackFunction) { - - // TODO: At this function is missing the following: If a market does not exists, it must be greated, and Id generated and returned. We automatically discover new markets when this function is called with a market that didn-t previuously existed. - - try { - - for (let i = 0; i < marketsArray.length; i++) { - - if (marketsArray[i][1] + "_" + marketsArray[i][2] === marketName) { - - callBackFunction(marketName, market, marketsArray[i][0]); - return; - - } - } - - - } catch (err) { - - const logText = "[ERROR] getExistingOrNewMarketId - ' ERROR : " + err.message + " marketId = " + marketId + " idAssetA = " + idAssetA + " idAssetB = " + idAssetB; - console.log(logText); - logger.write(logText); - - } - - } - - - function createNewAsset(assetCode, callBackFunction) { - - // TODO: Upgrade this function in order to update the file containing all assets, not the database that will be deprecated. - - try { - - dataLayer.newAsset(assetCode, onIdReady); - - function onIdReady(resultSet) { - - try { - - callBackFunction(resultSet); - resultSet = []; - - } catch (err) { - - const logText = "[ERROR] createNewAsset - onIdReady ' ERROR : " + err.message; - console.log(logText); - logger.write(logText); - - } - } - - } catch (err) { - - const logText = "[ERROR] createNewAsset - ' ERROR : " + err.message; - console.log(logText); - logger.write(logText); - - } - - } - - - - function createNewMarket(exchangeId, idAssetA, idAssetB, callBackFunction) { - - // TODO: Upgrade this function in order to update the file containing all markets, not the database that will be deprecated. - - try { - - dataLayer.newMarket(exchangeId, idAssetA, idAssetB, onIdReady); - - function onIdReady(resultSet) { - - try { - - callBackFunction(resultSet); - - } catch (err) { - - const logText = "[ERROR] createNewMarket - onIdReady ' ERROR : " + err.message; - console.log(logText); - logger.write(logText); - } - } - - } catch (err) { - - const logText = "[ERROR] createNewMarket - ' ERROR : " + err.message; - console.log(logText); - logger.write(logText); - } - } - - - function disableMarket(exchangeId, marketId, callBackFunction) { - - // This function puts the requested market in a DISABLED status. - - // TODO: Currently the exchangeId is ignored. - - try { - - for (let i = 0; i < marketsArray.length; i++) { - - if (marketsArray[i][0] === marketId) { - - marketsArray[i][3] = markets.DISABLED; - break; - - } - - } - - azureFileStorage.createTextFile(MARKETS_FOLDER_NAME, fileName, JSON.stringify(marketsArray), onFileReplaced); - - function onFileReplaced() { - - try { - - callBackFunction(); - - } catch (err) { - - const logText = "[ERROR] disableMarket - onFileReplaced ' ERROR : " + err.message; - console.log(logText); - logger.write(logText); - } - } - - } catch (err) { - - const logText = "[ERROR] disableMarket - ' ERROR : " + err.message; - console.log(logText); - logger.write(logText); - } - } - -}; \ No newline at end of file diff --git a/Poloniex API Client.js b/Poloniex API Client.js deleted file mode 100644 index d7e74a657..000000000 --- a/Poloniex API Client.js +++ /dev/null @@ -1,406 +0,0 @@ -module.exports = (function () { - 'use strict'; - - // Module dependencies - var crypto = require('crypto'), - request = require('request'), - nonce = require('nonce')(); - - // Constants - var version = '0.0.8', - PUBLIC_API_URL = 'https://poloniex.com/public', - PRIVATE_API_URL = 'https://poloniex.com/tradingApi', - USER_AGENT = 'poloniex.js ' + version; - //USER_AGENT = 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0' - - // Helper methods - function joinCurrencies(currencyA, currencyB) { - // If only one arg, then return the first - if (typeof currencyB !== 'string') { - return currencyA; - } - - return currencyA + '_' + currencyB; - } - - // Constructor - function Poloniex(key, secret) { - // Generate headers signed by this user's key and secret. - // The secret is encapsulated and never exposed - this._getPrivateHeaders = function (parameters) { - var paramString, signature; - - if (!key || !secret) { - throw 'Poloniex: Error. API key and secret required'; - } - - // Convert to `arg1=foo&arg2=bar` - paramString = Object.keys(parameters).map(function (param) { - return encodeURIComponent(param) + '=' + encodeURIComponent(parameters[param]); - }).join('&'); - - signature = crypto.createHmac('sha512', secret).update(paramString).digest('hex'); - - return { - Key: key, - Sign: signature - }; - }; - } - - // Currently, this fails with `Error: CERT_UNTRUSTED` - // Poloniex.STRICT_SSL can be set to `false` to avoid this. Use with caution. - // Will be removed in future, once this is resolved. - Poloniex.STRICT_SSL = true; - - // Customisable user agent string - Poloniex.USER_AGENT = USER_AGENT; - - // Prototype - Poloniex.prototype = { - constructor: Poloniex, - - // Make an API request - _request: function (options, callback) { - if (!('headers' in options)) { - options.headers = {}; - } - - options.json = true; - options.headers['User-Agent'] = Poloniex.USER_AGENT; - options.strictSSL = Poloniex.STRICT_SSL; - - request(options, function (err, response, body) { - // Empty response - if (!err && (typeof body === 'undefined' || body === null)) { - err = 'Empty response'; - } - - callback(err, body); - }); - - return this; - }, - - // Make a public API request - _public: function (command, parameters, callback) { - var options; - - if (typeof parameters === 'function') { - callback = parameters; - parameters = {}; - } - - parameters || (parameters = {}); - parameters.command = command; - options = { - method: 'GET', - url: PUBLIC_API_URL, - qs: parameters - }; - - options.qs.command = command; - return this._request(options, callback); - }, - - // Make a private API request - _private: function (command, parameters, callback) { - var options; - - if (typeof parameters === 'function') { - callback = parameters; - parameters = {}; - } - - parameters || (parameters = {}); - parameters.command = command; - parameters.nonce = nonce(); - - options = { - method: 'POST', - url: PRIVATE_API_URL, - form: parameters, - headers: this._getPrivateHeaders(parameters) - }; - - return this._request(options, callback); - }, - - ///// - // PUBLIC METHODS - - returnTicker: function (callback) { - return this._public('returnTicker', callback); - }, - - return24hVolume: function (callback) { - return this._public('return24hVolume', callback); - }, - - returnOrderBook: function (currencyA, currencyB, depth, callback) { - var parameters = { - currencyPair: joinCurrencies(currencyA, currencyB), - depth: depth - }; - - return this._public('returnOrderBook', parameters, callback); - }, - - returnOrderBooks: function (depth, callback) { - var parameters = { - currencyPair: 'all', - depth: depth - }; - - return this._public('returnOrderBook', parameters, callback); - }, - - returnPublicTradeHistory: function (currencyA, currencyB, start, end, callback) { - var parameters = { - currencyPair: joinCurrencies(currencyA, currencyB), - start: start, - end: end - }; - - return this._public('returnTradeHistory', parameters, callback); - }, - - returnChartData: function (currencyA, currencyB, period, start, end, callback) { - var parameters = { - currencyPair: joinCurrencies(currencyA, currencyB), - period: period, - start: start, - end: end - }; - - return this._public('returnChartData', parameters, callback); - }, - - returnCurrencies: function (callback) { - return this._public('returnCurrencies', callback); - }, - - returnLoanOrders: function (currency, callback) { - return this._public('returnLoanOrders', { currency: currency }, callback); - }, - - ///// - // PRIVATE METHODS - - returnBalances: function (callback) { - return this._private('returnBalances', {}, callback); - }, - - returnCompleteBalances: function (callback) { - return this._private('returnCompleteBalances', {}, callback); - }, - - returnDepositAddresses: function (callback) { - return this._private('returnDepositAddresses', {}, callback); - }, - - generateNewAddress: function (currency, callback) { - return this._private('returnDepositsWithdrawals', { currency: currency }, callback); - }, - - returnDepositsWithdrawals: function (start, end, callback) { - return this._private('returnDepositsWithdrawals', { start: start, end: end }, callback); - }, - - returnOpenOrders: function (currencyA, currencyB, callback) { - var parameters = { - currencyPair: joinCurrencies(currencyA, currencyB) - }; - - return this._private('returnOpenOrders', parameters, callback); - }, - - returnTradeHistory: function (currencyA, currencyB, callback) { - var parameters = { - currencyPair: joinCurrencies(currencyA, currencyB) - }; - - return this._private('returnTradeHistory', parameters, callback); - }, - - returnOrderTrades: function (orderNumber, callback) { - var parameters = { - orderNumber: orderNumber - }; - - return this._private('returnOrderTrades', parameters, callback); - }, - - buy: function (currencyA, currencyB, rate, amount, callback) { - var parameters = { - currencyPair: joinCurrencies(currencyA, currencyB), - rate: rate, - amount: amount - }; - - return this._private('buy', parameters, callback); - }, - - sell: function (currencyA, currencyB, rate, amount, callback) { - var parameters = { - currencyPair: joinCurrencies(currencyA, currencyB), - rate: rate, - amount: amount - }; - - return this._private('sell', parameters, callback); - }, - - cancelOrder: function (currencyA, currencyB, orderNumber, callback) { - var parameters = { - currencyPair: joinCurrencies(currencyA, currencyB), - orderNumber: orderNumber - }; - - return this._private('cancelOrder', parameters, callback); - }, - - moveOrder: function (orderNumber, rate, amount, callback) { - var parameters = { - orderNumber: orderNumber, - rate: rate, - amount: amount ? amount : null - }; - - return this._private('moveOrder', parameters, callback); - }, - - withdraw: function (currency, amount, address, callback) { - var parameters = { - currency: currency, - amount: amount, - address: address - }; - - return this._private('withdraw', parameters, callback); - }, - - returnFeeInfo: function (callback) { - return this._private('returnFeeInfo', {}, callback); - }, - - returnAvailableAccountBalances: function (account, callback) { - var options = {}; - if (account) { - options.account = account; - } - return this._private('returnAvailableAccountBalances', options, callback); - }, - - returnTradableBalances: function (callback) { - return this._private('returnTradableBalances', {}, callback); - }, - - transferBalance: function (currency, amount, fromAccount, toAccount, callback) { - var parameters = { - currency: currency, - amount: amount, - fromAccount: fromAccount, - toAccount: toAccount - }; - - return this._private('transferBalance', parameters, callback); - }, - - returnMarginAccountSummary: function (callback) { - return this._private('returnMarginAccountSummary', {}, callback); - }, - - marginBuy: function (currencyA, currencyB, rate, amount, lendingRate, callback) { - var parameters = { - currencyPair: joinCurrencies(currencyA, currencyB), - rate: rate, - amount: amount, - lendingRate: lendingRate ? lendingRate : null - }; - - return this._private('marginBuy', parameters, callback); - }, - - marginSell: function (currencyA, currencyB, rate, amount, lendingRate, callback) { - var parameters = { - currencyPair: joinCurrencies(currencyA, currencyB), - rate: rate, - amount: amount, - lendingRate: lendingRate ? lendingRate : null - }; - - return this._private('marginSell', parameters, callback); - }, - - getMarginPosition: function (currencyA, currencyB, callback) { - var parameters = { - currencyPair: joinCurrencies(currencyA, currencyB) - }; - - return this._private('getMarginPosition', parameters, callback); - }, - - closeMarginPosition: function (currencyA, currencyB, callback) { - var parameters = { - currencyPair: joinCurrencies(currencyA, currencyB) - }; - - return this._private('closeMarginPosition', parameters, callback); - }, - - createLoanOffer: function (currency, amount, duration, autoRenew, lendingRate, callback) { - var parameters = { - currency: currency, - amount: amount, - duration: duration, - autoRenew: autoRenew, - lendingRate: lendingRate - }; - - return this._private('createLoanOffer', parameters, callback); - }, - - cancelLoanOffer: function (orderNumber, callback) { - var parameters = { - orderNumber: orderNumber - }; - - return this._private('cancelLoanOffer', parameters, callback); - }, - - returnOpenLoanOffers: function (callback) { - return this._private('returnOpenLoanOffers', {}, callback); - }, - - returnActiveLoans: function (callback) { - return this._private('returnActiveLoans', {}, callback); - }, - - returnLendingHistory: function (start, end, limit, callback) { - var parameters = { - start: start, - end: end, - limit: limit - }; - - return this._private('returnLendingHistory', parameters, callback); - }, - - toggleAutoRenew: function (orderNumber, callback) { - return this._private('toggleAutoRenew', { orderNumber: orderNumber }, callback); - } - - }; - - // Backwards Compatibility - Poloniex.prototype.getTicker = Poloniex.prototype.returnTicker; - Poloniex.prototype.get24hVolume = Poloniex.prototype.return24hVolume; - Poloniex.prototype.getOrderBook = Poloniex.prototype.returnOrderBook; - Poloniex.prototype.getTradeHistory = Poloniex.prototype.returnChartData; - Poloniex.prototype.myBalances = Poloniex.prototype.returnBalances; - Poloniex.prototype.myOpenOrders = Poloniex.prototype.returnOpenOrders; - Poloniex.prototype.myTradeHistory = Poloniex.prototype.returnTradeHistory; - - return Poloniex; -})(); \ No newline at end of file diff --git a/Poloniex-Historic-Trades/Interval.js b/Poloniex-Historic-Trades/Interval.js index f3b236951..086fb1aab 100644 --- a/Poloniex-Historic-Trades/Interval.js +++ b/Poloniex-Historic-Trades/Interval.js @@ -1,7 +1,7 @@ -exports.newInterval = function newInterval(BOT) { +exports.newInterval = function newInterval(BOT, UTILITIES, AZURE_FILE_STORAGE, DEBUG_MODULE, MARKETS_MODULE, POLONIEX_CLIENT_MODULE) { let bot = BOT; - const ROOT_DIR = '../'; + const ROOT_DIR = './'; const GMT_SECONDS = ':00.000 GMT+0000'; const GMT_MILI_SECONDS = '.000 GMT+0000'; @@ -16,11 +16,6 @@ const GO_RANDOM = false; const FORCE_MARKET = 2; // This allows to debug the execution of an specific market. Not intended for production. - const MARKETS_MODULE = require(ROOT_DIR + 'Markets'); - - const POLONIEX_CLIENT_MODULE = require(ROOT_DIR + 'Poloniex API Client'); - - const DEBUG_MODULE = require(ROOT_DIR + 'Debug Log'); const logger = DEBUG_MODULE.newDebugLog(); logger.fileName = MODULE_NAME; logger.bot = bot; @@ -32,10 +27,8 @@ let markets; - const AZURE_FILE_STORAGE = require(ROOT_DIR + 'Azure File Storage'); let azureFileStorage = AZURE_FILE_STORAGE.newAzureFileStorage(bot); - const UTILITIES = require(ROOT_DIR + 'Utilities'); let utilities = UTILITIES.newUtilities(bot); let year; diff --git a/Poloniex-Historic-Trades/Poloniex Historic Trades.js b/Poloniex-Historic-Trades/Poloniex Historic Trades.js deleted file mode 100644 index af8431a81..000000000 --- a/Poloniex-Historic-Trades/Poloniex Historic Trades.js +++ /dev/null @@ -1,169 +0,0 @@ -exports.newPloniexHistoricTrades = function newPloniexHistoricTrades(BOT) { - - let bot = BOT; - const ROOT_DIR = '../'; - - const INTERVAL_LAPSE = 24 * 60 * 60 * 1000; - - const MODULE_NAME = "Poloniex Exchange Historic Trades"; - const LOG_INFO = true; - - const INTERVAL_MODULE = require('./Interval'); - - const DEBUG_MODULE = require(ROOT_DIR + 'Debug Log'); - const logger = DEBUG_MODULE.newDebugLog(); - logger.fileName = MODULE_NAME; - logger.bot = bot; - - const INTERVAL_MAX_LOOPS = -1; // -1 for infinite loop. - - poloniexHistoricTrades = { - initialize: initialize, - start: start - }; - - const SHUTDOWN_EVENT = require(ROOT_DIR + 'Azure Web Job Shutdown'); - let shutdownEvent = SHUTDOWN_EVENT.newShutdownEvent(bot); - - const UTILITIES = require(ROOT_DIR + 'Utilities'); - let utilities = UTILITIES.newUtilities(bot); - - let year; - let month; - - return poloniexHistoricTrades; - - function initialize(yearAssigend, monthAssigned, callBackFunction) { - - try { - - year = yearAssigend; - month = monthAssigned; - - month = utilities.pad(month, 2); // Adding a left zero when needed. - - logger.fileName = MODULE_NAME + "-" + year + "-" + month; - - const logText = "[INFO] initialize - Entering function 'initialize' " + " @ " + year + "-" + month; - console.log(logText); - logger.write(logText); - - callBackFunction(); - - } catch (err) { - - const logText = "[ERROR] initialize - ' ERROR : " + err.message; - console.log(logText); - logger.write(logText); - - } - } - - - function start() { - - try { - - if (LOG_INFO === true) { - logger.write("[INFO] Entering function 'start', with year = " + year + " and month = " + month); - } - - let intervalId; - - if (INTERVAL_MAX_LOOPS === 0) { - - intervalId = setInterval(startNewInterval, INTERVAL_LAPSE); - - } - - let intervalLoopCounter = 0; - - startNewInterval(); // First, inmadiate run. - - function startNewInterval() { - - try { - - if (LOG_INFO === true) { - - if (INTERVAL_MAX_LOOPS !== 0) { - - logger.write("[INFO] Entering function 'startNewInterval', next execution inmediately after the current Interval finishes."); - - } else { - - logger.write("[INFO] Entering function 'startNewInterval', next execution in " + INTERVAL_LAPSE / 1000 / 60 + " minutes."); - - } - - } - - - if (shutdownEvent.isShuttingDown() === false) { - - let fileProcessingInterval = INTERVAL_MODULE.newInterval(bot); - - fileProcessingInterval.initialize(year, month, onReadyToStart); - - function onReadyToStart() { - - fileProcessingInterval.start(loopControl); - - } - - } - else { - - clearInterval(intervalId); - - const logText = "[INFO] requestNewData - Terminating Set Interval - About to exit gracefully the process. "; - console.log(logText); - logger.write(logText); - - } - - } - catch (err) { - const logText = "[ERROR] 'startNewInterval' - ERROR : " + err.message; - logger.write(logText); - } - } - - function loopControl(moreIntervalExecutionsNeeded) { - - if (moreIntervalExecutionsNeeded === true) { - - intervalLoopCounter++; - - if (intervalLoopCounter === INTERVAL_MAX_LOOPS) { - - const logText = "[WARN] 'INTERVAL_MAX_LOOPS' reached. Stopping execution. "; - logger.write(logText); - - } else { - - const logText = "[WARN] 'loopControl'. Staring new Interval. "; - logger.write(logText); - - startNewInterval(); // Looped Execution. - - } - - } else { - - logger.write("[WARN] Received the signal from last Interval execution to not call it anymore. Stopping execution. "); - - } - - } - - } - catch (err) { - const logText = "[ERROR] 'Start' - ERROR : " + err.message; - logger.write(logText); - } - } -}; - - - diff --git a/Poloniex-Historic-Trades/run.js b/Poloniex-Historic-Trades/run.js deleted file mode 100644 index b04555958..000000000 --- a/Poloniex-Historic-Trades/run.js +++ /dev/null @@ -1,97 +0,0 @@ - -let bot = { - name: "Charly", - process: "Historic-Trades", - type: "Connectivity", - version: "1.0.0", - devTeam: "AA Masters" -}; - -const ROOT_DIR = '../'; - -const MODULE_NAME = "run"; - -const START_POLONIEX_HISTORIC_TRADES = true; -const START_POLONIEX_HISTORIC_TRADES_AT_ONE_MONTH = false; - -const POLONIEX_HISTORIC_TRADES_MODULE = require('./Poloniex Historic Trades'); - -const DEBUG_MODULE = require(ROOT_DIR + 'Debug Log'); -const logger = DEBUG_MODULE.newDebugLog(); -logger.fileName = MODULE_NAME; -logger.bot = bot; - -process.on('uncaughtException', function (err) { - logger.write('uncaughtException - ' + err.message); -}); - - -process.on('unhandledRejection', (reason, p) => { - logger.write("Unhandled Rejection at: Promise " + JSON.stringify(p) + " reason: " + reason); -}); - - -process.on('exit', function (code) { - logger.write('About to exit with code:' + code); -}); - - -try { - if (START_POLONIEX_HISTORIC_TRADES === true) { - - for (let year = 2018; year > 2014; year--) { - - for (let month = 12; month > 0; month--) { - - let timeDelay = Math.random() * 100 * 1000; // We need a delay so as not to get banned from the exchange for requesting to many things at the same time. - - setTimeout(startProcess, timeDelay); - - function startProcess() { - - const newPloniexHistoricTrades = POLONIEX_HISTORIC_TRADES_MODULE.newPloniexHistoricTrades(bot); - - newPloniexHistoricTrades.initialize(year, month, onInitializeReady); - - function onInitializeReady() { - - newPloniexHistoricTrades.start(); - - } - - } - - } - - } - - } - - - if (START_POLONIEX_HISTORIC_TRADES_AT_ONE_MONTH === true) { - - startProcess(); - - function startProcess() { - - const newPloniexHistoricTrades = POLONIEX_HISTORIC_TRADES_MODULE.newPloniexHistoricTrades(bot); - - let month = 12; - let year = 2017; - - newPloniexHistoricTrades.initialize(year, month, onInitializeReady); - - function onInitializeReady() { - - newPloniexHistoricTrades.start(); - - } - } - } - - -} catch (err) { - console.log(err.message); - logger.write(err.message); -} - diff --git a/Poloniex-Hole-Fixing/Interval.js b/Poloniex-Hole-Fixing/Interval.js index 744a74635..5a2153792 100644 --- a/Poloniex-Hole-Fixing/Interval.js +++ b/Poloniex-Hole-Fixing/Interval.js @@ -1,4 +1,4 @@ -exports.newInterval = function newInterval(BOT) { +exports.newInterval = function newInterval(BOT, UTILITIES, AZURE_FILE_STORAGE, DEBUG_MODULE, MARKETS_MODULE, POLONIEX_CLIENT_MODULE) { let bot = BOT; const ROOT_DIR = '../'; @@ -16,11 +16,6 @@ const GO_RANDOM = false; const FORCE_MARKET = 2; // This allows to debug the execution of an specific market. Not intended for production. - const MARKETS_MODULE = require(ROOT_DIR + 'Markets'); - - const POLONIEX_CLIENT_MODULE = require(ROOT_DIR + 'Poloniex API Client'); - - const DEBUG_MODULE = require(ROOT_DIR + 'Debug Log'); const logger = DEBUG_MODULE.newDebugLog(); logger.fileName = MODULE_NAME; logger.bot = bot; @@ -32,10 +27,8 @@ let markets; - const AZURE_FILE_STORAGE = require(ROOT_DIR + 'Azure File Storage'); let azureFileStorage = AZURE_FILE_STORAGE.newAzureFileStorage(bot); - const UTILITIES = require(ROOT_DIR + 'Utilities'); let utilities = UTILITIES.newUtilities(bot); let year; diff --git a/Poloniex-Hole-Fixing/Poloniex Hole Fixing.js b/Poloniex-Hole-Fixing/Poloniex Hole Fixing.js deleted file mode 100644 index a9d5210e2..000000000 --- a/Poloniex-Hole-Fixing/Poloniex Hole Fixing.js +++ /dev/null @@ -1,169 +0,0 @@ -exports.newPloniexHoleFixing = function newPloniexHoleFixing(BOT) { - - let bot = BOT; - const ROOT_DIR = '../'; - - const INTERVAL_LAPSE = 60 * 1000; - - const MODULE_NAME = "Poloniex Exchange Hole Fixing"; - const LOG_INFO = true; - - const INTERVAL_MODULE = require('./Interval'); - - const DEBUG_MODULE = require(ROOT_DIR + 'Debug Log'); - const logger = DEBUG_MODULE.newDebugLog(); - logger.fileName = MODULE_NAME; - logger.bot = bot; - - const INTERVAL_MAX_LOOPS = -1; // -1 for infinite loop. - - poloniexHoleFixing = { - initialize: initialize, - start: start - }; - - const SHUTDOWN_EVENT = require(ROOT_DIR + 'Azure Web Job Shutdown'); - let shutdownEvent = SHUTDOWN_EVENT.newShutdownEvent(bot); - - const UTILITIES = require(ROOT_DIR + 'Utilities'); - let utilities = UTILITIES.newUtilities(bot); - - let year; - let month; - - return poloniexHoleFixing; - - function initialize(yearAssigend, monthAssigned, callBackFunction) { - - try { - - year = yearAssigend; - month = monthAssigned; - - month = utilities.pad(month, 2); // Adding a left zero when needed. - - logger.fileName = MODULE_NAME + "-" + year + "-" + month; - - const logText = "[INFO] initialize - Entering function 'initialize' " + " @ " + year + "-" + month; - console.log(logText); - logger.write(logText); - - callBackFunction(); - - } catch (err) { - - const logText = "[ERROR] initialize - ' ERROR : " + err.message; - console.log(logText); - logger.write(logText); - - } - } - - - function start() { - - try { - - if (LOG_INFO === true) { - logger.write("[INFO] Entering function 'start', with year = " + year + " and month = " + month); - } - - let intervalId; - - if (INTERVAL_MAX_LOOPS === 0) { - - intervalId = setInterval(startNewInterval, INTERVAL_LAPSE); - - } - - let intervalLoopCounter = 0; - - startNewInterval(); // First, inmadiate run. - - function startNewInterval() { - - try { - - if (LOG_INFO === true) { - - if (INTERVAL_MAX_LOOPS !== 0) { - - logger.write("[INFO] Entering function 'startNewInterval', next execution inmediately after the current Interval finishes."); - - } else { - - logger.write("[INFO] Entering function 'startNewInterval', next execution in " + INTERVAL_LAPSE / 1000 / 60 + " minutes."); - - } - - } - - - if (shutdownEvent.isShuttingDown() === false) { - - let fileProcessingInterval = INTERVAL_MODULE.newInterval(bot); - - fileProcessingInterval.initialize(year, month, onReadyToStart); - - function onReadyToStart() { - - fileProcessingInterval.start(loopControl); - - } - - } - else { - - clearInterval(intervalId); - - const logText = "[INFO] requestNewData - Terminating Set Interval - About to exit gracefully the process. "; - console.log(logText); - logger.write(logText); - - } - - } - catch (err) { - const logText = "[ERROR] 'startNewInterval' - ERROR : " + err.message; - logger.write(logText); - } - } - - function loopControl(moreIntervalExecutionsNeeded) { - - if (moreIntervalExecutionsNeeded === true) { - - intervalLoopCounter++; - - if (intervalLoopCounter === INTERVAL_MAX_LOOPS) { - - const logText = "[WARN] 'INTERVAL_MAX_LOOPS' reached. Stopping execution. "; - logger.write(logText); - - } else { - - const logText = "[WARN] 'loopControl'. Staring new Interval. "; - logger.write(logText); - - setTimeout(startNewInterval, INTERVAL_LAPSE);// Looped Execution. - - } - - } else { - - logger.write("[WARN] Received the signal from last Interval execution to not call it anymore. Stopping execution. "); - - } - - } - - } - catch (err) { - const logText = "[ERROR] 'Start' - ERROR : " + err.message; - logger.write(logText); - } - } -}; - - - diff --git a/Poloniex-Hole-Fixing/run.js b/Poloniex-Hole-Fixing/run.js deleted file mode 100644 index 1d25ced2e..000000000 --- a/Poloniex-Hole-Fixing/run.js +++ /dev/null @@ -1,97 +0,0 @@ - -let bot = { - name: "Charly", - process: "Hole-Fixing", - type: "Connectivity", - version: "1.0.0", - devTeam: "AA Masters" -}; - -const ROOT_DIR = '../'; - -const MODULE_NAME = "run"; - -const START_POLONIEX_HOLE_FIXING = true; -const START_POLONIEX_HOLE_FIXING_AT_ONE_MONTH = false; - -const POLONIEX_HOLE_FIXING_MODULE = require('./Poloniex Hole Fixing'); - -const DEBUG_MODULE = require(ROOT_DIR + 'Debug Log'); -const logger = DEBUG_MODULE.newDebugLog(); -logger.fileName = MODULE_NAME; -logger.bot = bot; - -process.on('uncaughtException', function (err) { - logger.write('uncaughtException - ' + err.message); -}); - - -process.on('unhandledRejection', (reason, p) => { - logger.write("Unhandled Rejection at: Promise " + JSON.stringify(p) + " reason: " + reason); -}); - - -process.on('exit', function (code) { - logger.write('About to exit with code:' + code); -}); - - -try { - if (START_POLONIEX_HOLE_FIXING === true) { - - for (let year = 2018; year > 2014; year--) { - - for (let month = 12; month > 0; month--) { - - let timeDelay = Math.random() * 100 * 1000; // We need a delay so as not to get banned from the exchange for requesting to many things at the same time. - - setTimeout(startProcess, timeDelay); - - function startProcess() { - - const newPloniexHoleFixing = POLONIEX_HOLE_FIXING_MODULE.newPloniexHoleFixing(bot); - - newPloniexHoleFixing.initialize(year, month, onInitializeReady); - - function onInitializeReady() { - - newPloniexHoleFixing.start(); - - } - - } - - } - - } - - } - - - if (START_POLONIEX_HOLE_FIXING_AT_ONE_MONTH === true) { - - startProcess(); - - function startProcess() { - - const newPloniexHoleFixing = POLONIEX_HOLE_FIXING_MODULE.newPloniexHoleFixing(bot); - - let month = 2; - let year = 2015; - - newPloniexHoleFixing.initialize(year, month, onInitializeReady); - - function onInitializeReady() { - - newPloniexHoleFixing.start(); - - } - } - } - - -} catch (err) { - console.log(err.message); - logger.write(err.message); -} - diff --git a/Poloniex-Live-Trades/Interval.js b/Poloniex-Live-Trades/Interval.js index 775727b85..13af05eb9 100644 --- a/Poloniex-Live-Trades/Interval.js +++ b/Poloniex-Live-Trades/Interval.js @@ -1,7 +1,7 @@ -exports.newInterval = function newInterval(BOT) { +exports.newInterval = function newInterval(BOT, UTILITIES, AZURE_FILE_STORAGE, DEBUG_MODULE, MARKETS_MODULE, POLONIEX_CLIENT_MODULE) { let bot = BOT; - const ROOT_DIR = '../'; + const ROOT_DIR = './'; const GMT_SECONDS = ':00.000 GMT+0000'; const GMT_MILI_SECONDS = '.000 GMT+0000'; @@ -17,11 +17,6 @@ const FORCE_MARKET = 2; // This allows to debug the execution of an specific market. Not intended for production. const FORCED_INITIAL_TIME = undefined; //"2018-01-19 12:15:00.000 GMT+0000" - const MARKETS_MODULE = require(ROOT_DIR + 'Markets'); - - const POLONIEX_CLIENT_MODULE = require(ROOT_DIR + 'Poloniex API Client'); - - const DEBUG_MODULE = require(ROOT_DIR + 'Debug Log'); const logger = DEBUG_MODULE.newDebugLog(); logger.fileName = MODULE_NAME; logger.bot = bot; @@ -33,15 +28,13 @@ let markets; - const AZURE_FILE_STORAGE = require(ROOT_DIR + 'Azure File Storage'); let azureFileStorage = AZURE_FILE_STORAGE.newAzureFileStorage(bot); - const UTILITIES = require(ROOT_DIR + 'Utilities'); let utilities = UTILITIES.newUtilities(bot); return interval; - function initialize(callBackFunction) { + function initialize(pYear, pMonth, callBackFunction) { // Year and Month ignored at this process. try { diff --git a/Poloniex-Live-Trades/Poloniex Live Trades.js b/Poloniex-Live-Trades/Poloniex Live Trades.js deleted file mode 100644 index b4dc974c2..000000000 --- a/Poloniex-Live-Trades/Poloniex Live Trades.js +++ /dev/null @@ -1,106 +0,0 @@ -exports.newPloniexLiveTrades = function newPloniexLiveTrades(BOT) { - - let bot = BOT; - const ROOT_DIR = '../'; - - const INTERVAL_LAPSE = 60 * 1000; - - const MODULE_NAME = "Poloniex Exchange Live Trades"; - const LOG_INFO = true; - - const INTERVAL_MODULE = require('./Interval'); - - const DEBUG_MODULE = require(ROOT_DIR + 'Debug Log'); - const logger = DEBUG_MODULE.newDebugLog(); - logger.fileName = MODULE_NAME; - logger.bot = bot; - - poloniexLiveTrades = { - initialize: initialize, - start: start - }; - - const SHUTDOWN_EVENT = require(ROOT_DIR + 'Azure Web Job Shutdown'); - let shutdownEvent = SHUTDOWN_EVENT.newShutdownEvent(bot); - - return poloniexLiveTrades; - - function initialize(callBackFunction) { - - try { - - const logText = "[INFO] initialize - Entering function 'initialize' "; - console.log(logText); - logger.write(logText); - - callBackFunction(); - - } catch (err) { - - const logText = "[ERROR] initialize - ' ERROR : " + err.message; - console.log(logText); - logger.write(logText); - - } - } - - - function start() { - - try { - - let intervalId = setInterval(startNewInterval, INTERVAL_LAPSE); - - startNewInterval(); // First, inmadiate run. - - - - function startNewInterval() { - - try { - - if (LOG_INFO === true) { - logger.write("[INFO] Entering function 'startNewInterval', next execution in " + INTERVAL_LAPSE / 1000 / 60 + " minutes."); - } - - - if (shutdownEvent.isShuttingDown() === false) { - - let fileProcessingInterval = INTERVAL_MODULE.newInterval(bot); - - fileProcessingInterval.initialize(onReadyToStart); - - function onReadyToStart() { - - fileProcessingInterval.start(); - - } - - } - else { - - clearInterval(intervalId); - - const logText = "[INFO] requestNewData - Terminating Set Interval - About to exit gracefully the process. "; - console.log(logText); - logger.write(logText); - - } - - } - catch (err) { - const logText = "[ERROR] 'startNewInterval' - ERROR : " + err.message; - logger.write(logText); - } - } - - } - catch (err) { - const logText = "[ERROR] 'Start' - ERROR : " + err.message; - logger.write(logText); - } - } -}; - - - diff --git a/Poloniex-Live-Trades/run.js b/Poloniex-Live-Trades/run.js deleted file mode 100644 index 2782c137d..000000000 --- a/Poloniex-Live-Trades/run.js +++ /dev/null @@ -1,57 +0,0 @@ - -let bot = { - name: "Charly", - process: "Live-Trades", - type: "Connectivity", - version: "1.0.0", - devTeam: "AA Masters" -}; - -const ROOT_DIR = '../'; - -const MODULE_NAME = "run"; - -const START_POLONIEX_LIVE_TRADES = true; - -const POLONIEX_LIVE_TRADES_MODULE = require('./Poloniex Live Trades'); - -const DEBUG_MODULE = require(ROOT_DIR + 'Debug Log'); -const logger = DEBUG_MODULE.newDebugLog(); -logger.fileName = MODULE_NAME; -logger.bot = bot; - -process.on('uncaughtException', function (err) { - logger.write('uncaughtException - ' + err.message); -}); - - -process.on('unhandledRejection', (reason, p) => { - logger.write("Unhandled Rejection at: Promise " + JSON.stringify(p) + " reason: " + reason); -}); - - -process.on('exit', function (code) { - logger.write('About to exit with code:' + code); -}); - - -try { - if (START_POLONIEX_LIVE_TRADES === true) { - - const newPloniexLiveTrades = POLONIEX_LIVE_TRADES_MODULE.newPloniexLiveTrades(bot); - - newPloniexLiveTrades.initialize(onInitializeReady); - - function onInitializeReady() { - - newPloniexLiveTrades.start(); - - } - - } - -} catch (err) { - console.log(err.message); - logger.write(err.message); -} - diff --git a/Utilities.js b/Utilities.js deleted file mode 100644 index b70a5b5f2..000000000 --- a/Utilities.js +++ /dev/null @@ -1,81 +0,0 @@ - -exports.newUtilities = function newUtilities(BOT) { - - let bot = BOT; - const ROOT_DIR = '../'; - - const MODULE_NAME = "Utilities"; - - - const DEBUG_MODULE = require('./Debug Log'); - const logger = DEBUG_MODULE.newDebugLog(); - logger.fileName = MODULE_NAME; - logger.bot = bot; - - let utilities = { - pad: pad, - createFolderIfNeeded: createFolderIfNeeded, - calculatePresicion: calculatePresicion - }; - - return utilities; - - - function pad(str, max) { - str = str.toString(); - return str.length < max ? pad("0" + str, max) : str; - } - - function createFolderIfNeeded(path, azureFileStorage, callBackFunction) { - - let splittedPath = path.split("/"); - - let partialPath = ''; - let separator = ""; - - - let i = 0; - loop(); - - function loop() { - - partialPath = partialPath + separator + splittedPath[i]; - separator = "/"; - - i++; - - azureFileStorage.createFolder(partialPath, checkLoop); - - function checkLoop() { - - if (i === splittedPath.length) { - - callBackFunction(); - - } else { - - loop(); - - } - - - } - - } - - } - - - function calculatePresicion(number) { - - for (let i = -10; i <= 10; i++) { - if (number < Math.pow(10, i)) { - return Math.pow(10, i - 3); - } - } - } - - - - -} \ No newline at end of file diff --git a/logs/Dummy File.txt b/logs/Dummy File.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/this.bot.config.json b/this.bot.config.json new file mode 100644 index 000000000..6f955d748 --- /dev/null +++ b/this.bot.config.json @@ -0,0 +1,76 @@ +{ + "bot": { + "name": "Charly", + "type": "Extracting", + "version": "1.0.0", + "devTeam": "AA Masters" + }, + "processes": [ + { + "name": "Poloniex-Live-Trades", + "description": "Retrieves the trades done at the current and the previous minute and saves them at the storage account.", + "startMode": { + "allMonths": { + "run": "false", + "minYear": "", + "maxYear": "" + }, + "oneMonth": { + "run": "false", + "year": "", + "month": "" + }, + "noTime": { + "run": "true" + } + }, + "intervalLapse": 60000, + "intervalMaxLoops": 0 + }, + { + "name": "Poloniex-Historic-Trades", + "description": "Retrieves and saves the historical trades in batches going backwards from the current time until reaching the begining of the market.", + "startMode": { + "allMonths": { + "run": "true", + "minYear": "2014", + "maxYear": "2018" + }, + "oneMonth": { + "run": "false", + "year": "", + "month": "" + }, + "noTime": { + "run": "false" + } + }, + "intervalLapse": 30000, + "intervalMaxLoops": -1 + }, + { + "name": "Poloniex-Hole-Fixing", + "description": "Scans the trades saved by the Live Trades and Historic Trades processes searching for missing records. Once a hole is found on the data set, it patches it by retrieving the missing records from the exchange.", + "startMode": { + "allMonths": { + "run": "true", + "minYear": "2014", + "maxYear": "2018" + }, + "oneMonth": { + "run": "false", + "year": "", + "month": "" + }, + "noTime": { + "run": "false" + } + }, + "intervalLapse": 60000, + "intervalMaxLoops": -1 + } + ] +} + + +