From d425c2b7dce7a5c1d47ae7031f41284f71580b9b Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 16 Mar 2018 19:20:03 +0100 Subject: [PATCH] First part of start ready --- .vs/AACharly-Extraction-Bot/v15/.suo | Bin 25088 -> 24576 bytes Poloniex-Hole-Fixing/User.bot.js | 200 ++++----------------------- 2 files changed, 28 insertions(+), 172 deletions(-) diff --git a/.vs/AACharly-Extraction-Bot/v15/.suo b/.vs/AACharly-Extraction-Bot/v15/.suo index 5f7897589812b19622a39e04c08aeaab9c17ae84..42f18ca2d40a45b1a25b3ab04bb5626d3b2d8c52 100644 GIT binary patch delta 625 zcmZoT!q{+tae{#?0}Kc-FbD$Kj6nSF|Ns9WVaCaU9M&5XDi|j*<*)|m-VF`jT*ws6 z$ioAaQwCz7vj3AW>ZnZq!W^O^1{DAaN&wm7Kr9Nxl0YmC#2`Z#=ddub3WQGf0~*8@ z#5mbmz;N;xb_H2>pgboKa{w_L5OV=B$P$nq?#+fA;;bAf_LcBn;Q-kK0$>M}@Libf zVqh@2guiE!gbR-lP%lIlCT|eH12R+*Dgkk|#Ccvuptr$R!i-|o017Zo{>ksf%Lo!< zM$)mlMBoA=4>wQ*vRGbCwuVgz#YWSwaH0@n>Pk%0t}>1 pRt&wr$&Z~;a0*NaNS6R{#AXTqKdh*VH!FrdV-{SAsWS2f8vuQ5)f@l- delta 632 zcmZuu%SyvQ6wOSMHr9ls+DB?Bv|7+bp>b0|S3)R)N>d+*AjJ<5M98Ac?#-fPcH*jn zdpkeSMZu*H{04C&h;(7081JM_sN%pOcTUbd_smSIhgyBqHgcGoEREv?C=uY>^E}4# zq%LjToi>q+&qU+ue6vn3@II0w@Gk}cnMa=VA{p=p#q@+=Bs0)qp8{k6SwIqSb0%Q1 zo&CB5qsSgo5DfKQSku@kn$OJwDFN7+8GsC6j#2o==&F%@N+Z%=Gl;D^ zUBkrk5(t<+5K%kv$jb#_=B8NpM4(N52gy8;Y*Zi@k6`mmhUzxyV{p}Kihtt#l!gqn z2gUDTLBq}!*kC%$)RbQ-slDt7u5SLHp<*G4T~_Gg&!@w36uX*9OqFG@WECXrW&#;R zu>7M=XD4>q>6T11POds`!t~Gg=Q^$t)fPTbCxyG~iTP9!Y=dP&Ap*>M(y$iEd-axn p?j}*Z5(qf0S7jQi*G8fevQWshaQMo{S Entering function."); } let processDate = new Date(year + "-" + month + "-1 00:00:00.000 GMT+0000"); - let lastMinuteOfMonth = new Date(year + "-" + month + "-1 00:00:00.000 GMT+0000"); - lastMinuteOfMonth.setUTCMonth(lastMinuteOfMonth.getUTCMonth() + 1); // First we go 1 month into the future. - lastMinuteOfMonth.setUTCSeconds(lastMinuteOfMonth.getUTCSeconds() - 30); // Then we go back 30 seconds, or to the last minute of the original month. + lastMinuteOfMonth.setUTCMonth(lastMinuteOfMonth.getUTCMonth() + 1); // First we go 1 month into the future. + lastMinuteOfMonth.setUTCSeconds(lastMinuteOfMonth.getUTCSeconds() - 30); // Then we go back 30 seconds, or to the last minute of the original month. let thisDatetime = new Date(); if ((year === thisDatetime.getUTCFullYear() && month > thisDatetime.getUTCMonth() + 1) || year > thisDatetime.getUTCFullYear()) { - logger.write("[INFO] We are too far in the future. Interval will not execute. Sorry."); + logger.write("[ERROR] start -> writeStatusReport -> We are too far in the future. Bot will not execute. Sorry."); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; - } let nextIntervalExecution = false; // This tell weather the Interval module will be executed again or not. By default it will not unless some hole have been found in the current execution. - let currentDate; // This will hold the current datetime of each execution. - let cursorDatetime; // This holds the datetime we are using to request records from, backwards. + let currentDate; // This will hold the current datetime of each execution. + let cursorDatetime; // This holds the datetime we are using to request records from, backwards. - let marketQueue; // This is the queue of all markets to be procesesd at each interval. - let market = { // This is the current market being processed after removing it from the queue. - id: 0, - assetA: "", - assetB: "" - }; + let marketQueue; // This is the queue of all markets to be procesesd at each interval. + let market = global.MARKET; let dateForPath; - let filePath; - let exchangeCallTime; const MAX_EXCHANGE_CALL_RETRIES = 3; - let exchangeCallRetries = 0; - const MAX_HOLE_FIXING_RETRIES = 3; - const FIRST_TRADE_RECORD_ID = -1; const UNKNOWN_TRADE_RECORD_ID = -2; - let tradesWithHole = []; // File content of the file where a hole was discovered. + let exchangeCallRetries = 0; - let currentTradeId; // This points to the last Trade Id that is ok. - let currentDatetime; // This points to the last Trade datetime that is ok. + let tradesWithHole = []; // File content of the file where a hole was discovered. + + let currentTradeId; // This points to the last Trade Id that is ok. + let currentDatetime; // This points to the last Trade datetime that is ok. /* The next 3 variables hold the information read from varios Status Reports. */ - let lastLiveTradeFile; // Datetime of the last complete trades file written by the Live Trades process. - let lastHistoricTradeFile; // Datatime of the last trades file written by the Historic Trades process. - let lastHoleFixingFile; // Datetime of the last file certified by the Hole Fixing process as without permanent holes. + let lastLiveTradeFile; // Datetime of the last complete trades file written by the Live Trades process. + let lastHistoricTradeFile; // Datatime of the last trades file written by the Historic Trades process. + let lastHoleFixingFile; // Datetime of the last file certified by the Hole Fixing process as without permanent holes. /* The next 4 variables hold the results of the search of the next hole. */ - let holeInitialId; // This is the Id just before the hole. - let holeInitialDatetime; // This is the Datetime just before the hole. + let holeInitialId; // This is the Id just before the hole. + let holeInitialDatetime; // This is the Datetime just before the hole. - let holeFinalId; // This is the Id just after the hole. - let holeFinalDatetime; // This is the Datetime just after the hole. + let holeFinalId; // This is the Id just after the hole. + let holeFinalDatetime; // This is the Datetime just after the hole. - let holeFixingStatusReport; // Current hole Fixing Status Report. + let holeFixingStatusReport; // Current hole Fixing Status Report. marketsLoop(); @@ -191,134 +180,6 @@ What is the lastFile pointer? */ - function marketsLoop() { - - try { - - if (LOG_INFO === true) { - logger.write("[INFO] Entering function 'marketsLoop'"); - } - - currentDate = new Date(); - markets.getMarketsByExchange(EXCHANGE_ID, onMarketsReady); - - function onMarketsReady(marketsArray) { - - marketQueue = JSON.parse(marketsArray); - - openMarket(); // First execution and entering into the real loop. - - } - } - catch (err) { - const logText = "[ERROR] 'marketsLoop' - ERROR : " + err.message; - logger.write(logText); - } - } - - function openMarket() { - - // To open a Market means picking a new market from the queue. - - try { - - if (LOG_INFO === true) { - logger.write("[INFO] Entering function 'openMarket'"); - } - - - if (marketQueue.length === 0) { - - if (LOG_INFO === true) { - logger.write("[INFO] 'openMarket' - marketQueue.length === 0"); - } - - const logText = "[WARN] We processed all the markets."; - logger.write(logText); - - callBackFunction(nextIntervalExecution); - - return; - } - - if (GO_RANDOM === true) { - const index = parseInt(Math.random() * (marketQueue.length - 1)); - - market.id = marketQueue[index][0]; - market.assetA = marketQueue[index][1]; - market.assetB = marketQueue[index][2]; - market.status = marketQueue[index][3]; - - marketQueue.splice(index, 1); - } else { - let marketRecord = marketQueue.shift(); - - market.id = marketRecord[0]; - market.assetA = marketRecord[1]; - market.assetB = marketRecord[2]; - market.status = marketRecord[3]; - - if (FORCE_MARKET > 0) { - if (FORCE_MARKET !== market.id) { - closeAndOpenMarket(); - return; - } - } - } - - if (LOG_INFO === true) { - logger.write("[INFO] 'openMarket' - marketQueue.length = " + marketQueue.length); - logger.write("[INFO] 'openMarket' - market sucessfully opened : " + market.assetA + "_" + market.assetB); - } - - if (market.status === markets.ENABLED) { - - exchangeCallRetries = 0; // For each market we will count the retries, so we need to reset this here. - - getStatusReport(); - - } else { - - logger.write("[INFO] 'openMarket' - market " + market.assetA + "_" + market.assetB + " skipped because its status is not valid. Status = " + market.status); - closeAndOpenMarket(); - return; - - } - - - } - catch (err) { - const logText = "[ERROR] 'openMarket' - ERROR : " + err.message; - logger.write(logText); - closeMarket(); - } - } - - function closeMarket() { - - if (LOG_INFO === true) { - logger.write("[INFO] Entering function 'closeMarket'"); - } - - } - - function closeAndOpenMarket() { - - if (LOG_INFO === true) { - logger.write("[INFO] Entering function 'closeAndOpenMarket'"); - } - - openMarket(); - } - - - /* - - The following code executes for each market, trying to fix the hole in trades history. - - */ - - function getStatusReport() { /* @@ -1552,7 +1413,6 @@ What is the lastFile pointer? } } - function verifyMarketComplete(isMonthComplete, callBack) { if (isMonthComplete === true) { @@ -1733,13 +1593,9 @@ What is the lastFile pointer? } - - - - } - catch (err) { - const logText = "[ERROR] 'Start' - ERROR : " + err.message; - logger.write(logText); + } catch (err) { + logger.write("[ERROR] start -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } };