diff --git a/AAArtudito-Trading-Bot.sln b/AAArtudito-Trading-Bot.sln index da30e179e..96d26e1f6 100644 --- a/AAArtudito-Trading-Bot.sln +++ b/AAArtudito-Trading-Bot.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.27130.2027 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}") = "Project", "Project.njsproj", "{AA2901BC-8F81-40F0-A402-5CA79A3F22AD}" +Project("{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}") = "Project", "Artudito.njsproj", "{AA2901BC-8F81-40F0-A402-5CA79A3F22AD}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Project.njsproj b/AAArtudito.njsproj similarity index 98% rename from Project.njsproj rename to AAArtudito.njsproj index 319a734ad..c845e44e4 100644 --- a/Project.njsproj +++ b/AAArtudito.njsproj @@ -3,7 +3,7 @@ Debug 2.0 - {aa2901bc-8f81-40f0-a402-5ca79a3f22ad} + {a54d4656-3db8-407a-9333-e65115e994ab} ShowAllFiles User.Bot.js diff --git a/Trading-Process/User.Bot.js b/Trading-Process/User.Bot.js index 872f2d03c..9268111b7 100644 --- a/Trading-Process/User.Bot.js +++ b/Trading-Process/User.Bot.js @@ -9,12 +9,13 @@ start: start }; + let genes; let assistant; // The reference to the Traing Platform Advanced Algos Assistant. let gaussStorage; // This is an example of dependency to other bots return thisObject; - function initialize(pAssistant, callBackFunction) { + function initialize(pAssistant, pGenes, callBackFunction) { try { if (LOG_INFO === true) { logger.write(MODULE_NAME, "[INFO] initialize -> Entering function."); } @@ -26,13 +27,55 @@ gaussStorage = assistant.dataDependencies.dataSets.get(key); - callBackFunction(global.DEFAULT_OK_RESPONSE); + checkGenes(pGenes, callBackFunction); + } catch (err) { logger.write(MODULE_NAME, "[ERROR] initialize -> onDone -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } + function checkGenes(pGenes, callBackFunction) { + + try { + if (LOG_INFO === true) { logger.write(MODULE_NAME, "[INFO] checkGenes -> Entering function."); } + + function getGeneticRulesByName(pName) { + + for (let i = 0; i < bot.genes.length; i++) { + + let gene = bot.genes[i]; + + if (gene.name === pName) { + + return gene; + + } + } + + return undefined; + } + + let stopLoss = getGeneticRulesByName("stopLoss"); + + if (pGenes.stopLoss < stopLoss.lowerLimit || pGenes.stopLoss > stopLoss.upperLimit ) { + logger.write(MODULE_NAME, "[ERROR] getGeneticRules -> Genes received are out of range."); + logger.write(MODULE_NAME, "[ERROR] getGeneticRules -> pGenes = " + JSON.stringify(pGenes)); + logger.write(MODULE_NAME, "[ERROR] getGeneticRules -> bot.genes = " + JSON.stringify(bot.genes)); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; + } + + genes = pGenes; + + callBackFunction(global.DEFAULT_OK_RESPONSE); + + } catch (err) { + logger.write(MODULE_NAME, "[ERROR] checkGenes -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + } + } + function start(callBackFunction) { if (LOG_INFO === true) { logger.write(MODULE_NAME, "[INFO] start -> Entering function."); } @@ -46,8 +89,8 @@ // Parameters let targetTradeEnabled = false; const TRADE_TARGET = 2.0; - let stopLossEnabled = false; - let stopLossPorcentage = 0.006; + let stopLossEnabled = true; + let stopLossPorcentage = genes.stopLoss / 100; let lastBuyRate = assistant.remindMeOf(LAST_BUY_RATE_KEY); if (lastBuyRate === undefined) { @@ -101,8 +144,15 @@ function businessLogic(callBack) { if (LOG_INFO === true) { logger.write(MODULE_NAME, "[INFO] start -> businessLogic -> Entering function."); } let firstChannelTilt = 0; + + //Simulation for testing + if (Math.random(1) <= 0.5){ + createBuyPosition(callBack); + }else{ + createSellPosition(callBack); + } - getChannelTilt(firstTiltCheck); + //getChannelTilt(firstTiltCheck); function firstTiltCheck(err, channelTilt) { try { @@ -540,11 +590,11 @@ if (LOG_INFO === true) { logger.write(MODULE_NAME, "[INFO] start -> businessLogic -> createBuyPosition -> Entering function."); } let assetABalance = assistant.getAvailableBalance().assetA; - let currentRate = assistant.getTicker().bid; + let currentRate = assistant.getTicker().ask; // *.9 let amountA = assistant.getAvailableBalance().assetA; let amountB = Number((amountA / currentRate).toFixed(8)); - if (positions.length > 0 && positions[0].type === "buy" && positions[0].status !== "executed" && (bot.processDatetime.valueOf() - positions[0].date) > (60000 * 5)) { + if (positions.length > 0 && positions[0].type === "buy" && positions[0].status !== "executed" ) { if (LOG_INFO === true) { logger.write(MODULE_NAME, "[INFO] start -> businessLogic -> createBuyPosition -> Moving an existing BUY position to a new price: $" + Number(currentRate).toLocaleString()); } @@ -583,11 +633,11 @@ if (LOG_INFO === true) { logger.write(MODULE_NAME, "[INFO] start -> businessLogic -> createSellPosition -> Entering function."); } let assetBBalance = assistant.getAvailableBalance().assetB; - let currentRate = assistant.getTicker().bid; + let currentRate = assistant.getTicker().bid; // *1.1 let amountB = assistant.getAvailableBalance().assetB; let amountA = amountB * currentRate; - if (positions.length > 0 && positions[0].type === "sell" && positions[0].status !== "executed" && (bot.processDatetime.valueOf() - positions[0].date) > (60000 * 10)) { + if (positions.length > 0 && positions[0].type === "sell" && positions[0].status !== "executed" ) { if (LOG_INFO === true) { logger.write(MODULE_NAME, "[INFO] start -> businessLogic -> createSellPosition -> Artuditu is moving an existing SELL position to a new price: $" + Number(currentRate).toLocaleString()); } diff --git a/this.bot.config.json b/this.bot.config.json index c89b6f6a4..a86fd9f84 100644 --- a/this.bot.config.json +++ b/this.bot.config.json @@ -10,17 +10,25 @@ "devTeam": "AAVikings", "profilePicture": "Artudito.png", "dataSetVersion": "dataSet.V1", + "genes": [ + { + "name": "stopLoss", + "description": "This represent the percentage of the stop loss configuration. It could be from 0 (disabled) to 100.", + "lowerLimit": 0, + "upperLimit": 5 + } + ], "processes": [ { "name": "Trading-Process", "description": "Simple trading strategy to be used as a template.", "startMode": { "live": { - "run": "false", + "run": "true", "resumeExecution": "false" }, "backtest": { - "run": "true", + "run": "false", "beginDatetime": "2018-04-11T00:00:00.000Z", "endDatetime": "2018-06-17T23:59:59.000Z", "waitTime": 1 @@ -32,7 +40,7 @@ "resumeExecution": "true" } }, - "normalWaitTime": 60000, + "normalWaitTime": 10000, "retryWaitTime": 10000, "sleepWaitTime": 3600000, "comaWaitTime": 86400000, @@ -197,5 +205,5 @@ } } ], - "emailSubscriptions": "mati108@gmail.com" + "emailSubscriptions": "vikings.alerts@gmail.com" } \ No newline at end of file