From 93bc2ebed6014d5c1869c06894c7a1955c8b2c68 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 7 Mar 2018 12:58:46 +0100 Subject: [PATCH] Cloud Platform fully Implemented to run Trading Bots --- .vs/AAMariam-Trading-Bot/v15/.suo | Bin 27648 -> 28672 bytes Project.njsproj | 3 +- This.Bot.js => Trading-Process/User.Bot.js | 74 ++++++++++++++------- 3 files changed, 52 insertions(+), 25 deletions(-) rename This.Bot.js => Trading-Process/User.Bot.js (72%) diff --git a/.vs/AAMariam-Trading-Bot/v15/.suo b/.vs/AAMariam-Trading-Bot/v15/.suo index f4eb38ccd77f4b8fad5eb02ff59466c3ef7407f0..446214d5f330a9cbd00f5098523a21635550669c 100644 GIT binary patch delta 2067 zcmds&T}+#06vyA^r4;BFj*qodzUGz;mDW;7Klm8^WTl-TY@iujtT4*TW~;muv4C`X z|IwWlOWi?IL?c6WDqS*V+ul-N8Q+|ph&ZTzZStNHq_XlF|+ zW#l3HrlM1<(6&5ccn)iI00(#JlKH6ic}#xOP^Ky)UZ?GfV~1OcJJ@$8#@z3c!K?n?j6CezDUj%&=oCGg{VK4$- z2BTmMoC2r8IG6yhND@uzL&gNg^WXxwNSnI)_BSwE018+HX|M#|1k2zpkO6c| ziWH>{>mo_p_7|+!J<3>km7>8N?vuupn;*H)QERKFf5GHK`a_d3~Ij4 zBuH-iwwl$s=Zo?OM_9?UXue8zSwr6k>U53Rz^V)0q2vCy=|ZqpGp@`o&>g?Ml?OI| zYSA{YoC)+y@l=^QnNBEEN-DiD^J!GjJE605FVaTmLKf8$KQF#|Ixkla!QUj^Z~9XV z(022>IIgB!^cKSqVy}gXuO8iW9;Gjwzf@?X7V34ksJC3xLVQjlx(|7!_SI7hM z^CGSEn?zZQ2ItEe?1qw*j?t>$TVLX{nCim%zGqzyOf(!q9A>~}W({zopSxOXe7JwH z!mKmWU-jw_Tue!=3f~u$4Yt!CE(_&?Ij&VUl%?DW9qGbOvPYL`Ir1LYjV$pdH6Oid z`qu>-MlHA;%>Dv>QY=s#z3&-sv~x)KoRllal3bGTN_>|&;j(la31919JfBc((-7cH zDj84AL5Hd2>gtNe?sNLPd@gIC)7NF~w%a{cpTq68h8%-~ZcoVL9Q4`O9@F!~da>gU z`oM2xsh5`H4431P{x1h2ZLEyFRyO}1`wzD~Ucipntiu&^PV-T^9_V|fSQMU{z~4)# zeON*+mqmeor;9qCL7$Z3QbL-OXx=~SeUfy@Qm~NIu_tlTQ10+4ByOPbA1!6i&_>_| p*|ADD91UtXd|UiSpCi>9&k5Qvcf+4S%>})pRPgxo<(qR&`U|N8DPjNs delta 1478 zcmd6n%TE(g6o=>bI<8$yQICN4X<04 zGOJLMjMx(Ro=hf%)&Sz6E#f2%kiwO!+u9iMtUP~9rLbrYj+&x0$NQ!S@=XIr4SoDl z_R$sIH=J6t!ovdcfXG(@36adtNU^tLZ_Yd)hb#icpbVfKsT?@K3E%`3zzsyKSe4jU z1ChT5vMOtfk55rdUa)ybW+yZhTnE$d1xH1(xvw~3HWt=r5;Z`c1M$#likaWv5Xl9t z(6xc{-~wm|7l8^cfes-2Iw8A2H|PPqpbrGWWzY`>z#tgnO>;5#TSjwIr)-9<#gs6O z@UpT-A>PODu)b`ap?_M$kYYor;sWt@NxolFBdRJIBrA!55lXRyLEk%OBbHqqifE}9Gmg&AEpfc`Yym+B zQfp2X#z@S$m#x^;0#iiRzgC-M%i_$LjyvJ&2f;>?I)6#$RfNd{AJ6gtNGVbbSsX%Y(F4mffwspHhiioEgH;vWe0o0%$p6v*X= zlli9fiLu@~{yc5pSya)}o>H_l{ZbyuEBR6}AN}Q=u&cV(tr2TMRad(c^ehpir)9L$ nui5_7Ze&~a=eHg7iI2g-x{8hXK>VGX*B{&GiFfVV(L4SDOsb!A diff --git a/Project.njsproj b/Project.njsproj index 83de1393a..a65b8170e 100644 --- a/Project.njsproj +++ b/Project.njsproj @@ -36,11 +36,12 @@ + - + diff --git a/This.Bot.js b/Trading-Process/User.Bot.js similarity index 72% rename from This.Bot.js rename to Trading-Process/User.Bot.js index e2eeda39f..52f2eef73 100644 --- a/This.Bot.js +++ b/Trading-Process/User.Bot.js @@ -1,4 +1,4 @@ -exports.newThisBot = function newThisBot(BOT, DEBUG_MODULE) { +exports.newUserBot = function newUserBot(BOT, DEBUG_MODULE) { let bot = BOT; @@ -8,30 +8,56 @@ logger.fileName = MODULE_NAME; logger.bot = bot; - interval = { + thisObject = { initialize: initialize, start: start }; - let botContext; - let processDatetime; - let datasource; - let assistant; + let platform; // You will receive a reference to the platform at your initialize function. - return interval; + /* - function initialize(pBotContext, pProcessDatetime, pDatasource, pAssistant, callBackFunction) { + The Platform object represents what the AA Platform provides you to help you with your bot. Inside it you can access to these inner objects: + + platform = { + context: context, // This one will allow you to get historical information of what your bot did on previous executions and learn about which is your current status every time your bot runs. + datasource: datasource, // This one will provide you with pre-loaded data ready for you to consume. In this version candlesticks and stari patterns. + assistant: assistant, // This one will help you to to create, and move positions at the exchange. + processDatetime: processDatetime // This is the current oficial execution time that will be recorded in logs, and used to retrieve stored data. + }; + + More details about these objects: + + context = { + 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. + }; + + 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 = { + putPositionAtExchange: putPositionAtExchange, + movePositionAtExchange: movePositionAtExchange + }; + + */ + + return thisObject; + + function initialize(pProcessDatetime, pPlatform, callBackFunction) { try { logger.fileName = MODULE_NAME; /* Store local values. */ - - botContext = pBotContext; - processDatetime = pProcessDatetime; - datasource = pDatasource; - assistant = pAssistant; + platform = pPlatform; logger.write("[INFO] initialize -> Entering function 'initialize' "); @@ -107,12 +133,12 @@ */ - if (botContext.executionContext.positions.length > 0) { + if (platform.context.executionContext.positions.length > 0) { - if (botContext.executionContext.positions[0].type === "buy") { - decideAboutBuyPosition(botContext.executionContext.positions[0], callBack); + if (platform.context.executionContext.positions[0].type === "buy") { + decideAboutBuyPosition(platform.context.executionContext.positions[0], callBack); } else { - decideAboutSellPosition(botContext.executionContext.positions[0], callBack); + decideAboutSellPosition(platform.context.executionContext.positions[0], callBack); } } else { @@ -128,7 +154,7 @@ */ - let candleArray = datasource.candlesMap.get("01-min"); // In this version of the platform, this array will contain the las 10 candles. + let candleArray = platform.datasource.candlesMap.get("01-min"); // In this version of the platform, this array will contain the las 10 candles. let candle = candleArray[candleArray.length - 1]; // The last candle of the 10 candles array for the 1 min Time Period. let currentRate = candle.close; @@ -138,7 +164,7 @@ any reason stops being updated. */ - if (candle.begin < processDatetime.valueOf() - 5 * 60 * 1000) { + if (candle.begin < platform.processDatetime.valueOf() - 5 * 60 * 1000) { const logText = ; logger.write("[WARN] start -> businessLogic -> Last one min candle more than 5 minutes old. Bot cannot operate with this delay. Retrying later."); @@ -160,8 +186,8 @@ const INITIAL_BALANCE_A = 0.0000; const INITIAL_BALANCE_B = 0.0001; - let AmountA = botContext.statusReport.initialBalance.amountA; - let AmountB = botContext.statusReport.initialBalance.amountB; + let AmountA = platform.context.statusReport.initialBalance.amountA; + let AmountB = platform.context.statusReport.initialBalance.amountB; /* Here is this bot example, we are going to sell all AmountB at once. You can do this or whatever you think is better. @@ -169,7 +195,7 @@ AmountA = AmountB * rate; - assistant.putPositionAtExchange("sell", rate, AmountA, AmountB, writeStatusAndContext, callBack); + platform.assistant.putPositionAtExchange("sell", rate, AmountA, AmountB, writeStatusAndContext, callBack); } } catch (err) { @@ -242,7 +268,7 @@ timePeriodName = marketFilesPeriods[i][1]; - candleArray = datasource.candlesMap.get(timePeriodName); + candleArray = platform.datasource.candlesMap.get(timePeriodName); candle = candleArray[candleArray.length - 1]; // The last candle of the 10 candles array. diff = candle.close - candle.open; @@ -254,7 +280,7 @@ /* Finally we move the order position to where we have just estimated is a better place. */ - assistant.movePositionAtExchange(pPosition, targetRate, writeStatusAndContext, callBack); + platform.assistant.movePositionAtExchange(pPosition, targetRate, writeStatusAndContext, callBack); } catch (err) { logger.write("[ERROR] start -> decideAboutSellPosition -> err = " + err.message);