From b882f7c096865d8b3761b2fcd42558b85d5ec615 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 6 Mar 2018 15:57:11 +0100 Subject: [PATCH] Some Refactoring --- .vs/AACloudPlatform/v15/.suo | Bin 69632 -> 70144 bytes Assistant.js | 24 ++++++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.vs/AACloudPlatform/v15/.suo b/.vs/AACloudPlatform/v15/.suo index f79bcdb1fbcaa0ebcb2cd59e1f9028e1c6201b9d..184e98d2b5d7f661c7642ac8099f0438cf06209c 100644 GIT binary patch delta 131 zcmZozz|ydUWrD$E0~byS0R{#+1_lOZApZCN|9>FGzzD=@8v~`8SOrXW%SUf6Wctm_ zx}a`bXvpS5wo9i4Iha7IKtTO~G?3l6IporNML}JN7??Bw3NrzP*9b0SW8|8Aw$xd1vpQI9 vFACmV$ad+ppa&yJ6$nTihzGLGHiuk#uPEpQ5d)KcKvD-Nyhd;t8zUD0Btja3 diff --git a/Assistant.js b/Assistant.js index 2db910e26..8eca17224 100644 --- a/Assistant.js +++ b/Assistant.js @@ -9,7 +9,9 @@ const MODULE_NAME = "Assistant"; thisObject = { - initialize: initialize + initialize: initialize, + putPositionAtExchange: putPositionAtExchange, + movePositionAtExchange: movePositionAtExchange }; let bot = BOT; @@ -49,15 +51,25 @@ let exchangePositions = []; // These are the open positions at the exchange at the account the bot is authorized to use. let openPositions = []; // These are the open positions the bot knows it made by itself. + let botContext; + let processDatetime; + let exchangeAPI; + return thisObject; - function initialize(callBackFunction) { + function initialize(pBotContext, pProcessDatetime, pExchangeAPI, callBackFunction) { try { let nextIntervalExecution = false; // This tell the AAPlatform if it must execute the bot code again or not. let nextIntervalLapse = 10 * 1000; // If something fails and we need to retry after a few seconds, we will use this amount of time to request a new execution of this bot code. + /* Store local values. */ + + botContext = pBotContext; + processDatetime = pProcessDatetime; + exchangeAPI = pExchangeAPI; + /* The bot trades only at one market: USDT_BTC. */ const market = { @@ -98,7 +110,7 @@ } break; case 'Retry Later.': { // Something bad happened, but if we retry in a while it might go through the next time. - logger.write("[ERROR] getPositionsAtExchange -> onResponse -> Retry Later. Requesting Interval Retry."); + logger.write("[ERROR] getPositionsAtExchange -> onResponse -> Retry Later. Requesting Execution Retry."); callBackFunction(true, nextIntervalLapse); return; } @@ -392,7 +404,7 @@ } break; case 'Retry Later.': { // Something bad happened, but if we retry in a while it might go through the next time. - logger.write("[ERROR] getPositionTradesAtExchange -> onResponse -> Retry Later. Requesting Interval Retry."); + logger.write("[ERROR] getPositionTradesAtExchange -> onResponse -> Retry Later. Requesting Execution Retry."); callBackFunction(true, nextIntervalLapse); return; } @@ -452,7 +464,7 @@ } break; case 'Retry Later.': { // Something bad happened, but if we retry in a while it might go through the next time. - logger.write("[ERROR] putPositionAtExchange -> onResponse -> Retry Later. Requesting Interval Retry."); + logger.write("[ERROR] putPositionAtExchange -> onResponse -> Retry Later. Requesting Execution Retry."); callBackFunction(true, nextIntervalLapse); return; } @@ -525,7 +537,7 @@ } break; case 'Retry Later.': { // Something bad happened, but if we retry in a while it might go through the next time. - logger.write("[ERROR] movePositionAtExchange -> onResponse -> Retry Later. Requesting Interval Retry."); + logger.write("[ERROR] movePositionAtExchange -> onResponse -> Retry Later. Requesting Execution Retry."); callBackFunction(true, nextIntervalLapse); return; }