From 70dd47edeb8ddccb797e305f9b9f62a2e4492f39 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 9 Mar 2018 14:53:29 +0100 Subject: [PATCH] Something Went Wrong function created --- .vs/AACloudPlatform/v15/.suo | Bin 76800 -> 76800 bytes AACloudPlatform.sln | 4 +- ExchangeAPI.js | 154 +++++------------- AACloudPlatform.njsproj => Project.njsproj | 2 +- .../Project.njsproj.FileListAbsolute.txt | 2 + 5 files changed, 48 insertions(+), 114 deletions(-) rename AACloudPlatform.njsproj => Project.njsproj (99%) create mode 100644 obj/Debug/Project.njsproj.FileListAbsolute.txt diff --git a/.vs/AACloudPlatform/v15/.suo b/.vs/AACloudPlatform/v15/.suo index a22487ba6e2c30145f8dab4022d7bb7fef9fba8b..32d71c9502dc3d853b7b3a6f9b71a0d3cc925402 100644 GIT binary patch delta 2509 zcmds(dr(wW7{Kp$_U@AfmOwxOSqO1c9*YuSiY-D`hQJy&OgW9urW}wJ7sn};n`rpJ zV)x5vMr-KCF!(@Wj}z6PuJ$J1%$Pb>j5Ynyl;sT6h!6S>tcf*ck3X8}&iwW}=R4WF!&#~Fj|M%hyuk((LNXN_1F@0e+x9?*>^wED~KvW=qvD;ak7^cVxi8el?=YhHeAl;;Cs3Z*o*zF z*dTIGBe3aXE83YES7{WcV>qB612Ghq|n!s+)7}k#T_OT zduY-YSiIp`5YCU9S^;XX+FS#>u%CW+Vs-eVvgoEj@eF2_CZay#`J2`)t6=CbM%n}S zZ`>6d#3=|5H(hFnT;i4d6S8@Pn)gMNf-G9{=0;e?t0Rj5^CNP7A$!15PHPo}$W?${ zp-I>~&he%-nsKYO7rgN@%CRokgw?S%x3u+=$ z3z(7246dWqdOD0?QOy^Lmxu=JFoi>DhjSmO4yMjxzNZ;OHhre7r`1~_V)gXnm>;Ex zC_SZ_Jkx#@{w!Lnn#oiv8yRXX8x9jHdH?JnrcPt(W4Gd*!6;OyMVJ&7R!6Qk5}Sz4 z#1;xN#^W;I9;cP6QPit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oWCH39~k%&c-QYDA-PKu{b`T?jYhLYUuyZT*c|}k1=}EnTinp{en?3 zUbza9P!z%+EQJy*IaQw3OFemy&=Y=PDcJbmWjLq@TlNM@4=>5Pg-z%`>B`#qo|Z3z z@An#LS1EUQ^Je-^eMu7#?ry_)39X#a@--2U{=RhTO$jCerE5FG<5^IkI6sbp{AuP{ z9sQ+k{jm#&Uw9bLOt_T+`4RZvYV9BW653uVqe9EUnaJyWZ}fH5hnw_p&VvFhxLTglIq*?c__furRf%480ygeznQGC&WcF+M npi{vB20wWSPev=kq7l45DuaQk0W*Dy!aYXVHMQ$rIHUSEN5&rP diff --git a/AACloudPlatform.sln b/AACloudPlatform.sln index 3de48b31a..a21837e88 100644 --- a/AACloudPlatform.sln +++ b/AACloudPlatform.sln @@ -1,9 +1,9 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26730.10 +VisualStudioVersion = 15.0.27130.2027 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}") = "AACloudPlatform", "AACloudPlatform.njsproj", "{AE0A3FE2-7021-4CC2-9922-A887CA5CDD7C}" +Project("{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}") = "Project", "Project.njsproj", "{AE0A3FE2-7021-4CC2-9922-A887CA5CDD7C}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/ExchangeAPI.js b/ExchangeAPI.js index d123c3f6d..9163b3fe8 100644 --- a/ExchangeAPI.js +++ b/ExchangeAPI.js @@ -80,35 +80,9 @@ if (FULL_LOG === true) { logger.write("[INFO] getOpenPositions -> onExchangeCallReturned -> err = " + err); } if (FULL_LOG === true) { logger.write("[INFO] getOpenPositions -> onExchangeCallReturned -> exchangeResponse = " + JSON.stringify(exchangeResponse)); } - if (err || exchangeResponse.error !== undefined || exchangeResponse.indexOf("Connection timed out") > 0) { - try { + if (err || exchangeResponse.error !== undefined || JSON.stringify(exchangeResponse).indexOf("Connection timed out") > 0) { - if (err.message.indexOf("ETIMEDOUT") > 0 || exchangeResponse.indexOf("Connection timed out") > 0) { - - logger.write("[WARN] getOpenPositions -> onExchangeCallReturned -> Timeout reached while trying to access the Exchange API. Requesting new execution later. : ERROR = " + err.message); - callBackFunction(global.DEFAULT_RETRY_RESPONSE); - return; - - } else { - - if (err.message.indexOf("ECONNRESET") > 0) { - - logger.write("[WARN] getOpenPositions -> onExchangeCallReturned -> The exchange reseted the connection. Requesting new execution later. : ERROR = " + err.message); - 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(global.DEFAULT_FAIL_RESPONSE); - return; - } - } - - } catch (err) { - logger.write("[ERROR] getOpenPositions -> onExchangeCallReturned -> exchangeResponse.error = " + exchangeResponse.error); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } + somethingWentWrong(err, exchangeResponse, callBackFunction); } else { @@ -174,35 +148,10 @@ if (FULL_LOG === true) { logger.write("[INFO] getExecutedTrades -> onExchangeCallReturned -> err = " + err); } if (FULL_LOG === true) { logger.write("[INFO] getExecutedTrades -> onExchangeCallReturned -> exchangeResponse = " + JSON.stringify(exchangeResponse)); } - if (err || exchangeResponse.error !== undefined || exchangeResponse.indexOf("Connection timed out") > 0) { - try { + if (err || exchangeResponse.error !== undefined || JSON.stringify(exchangeResponse).indexOf("Connection timed out") > 0) { - if (err.message.indexOf("ETIMEDOUT") > 0 || exchangeResponse.indexOf("Connection timed out") > 0) { + somethingWentWrong(err, exchangeResponse, callBackFunction); - logger.write("[WARN] getExecutedTrades -> onExchangeCallReturned -> Timeout reached while trying to access the Exchange API. Requesting new execution later. : ERROR = " + err.message); - callBackFunction(global.DEFAULT_RETRY_RESPONSE); - return; - - } else { - - if (err.message.indexOf("ECONNRESET") > 0) { - - logger.write("[WARN] getExecutedTrades -> onExchangeCallReturned -> The exchange reseted the connection. Requesting new execution later. : ERROR = " + err.message); - 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(global.DEFAULT_FAIL_RESPONSE); - return; - } - } - - } catch (err) { - logger.write("[ERROR] getExecutedTrades -> onExchangeCallReturned -> exchangeResponse.error = " + exchangeResponse.error); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } } else { /* @@ -290,35 +239,9 @@ if (FULL_LOG === true) { logger.write("[INFO] putPosition -> onExchangeCallReturned -> err = " + err); } if (FULL_LOG === true) { logger.write("[INFO] putPosition -> onExchangeCallReturned -> exchangeResponse = " + JSON.stringify(exchangeResponse)); } - if (err || exchangeResponse.error !== undefined || exchangeResponse.indexOf("Connection timed out") > 0) { - try { + if (err || exchangeResponse.error !== undefined || JSON.stringify(exchangeResponse).indexOf("Connection timed out") > 0) { - if (err.message.indexOf("ETIMEDOUT") > 0 || exchangeResponse.indexOf("Connection timed out") > 0) { - - logger.write("[WARN] putPosition -> onExchangeCallReturned -> Timeout reached while trying to access the Exchange API. Requesting new execution later. : ERROR = " + err.message); - callBackFunction(global.DEFAULT_RETRY_RESPONSE); - return; - - } else { - - if (err.message.indexOf("ECONNRESET") > 0) { - - logger.write("[WARN] putPosition -> onExchangeCallReturned -> The exchange reseted the connection. Requesting new execution later. : ERROR = " + err.message); - 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(global.DEFAULT_FAIL_RESPONSE); - return; - } - } - - } catch (err) { - logger.write("[ERROR] putPosition -> onExchangeCallReturned -> exchangeResponse.error = " + exchangeResponse.error); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } + somethingWentWrong(err, exchangeResponse, callBackFunction); } else { @@ -374,35 +297,9 @@ try { - if (err || exchangeResponse.error !== undefined || exchangeResponse.indexOf("Connection timed out") > 0) { - try { + if (err || exchangeResponse.error !== undefined || JSON.stringify(exchangeResponse).indexOf("Connection timed out") > 0) { - if (err.message.indexOf("ETIMEDOUT") > 0 || exchangeResponse.indexOf("Connection timed out") > 0) { - - logger.write("[WARN] movePosition -> onExchangeCallReturned -> Timeout reached while trying to access the Exchange API. Requesting new execution later. : ERROR = " + err.message); - callBackFunction(global.DEFAULT_RETRY_RESPONSE); - return; - - } else { - - if (err.message.indexOf("ECONNRESET") > 0) { - - logger.write("[WARN] movePosition -> onExchangeCallReturned -> The exchange reseted the connection. Requesting new execution later. : ERROR = " + err.message); - 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(global.DEFAULT_FAIL_RESPONSE); - return; - } - } - - } catch (err) { - logger.write("[ERROR] movePosition -> onExchangeCallReturned -> exchangeResponse.error = " + exchangeResponse.error); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } + somethingWentWrong(err, exchangeResponse, callBackFunction); } else { @@ -444,4 +341,39 @@ callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } + + function somethingWentWrong(err, exchangeResponse, callBackFunction) { + + try { + + logger.write("[WARN] somethingWentWrong -> err = " + JSON.stringify(err)); + logger.write("[WARN] somethingWentWrong -> exchangeResponse = " + JSON.stringify(exchangeResponse)); + + if (JSON.stringify(err).indexOf("ETIMEDOUT") > 0 || JSON.stringify(exchangeResponse).indexOf("Connection timed out") > 0) { + + logger.write("[WARN] somethingWentWrong -> Timeout reached while trying to access the Exchange API. Requesting new execution later."); + callBackFunction(global.DEFAULT_RETRY_RESPONSE); + return; + + } else { + + if (JSON.stringify(err).indexOf("ECONNRESET") > 0) { + + logger.write("[WARN] somethingWentWrong -> The exchange reseted the connection. Requesting new execution later."); + callBackFunction(global.DEFAULT_RETRY_RESPONSE); + return; + + } else { + logger.write("[ERROR] somethingWentWrong -> Unexpected error trying to contact the Exchange. This will halt this bot process."); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; + } + } + + } catch (err) { + logger.write("[ERROR] somethingWentWrong -> err.message = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; + } + } }; \ No newline at end of file diff --git a/AACloudPlatform.njsproj b/Project.njsproj similarity index 99% rename from AACloudPlatform.njsproj rename to Project.njsproj index df7231810..1eb413ca3 100644 --- a/AACloudPlatform.njsproj +++ b/Project.njsproj @@ -12,7 +12,7 @@ {3AF33F2E-1136-4D97-BBB7-1795711AC8B8};{349c5851-65df-11da-9384-00065b846f21};{9092AA53-FB77-4645-B42D-1CCCA6BD08BD} 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - AACloudPlatform + Project Trading-Process C:\Program Files\nodejs\node.exe False diff --git a/obj/Debug/Project.njsproj.FileListAbsolute.txt b/obj/Debug/Project.njsproj.FileListAbsolute.txt new file mode 100644 index 000000000..71fd7f7bc --- /dev/null +++ b/obj/Debug/Project.njsproj.FileListAbsolute.txt @@ -0,0 +1,2 @@ +C:\Users\Luis\source\repos\AACloudPlatform\obj\Debug\Project.njsproj.CoreCompileInputs.cache +C:\Users\Luis\source\repos\AACloudPlatform\bin\Microsoft.NodejsTools.WebRole.dll