From e78f9278fe71f1a236476e12ed0377ed71c602a7 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 6 Mar 2018 08:57:22 +0100 Subject: [PATCH] Context Implemented --- .vs/AAMariam-Trading-Bot/v15/.suo | Bin 27648 -> 19456 bytes Trading-Process/Interval.js | 440 ++++-------------------------- 2 files changed, 51 insertions(+), 389 deletions(-) diff --git a/.vs/AAMariam-Trading-Bot/v15/.suo b/.vs/AAMariam-Trading-Bot/v15/.suo index 25d2d6041e5758168dba216511581fbf32927927..cc4f48ad4f205591f736d3cdb1bc744d312d96a7 100644 GIT binary patch delta 556 zcma)&KTE?<6vcD%Vw=`PO&j}9Z6ZzEC_)tqE(+Qf2NAlcn@|Pu3slfS=-?taw0Vnj zrY;u>Biv(_ZcFie3cDzR zf~VtGL*hsh!B8QMWaz1!i&$9kxtyQ7#dAY+D4O!g`%M;O?Xg%Dc%F@LXF5z;bQCrr zOFQyhI_ArYZ@KLEMZ7IdOkp>TRZ=ftWgvNE3E>OTZq$^@Sg^i)At`)cf&?k7sSbz= z+=DOhD{K28^SmEr6szNoyybs3kZDt|)2eaAOv3_&tLE4(YbFN3s@4-YnU}wI3b+N) z(QDsRe1ZRZnzzKA7u}TDTS;qhNHd%F&RLgURSwv5WrMi3)Z57sErOQ8dBr!cv+{92 F^aW1~u~Gm4 delta 802 zcmZ{i&rcIU6vz8^R@llew58Be6{-|0v_RW{KPvG6B`BCch$fy4A$rEcn&=5kJVHYE zCB}H%vtAft^gyC9F+_aJNdO!CQl^EU7MzB99%FKF{8?Uc@G5r4%Z z5gjRkU(IGyRfVkU>r`K@Iod5U`Mfp|-4X2@Z}xuBuzaKmq7{B37I-#MW>4hD66omw z22dJ9hzQNoepGqh&!b$|Cr%AuXCX^X^&`6oU?VaDMnM4-!5A0^6QBetKw7gXEARlDa~ zYh*T5ly+}}G7N-w!grgDCKLUv2IY0W*Wx!3jG zd|#aIbLQ%6+GAS0vYW3F*AgXZkDyoGk$S}7ocz9`^U>(Cp|109(JpK`)p=gMd5PDn zcjWi#xZuXjw%ne1uEmwr@S2yCbBCH!JTTNB5@<-TIAn%=Y@DF>B_wqZzxRq#YvX5g k({lR88u91Kg;?ji^xK!O);d1fclWy 0) { + if (botContext.executionContext.positions.length > 0) { - if (executionContext.positions[0].type === "buy") { + if (botContext.executionContext.positions[0].type === "buy") { - validateBuyPosition(executionContext.positions[0]); + validateBuyPosition(botContext.executionContext.positions[0]); } else { - validateSellPosition(executionContext.positions[0]); + validateSellPosition(botContext.executionContext.positions[0]); } @@ -998,8 +809,8 @@ */ - let AmountA = statusReport.initialBalance.amountA; - let AmountB = statusReport.initialBalance.amountB; + let AmountA = botContext.statusReport.initialBalance.amountA; + let AmountB = botContext.statusReport.initialBalance.amountB; /* We are going to sell all AmountB */ @@ -1086,17 +897,17 @@ trades: [] }; - executionContext.positions.push(position); + botContext.executionContext.positions.push(position); let newTransaction = { type: "newPosition", position: position }; - executionContext.transactions.push(newTransaction); + botContext.executionContext.transactions.push(newTransaction); - newHistoryRecord.newPositions++; - newHistoryRecord.rate = pRate; + botContext.newHistoryRecord.newPositions++; + botContext.newHistoryRecord.rate = pRate; callBack(); } @@ -1140,11 +951,11 @@ /* We need to update the position we have on file. */ - for (let i = 0; i < executionContext.positions.length; i++) { + for (let i = 0; i < botContext.executionContext.positions.length; i++) { - if (executionContext.positions[i].id === pPosition.id) { + if (botContext.executionContext.positions[i].id === pPosition.id) { - executionContext.positions[i] = newPosition; + botContext.executionContext.positions[i] = newPosition; break; } @@ -1156,10 +967,10 @@ newPosition: newPosition }; - executionContext.transactions.push(newTransaction); + botContext.executionContext.transactions.push(newTransaction); - newHistoryRecord.movedPositions++; - newHistoryRecord.rate = pNewRate; + botContext.newHistoryRecord.movedPositions++; + botContext.newHistoryRecord.rate = pNewRate; callBack(); } @@ -1178,155 +989,6 @@ } } } - - function writeStatusAndContext() { - - writeExecutionContext(); - - function writeExecutionContext() { - - if (LOG_INFO === true) { - logger.write("[INFO] Entering function 'writeExecutionContext'"); - } - - try { - - 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; - - utilities.createFolderIfNeeded(filePath, mariamAzureFileStorage, onFolderCreated); - - function onFolderCreated() { - - try { - - let fileContent = JSON.stringify(executionContext); - - mariamAzureFileStorage.createTextFile(filePath, fileName, fileContent + '\n', onFileCreated); - - function onFileCreated() { - - if (LOG_INFO === true) { - logger.write("[INFO] 'writeExecutionContext' - Content written: " + fileContent); - } - - writeExucutionHistory(); - } - } - catch (err) { - const logText = "[ERROR] 'writeExecutionContext - onFolderCreated' - ERROR : " + err.message; - logger.write(logText); - } - } - - } - catch (err) { - const logText = "[ERROR] 'writeExecutionContext' - ERROR : " + err.message; - logger.write(logText); - } - } - - function writeExucutionHistory() { - - if (LOG_INFO === true) { - logger.write("[INFO] Entering function 'writeExucutionHistory'"); - } - - try { - - let fileName = "Execution.History.json" - let filePath = EXCHANGE_NAME + "/" + bot.name + "/" + bot.dataSetVersion + "/Output/" + bot.process; - - utilities.createFolderIfNeeded(filePath, mariamAzureFileStorage, onFolderCreated); - - function onFolderCreated() { - - try { - - let newRecord = [ - newHistoryRecord.date.valueOf(), - newHistoryRecord.rate, - newHistoryRecord.newPositions, - newHistoryRecord.newTrades, - newHistoryRecord.movedPositions - ]; - - executionHistory.push(newRecord); - - let fileContent = JSON.stringify(executionHistory); - - mariamAzureFileStorage.createTextFile(filePath, fileName, fileContent + '\n', onFileCreated); - - function onFileCreated() { - - if (LOG_INFO === true) { - logger.write("[INFO] 'writeExucutionHistory'"); - } - - writeStatusReport(); - } - } - catch (err) { - const logText = "[ERROR] 'writeExucutionHistory - onFolderCreated' - ERROR : " + err.message; - logger.write(logText); - } - } - - } - catch (err) { - const logText = "[ERROR] 'writeExucutionHistory' - ERROR : " + err.message; - logger.write(logText); - } - } - - function writeStatusReport() { - - if (LOG_INFO === true) { - logger.write("[INFO] Entering function 'writeStatusReport'"); - } - - try { - - let fileName = "Status.Report.json" - let filePath = EXCHANGE_NAME + "/" + bot.name + "/" + bot.dataSetVersion + "/Processes/" + bot.process; - - utilities.createFolderIfNeeded(filePath, mariamAzureFileStorage, onFolderCreated); - - function onFolderCreated() { - - try { - - statusReport.lastExecution = processDatetime; - - let fileContent = JSON.stringify(statusReport); - - mariamAzureFileStorage.createTextFile(filePath, fileName, fileContent + '\n', onFileCreated); - - function onFileCreated() { - - if (LOG_INFO === true) { - logger.write("[INFO] 'writeStatusReport' - Content written: " + fileContent); - } - - callBackFunction(true); // We tell the AA Platform that we request a regular execution and finish the bot s process. - return; - } - } - catch (err) { - const logText = "[ERROR] 'writeStatusReport - onFolderCreated' - ERROR : " + err.message; - logger.write(logText); - } - } - - } - catch (err) { - const logText = "[ERROR] 'writeStatusReport' - ERROR : " + err.message; - logger.write(logText); - } - } - - } } catch (err) {