From 14575a74db1cf12488f832c6df8d3bbb1a513abe Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 8 Mar 2018 17:29:21 +0100 Subject: [PATCH] Improves at main loop --- .vs/AACloudPlatform/v15/.suo | Bin 74240 -> 74240 bytes Trading Bot Main Loop.js | 131 ++++++++++++++++++++++++++--------- 2 files changed, 100 insertions(+), 31 deletions(-) diff --git a/.vs/AACloudPlatform/v15/.suo b/.vs/AACloudPlatform/v15/.suo index 5b165dc5ee96a7db7fd789679fe7010e9288eb0a..049d242be999eb0776f6e4cc93f8ced8ec601fd6 100644 GIT binary patch delta 738 zcmb`DTWAwO6o&WA?xwjB*wji4v9wAdl2Er8lt>>+Fm{(jbayHzi(>CfyNJsz{Ld9t%Pqq=HmI5WIkQn{_r;@XZ$wd~?p3f94%(DIuTpq}=MG;!WcP#$z+_k|p_z5mGL(+3{v8GXhpW5g`mIj)v@896#Lz6-G7 z_D!rTWiaw(0z0o#eE4~a^?mp*ZN<^F8#_`qoEg7`jier9BU>>xd|kQ5oA$S~L^nnK z{vKLMEfL8A%(5Def`iq5YE5gR6j|QX(?Na7yG+mv(ht2}j(L{7XiX1btm4B!HmBSX zEPq6fb6ioIs61Wbm05xxG6|Zvm*AB-A>#yseRFNJ?NNbO$^;)Tx~aQZuEq9fkOrUU zfKI)Y0p+2RvLIk7)SPd&!#t=j&luRORN?OtiT@gl@>Ni8gn&&#rCRFe|NC$ens56w@!`G^xHM0G(DXnWcR7@V{wcQ!)y7aq0$H~;_u delta 932 zcma))T}YE*6o7ZWADucSHLYyPX3iE46Eh((8nUtkLAqLMrVtfnFb#h%YW@ZjN;%s; z`}1e6DT!Kp1G7Yz*+tMr34u`2kO~7SZzR3Qb-t-xgclunIEVK=?|HxP;kC{P)*0bZ z1t%`qefAYr$sOR}81@O5cbOCl#abW`I6*m&un;GSV$_KTxnk@HSCrEH&}I4fQJ%R9dlhN=F^6bttO;~f(<*v zcd(qKoKVgd!y5KCM2ijUyV)1^KqM(vjutt|dh?93V!$`#u!W8_L*@45ZhXO_n+OW7s#hfFTc#Ig);bZe5yx$(hEoc`&fDiC)0zFM6h*nTvHzbC?{b zCND~+X;YD)`nQ;Su5hd{0bYnKdj4w27J^yJf>+>7!}7mMZ?uq!YmP8{Jya|Cw4lXL z{WDNm<|uR%wn5a_jjIzu4M6FN!2d%PM;AK)n2N z*F)=*-?*CC+Vn@*XjJU;{iJ$W?%Xi_a?BPEH6V2;L6mK8m&axiDuO5EU^@Q?Ah`lI qrNraN^KGb^QL;4uEJ%g1kc-Bl loop -> initializeContext -> err = " + err.message); - if (err.result === global.DEFAULT_RETRY_RESPONSE.result) { + switch (err.result) { + case global.DEFAULT_OK_RESPONSE.result: { + logger.write("[INFO] run -> loop -> initializeContext -> onInizialized > Execution finished well. :-)"); + initializeDatasource(); + return; + } + break; + 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] run -> loop -> initializeContext -> onInizialized > Retry Later. Requesting Execution Retry."); nextWaitTime = 'Retry'; loopControl(nextWaitTime); + return; } - else { + break; + case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + logger.write("[ERROR] run -> loop -> initializeContext -> onInizialized > Operation Failed. Aborting the process."); callBackFunction(err); + return; } + break; } } } @@ -110,13 +119,27 @@ datasource.initialize(onInizialized); function onInizialized(err) { - logger.write("[ERROR] run -> loop -> initializeDatasource -> err = " + err.message); - if (err.result === global.DEFAULT_RETRY_RESPONSE.result) { - nextWaitTime = 'Retry'; - loopControl(nextWaitTime); - } - else { - callBackFunction(err); + + switch (err.result) { + case global.DEFAULT_OK_RESPONSE.result: { + logger.write("[INFO] run -> loop -> initializeDatasource -> onInizialized > Execution finished well. :-)"); + initializeExchangeAPI(); + return; + } + break; + 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] run -> loop -> initializeDatasource -> onInizialized > Retry Later. Requesting Execution Retry."); + nextWaitTime = 'Retry'; + loopControl(nextWaitTime); + return; + } + break; + case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + logger.write("[ERROR] run -> loop -> initializeDatasource -> onInizialized > Operation Failed. Aborting the process."); + callBackFunction(err); + return; + } + break; } } } @@ -130,11 +153,26 @@ function onInizialized(err) { - if (err.result === global.DEFAULT_OK_RESPONSE.result) { - initializeAssistant(); - } else { - logger.write("[ERROR] run -> loop -> initializeExchangeAPI -> err = " + err.message); - callBackFunction(err); + switch (err.result) { + case global.DEFAULT_OK_RESPONSE.result: { + logger.write("[INFO] run -> loop -> initializeExchangeAPI -> onInizialized > Execution finished well. :-)"); + initializeAssistant(); + return; + } + break; + 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] run -> loop -> initializeExchangeAPI -> onInizialized > Retry Later. Requesting Execution Retry."); + nextWaitTime = 'Retry'; + loopControl(nextWaitTime); + return; + } + break; + case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + logger.write("[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized > Operation Failed. Aborting the process."); + callBackFunction(err); + return; + } + break; } } } @@ -173,11 +211,26 @@ function onInizialized(err) { - if (err.result === global.DEFAULT_OK_RESPONSE.result) { - startUserBot(); - } else { - logger.write("[ERROR] run -> loop -> initializeUserBot -> err = " + err.message); - callBackFunction(err); + switch (err.result) { + case global.DEFAULT_OK_RESPONSE.result: { + logger.write("[INFO] run -> loop -> initializeUserBot -> onInizialized > Execution finished well. :-)"); + startUserBot(); + return; + } + break; + 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] run -> loop -> initializeUserBot -> onInizialized > Retry Later. Requesting Execution Retry."); + nextWaitTime = 'Retry'; + loopControl(nextWaitTime); + return; + } + break; + case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized > Operation Failed. Aborting the process."); + callBackFunction(err); + return; + } + break; } } } @@ -192,19 +245,20 @@ switch (err.result) { case global.DEFAULT_OK_RESPONSE.result: { - nextWaitTime = 'Normal'; + logger.write("[INFO] run -> loop -> startUserBot -> onFinished > Execution finished well. :-)"); saveContext(); return; } break; 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] run -> loop -> startUserBot -> onFinished > Retry Later. Requesting Execution Retry."); nextWaitTime = 'Retry'; - loopControl(nextWaitTime); // Note that we do not save the context, since the processing was aborted. + loopControl(nextWaitTime); return; } break; case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - logger.write("[ERROR] run -> loop -> startUserBot -> Operation Failed. Aborting the process."); + logger.write("[ERROR] run -> loop -> startUserBot -> onFinished > Operation Failed. Aborting the process."); callBackFunction(err); return; } @@ -221,11 +275,26 @@ function onFinished(err) { - if (err.result === global.DEFAULT_OK_RESPONSE.result) { - loopControl(nextWaitTime); - } else { - logger.write("[ERROR] run -> loop -> saveContext -> err = " + err.message); - callBackFunction(err); + switch (err.result) { + case global.DEFAULT_OK_RESPONSE.result: { + logger.write("[INFO] run -> loop -> startUserBot -> onFinished > Execution finished well. :-)"); + nextWaitTime = 'Normal'; + loopControl(nextWaitTime); + return; + } + break; + 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] run -> loop -> startUserBot -> onFinished > Can not retry at this point."); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; + } + break; + case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + logger.write("[ERROR] run -> loop -> startUserBot -> onFinished > Operation Failed. Aborting the process."); + callBackFunction(err); + return; + } + break; } } }