From 4b6fddfffff0f6e8551f1028d2bfdf9a7576f0d2 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 9 Mar 2018 18:53:15 +0100 Subject: [PATCH] Context acess forbidden --- .vs/AACloudPlatform/v15/.suo | Bin 76800 -> 76800 bytes Assistant.js | 139 ++++++++++++++++++----------------- Run.js | 1 + Trading Bot Main Loop.js | 3 +- this.vm.config.json | 2 +- 5 files changed, 76 insertions(+), 69 deletions(-) diff --git a/.vs/AACloudPlatform/v15/.suo b/.vs/AACloudPlatform/v15/.suo index 32d71c9502dc3d853b7b3a6f9b71a0d3cc925402..33b4fe5957fa362e7d1f2652476223d6f90bb189 100644 GIT binary patch delta 1392 zcmd5+T}abW6#t+9miuU0bGmvc(y}J5|CrNi3yM~A5R^C~f*zvLhbiTnPWw=6MbJZE z&JzThX#d&NFjwBFx73HAhjN7(5fKtSn0?TL(w85d|Jp{;2p>D}p9EN6AN86Ze<+G146;)Dol|^)yN`PqJ^SS{_cYYR#YwH)-e$z5v<{1V5QO~|FN>jl(+VUML3-wC4Z|a6{Z7j11oXf+BWy2p5t`npyq-&6*MVIDm~@< z_W1B~Qz7~ab%wgSTASIvdSiiojj$=-ULX{j%{IYqv08;9i_>Yf71>rh?PlEFd<~~s z?ju|cfk=_OxFoE`{+?XyxY~;Yot@a*6o%_ji_rQGl4e^u%WU;(&XF|0y4eQM`3{s- znQ9K1_IN7xmzA2zt2`C!(bZ&>4h;#0cF_nHd=fOsfa6$S+XKjyu1;J|6WLC1pu4#Z zZNVPxSlmRTg4SfRufZnBEGGI(4E?3V*U`j5#j3>nAq|eS=CZA!(;(iE2O}N4c#CI| zi6P+AIcyIbQQNu*Uw5UkygSbqs7DhGlX51nWA1FrfCFvGTh=8$;Z^zhd)Mr>+1&Mi z_fN_#|6jY%jNX==D73C(yL!DKzTz?R?XgyR`f=Go4{Rged^r&>@zeK4W_&#i=oNK; z^pK-wE&q291@WyMy*)+0wel>8Bl0Vv7W7O%Iwr%^?t&}*M##pj?yM+bW#cv(C1>ql zzVgfe+8XUsLy$hagrK`n7kgB1GSU-jx=XP?6QhTi99D>*c=1EZT@Cm(_xu^)hr4PR QOk;y%76|Eq59I;>6TrE^c>n+a delta 1131 zcmchXdq~q!6vywm`|V|$Zn~^U%ca;*vswL7^wKivpK?-Al#)v1KS^ru)?)<`lx6D# zqq1DX?1eRV#X(6dcFoagZDj5q9D*Aun{4`ZDodYv*uG?A3KDw4f)66XP4xz#baN z1&xt3X_AgZ#ut)qk|2hnZ4k~Ya*~RBOu4vvegP)TfA5POQSoMz_z@SWg-U1MT;o~t zJV#U!=ZR5~mD8#gJpF4#*l}^XUU^2=okfYlmgC(prP;(-3@KVxheb8z*fki5rGpl1 zxON||g_Yn96)t~mLAARAk5w$bHdKqbS00JNnymnTOa!e6dD_7kq%|knCo+mf zYxhbzkee}B=+i|g$H%h0atu*ZmjuRT^67?~Ik1*&0|q~2py6u{hHg!96{Nr?TyeV% zAKyLb3Z#NrT)wvh&^8#4@jjF1jwCXC9^ht&&sot7*`6+rp;r(8N9ymZ)3Cxbm8!18bt87;mWleXxq)qDTd=oxcp~FB9G`tj z6{$a7Dm?uhPdu69e-Hs)Kq<7@<<>*2$ov=pmnVv>*nvJpEl715pfcT}GW}Ik5$|h~ ziz&K>M|i?tfho9rRpqBCH_U38iBC@_8&!_tru_wJmX4~*yKOhW1sOdQG&|o-Y)y@; zN^E``?Ms2Yb&)&=t?ep*p$ZZVE=Mw~_jj6L0W{5mPK|8(;KJLqn5AqbMX|FiwuV{h zyO8BzOJA#cb5Q<4Fg(?_1OxsQyfYB%sz`=>ksqoBbbQXl%u5 loopBody -> confirmOrderWasPartiallyExecuted -> Cannot be confirmed that a partially execution was done well."); callBack(global.DEFAULT_FAIL_RESPONSE); @@ -244,24 +247,24 @@ */ - botContext.executionContext.positions[i].amountA = exchangePositions[j].amountA; - botContext.executionContext.positions[i].amountB = exchangePositions[j].amountB; - botContext.executionContext.positions[i].date = (new Date(exchangePositions[j].date)).valueOf(); + context.executionContext.positions[i].amountA = exchangePositions[j].amountA; + context.executionContext.positions[i].amountB = exchangePositions[j].amountB; + context.executionContext.positions[i].date = (new Date(exchangePositions[j].date)).valueOf(); for (k = 0; k < pTrades.length; k++) { - botContext.executionContext.positions[i].pTrades.push(pTrades[k]); + context.executionContext.positions[i].pTrades.push(pTrades[k]); - botContext.newHistoryRecord.newTrades++; + context.newHistoryRecord.newTrades++; } let newTransaction = { - type: botContext.executionContext.positions[i].type + " partially executed", - position: botContext.executionContext.positions[i] + type: context.executionContext.positions[i].type + " partially executed", + position: context.executionContext.positions[i] }; - botContext.executionContext.transactions.push(newTransaction); + context.executionContext.transactions.push(newTransaction); /* All done. */ @@ -279,7 +282,7 @@ /* Position not found: we need to know if the order was executed. */ - getPositionTradesAtExchange(botContext.executionContext.positions[i].id, confirmOrderWasExecuted); + getPositionTradesAtExchange(context.executionContext.positions[i].id, confirmOrderWasExecuted); function getPositionTradesAtExchange(pPositionId, innerCallBack) { @@ -359,8 +362,8 @@ sumAssetA = sumAssetA + exchangePositions[j].fee; if ( - botContext.executionContext.positions[i].amountA !== sumAssetA || - botContext.executionContext.positions[i].amountB !== sumAssetB + context.executionContext.positions[i].amountA !== sumAssetA || + context.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(global.DEFAULT_FAIL_RESPONSE); @@ -373,22 +376,22 @@ */ - botContext.executionContext.positions[i].status = "executed"; + context.executionContext.positions[i].status = "executed"; for (k = 0; k < pTrades.length; k++) { - botContext.executionContext.positions[i].pTrades.push(pTrades[k]); + context.executionContext.positions[i].pTrades.push(pTrades[k]); - botContext.newHistoryRecord.newTrades++; + context.newHistoryRecord.newTrades++; } let newTransaction = { - type: botContext.executionContext.positions[i].type + " executed", - position: botContext.executionContext.positions[i] + type: context.executionContext.positions[i].type + " executed", + position: context.executionContext.positions[i] }; - botContext.executionContext.transactions.push(newTransaction); + context.executionContext.transactions.push(newTransaction); /* All done. */ @@ -417,7 +420,7 @@ function controlLoop() { - if (i < botContext.executionContext.positions.length) { + if (i < context.executionContext.positions.length) { loopBody(); @@ -439,26 +442,26 @@ } } - function putPositionAtExchange(pType, pRate, pAmountA, pAmountB, callBack) { + function putPosition(pType, pRate, pAmountA, pAmountB, callBack) { try { - if (FULL_LOG === true) { logger.write("[INFO] putPositionAtExchange -> Entering function."); } - if (FULL_LOG === true) { logger.write("[INFO] putPositionAtExchange -> pType = " + pType); } - if (FULL_LOG === true) { logger.write("[INFO] putPositionAtExchange -> pRate = " + pRate); } - if (FULL_LOG === true) { logger.write("[INFO] putPositionAtExchange -> pAmountA = " + pAmountA); } - if (FULL_LOG === true) { logger.write("[INFO] putPositionAtExchange -> pAmountB = " + pAmountB); } + if (FULL_LOG === true) { logger.write("[INFO] putPosition -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] putPosition -> pType = " + pType); } + if (FULL_LOG === true) { logger.write("[INFO] putPosition -> pRate = " + pRate); } + if (FULL_LOG === true) { logger.write("[INFO] putPosition -> pAmountA = " + pAmountA); } + if (FULL_LOG === true) { logger.write("[INFO] putPosition -> pAmountB = " + pAmountB); } exchangeAPI.putPosition(global.MARKET, pType, pRate, pAmountA, pAmountB, onResponse); function onResponse(err, pPositionId) { try { - if (FULL_LOG === true) { logger.write("[INFO] putPositionAtExchange -> onResponse -> Entering function."); } - if (FULL_LOG === true) { logger.write("[INFO] putPositionAtExchange -> onResponse -> pPositionId = " + pPositionId); } + if (FULL_LOG === true) { logger.write("[INFO] putPosition -> onResponse -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] putPosition -> onResponse -> pPositionId = " + pPositionId); } switch (err.result) { case global.DEFAULT_OK_RESPONSE.result: { // Everything went well, we have the information requested. - logger.write("[INFO] putPositionAtExchange -> onResponse -> Execution finished well. :-)"); + logger.write("[INFO] putPosition -> onResponse -> Execution finished well. :-)"); let position = { id: pPositionId, @@ -471,64 +474,64 @@ trades: [] }; - botContext.executionContext.positions.push(position); + context.executionContext.positions.push(position); let newTransaction = { type: "newPosition", position: position }; - botContext.executionContext.transactions.push(newTransaction); + context.executionContext.transactions.push(newTransaction); - botContext.newHistoryRecord.newPositions++; - botContext.newHistoryRecord.rate = pRate; + context.newHistoryRecord.newPositions++; + context.newHistoryRecord.rate = pRate; callBack(global.DEFAULT_OK_RESPONSE); 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] putPositionAtExchange -> onResponse -> Retry Later. Requesting Execution Retry."); + logger.write("[ERROR] putPosition -> onResponse -> Retry Later. Requesting Execution Retry."); callBack(global.DEFAULT_RETRY_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] putPositionAtExchange -> onResponse -> Operation Failed. Aborting the process."); + logger.write("[ERROR] putPosition -> onResponse -> Operation Failed. Aborting the process."); callBack(global.DEFAULT_FAIL_RESPONSE); return; } break; } } catch (err) { - logger.write("[ERROR] putPositionAtExchange -> onResponse -> err = " + err.message); + logger.write("[ERROR] putPosition -> onResponse -> err = " + err.message); callBack(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write("[ERROR] putPositionAtExchange -> err = " + err.message); + logger.write("[ERROR] putPosition -> err = " + err.message); callBack(global.DEFAULT_FAIL_RESPONSE); } } - function movePositionAtExchange(pPosition, pNewRate, callBack) { + function movePosition(pPosition, pNewRate, callBack) { try { - if (FULL_LOG === true) { logger.write("[INFO] movePositionAtExchange -> Entering function."); } - if (FULL_LOG === true) { logger.write("[INFO] movePositionAtExchange -> pPosition = " + JSON.stringify(pPosition)); } - if (FULL_LOG === true) { logger.write("[INFO] movePositionAtExchange -> pNewRate = " + pNewRate); } + if (FULL_LOG === true) { logger.write("[INFO] movePosition -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] movePosition -> pPosition = " + JSON.stringify(pPosition)); } + if (FULL_LOG === true) { logger.write("[INFO] movePosition -> pNewRate = " + pNewRate); } exchangeAPI.movePosition(pPosition, pNewRate, onResponse); function onResponse(err, pPositionId) { try { - if (FULL_LOG === true) { logger.write("[INFO] movePositionAtExchange -> onResponse -> Entering function."); } - if (FULL_LOG === true) { logger.write("[INFO] movePositionAtExchange -> onResponse -> pPositionId = " + pPositionId); } + if (FULL_LOG === true) { logger.write("[INFO] movePosition -> onResponse -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] movePosition -> onResponse -> pPositionId = " + pPositionId); } switch (err.result) { case global.DEFAULT_OK_RESPONSE.result: { // Everything went well, we have the information requested. - logger.write("[INFO] movePositionAtExchange -> onResponse -> Execution finished well. :-)"); + logger.write("[INFO] movePosition -> onResponse -> Execution finished well. :-)"); let newPosition = { id: pPositionId, @@ -545,11 +548,11 @@ /* We need to update the position we have on file. */ - for (let i = 0; i < botContext.executionContext.positions.length; i++) { + for (let i = 0; i < context.executionContext.positions.length; i++) { - if (botContext.executionContext.positions[i].id === pPosition.id) { + if (context.executionContext.positions[i].id === pPosition.id) { - botContext.executionContext.positions[i] = newPosition; + context.executionContext.positions[i] = newPosition; break; } @@ -561,35 +564,39 @@ newPosition: newPosition }; - botContext.executionContext.transactions.push(newTransaction); + context.executionContext.transactions.push(newTransaction); - botContext.newHistoryRecord.movedPositions++; - botContext.newHistoryRecord.rate = pNewRate; + context.newHistoryRecord.movedPositions++; + context.newHistoryRecord.rate = pNewRate; callBack(global.DEFAULT_OK_RESPONSE); } 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] movePositionAtExchange -> onResponse -> Retry Later. Requesting Execution Retry."); + logger.write("[ERROR] movePosition -> onResponse -> Retry Later. Requesting Execution Retry."); callBack(global.DEFAULT_RETRY_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] movePositionAtExchange -> onResponse -> Operation Failed. Aborting the process."); + logger.write("[ERROR] movePosition -> onResponse -> Operation Failed. Aborting the process."); callBack(global.DEFAULT_FAIL_RESPONSE); return; } break; } } catch (err) { - logger.write("[ERROR] movePositionAtExchange -> onResponse -> err = " + err.message); + logger.write("[ERROR] movePosition -> onResponse -> err = " + err.message); callBack(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write("[ERROR] movePositionAtExchange -> err = " + err.message); + logger.write("[ERROR] movePosition -> err = " + err.message); callBack(global.DEFAULT_FAIL_RESPONSE); } } + + function getPositions() { + return JSON.parse(JSON.stringify(context.executionContext.positions)); + } }; \ No newline at end of file diff --git a/Run.js b/Run.js index 6a05124b2..a447366de 100644 --- a/Run.js +++ b/Run.js @@ -254,6 +254,7 @@ function runTradingBot(pProcessConfig) { if (err.result === global.DEFAULT_OK_RESPONSE.result) { logger.write("[INFO] trading bot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully. :-)"); + console.log("Bot execution finished sucessfully. :-)"); } else { diff --git a/Trading Bot Main Loop.js b/Trading Bot Main Loop.js index 23c8cbe11..0a6b6200d 100644 --- a/Trading Bot Main Loop.js +++ b/Trading Bot Main Loop.js @@ -217,7 +217,6 @@ usertBot = USER_BOT_MODULE.newUserBot(bot, DEBUG_MODULE); let platform = { - context: context, datasource: datasource, assistant: assistant }; @@ -358,7 +357,7 @@ try { vmConfig = JSON.parse(fs.readFileSync('this.vm.config.json', 'utf8')); - return JSON.parse(vmConfig.stopGrafully); + return JSON.parse(vmConfig.stopGracefully); } catch (err) { const logText = "[ERROR] 'readConfig' - ERROR : " + err.message; diff --git a/this.vm.config.json b/this.vm.config.json index 4d1d36e09..aa2288eab 100644 --- a/this.vm.config.json +++ b/this.vm.config.json @@ -2,5 +2,5 @@ "bot": { "path": "../Bots/AAMasters/AAMariam-Trading-Bot" }, - "stopGrafully": "false" + "stopGracefully": "false" } \ No newline at end of file