From 2134635f0cd65a93c03071b89408a579857990da Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 7 Mar 2018 15:02:35 +0100 Subject: [PATCH] First Debug Session Ended --- .vs/AACloudPlatform/v15/.suo | Bin 71680 -> 74240 bytes AACloudPlatform.njsproj | 2 +- ...tring => AAOlivia.azure.storage.connstring | 0 ...nnstring => AATom.azure.storage.connstring | 0 Assistant.js | 84 +++++++++--------- Azure File Storage.js | 2 +- Context.js | 77 ++++++++-------- Datasource.js | 34 +++---- Debug Log.js | 8 +- ExchangeAPI.js | 62 +++++++------ Run.js | 69 +++++++------- TradingBot.js | 25 +++--- this.vm.config.json | 2 +- 13 files changed, 194 insertions(+), 171 deletions(-) rename Olivia.azure.storage.connstring => AAOlivia.azure.storage.connstring (100%) rename Tom.azure.storage.connstring => AATom.azure.storage.connstring (100%) diff --git a/.vs/AACloudPlatform/v15/.suo b/.vs/AACloudPlatform/v15/.suo index 8663604b49338682af199158d214558b45973938..0c8416988515e8fcba398bffa342481801dc8d59 100644 GIT binary patch delta 3942 zcmd6pe^6A{702IwyNj$ma5umLWtCk~vjV|IVK5fs63j&64_qMDjF=FsrvBtdS+vH; zDpDjGVE06!CXTwsAB{m^A6248S3_oK5)(CTv`tfJYyRmt7A;I_Ck_2xe2*cGMw8fS z@66|&bMCM6?s@0lcik;ocZas#PWDCmXoDb_1VPY%FZ=uZAp{0&tb;$GOSeURzVg4YS)=<+_w|PTJSTl4m=OmgBQRCPzUG>HkV0c z731`UH&#^f=#3kUUQTc*y6~mZo=ywdMTypG)~g{M7GE&}P52@MuQUpBxT5PIBR~k? zVdmi*19+IDfx3P!t*{plspC;hg&haR0=^QX($1r90b$@FLC77PXb~#-WNJzI4|{0P z)6kZ#v`>bdqUb+_%<(vLLUWahe8@b?)~7r9XZbPUpXNER1S|zV0VSXctN`5oYDIFr zSkZq9Sqk`C${;H|&P1&nihp>LC~brC67T_WLA5%>?&F=-rLgQOcjYiNR7*|F4pVlDJKguG?mT}!0uO(|Bkh5f$tToFzL6nf+D7!)1S-L1zysujtOi>^4R{go zfTU*?O>>MGlo0%=@SUmdj^pJaV@*tk zeMKMTO|728gG3XrR9&MZkI(jTq6i(@~qCJ zKy@Z<$~VbTOZAL}$kyk(hTXQ~zCb0Ti>s&5y2{7t^p;4R`C2O6v_YP~bqXVUl}&?8 zCQsLoVsizTup0k{5IKJTmNCe^=;)e- zNw&_qZHLbu{QN@!mjc=P$!q zcv6cyf}O6{j#M2|AR(aVl^B4rdQUnQlj)g8?m9QQ>m3x>8IS|@4(5H?O^#gwa=*Ni zEIT8-+dHXb$7JomsOu*(g6Dt8|HGIf^W#wzI1xlw_eO+Ny}v(|9L;(RI6!~>g^4UX z3g~Z5Mq1VWh<9_~b_qlCt8C!FUlW5k77Bc#sa`(ArMt`b_qupEo{@+il z@xIr!)U!1CduG>YUyDc=oC(+v61lfT+}C7t(Dg>MY;L=vp)-3E>G)okk^jEcatcbY z+;lRJQS-i7<8iefa$r-*N$;N5_)clbQ9I#Vq%B!L>7uh&Y_hH6GNX<8QFP=lHk$T_ zjrWwwzD~sBer2;*HjY|OPbWv(XnEWDGIrn68`=B@r8GxV)oTHhen{X(Ltg==Hx29v zHOYT{crop1Tt()#Fe>)j?yxaTbm7%Fl3ErsjqJWy&P@C+tQM=HOjk4is*zs>)x!UJ z0yUj1r=H(R)Y@3^O&g3h?if#FKYly%L3KD}rlL>4xtzy}w72mz*nN_xAnQP+-56>=$#s=ePaGUB8(t=8iEXwlIqf3sY~4UDVx= QKxrxWe8#a16YF6A2CuIV&;S4c delta 3548 zcmc(he^6A{702Iw`xaSPbT@#k0wnrNC%nCPTy$7wnlYcvBLX$$n6$9rbg{?W-a z>D~G4x#!$_&%N(^-;eA5P;mDME!KFRQ;LD(Lb0kr#>U6TDN6Mj#~snU&iQFfLFkD; zuyknO>z^(*-hBgm* z2+3Ds^=OwPtC5G10)z$@qIE#FHiK1wOPk>-iGY5sDZK{6&mpzQHlz-rrKO+^M_xc0 z5I5rGS1(VY#ZvNfMO-h^>hJ8_Zd0I1CEiwg(Lr5kgLek!cWFoS(9!I#H zw4}AFw3k{Lc36@qrluE1g;Aax?Cl= z6qk|mh~lVIs4^B|T$T}SF;WKky7`U`SbG9_5_txB3V9lN7TJPqL`soONT9Nn=+g{U zXtyeD)o6Ek92t@jV&UOmdOc+63&W^aH@3V=y*%rqbZ=titqCVicLFQD6V4N03%mLQ zhDo+58m42kFZAR<*GFcs^1-YeT!sd=2Zr%~H@J)|g|NWpT4~tWz_aIX?-kjgrJG5R zMyAy>wiaAb4Q!1x96g`u>G>fsNnpr|wZf3zU|oj}>9QVepq3OPNK?{}bR-{MkBu>t zU?dy`TxiwXSREu?iTx8^5w^+?nR-Pq6z68u;4(L8SK_Ef7%~4Ym~KV7UDZxOw0l>1 z=^u&7JeX4xwQM%EUf7q;o|RmAZ!pQ6;Ai4oUQ8C?!i_XY^R5D4uLUl5n84@t87lie zdAZ5=((hlW^M28I&GaBRyOZE=o#Eauvfi0qt!ScMgGnP`B(0u3CArdj`TxH+HswpoC)jsJwAs)I1t^txD!c>|laErKFVqTH=zS1Eku z)`Ph=0i3mZa8?CFadW!Of9=-h<4dyagY(9BbGWXV%VIy9xYF;hncl8NoQo^R4_2xC z7*Y>!a|H04r$gLc1J5|HH9rhRZ)SLR_-IkmVADeO6HW`h=8CYjxGJWQ3~aACw2CXk zRZ~p%r%w2*ls-$X`1Qsg>}{R}Z!|{+%Puy;dQTi}_^lT2ez$kqJoxRt<>20LliV-c z*pELW_zt+e2g|~$#BSS9k^44pz`WDrB&JBIFyE2r^18pH^G`ydbpPl2FH=N zp)(~OdR{TWqlc2=vA+CBI$o$H2`h98vg5*zK~w)Aocs2EaCSQ2bhp0sI%9v8Q#oFJ z`+uPX&cV9H-w5&*nGa`@EKq#7SM1@zczFXTS3U9GUMEZRO?w|W+EU^9i;qg~cikE= zww1uQZyDk7{_w`y41Za{SI~H_}I2E$6UuzjVBBB@<5z;D3Lkdd-%* z6A4?ZN>+#;^3c*54@rIXw7>PrD^6$)|2No2Y5DkOU9NCU2B_$ zZG_MEBtg%B9c=Rwq&?@W8Dw`@A@j=usO&L7Ugsu7jcY~?Wm1Y0pQGhc=%o$JXrxC< zDRjUMhvR)U(B=<=%=c0t)&Bua$wHv?R2`t!t*_~r53c(4F?9T+LIyEzT4VK-_WR?C?597^ zIe2z!=wsJ8Jl{$2`#RaApMM%cDIt1nc4)vb80bxfNBX1g{)m6sZUwi;Enfd#)+?C6 zgR*|k#P4|6{&9kI^5zU)vi;=@1I?KX2sxWBIfuG5(w1w#VETTVPc9~3??%Qd*qs~k z^^dK0*ll{_Q9csi(RsMe diff --git a/AACloudPlatform.njsproj b/AACloudPlatform.njsproj index 91da2bf4b..b7d3265dd 100644 --- a/AACloudPlatform.njsproj +++ b/AACloudPlatform.njsproj @@ -13,7 +13,7 @@ 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) AACloudPlatform - Order-Books + Trading-Process C:\Program Files\nodejs\node.exe False diff --git a/Olivia.azure.storage.connstring b/AAOlivia.azure.storage.connstring similarity index 100% rename from Olivia.azure.storage.connstring rename to AAOlivia.azure.storage.connstring diff --git a/Tom.azure.storage.connstring b/AATom.azure.storage.connstring similarity index 100% rename from Tom.azure.storage.connstring rename to AATom.azure.storage.connstring diff --git a/Assistant.js b/Assistant.js index b6a813d51..451236793 100644 --- a/Assistant.js +++ b/Assistant.js @@ -1,5 +1,7 @@ exports.newAssistant = function newAssistant(BOT, DEBUG_MODULE) { + const FULL_LOG = true; + /* This module allows trading bots to execute actions on the exchange, and also on its current recorded state. @@ -39,6 +41,8 @@ try { + if (LOG_INFO === true) { logger.write("[INFO] initialize -> Entering function."); } + /* Store local values. */ botContext = pBotContext; @@ -51,18 +55,18 @@ try { switch (err.result) { - case DEFAULT_OK_RESPONSE.result: { - callBackFunction(DEFAULT_OK_RESPONSE); + case global.DEFAULT_OK_RESPONSE.result: { + callBackFunction(global.DEFAULT_OK_RESPONSE); return; } break; - case DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. + case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. logger.write("[ERROR] initialize -> onDone -> Retry Later. Requesting Execution Retry."); callBackFunction(err); return; } break; - case DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. logger.write("[ERROR] initialize -> onDone -> Operation Failed. Aborting the process."); callBackFunction(err); return; @@ -72,14 +76,14 @@ } catch (err) { logger.write("[ERROR] initialize -> onDone -> err = " + err.message); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { logger.write("[ERROR] initialize -> err = " + err.message); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -100,19 +104,19 @@ function onResponse(err, pExchangePositions) { switch (err.result) { - case DEFAULT_OK_RESPONSE.result: { // Everything went well, we have the information requested. + case global.DEFAULT_OK_RESPONSE.result: { // Everything went well, we have the information requested. exchangePositions = pExchangePositions; ordersExecutionCheck(callBack); return; } break; - case DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. + case global.DEFAULT_RETRY_RESPONSE.result: { // 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 Execution Retry."); callBack(err); return; } break; - case DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. logger.write("[ERROR] getPositionsAtExchange -> onResponse -> Operation Failed. Aborting the process."); callBack(err); return; @@ -122,7 +126,7 @@ } } catch (err) { logger.write("[ERROR] getPositionsAtExchange -> err = " + err.message); - callBack(DEFAULT_FAIL_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); } } @@ -229,7 +233,7 @@ botContext.executionContext.positions[i].amountB !== sumAssetB ) { logger.write("[ERROR] ordersExecutionCheck -> loopBody -> confirmOrderWasPartiallyExecuted -> Cannot be confirmed that a partially execution was done well."); - callBack(DEFAULT_FAIL_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); return; } @@ -264,7 +268,7 @@ } catch (err) { logger.write("[ERROR] ordersExecutionCheck -> loopBody -> confirmOrderWasPartiallyExecuted -> err = " + err.message); - callBack(DEFAULT_FAIL_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); return; } } @@ -306,7 +310,7 @@ botContext.executionContext.positions[i].amountB !== sumAssetB ) { logger.write("[ERROR] ordersExecutionCheck -> loopBody -> confirmOrderWasExecuted -> Cannot be confirmed that the order was executed. It must be manually cancelled by the user or cancelled by the exchange itself."); - callBack(DEFAULT_FAIL_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); return; } @@ -339,7 +343,7 @@ } catch (err) { logger.write("[ERROR] ordersExecutionCheck -> loopBody -> confirmOrderWasExecuted -> err = " + err.message); - callBack(DEFAULT_FAIL_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); return; } } @@ -359,37 +363,37 @@ try { switch (err.result) { - case DEFAULT_OK_RESPONSE.result: { // Everything went well, we have the information requested. + case global.DEFAULT_OK_RESPONSE.result: { // Everything went well, we have the information requested. innerCallBack(pTrades); } break; - case DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. + case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. logger.write("[ERROR] ordersExecutionCheck -> loopBody -> getPositionTradesAtExchange -> onResponse -> Retry Later. Requesting Execution Retry."); - callBack(DEFAULT_RETRY_RESPONSE); + callBack(global.DEFAULT_RETRY_RESPONSE); return; } break; - case DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. logger.write("[ERROR] ordersExecutionCheck -> loopBody -> getPositionTradesAtExchange -> onResponse -> Operation Failed. Aborting the process."); - callBack(DEFAULT_FAIL_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); return; } break; } } catch (err) { logger.write("[ERROR] ordersExecutionCheck -> loopBody -> getPositionTradesAtExchange -> onResponse -> err = " + err.message); - callBack(DEFAULT_FAIL_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { logger.write("[ERROR] ordersExecutionCheck -> loopBody -> getPositionTradesAtExchange -> err = " + err.message); - callBack(DEFAULT_FAIL_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { logger.write("[ERROR] ordersExecutionCheck -> loopBody -> err = " + err.message); - callBack(DEFAULT_FAIL_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); return; } } @@ -416,12 +420,12 @@ function final() { - callBack(DEFAULT_OK_RESPONSE); + callBack(global.DEFAULT_OK_RESPONSE); } } catch (err) { logger.write("[ERROR] ordersExecutionCheck -> err = " + err.message); - callBack(DEFAULT_FAIL_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); } } @@ -434,7 +438,7 @@ try { switch (err.result) { - case DEFAULT_OK_RESPONSE.result: { // Everything went well, we have the information requested. + case global.DEFAULT_OK_RESPONSE.result: { // Everything went well, we have the information requested. let position = { id: pPositionId, @@ -459,31 +463,31 @@ botContext.newHistoryRecord.newPositions++; botContext.newHistoryRecord.rate = pRate; - callBack(DEFAULT_OK_RESPONSE); + callBack(global.DEFAULT_OK_RESPONSE); return; } break; - case DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. + case global.DEFAULT_RETRY_RESPONSE.result: { // 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 Execution Retry."); - callBack(DEFAULT_RETRY_RESPONSE); + callBack(global.DEFAULT_RETRY_RESPONSE); return; } break; - case DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. logger.write("[ERROR] putPositionAtExchange -> onResponse -> Operation Failed. Aborting the process."); - callBack(DEFAULT_FAIL_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); return; } break; } } catch (err) { logger.write("[ERROR] putPositionAtExchange -> onResponse -> err = " + err.message); - callBack(DEFAULT_FAIL_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { logger.write("[ERROR] putPositionAtExchange -> err = " + err.message); - callBack(DEFAULT_FAIL_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); } } @@ -496,7 +500,7 @@ try { switch (err.result) { - case DEFAULT_OK_RESPONSE.result: { // Everything went well, we have the information requested. + case global.DEFAULT_OK_RESPONSE.result: { // Everything went well, we have the information requested. let newPosition = { id: pPositionId, @@ -534,30 +538,30 @@ botContext.newHistoryRecord.movedPositions++; botContext.newHistoryRecord.rate = pNewRate; - callBack(DEFAULT_OK_RESPONSE); + callBack(global.DEFAULT_OK_RESPONSE); } break; - case DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. + case global.DEFAULT_RETRY_RESPONSE.result: { // 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 Execution Retry."); - callBack(DEFAULT_RETRY_RESPONSE); + callBack(global.DEFAULT_RETRY_RESPONSE); return; } break; - case DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. logger.write("[ERROR] movePositionAtExchange -> onResponse -> Operation Failed. Aborting the process."); - callBack(DEFAULT_FAIL_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); return; } break; } } catch (err) { logger.write("[ERROR] movePositionAtExchange -> onResponse -> err = " + err.message); - callBack(DEFAULT_FAIL_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { logger.write("[ERROR] movePositionAtExchange -> err = " + err.message); - callBack(DEFAULT_FAIL_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); } } }; \ No newline at end of file diff --git a/Azure File Storage.js b/Azure File Storage.js index 383c139d4..252a336f1 100644 --- a/Azure File Storage.js +++ b/Azure File Storage.js @@ -41,7 +41,7 @@ exports.newAzureFileStorage = function newAzureFileStorage(BOT) { if (dataOwnerBotName === undefined) { - dataOwner = bot.name; + dataOwner = bot.codeName; } else { diff --git a/Context.js b/Context.js index 68cfa73c8..d85063a57 100644 --- a/Context.js +++ b/Context.js @@ -1,5 +1,7 @@ exports.newContext = function newContext(BOT, DEBUG_MODULE, FILE_STORAGE) { + const FULL_LOG = true; + /* This module allows trading bots to connect to the exchange and do trding operations on it. So far it can only work with Poloniex. @@ -34,7 +36,7 @@ executionHistory: [], // This is the record of bot execution. executionContext: undefined, // Here is the business information of the last execution of this bot process. newHistoryRecord : { - date: processDatetime, + date: undefined, rate: 0, // This will be used to know where to plot this information in the time line. newPositions: 0, newTrades: 0, @@ -70,6 +72,9 @@ function initialize(pProcessDatetime, callBackFunction) { try { + + if (LOG_INFO === true) { logger.write("[INFO] initialize -> Entering function."); } + /* Here we get the positions the bot did and that are recorded at the bot storage account. We will use them through out the rest @@ -77,7 +82,7 @@ */ - cloudStorage.initialize(bot.name); + cloudStorage.initialize(bot.codeName); thisObject.newHistoryRecord.date = pProcessDatetime; processDatetime = pProcessDatetime; @@ -88,18 +93,18 @@ try { switch (err.result) { - case DEFAULT_OK_RESPONSE.result: { - callBackFunction(DEFAULT_OK_RESPONSE); + case global.DEFAULT_OK_RESPONSE.result: { + callBackFunction(global.DEFAULT_OK_RESPONSE); return; } break; - case DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. + case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. logger.write("[ERROR] initialize -> onDone -> Retry Later. Requesting Execution Retry."); callBackFunction(err); return; } break; - case DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. logger.write("[ERROR] initialize -> onDone -> Operation Failed. Aborting the process."); callBackFunction(err); return; @@ -109,7 +114,7 @@ } catch (err) { logger.write("[ERROR] initialize -> onDone -> err = " + err.message); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -119,7 +124,7 @@ /* If the process run and was interrupted, there should be a status report that allows us to resume execution. */ let fileName = "Status.Report.json" - let filePath = EXCHANGE_NAME + "/" + bot.name + "/" + bot.dataSetVersion + "/Processes/" + bot.process; + let filePath = EXCHANGE_NAME + "/" + bot.codeName + "/" + bot.dataSetVersion + "/Processes/" + bot.process; cloudStorage.getTextFile(filePath, fileName, onFileReceived, true); @@ -150,12 +155,12 @@ */ logger.write("[ERROR] initialize -> getStatusReport -> Bot cannot execute without the Status report. -> Err = " + err.message); - callBack(DEFAULT_FAIL_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { logger.write("[ERROR] initialize -> getExecutionHistory -> err = " + err.message); - callBack(DEFAULT_FAIL_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); } } @@ -163,7 +168,7 @@ try { let fileName = "Execution.History.json" - let filePath = EXCHANGE_NAME + "/" + bot.name + "/" + bot.dataSetVersion + "/Output/" + bot.process; + let filePath = EXCHANGE_NAME + "/" + bot.codeName + "/" + bot.dataSetVersion + "/Output/" + bot.process; cloudStorage.getTextFile(filePath, fileName, onFileReceived, true); @@ -185,12 +190,12 @@ */ logger.write("[ERROR] initialize -> getExecutionHistory -> Bot cannot execute without the Execution History. -> Err = " + err.message); - callBack(DEFAULT_FAIL_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { logger.write("[ERROR] initialize -> getExecutionHistory -> err = " + err.message); - callBack(DEFAULT_FAIL_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); } } @@ -201,7 +206,7 @@ let fileName = "Execution.Context.json" let dateForPath = date.getUTCFullYear() + '/' + utilities.pad(date.getUTCMonth() + 1, 2) + '/' + utilities.pad(date.getUTCDate(), 2) + '/' + utilities.pad(date.getUTCHours(), 2) + '/' + utilities.pad(date.getUTCMinutes(), 2); - let filePath = EXCHANGE_NAME + "/" + bot.name + "/" + bot.dataSetVersion + "/Output/" + bot.process + "/" + dateForPath; + let filePath = EXCHANGE_NAME + "/" + bot.codeName + "/" + bot.dataSetVersion + "/Output/" + bot.process + "/" + dateForPath; cloudStorage.getTextFile(filePath, fileName, onFileReceived, true); @@ -213,7 +218,7 @@ thisObject.executionContext.transactions = []; // We record here the transactions that happened duting this execution. - callBack(DEFAULT_OK_RESPONSE); + callBack(global.DEFAULT_OK_RESPONSE); } catch (err) { @@ -226,13 +231,13 @@ */ logger.write("[ERROR] initialize -> getExecutionContext -> Bot cannot execute without the Execution Context. -> Err = " + err.message); - callBack(DEFAULT_FAIL_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { logger.write("[ERROR] initialize -> getExecutionContext -> err = " + err.message); - callBack(DEFAULT_FAIL_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); } } @@ -261,17 +266,17 @@ transactions: [] }; - callBack(DEFAULT_OK_RESPONSE); + callBack(global.DEFAULT_OK_RESPONSE); } catch (err) { logger.write("[ERROR] initialize -> createConext -> err = " + err.message); - callBack(DEFAULT_FAIL_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { logger.write("[ERROR] initialize -> err = " + err.message); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -285,18 +290,18 @@ try { switch (err.result) { - case DEFAULT_OK_RESPONSE.result: { - callBackFunction(DEFAULT_OK_RESPONSE); + case global.DEFAULT_OK_RESPONSE.result: { + callBackFunction(global.DEFAULT_OK_RESPONSE); return; } break; - case DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. + case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. logger.write("[ERROR] saveThemAll -> onDone -> Retry Later. Requesting Execution Retry."); callBackFunction(err); return; } break; - case DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. logger.write("[ERROR] saveThemAll -> onDone -> Operation Failed. Aborting the process."); callBackFunction(err); return; @@ -306,7 +311,7 @@ } catch (err) { logger.write("[ERROR] saveThemAll -> onDone -> err = " + err.message); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -320,7 +325,7 @@ let fileName = "Execution.Context.json" let dateForPath = processDatetime.getUTCFullYear() + '/' + utilities.pad(processDatetime.getUTCMonth() + 1, 2) + '/' + utilities.pad(processDatetime.getUTCDate(), 2) + '/' + utilities.pad(processDatetime.getUTCHours(), 2) + '/' + utilities.pad(processDatetime.getUTCMinutes(), 2); - let filePath = EXCHANGE_NAME + "/" + bot.name + "/" + bot.dataSetVersion + "/Output/" + bot.process + "/" + dateForPath; + let filePath = EXCHANGE_NAME + "/" + bot.codeName + "/" + bot.dataSetVersion + "/Output/" + bot.process + "/" + dateForPath; utilities.createFolderIfNeeded(filePath, cloudStorage, onFolderCreated); @@ -343,14 +348,14 @@ } catch (err) { logger.write("[ERROR] saveThemAll -> writeExecutionContext -> onFolderCreated -> err = " + err.message); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { logger.write("[ERROR] saveThemAll -> writeExecutionContext -> err = " + err.message); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -363,7 +368,7 @@ try { let fileName = "Execution.History.json" - let filePath = EXCHANGE_NAME + "/" + bot.name + "/" + bot.dataSetVersion + "/Output/" + bot.process; + let filePath = EXCHANGE_NAME + "/" + bot.codeName + "/" + bot.dataSetVersion + "/Output/" + bot.process; utilities.createFolderIfNeeded(filePath, cloudStorage, onFolderCreated); @@ -392,14 +397,14 @@ } catch (err) { logger.write("[ERROR] saveThemAll -> writeExucutionHistory -> onFolderCreated -> err = " + err.message); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { logger.write("[ERROR] saveThemAll -> writeExucutionHistory -> err = " + err.message); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -412,7 +417,7 @@ try { let fileName = "Status.Report.json" - let filePath = EXCHANGE_NAME + "/" + bot.name + "/" + bot.dataSetVersion + "/Processes/" + bot.process; + let filePath = EXCHANGE_NAME + "/" + bot.codeName + "/" + bot.dataSetVersion + "/Processes/" + bot.process; utilities.createFolderIfNeeded(filePath, cloudStorage, onFolderCreated); @@ -432,26 +437,26 @@ logger.write("[INFO] saveThemAll -> writeStatusReport -> onFolderCreated -> Content written = " + fileContent); } - callBack(DEFAULT_OK_RESPONSE); + callBack(global.DEFAULT_OK_RESPONSE); return; } } catch (err) { logger.write("[ERROR] saveThemAll -> writeStatusReport -> onFolderCreated -> err = " + err.message); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { logger.write("[ERROR] saveThemAll -> writeStatusReport -> err = " + err.message); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { logger.write("[ERROR] saveThemAll -> Error = " + err.message); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } diff --git a/Datasource.js b/Datasource.js index df2fed165..dcc28fd8a 100644 --- a/Datasource.js +++ b/Datasource.js @@ -1,5 +1,7 @@ exports.newDatasource = function newDatasource(BOT, DEBUG_MODULE, FILE_STORAGE) { + const FULL_LOG = true; + /* This module allows trading bots to access information stored at the cloud storage. @@ -60,6 +62,8 @@ try { + if (LOG_INFO === true) { logger.write("[INFO] initialize -> Entering function."); } + oliviaAzureFileStorage.initialize("Olivia"); tomAzureFileStorage.initialize("Tom"); @@ -69,18 +73,18 @@ try { switch (err.result) { - case DEFAULT_OK_RESPONSE.result: { - callBackFunction(DEFAULT_OK_RESPONSE); + case global.DEFAULT_OK_RESPONSE.result: { + callBackFunction(global.DEFAULT_OK_RESPONSE); return; } break; - case DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. + case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. logger.write("[ERROR] initialize -> onDone -> Retry Later. Requesting Execution Retry."); callBackFunction(err); return; } break; - case DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. logger.write("[ERROR] initialize -> onDone -> Operation Failed. Aborting the process."); callBackFunction(err); return; @@ -90,7 +94,7 @@ } catch (err) { logger.write("[ERROR] initialize -> onDone -> err = " + err.message); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -132,7 +136,7 @@ } } catch (err) { logger.write("[ERROR] getCandles -> getMarketFiles -> err = " + err.message); - callBack(DEFAULT_FAIL_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); } } @@ -159,7 +163,7 @@ } } catch (err) { logger.write("[ERROR] getCandles -> getDailyFiles -> err = " + err.message); - callBack(DEFAULT_FAIL_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); } } @@ -222,13 +226,13 @@ } } catch (err) { logger.write("[ERROR] getCandles -> getCandlesWeAreIn -> err = " + err.message); - callBack(DEFAULT_FAIL_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { logger.write("[ERROR] getCandles -> err = " + err.message); - callBack(DEFAULT_FAIL_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); } } @@ -269,7 +273,7 @@ } } catch (err) { logger.write("[ERROR] getPatterns -> getMarketFiles -> err = " + err.message); - callBack(DEFAULT_FAIL_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); } } @@ -296,7 +300,7 @@ } } catch (err) { logger.write("[ERROR] getPatterns -> getDailyFiles -> err = " + err.message); - callBack(DEFAULT_FAIL_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); } } @@ -355,19 +359,19 @@ if (counter === thisObject.stairsFiles.size) { - callBack(DEFAULT_OK_RESPONSE); + callBack(global.DEFAULT_OK_RESPONSE); } } } catch (err) { logger.write("[ERROR] getPatterns -> getStairsWeAreIn -> err = " + err.message); - callBack(DEFAULT_FAIL_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { logger.write("[ERROR] getPatterns -> err = " + err.message); - callBack(DEFAULT_FAIL_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); } } @@ -416,7 +420,7 @@ } catch (err) { logger.write("[ERROR] initialize -> err = " + err.message); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } }; \ No newline at end of file diff --git a/Debug Log.js b/Debug Log.js index f78c18965..788099f3d 100644 --- a/Debug Log.js +++ b/Debug Log.js @@ -12,7 +12,7 @@ let firstCall = true; let folderPath; - thisObject = { + let thisObject = { bot: undefined, fileName: undefined, write: write @@ -32,15 +32,15 @@ createFolderSync(folderPath); - folderPath = thisObject.bot.devTeam + "/" + thisObject.bot.type + "/" + thisObject.bot.name; + folderPath = thisObject.bot.devTeam + "/" + thisObject.bot.type + "/" + thisObject.bot.codeName; createFolderSync(folderPath); - folderPath = thisObject.bot.devTeam + "/" + thisObject.bot.type + "/" + thisObject.bot.name + "/" + thisObject.bot.version; + folderPath = thisObject.bot.devTeam + "/" + thisObject.bot.type + "/" + thisObject.bot.codeName + "/" + thisObject.bot.version; createFolderSync(folderPath); - folderPath = thisObject.bot.devTeam + "/" + thisObject.bot.type + "/" + thisObject.bot.name + "/" + thisObject.bot.version + "/" + thisObject.bot.process; + folderPath = thisObject.bot.devTeam + "/" + thisObject.bot.type + "/" + thisObject.bot.codeName + "/" + thisObject.bot.version + "/" + thisObject.bot.process; createFolderSync(folderPath); diff --git a/ExchangeAPI.js b/ExchangeAPI.js index 0651d9333..7497135cb 100644 --- a/ExchangeAPI.js +++ b/ExchangeAPI.js @@ -1,5 +1,7 @@ exports.newExchangeAPI = function newExchangeAPI(BOT, DEBUG_MODULE, POLONIEX_CLIENT_MODULE) { + const FULL_LOG = true; + /* This module allows trading bots to connect to the exchange and do trding operations on it. So far it can only work with Poloniex. @@ -29,10 +31,12 @@ try { + if (LOG_INFO === true) { logger.write("[INFO] initialize -> Entering function."); } + let apiKey = readApiKey(); poloniexApiClient = new POLONIEX_CLIENT_MODULE(apiKey.Key, apiKey.Secret); - callBackFunction(DEFAULT_OK_RESPONSE); + callBackFunction(global.DEFAULT_OK_RESPONSE); function readApiKey() { @@ -47,14 +51,14 @@ logger.write("[HINT] The file must have the keys to access your poloniex account, in this format -> " + '{ "Key" : "4FB9TMEB-234VH2W1-BYJIXHGM-GL15DSA1", "Secret" : "1a24298skdjdf734uuyhbdagdasdtyut276587256hdsdas765asdasdasd76asdasda765asdasfas6asfda57657asd5a76sd5a7s65d7a6sd57as65d7as65d"}'); logger.write("[HINT] You get this key logging in to your Poloniex web account, enabling API keys and getting a new one. "); logger.write("[HINT] Be sure not to allow withdrawls with this Key. When asked at the exchange key page, say no. "); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { logger.write("[ERROR] initialize -> err = " + err.message); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -74,7 +78,7 @@ if (err.message.indexOf("ETIMEDOUT") > 0) { logger.write("[WARN] getOpenPositions -> onExchangeCallReturned -> Timeout reached while trying to access the Exchange API. Requesting new execution later. : ERROR = " + err.message); - callBackFunction(DEFAULT_RETRY_RESPONSE); + callBackFunction(global.DEFAULT_RETRY_RESPONSE); return; } else { @@ -82,19 +86,19 @@ if (err.message.indexOf("ECONNRESET") > 0) { logger.write("[WARN] getOpenPositions -> onExchangeCallReturned -> The exchange reseted the connection. Requesting new execution later. : ERROR = " + err.message); - callBackFunction(DEFAULT_RETRY_RESPONSE); + callBackFunction(global.DEFAULT_RETRY_RESPONSE); return; } else { logger.write("[ERROR] getOpenPositions -> onExchangeCallReturned -> Unexpected error trying to contact the Exchange. This will halt this bot process. : ERROR = " + err.message); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } } } catch (err) { logger.write("[ERROR] getOpenPositions -> onExchangeCallReturned -> exchangeResponse.error = " + exchangeResponse.error); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } @@ -136,12 +140,12 @@ } catch (err) { logger.write("[ERROR] getOpenPositions -> onExchangeCallReturned -> Error = " + err.message); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { logger.write("[ERROR] getOpenPositions -> Error = " + err.message); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -161,7 +165,7 @@ if (err.message.indexOf("ETIMEDOUT") > 0) { logger.write("[WARN] getExecutedTrades -> onExchangeCallReturned -> Timeout reached while trying to access the Exchange API. Requesting new execution later. : ERROR = " + err.message); - callBackFunction(DEFAULT_RETRY_RESPONSE); + callBackFunction(global.DEFAULT_RETRY_RESPONSE); return; } else { @@ -169,19 +173,19 @@ if (err.message.indexOf("ECONNRESET") > 0) { logger.write("[WARN] getExecutedTrades -> onExchangeCallReturned -> The exchange reseted the connection. Requesting new execution later. : ERROR = " + err.message); - callBackFunction(DEFAULT_RETRY_RESPONSE); + callBackFunction(global.DEFAULT_RETRY_RESPONSE); return; } else { logger.write("[ERROR] getExecutedTrades -> onExchangeCallReturned -> Unexpected error trying to contact the Exchange. This will halt this bot process. : ERROR = " + err.message); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } } } catch (err) { logger.write("[ERROR] getExecutedTrades -> onExchangeCallReturned -> exchangeResponse.error = " + exchangeResponse.error); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } } else { @@ -229,12 +233,12 @@ } catch (err) { logger.write("[ERROR] getExecutedTrades -> onExchangeCallReturned -> Error = " + err.message); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { logger.write("[ERROR] getExecutedTrades -> Error = " + err.message); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -253,7 +257,7 @@ } logger.write("[ERROR] putPosition -> pType must be either 'buy' or 'sell'."); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; function onExchangeCallReturned(err, exchangeResponse) { @@ -266,7 +270,7 @@ if (err.message.indexOf("ETIMEDOUT") > 0) { logger.write("[WARN] putPosition -> onExchangeCallReturned -> Timeout reached while trying to access the Exchange API. Requesting new execution later. : ERROR = " + err.message); - callBackFunction(DEFAULT_RETRY_RESPONSE); + callBackFunction(global.DEFAULT_RETRY_RESPONSE); return; } else { @@ -274,19 +278,19 @@ if (err.message.indexOf("ECONNRESET") > 0) { logger.write("[WARN] putPosition -> onExchangeCallReturned -> The exchange reseted the connection. Requesting new execution later. : ERROR = " + err.message); - callBackFunction(DEFAULT_RETRY_RESPONSE); + callBackFunction(global.DEFAULT_RETRY_RESPONSE); return; } else { logger.write("[ERROR] putPosition -> onExchangeCallReturned -> Unexpected error trying to contact the Exchange. This will halt this bot process. : ERROR = " + err.message); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } } } catch (err) { logger.write("[ERROR] putPosition -> onExchangeCallReturned -> exchangeResponse.error = " + exchangeResponse.error); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } @@ -316,13 +320,13 @@ } catch (err) { logger.write("[ERROR] putPosition -> onExchangeCallReturned -> Error = " + err.message); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { logger.write("[ERROR] putPosition -> err = " + err.message); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -342,7 +346,7 @@ if (err.message.indexOf("ETIMEDOUT") > 0) { logger.write("[WARN] movePosition -> onExchangeCallReturned -> Timeout reached while trying to access the Exchange API. Requesting new execution later. : ERROR = " + err.message); - callBackFunction(DEFAULT_RETRY_RESPONSE); + callBackFunction(global.DEFAULT_RETRY_RESPONSE); return; } else { @@ -350,19 +354,19 @@ if (err.message.indexOf("ECONNRESET") > 0) { logger.write("[WARN] movePosition -> onExchangeCallReturned -> The exchange reseted the connection. Requesting new execution later. : ERROR = " + err.message); - callBackFunction(DEFAULT_RETRY_RESPONSE); + callBackFunction(global.DEFAULT_RETRY_RESPONSE); return; } else { logger.write("[ERROR] movePosition -> onExchangeCallReturned -> Unexpected error trying to contact the Exchange. This will halt this bot process. : ERROR = " + err.message); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } } } catch (err) { logger.write("[ERROR] movePosition -> onExchangeCallReturned -> exchangeResponse.error = " + exchangeResponse.error); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } @@ -370,7 +374,7 @@ if (exchangeResponse.success !== 1) { logger.write("[ERROR] movePosition -> onExchangeCallReturned -> exchangeResponse.success = " + exchangeResponse.success); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } /* @@ -397,13 +401,13 @@ } catch (err) { logger.write("[ERROR] movePosition -> onExchangeCallReturned -> Error = " + err.message); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { logger.write("[ERROR] movePosition -> err = " + err.message); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } }; \ No newline at end of file diff --git a/Run.js b/Run.js index fb0aa43d9..5473b2272 100644 --- a/Run.js +++ b/Run.js @@ -1,4 +1,7 @@ -/* First thing to do is to read the config and guess which bot we will be running. */ + +const LOG_INFO = true; + +/* First thing to do is to read the config and guess which bot we will be running. */ var fs = require('fs'); let vmConfig; @@ -22,24 +25,19 @@ let botConfig; try { botConfig = JSON.parse(fs.readFileSync(vmConfig.bot.path + '/this.bot.config.json', 'utf8')); - } catch (err) { - const logText = "[ERROR] 'readConfig' - ERROR : " + err.message; - console.log.write(logText); - + console.log("[ERROR] 'readConfig' - ERROR : " + err.message); return; } -let bot = { +let bot = { // TODO > REPLACE THIS FOR THE ENTIRE BOT CONFIGURATION. NOTE THAT NAME NOW IS CODENAME "name": botConfig.displayName, "type": botConfig.type, "version": botConfig.version, "devTeam": botConfig.devTeam }; -botConfig.bot; - /* Now we will run according to what we see at the config file. */ const ROOT_DIR = './'; @@ -48,7 +46,7 @@ const MODULE_NAME = "Run"; const DEBUG_MODULE = require(ROOT_DIR + 'Debug Log'); const logger = DEBUG_MODULE.newDebugLog(); logger.fileName = MODULE_NAME; -logger.bot = bot; +logger.bot = botConfig; process.on('uncaughtException', function (err) { logger.write('uncaughtException - ' + err.message); @@ -64,17 +62,17 @@ process.on('exit', function (code) { logger.write('About to exit with code:' + code); }); -const DEFAULT_OK_RESPONSE = { +global.DEFAULT_OK_RESPONSE = { result: "Ok", message: "Operation Succeeded" }; -const DEFAULT_FAIL_RESPONSE = { +global.global.DEFAULT_FAIL_RESPONSE = { result: "Fail", message: "Operation Failed" }; -const DEFAULT_RETRY_RESPONSE = { +global.global.DEFAULT_RETRY_RESPONSE = { result: "Retry", message: "Retry Later" }; @@ -97,7 +95,7 @@ for (let i = 0; i < botConfig.processes.length; i++) { let processConfig = botConfig.processes[i]; - bot.process = processConfig.name; + botConfig.process = processConfig.name; try { @@ -159,9 +157,9 @@ for (let i = 0; i < botConfig.processes.length; i++) { function startProcess() { - if (bot.type === "trading") { + if (bot.type === "Trading") { - runTradingBot(); + runTradingBot(processConfig); return; } @@ -187,34 +185,41 @@ for (let i = 0; i < botConfig.processes.length; i++) { } -function runTradingBot() { +function runTradingBot(pProcessConfig) { - let tradingBot = TRADING_BOT_MODULE.newTradingBot(bot); - tradingBot.initialize(vmConfig.bot.path, processConfig, onInitializeReady); + try { + if (LOG_INFO === true) { logger.write("[INFO] runTradingBot -> Entering function."); } - function onInitializeReady(err) { + let tradingBot = TRADING_BOT_MODULE.newTradingBot(botConfig); + tradingBot.initialize(vmConfig.bot.path, pProcessConfig, onInitializeReady); - if (err.result !== DEFAULT_OK_RESPONSE.result) { + function onInitializeReady(err) { - tradingBot.start(whenStartFinishes); + if (err.result === global.DEFAULT_OK_RESPONSE.result) { - function whenStartFinishes() { + tradingBot.start(whenStartFinishes); - if (err.result !== DEFAULT_OK_RESPONSE.result) { + function whenStartFinishes() { - logger.write("[INFO] trading bot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully. :-)"); + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - } else { + logger.write("[INFO] trading bot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully. :-)"); - logger.write("[ERR] trading bot -> onInitializeReady -> whenStartFinishes -> err = " + err.message); - logger.write("[ERR] trading bot -> onInitializeReady -> whenStartFinishes -> Execution will be stopped. "); - logger.write("[ERR] trading bot -> onInitializeReady -> whenStartFinishes -> Bye. :-("); + } else { + + logger.write("[ERR] trading bot -> onInitializeReady -> whenStartFinishes -> err = " + err.message); + logger.write("[ERR] trading bot -> onInitializeReady -> whenStartFinishes -> Execution will be stopped. "); + logger.write("[ERR] trading bot -> onInitializeReady -> whenStartFinishes -> Bye. :-("); + } } - } - } else { - logger.write("[ERR] trading bot -> onInitializeReady -> err = " + err.message); - logger.write("[ERR] trading bot -> onInitializeReady -> Bot will not be started. "); + } else { + logger.write("[ERR] trading bot -> onInitializeReady -> err = " + err.message); + logger.write("[ERR] trading bot -> onInitializeReady -> Bot will not be started. "); + } } } + catch (err) { + logger.write("[ERROR] runTradingBot -> err = " + err.message); + } } \ No newline at end of file diff --git a/TradingBot.js b/TradingBot.js index ab726eea3..bcbd12729 100644 --- a/TradingBot.js +++ b/TradingBot.js @@ -30,11 +30,11 @@ USER_BOT_MODULE = require(pBotPath + "/" + pProcessConfig.name + "/" + 'User.Bot'); - callBackFunction(DEFAULT_OK_RESPONSE); + callBackFunction(global.DEFAULT_OK_RESPONSE); } catch (err) { logger.write("[ERROR] initialize -> err = " + err.message); - callBackFunction(DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -77,6 +77,8 @@ let nextWaitTime; + initializeContext(); + function initializeContext() { context = CONTEXT.newContext(bot, DEBUG_MODULE, AZURE_FILE_STORAGE); @@ -84,7 +86,7 @@ function onInizialized(err) { - if (err.result === DEFAULT_OK_RESPONSE.result) { + if (err.result === global.DEFAULT_OK_RESPONSE.result) { initializeDatasource(); } else { logger.write("[ERROR] start -> loop -> initializeContext -> err = " + err.message); @@ -100,7 +102,7 @@ function onInizialized(err) { - if (err.result === DEFAULT_OK_RESPONSE.result) { + if (err.result === global.DEFAULT_OK_RESPONSE.result) { initializeExchangeAPI(); } else { logger.write("[ERROR] start -> loop -> initializeDatasource -> err = " + err.message); @@ -116,7 +118,7 @@ function onInizialized(err) { - if (err.result === DEFAULT_OK_RESPONSE.result) { + if (err.result === global.DEFAULT_OK_RESPONSE.result) { initializeAssistant(); } else { logger.write("[ERROR] start -> loop -> initializeExchangeAPI -> err = " + err.message); @@ -132,7 +134,7 @@ function onInizialized(err) { - if (err.result === DEFAULT_OK_RESPONSE.result) { + if (err.result === global.DEFAULT_OK_RESPONSE.result) { initializeUserBot(); } else { logger.write("[ERROR] start -> loop -> initializeAssistant -> err = " + err.message); @@ -156,7 +158,7 @@ function onInizialized(err) { - if (err.result === DEFAULT_OK_RESPONSE.result) { + if (err.result === global.DEFAULT_OK_RESPONSE.result) { startUserBot(); } else { logger.write("[ERROR] start -> loop -> initializeUserBot -> err = " + err.message); @@ -172,19 +174,19 @@ function onFinished(err) { switch (err.result) { - case DEFAULT_OK_RESPONSE.result: { + case global.DEFAULT_OK_RESPONSE.result: { nextWaitTime = 'Normal'; saveContext(); return; } break; - case DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. + case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. nextWaitTime = 'Retry'; loopControl(nextWaitTime); // Note that we do not save the context, since the processing was aborted. return; } break; - case DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. logger.write("[ERROR] start -> loop -> startUserBot -> Operation Failed. Aborting the process."); callBackFunction(err); return; @@ -200,7 +202,7 @@ function onFinished(err) { - if (err.result === DEFAULT_OK_RESPONSE.result) { + if (err.result === global.DEFAULT_OK_RESPONSE.result) { loopControl(nextWaitTime); } else { logger.write("[ERROR] start -> loop -> saveContext -> err = " + err.message); @@ -236,7 +238,6 @@ catch (err) { logger.write("[ERROR] start -> err = " + err.message); - logger.write(logText); } } }; diff --git a/this.vm.config.json b/this.vm.config.json index 2633e2148..5d775bb42 100644 --- a/this.vm.config.json +++ b/this.vm.config.json @@ -1,5 +1,5 @@ { "bot": { - "path": "../AACarol-Extraction-Bot" + "path": "../Bots/AAMasters/AAMariam-Trading-Bot" } } \ No newline at end of file