From fbe86ab8e585cb0c25711090af541d5d6e9d6a5f Mon Sep 17 00:00:00 2001 From: Matias Benitez Date: Mon, 4 Jun 2018 18:28:37 -0300 Subject: [PATCH] Dev Team and Gauss dependency Moving to AAVikings and implementing Gauss dependency. --- .gitignore | 1 - Trading-Process/User.Bot.js | 253 ++++++++++-------------------------- this.bot.config.json | 51 +++----- 3 files changed, 92 insertions(+), 213 deletions(-) diff --git a/.gitignore b/.gitignore index 0aa846208..82c487bdd 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,3 @@ bin/* *.cache node_modules/* -package-lock.json diff --git a/Trading-Process/User.Bot.js b/Trading-Process/User.Bot.js index 9a7c6fe97..002cf1228 100644 --- a/Trading-Process/User.Bot.js +++ b/Trading-Process/User.Bot.js @@ -1,5 +1,4 @@ -var LRCIndicator = require('./LRCIndicator'); -exports.newUserBot = function newUserBot(BOT, DEBUG_MODULE, COMMONS_MODULE) { +exports.newUserBot = function newUserBot(BOT, DEBUG_MODULE, COMMONS_MODULE) { let bot = BOT; const FULL_LOG = true; @@ -14,30 +13,9 @@ exports.newUserBot = function newUserBot(BOT, DEBUG_MODULE, COMMONS_MODULE) { start: start }; - let assistant; // You will receive a reference to the Traing Platform Advanced Algos Assistant at initialization. + let assistant; // The reference to the Traing Platform Advanced Algos Assistant. + let gaussStorage; // This is an example of dependency to other bots - /* - - The Traing Platform Advanced Algos Assistant object represents the implementation of the assistant that will allow to create and move positions on the exchange market. - - More details about these objects: - - datasource = { - 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. - stairsFiles: new Map, // Complete sets of patterns for different Time Periods. For Time Periods < 1hs sets are of current day only, otherwise whole market. - stairsMap: new Map // The patterns we are currently in will be stored here. - }; - - assistant = { - putPosition: putPosition, // To create a buy or sell position. - movePosition: movePosition // To modify an existing position. - }; - - */ - - let oliviaStorage; // This is an example of dependency to other bots - let commons; return thisObject; function initialize(pAssistant, callBackFunction) { @@ -45,24 +23,19 @@ exports.newUserBot = function newUserBot(BOT, DEBUG_MODULE, COMMONS_MODULE) { if (LOG_INFO === true) { logger.write("[INFO] initialize -> Entering function."); } logger.fileName = MODULE_NAME; - commons = COMMONS_MODULE; + assistant = pAssistant; - let key = "AAMasters-AAOlivia-Candles-Multi-Period-Daily-dataSet.V1"; + let key = "AAVikings-AAGauss-LRC-Points-Multi-Period-Daily-dataSet.V1"; - oliviaStorage = assistant.dataDependencies.dataSets.get(key); + gaussStorage = assistant.dataDependencies.dataSets.get(key); callBackFunction(global.DEFAULT_OK_RESPONSE); } catch (err) { logger.write("[ERROR] initialize -> onDone -> err = " + err.message); callBackFunction(global.DEFAULT_RETRY_RESPONSE); } } - - function pad(str, max) { - str = str.toString(); - return str.length < max ? pad("0" + str, max) : str; - } - + function start(callBackFunction) { try { if (LOG_INFO === true) { logger.write("[INFO] start -> Entering function."); } @@ -201,218 +174,136 @@ exports.newUserBot = function newUserBot(BOT, DEBUG_MODULE, COMMONS_MODULE) { const CHANNEL_DOWN = -1; const CHANNEL_UP = 1; const NO_CHANNEL = 0; - const maxLRCDepth = 62; // 61 to be able to calculate current lrc60, plus one to calculate previous lrc60 - const maxBackwardsCount = 60; - - let backwardsCount = 0; - let candleArray = []; + let lrcPoint, previousLRCPoint; let queryDate = new Date(bot.processDatetime); - let candleFile = getDailyFile(queryDate, onDailyFileReceived); + getLRCPointsFile(queryDate, onLRCPointsFileReceived); - function onDailyFileReceived(err, candleFile) { - if (LOG_INFO === true) { logger.write("[INFO] start -> getChannelTilt -> onDailyFileReceived." ); } + function onLRCPointsFileReceived(err, lrcPointsFile) { + if (LOG_INFO === true) { logger.write("[INFO] start -> getChannelTilt -> onDailyFileReceived."); } - if (err.result === global.DEFAULT_OK_RESPONSE.result) { - for (let i = 0; i < candleFile.length; i++) { - let candle = { - open: undefined, - close: undefined, - min: 10000000000000, - max: 0, - begin: undefined, - end: undefined, - direction: undefined + for (let i = 0; i < lrcPointsFile.length; i++) { + + if (lrcPointsFile[i][0] === bot.processDatetime.valueOf()) { + lrcPoint = { + begin: lrcPointsFile[i][0], + end: lrcPointsFile[i][1], + min: lrcPointsFile[i][2], + mid: lrcPointsFile[i][3], + max: lrcPointsFile[i][4] }; - candle.min = candleFile[i][0]; - candle.max = candleFile[i][1]; + if (i >= 1) { + let previous = i - 1; + previousLRCPoint = { + begin: lrcPointsFile[previous][0], + end: lrcPointsFile[previous][1], + min: lrcPointsFile[previous][2], + mid: lrcPointsFile[previous][3], + max: lrcPointsFile[previous][4] + }; - candle.open = candleFile[i][2]; - candle.close = candleFile[i][3]; + applyBotRules(); - candle.begin = candleFile[i][4]; - candle.end = candleFile[i][5]; - - if (candle.open > candle.close) { candle.direction = 'down'; } - if (candle.open < candle.close) { candle.direction = 'up'; } - if (candle.open === candle.close) { candle.direction = 'side'; } - - - if (LOG_INFO === true) { logger.write("[INFO] Candle Date: " + new Date(candle.begin).toISOString() + ". Process Date: " + bot.processDatetime.toISOString()); } - - if (candleArray.length < maxLRCDepth && candle.begin <= bot.processDatetime.valueOf()) { - candleArray.push(candleFile[i]); + } else { + queryDate.setDate(queryDate.getDate() - 1); + getLRCPointsFile(queryDate, onPreviousLRCPointsFileReceived); } - } - - if (LOG_INFO === true) { logger.write("[INFO] start -> getChannelTilt -> Candle Array Length: " + candleArray.length); } - if (candleArray.length >= maxLRCDepth) { - if (LOG_INFO === true) { logger.write("[INFO] start -> getChannelTilt -> All candles available proceed with LRC calculations."); } - - performLRCCalculations(callBack); - }else if (backwardsCount <= maxBackwardsCount) { - if (LOG_INFO === true) { logger.write("[INFO] start -> getChannelTilt -> Getting file for day before."); } - - queryDate.setDate(queryDate.getDate() - 1); - getDailyFile(queryDate, onDailyFileReceived); - backwardsCount++; - } else { - logger.write("[ERROR] start -> getChannelTilt -> Not enough history to calculate LRC."); - callBack(global.DEFAULT_RETRY_RESPONSE); + break; } } } - function performLRCCalculations(callBack){ - /* - * It's needed to order since it's possible that we need to get another file and it will put an older candle at the end of the array. - */ - candleArray.sort(function (a, b) { - return a[4] - b[4]; - }); + function onLRCPointsFileReceived(err, lrcPointsFile) { + if (LOG_INFO === true) { logger.write("[INFO] start -> getChannelTilt -> onDailyFileReceived."); } - let lrcPoints = calculateLRC(candleArray); + let previous = lrcPointsFile.length - 2; + previousLRCPoint = { + begin: lrcPointsFile[previous][0], + end: lrcPointsFile[previous][1], + min: lrcPointsFile[previous][2], + mid: lrcPointsFile[previous][3], + max: lrcPointsFile[previous][4] + }; - let lrc15 = lrcPoints.minimumChannelValue; - let lrc30 = lrcPoints.middleChannelValue; - let lrc60 = lrcPoints.maximumChannelValue; + applyBotRules(); + } - /** - * We take the last candle (because it's the newest) and calculate the LRC points again to detect the tilt. - */ - let previousCandleArray = candleArray.slice(0, candleArray.length - 1); - let lrcPreviousPoints = calculateLRC(previousCandleArray); - - let previousLrc15 = lrcPreviousPoints.minimumChannelValue; - let previousLrc30 = lrcPreviousPoints.middleChannelValue; - let previousLrc60 = lrcPreviousPoints.maximumChannelValue; - + function applyBotRules() { + if (LOG_INFO === true) { logger.write("[INFO] start -> getChannelTilt -> applyBotRules -> LRC Point Found: " + JSON.stringify(lrcPoint)); } let channelTilt = NO_CHANNEL; let ruleApplied = ""; - if (lrc60 < lrc30 && lrc15 > lrc30 && lrc30 < lrc15) { - if (lrc15 > previousLrc15 && lrc30 > previousLrc30 && lrc60 > previousLrc60) { + if (lrcPoint.mid < lrcPoint.mid && lrcPoint.min > lrcPoint.mid && lrcPoint.mid < lrcPoint.min) { + if (lrcPoint.min > previousLrc15 && lrcPoint.mid > previousLrc30 && lrcPoint.mid > previousLrc60) { channelTilt = CHANNEL_UP; // The channel points UP ruleApplied += "Rule_1."; } } - if (lrc15 < lrc30 && lrc60 > lrc30 && lrc30 < lrc60) { - if (lrc15 < previousLrc15 && lrc30 < previousLrc30 && lrc60 < previousLrc60) { + if (lrcPoint.min < lrcPoint.mid && lrcPoint.mid > lrcPoint.mid && lrcPoint.mid < lrcPoint.mid) { + if (lrcPoint.min < previousLrc15 && lrcPoint.mid < previousLrc30 && lrcPoint.mid < previousLrc60) { channelTilt = CHANNEL_DOWN; // The channel points DOWN ruleApplied += "Rule_2."; } } - if (lrc15 < previousLrc15 && lrc30 <= previousLrc30) { + if (lrcPoint.min < previousLrc15 && lrcPoint.mid <= previousLrc30) { // 15 AND 30 changed direction from up to down channelTilt = CHANNEL_DOWN; ruleApplied += "Rule_3a."; } - if (lrc15 > previousLrc15 && lrc30 >= previousLrc30) { + if (lrcPoint.min > previousLrc15 && lrcPoint.mid >= previousLrc30) { // 15 AND 30 changed direction from down to up channelTilt = CHANNEL_UP; ruleApplied += "Rule_3b."; } - let logMessage = bot.processDatetime.toISOString() + "\t" + ruleApplied + "\t" + channelTilt + "\t" + lrc15 + "\t" + lrc30 + "\t" + lrc60 ; - if (LOG_INFO === true) { logger.write("[INFO] start -> getChannelTilt -> performLRCCalculations -> Results: "+ logMessage); } + let logMessage = bot.processDatetime.toISOString() + "\t" + ruleApplied + "\t" + channelTilt + "\t" + lrcPoint.min + "\t" + lrcPoint.mid + "\t" + lrcPoint.mid; + if (LOG_INFO === true) { logger.write("[INFO] start -> getChannelTilt -> applyBotRules -> Results: " + logMessage); } callBack(global.DEFAULT_OK_RESPONSE, channelTilt); + } } - function getDailyFile(dateTime, onDailyFileReceived) { + function getLRCPointsFile(dateTime, onDailyFileReceived) { try { - if (FULL_LOG === true) { logger.write("[INFO] start -> getChannelTilt -> getDailyFile -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] start -> getChannelTilt -> getLRCPointsFile -> Entering function."); } - //TODO Hardcoded parameters - let periodTime = 1800000; let periodName = "30-min"; + let datePath = dateTime.getUTCFullYear() + "/" + pad(dateTime.getUTCMonth() + 1, 2) + "/" + pad(dateTime.getUTCDate(), 2); + let filePath = "AAVikings/AAGauss.1.0/AACloud.1.1/Poloniex/dataSet.V1/Output/LRC-Points/Multi-Period-Daily/" + periodName + "/" + datePath; + let fileName = market.assetA + '_' + market.assetB + ".json" - let pFileName = MARKET.assetA + "_" + MARKET.assetB + ".json"; - let pFilePath = "Candles/Multi-Period-Daily/"; - pFilePath += periodName; - pFilePath += "/" + dateTime.getUTCFullYear(); - pFilePath += "/" + pad(dateTime.getUTCMonth() + 1, 2); - pFilePath += "/" + pad(dateTime.getUTCDate(), 2); - - oliviaStorage.getTextFile(pFilePath, pFileName, onFileReceived); + gaussStorage.getTextFile(pFilePath, pFileName, onFileReceived); function onFileReceived(err, text) { if (err.result === global.DEFAULT_OK_RESPONSE.result) { - if (FULL_LOG === true) { logger.write("[INFO] start -> getChannelTilt -> getDailyFile -> onFileReceived > Entering Function."); } + if (FULL_LOG === true) { logger.write("[INFO] start -> getChannelTilt -> getLRCPointsFile -> onFileReceived > Entering Function."); } - let candleFile = JSON.parse(text); - onDailyFileReceived(global.DEFAULT_OK_RESPONSE, candleFile); + let lrcPointsFile = JSON.parse(text); + onDailyFileReceived(global.DEFAULT_OK_RESPONSE, lrcPointsFile); } else { - logger.write("[ERROR] start -> getChannelTilt -> getDailyFile -> onFileReceived -> Failed to get the file. Will abort the process and request a retry."); + logger.write("[ERROR] start -> getChannelTilt -> getLRCPointsFile -> onFileReceived -> Failed to get the file. Will abort the process and request a retry."); callBackFunction(global.DEFAULT_RETRY_RESPONSE); return; } } } catch (err) { - logger.write("[ERROR] start -> getChannelTilt -> getDailyFile -> err = " + err.message); + logger.write("[ERROR] start -> getChannelTilt -> getLRCPointsFile -> err = " + err.message); callBackFunction(global.DEFAULT_RETRY_RESPONSE); } } - function calculateLRC(candlesArray) { - if (LOG_INFO === true) { logger.write("[INFO] start -> getChannelTilt -> calculateLRC -> Entering function."); } - - let minimumChannelDepth = 15; - let middleChannelDepth = 30; - let maximumChannelDepth = 60; - - let lrcPoints = { - minimumChannelValue: 0, - middleChannelValue: 0, - maximumChannelValue: 0, - lrcTimeBegin: 0 - }; - - let lrcMinIndicator = new LRCIndicator(minimumChannelDepth); - let lrcMidIndicator = new LRCIndicator(middleChannelDepth); - let lrcMaxIndicator = new LRCIndicator(maximumChannelDepth); - let currentCandle = candlesArray[candlesArray.length - 1]; - - for (let i = 0; i < candlesArray.length; i++) { - let tempCandle = candlesArray[i]; - let averagePrice = (tempCandle[0] + tempCandle[1] + tempCandle[2] + tempCandle[3]) / 4; // TODO Check which price should be take to get the LRC - lrcMinIndicator.update(averagePrice); - lrcMidIndicator.update(averagePrice); - lrcMaxIndicator.update(averagePrice); - } - if (FULL_LOG === true) { - logger.write("[INFO] start -> getChannelTilt -> calculateLRC -> candlesArray.length: " + candlesArray.length + ". lrcMinIndicator: " + lrcMinIndicator.age + ". lrcMidIndicator: " - + lrcMidIndicator.age + ". lrcMaxIndicator: " + lrcMaxIndicator.age); - - } - - if (FULL_LOG === true) { - logger.write("[INFO] start -> getChannelTilt -> calculateLRC -> Values: " + "lrcMinIndicator: " + lrcMinIndicator.result + ". lrcMidIndicator: " - + lrcMidIndicator.result + ". lrcMaxIndicator: " + lrcMaxIndicator.result); - } - - /* - * Only if there is enough history the result will be calculated - */ - if (lrcMinIndicator.result != false && lrcMidIndicator.result != false && lrcMaxIndicator.result != false) { - lrcPoints.minimumChannelValue = lrcMinIndicator.result; - lrcPoints.middleChannelValue = lrcMidIndicator.result; - lrcPoints.maximumChannelValue = lrcMaxIndicator.result; - lrcPoints.lrcTimeBegin = currentCandle[4]; - - return lrcPoints; - } else { - logger.write("[ERROR] start -> getChannelTilt -> calculateLRC -> There is not enough history to calculate the LRC."); - callBackFunction(global.DEFAULT_RETRY_RESPONSE); - } + function pad(str, max) { + str = str.toString(); + return str.length < max ? pad("0" + str, max) : str; } + } catch (err) { logger.write("[ERROR] start -> err = " + err.message); callBackFunction(global.DEFAULT_RETRY_RESPONSE); diff --git a/this.bot.config.json b/this.bot.config.json index 4b7783f06..a8514fa7d 100644 --- a/this.bot.config.json +++ b/this.bot.config.json @@ -7,7 +7,7 @@ "minor": 0, "patch": 0 }, - "devTeam": "AAMasters", + "devTeam": "AAVikings", "profilePicture": "Artudito.png", "dataSetVersion": "dataSet.V1", "processes": [ @@ -38,8 +38,8 @@ "comaWaitTime": 86400000, "statusDependencies": [ { - "devTeam": "AAMasters", - "bot": "AAOlivia", + "devTeam": "AAVikings", + "bot": "AAGauss", "botVersion": { "major": 1, "minor": 0 @@ -48,38 +48,27 @@ "dataSetVersion": "dataSet.V1" }, { - "devTeam": "AAMasters", - "bot": "AAArtudito", - "botVersion": { - "major": 1, - "minor": 0 - }, - "process": "Trading-Process", - "dataSetVersion": "dataSet.V1" + "devTeam": "AAVikings", + "bot": "AAArtudito", + "botVersion": { + "major": 1, + "minor": 0 + }, + "process": "Trading-Process", + "dataSetVersion": "dataSet.V1" } ], "dataDependencies": [ { - "devTeam": "AAMasters", - "bot": "AAOlivia", - "botVersion": { - "major": 1, - "minor": 0 - }, - "product": "Candles", - "dataSetVersion": "dataSet.V1", - "dataSet": "Multi-Period-Daily" - }, - { - "devTeam": "AAMasters", - "bot": "AABruce", - "botVersion": { - "major": 1, - "minor": 0 - }, - "product": "Candles", - "dataSetVersion": "dataSet.V1", - "dataSet": "One-Min" + "devTeam": "AAVikings", + "bot": "AAGauss", + "botVersion": { + "major": 1, + "minor": 0 + }, + "product": "LRC-Points", + "dataSetVersion": "dataSet.V1", + "dataSet": "Multi-Period-Daily" } ] }