From 450aba0b09de5d4a77e93048f49515989edca1cc Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 6 Mar 2018 17:00:59 +0100 Subject: [PATCH] Some refactoring --- .vs/AACloudPlatform/v15/.suo | Bin 70144 -> 69632 bytes Assistant.js | 44 ++++++++++++++-------------- Context.js | 4 +-- Datasource.js | 20 ++++++------- ExchangeAPI.js | 54 +++++++++++++++++------------------ 5 files changed, 61 insertions(+), 61 deletions(-) diff --git a/.vs/AACloudPlatform/v15/.suo b/.vs/AACloudPlatform/v15/.suo index 184e98d2b5d7f661c7642ac8099f0438cf06209c..4d650fe77650401e0a2ad044d024b030b807ce3f 100644 GIT binary patch delta 118 zcmZoz!qTvSWrBes69W_oFfecdnan`^@Bjb*AW;yTcVnP56YGP1&Hu@p3z>d1vnrG; oyQgd}WV>`)kQJ_3{eT9Lt+zSk(tAY|VUYPHK;bol%h(vX03)m#?f?J) delta 131 zcmZozz|ydUWrD$E0~byS0R{#+1_lOZApZCN|9>FGzzD=@8v~`8SOrXW%SUf6Wctm_ zx}a`bXvpS5wo9i4Iha7IKtTO~G?3l6IporNML}JN7??Bw3NrzP*9b0SW8|8Aw$x err = " + err); - callBackFunction("Operation Failed."); + callBackFunction("Operation Failed"); } } @@ -109,13 +109,13 @@ readStatusAndContext(); } break; - case 'Retry Later.': { // Something bad happened, but if we retry in a while it might go through the next time. + 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 Execution Retry."); callBackFunction(true, nextIntervalLapse); return; } break; - case 'Operation Failed.': { // This is an unexpected exception that we do not know how to handle. + case 'Operation Failed': { // This is an unexpected exception that we do not know how to handle. logger.write("[ERROR] getPositionsAtExchange -> onResponse -> Operation Failed. Aborting the process."); return; } @@ -124,7 +124,7 @@ } } catch (err) { logger.write("[ERROR] getPositionsAtExchange -> err = " + err); - callBack("Operation Failed."); + callBack("Operation Failed"); } } @@ -231,7 +231,7 @@ botContext.executionContext.positions[i].amountB !== sumAssetB ) { logger.write("[ERROR] ordersExecutionCheck -> loopBody -> confirmOrderWasPartiallyExecuted -> Cannot be confirmed that a partially execution was done well."); - callBack("Operation Failed."); + callBack("Operation Failed"); return; } @@ -266,7 +266,7 @@ } catch (err) { logger.write("[ERROR] ordersExecutionCheck -> loopBody -> confirmOrderWasPartiallyExecuted -> err = " + err); - callBack("Operation Failed."); + callBack("Operation Failed"); return; } } @@ -308,7 +308,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("Operation Failed."); + callBack("Operation Failed"); return; } @@ -341,14 +341,14 @@ } catch (err) { logger.write("[ERROR] ordersExecutionCheck -> loopBody -> confirmOrderWasExecuted -> err = " + err); - callBack("Operation Failed."); + callBack("Operation Failed"); return; } } } catch (err) { logger.write("[ERROR] ordersExecutionCheck -> loopBody -> err = " + err); - callBack("Operation Failed."); + callBack("Operation Failed"); return; } } @@ -380,7 +380,7 @@ } } catch (err) { logger.write("[ERROR] ordersExecutionCheck -> err = " + err); - callBack("Operation Failed."); + callBack("Operation Failed"); } } @@ -403,13 +403,13 @@ callBack(pTrades); } break; - case 'Retry Later.': { // Something bad happened, but if we retry in a while it might go through the next time. + 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 Execution Retry."); callBackFunction(true, nextIntervalLapse); return; } break; - case 'Operation Failed.': { // This is an unexpected exception that we do not know how to handle. + case 'Operation Failed': { // This is an unexpected exception that we do not know how to handle. logger.write("[ERROR] getPositionTradesAtExchange -> onResponse -> Operation Failed. Aborting the process."); return; } @@ -417,12 +417,12 @@ } } catch (err) { logger.write("[ERROR] getPositionTradesAtExchange -> onResponse -> err = " + err); - callBack("Operation Failed."); + callBack("Operation Failed"); } } } catch (err) { logger.write("[ERROR] getPositionTradesAtExchange -> err = " + err); - callBack("Operation Failed."); + callBack("Operation Failed"); } } @@ -463,13 +463,13 @@ callBack(); } break; - case 'Retry Later.': { // Something bad happened, but if we retry in a while it might go through the next time. + 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 Execution Retry."); callBackFunction(true, nextIntervalLapse); return; } break; - case 'Operation Failed.': { // This is an unexpected exception that we do not know how to handle. + case 'Operation Failed': { // This is an unexpected exception that we do not know how to handle. logger.write("[ERROR] putPositionAtExchange -> onResponse -> Operation Failed. Aborting the process."); return; } @@ -477,12 +477,12 @@ } } catch (err) { logger.write("[ERROR] putPositionAtExchange -> onResponse -> err = " + err); - callBack("Operation Failed."); + callBack("Operation Failed"); } } } catch (err) { logger.write("[ERROR] putPositionAtExchange -> err = " + err); - callBack("Operation Failed."); + callBack("Operation Failed"); } } @@ -536,13 +536,13 @@ callBack(); } break; - case 'Retry Later.': { // Something bad happened, but if we retry in a while it might go through the next time. + 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 Execution Retry."); callBackFunction(true, nextIntervalLapse); return; } break; - case 'Operation Failed.': { // This is an unexpected exception that we do not know how to handle. + case 'Operation Failed': { // This is an unexpected exception that we do not know how to handle. logger.write("[ERROR] movePositionAtExchange -> onResponse -> Operation Failed. Aborting the process."); return; } @@ -550,12 +550,12 @@ } } catch (err) { logger.write("[ERROR] movePositionAtExchange -> onResponse -> err = " + err); - callBack("Operation Failed."); + callBack("Operation Failed"); } } } catch (err) { logger.write("[ERROR] movePositionAtExchange -> err = " + err); - callBack("Operation Failed."); + callBack("Operation Failed"); } } }; \ No newline at end of file diff --git a/Context.js b/Context.js index 867466340..026f08d69 100644 --- a/Context.js +++ b/Context.js @@ -223,7 +223,7 @@ } catch (err) { logger.write("[ERROR] initialize -> err = " + err); - callBackFunction("Operation Failed."); + callBackFunction("Operation Failed"); } } @@ -378,7 +378,7 @@ } catch (err) { logger.write("[ERROR] saveAll -> Error = " + err.message); - callBackFunction("Operation Failed."); + callBackFunction("Operation Failed"); } } diff --git a/Datasource.js b/Datasource.js index e5c27c7d8..173f93723 100644 --- a/Datasource.js +++ b/Datasource.js @@ -42,7 +42,7 @@ } catch (err) { logger.write("[ERROR] initialize -> err = " + err); - callBackFunction("Operation Failed."); + callBackFunction("Operation Failed"); } } @@ -84,7 +84,7 @@ } } catch (err) { logger.write("[ERROR] getCandles -> getMarketFiles -> err = " + err); - callBack("Operation Failed."); + callBack("Operation Failed"); } } @@ -111,7 +111,7 @@ } } catch (err) { logger.write("[ERROR] getCandles -> getDailyFiles -> err = " + err); - callBack("Operation Failed."); + callBack("Operation Failed"); } } @@ -174,13 +174,13 @@ } } catch (err) { logger.write("[ERROR] getCandles -> getCandlesWeAreIn -> err = " + err); - callBack("Operation Failed."); + callBack("Operation Failed"); } } } catch (err) { logger.write("[ERROR] getCandles -> err = " + err); - callBack("Operation Failed."); + callBack("Operation Failed"); } } @@ -221,7 +221,7 @@ } } catch (err) { logger.write("[ERROR] getPatterns -> getMarketFiles -> err = " + err); - callBack("Operation Failed."); + callBack("Operation Failed"); } } @@ -248,7 +248,7 @@ } } catch (err) { logger.write("[ERROR] getPatterns -> getDailyFiles -> err = " + err); - callBack("Operation Failed."); + callBack("Operation Failed"); } } @@ -313,13 +313,13 @@ } } catch (err) { logger.write("[ERROR] getPatterns -> getStairsWeAreIn -> err = " + err); - callBack("Operation Failed."); + callBack("Operation Failed"); } } } catch (err) { logger.write("[ERROR] getPatterns -> err = " + err); - callBack("Operation Failed."); + callBack("Operation Failed"); } } @@ -361,7 +361,7 @@ } catch (err) { logger.write("[ERROR] getPatterns -> err = " + err); - callBack("Operation Failed."); + callBack("Operation Failed"); } } }; \ No newline at end of file diff --git a/ExchangeAPI.js b/ExchangeAPI.js index c1db28746..c1703db7a 100644 --- a/ExchangeAPI.js +++ b/ExchangeAPI.js @@ -47,14 +47,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("Operation Failed."); + callBackFunction("Operation Failed"); } } } catch (err) { logger.write("[ERROR] initialize -> err = " + err); - callBackFunction("Operation Failed."); + callBackFunction("Operation Failed"); } } @@ -74,7 +74,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("Retry Later."); + callBackFunction("Retry Later"); return; } else { @@ -82,19 +82,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("Retry Later."); + callBackFunction("Retry Later"); return; } else { logger.write("[ERROR] getOpenPositions -> onExchangeCallReturned -> Unexpected error trying to contact the Exchange. This will halt this bot process. : ERROR = " + err.message); - callBackFunction("Operation Failed."); + callBackFunction("Operation Failed"); return; } } } catch (err) { logger.write("[ERROR] getOpenPositions -> onExchangeCallReturned -> exchangeResponse.error = " + exchangeResponse.error); - callBackFunction("Operation Failed."); + callBackFunction("Operation Failed"); return; } @@ -138,12 +138,12 @@ } catch (err) { logger.write("[ERROR] getOpenPositions -> onExchangeCallReturned -> Error = " + err.message); - callBackFunction("Operation Failed."); + callBackFunction("Operation Failed"); } } } catch (err) { logger.write("[ERROR] getOpenPositions -> onExchangeCallReturned -> Error = " + err.message); - callBackFunction("Operation Failed."); + callBackFunction("Operation Failed"); } } @@ -163,7 +163,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("Retry Later."); + callBackFunction("Retry Later"); return; } else { @@ -171,19 +171,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("Retry Later."); + callBackFunction("Retry Later"); return; } else { logger.write("[ERROR] getExecutedTrades -> onExchangeCallReturned -> Unexpected error trying to contact the Exchange. This will halt this bot process. : ERROR = " + err.message); - callBackFunction("Operation Failed."); + callBackFunction("Operation Failed"); return; } } } catch (err) { logger.write("[ERROR] getExecutedTrades -> onExchangeCallReturned -> exchangeResponse.error = " + exchangeResponse.error); - callBackFunction("Operation Failed."); + callBackFunction("Operation Failed"); return; } @@ -234,12 +234,12 @@ } catch (err) { logger.write("[ERROR] getExecutedTrades -> onExchangeCallReturned -> Error = " + err.message); - callBackFunction("Operation Failed."); + callBackFunction("Operation Failed"); } } } catch (err) { logger.write("[ERROR] getExecutedTrades -> onExchangeCallReturned -> Error = " + err.message); - callBackFunction("Operation Failed."); + callBackFunction("Operation Failed"); } } @@ -263,7 +263,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("Retry Later."); + callBackFunction("Retry Later"); return; } else { @@ -271,19 +271,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("Retry Later."); + callBackFunction("Retry Later"); return; } else { logger.write("[ERROR] putPosition -> onExchangeCallReturned -> Unexpected error trying to contact the Exchange. This will halt this bot process. : ERROR = " + err.message); - callBackFunction("Operation Failed."); + callBackFunction("Operation Failed"); return; } } } catch (err) { logger.write("[ERROR] putPosition -> onExchangeCallReturned -> exchangeResponse.error = " + exchangeResponse.error); - callBackFunction("Operation Failed."); + callBackFunction("Operation Failed"); return; } @@ -315,13 +315,13 @@ } catch (err) { logger.write("[ERROR] putPosition -> onExchangeCallReturned -> Error = " + err.message); - callBackFunction("Operation Failed."); + callBackFunction("Operation Failed"); } } } catch (err) { logger.write("[ERROR] putPosition -> err = " + err); - callBackFunction("Operation Failed."); + callBackFunction("Operation Failed"); } } @@ -341,7 +341,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("Retry Later."); + callBackFunction("Retry Later"); return; } else { @@ -349,19 +349,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("Retry Later."); + callBackFunction("Retry Later"); return; } else { logger.write("[ERROR] movePosition -> onExchangeCallReturned -> Unexpected error trying to contact the Exchange. This will halt this bot process. : ERROR = " + err.message); - callBackFunction("Operation Failed."); + callBackFunction("Operation Failed"); return; } } } catch (err) { logger.write("[ERROR] movePosition -> onExchangeCallReturned -> exchangeResponse.error = " + exchangeResponse.error); - callBackFunction("Operation Failed."); + callBackFunction("Operation Failed"); return; } @@ -371,7 +371,7 @@ if (exchangeResponse.success !== 1) { logger.write("[ERROR] movePosition -> onExchangeCallReturned -> exchangeResponse.success = " + exchangeResponse.success); - callBackFunction("Operation Failed."); + callBackFunction("Operation Failed"); return; } /* @@ -398,13 +398,13 @@ } catch (err) { logger.write("[ERROR] movePosition -> onExchangeCallReturned -> Error = " + err.message); - callBackFunction("Operation Failed."); + callBackFunction("Operation Failed"); } } } catch (err) { logger.write("[ERROR] movePosition -> err = " + err); - callBackFunction("Operation Failed."); + callBackFunction("Operation Failed"); } } }; \ No newline at end of file