Bug fixed, bittrex working

This commit is contained in:
Luis Fernando Molina committed 2020-03-09 16:20:37 +01:00
1 parent 778cebdb0a
commit 36894f1662
4 files changed
+73 -57

No files matched your search

@@ -428,7 +428,9 @@ function newUiObjectsFromNodes () {
/* Check if there are tasks to run */
if (userAddingNew === false && uiObjectType === 'Task' && node.savedPayload !== undefined) {
if (node.savedPayload.uiObject.isRunning === true) {
tasksToRun.push(node)
if (node.payload.parentNode !== undefined) {
tasksToRun.push(node)
}
}
}
@@ -436,7 +438,9 @@ function newUiObjectsFromNodes () {
if (userAddingNew === false && node.savedPayload !== undefined) {
if (uiObjectType === 'Live Trading Session' || uiObjectType === 'Fordward Testing Session' || uiObjectType === 'Backtesting Session' || uiObjectType === 'Paper Trading Session') {
if (node.savedPayload.uiObject.isRunning === true) {
sessionsToRun.push(node)
if (node.payload.parentNode !== undefined) {
sessionsToRun.push(node)
}
}
}
}
+15
View File
@@ -96,6 +96,7 @@ function newUiObject () {
let eventSubscriptionIdHeartbeat
let eventSubscriptionIdOnStopped
let lastHeartBeat
return thisObject
@@ -143,6 +144,7 @@ function newUiObject () {
icon = undefined
chainAttachToNode = undefined
referenceAttachToNode = undefined
lastHeartBeat = undefined
}
function initialize (payload, menuItemsInitialValues) {
@@ -280,6 +282,17 @@ function newUiObject () {
childrenRunningPhysics()
}
function heartBeatPhysics () {
if (lastHeartBeat !== undefined) {
const ONE_MIN = 60000
nowTimestamp = (new Date()).valueOf()
if (nowTimestamp - lastHeartBeat.valueOf() > ONE_MIN) {
lastHeartBeat = undefined
thisObject.isRunning = false
}
}
}
function childrenRunningPhysics () {
let nodeDefinition = APP_SCHEMA_MAP.get(thisObject.payload.node.type)
if (nodeDefinition.properties === undefined) { return }
@@ -634,6 +647,7 @@ function newUiObject () {
function onHeartBeat () {
if (thisObject.payload === undefined) { return }
lastHeartBeat = new Date()
let key = thisObject.payload.node.name + '-' + thisObject.payload.node.type + '-' + thisObject.payload.node.id
systemEventHandler.stopListening(key, eventSubscriptionIdHeartbeat, 'UiObject')
@@ -681,6 +695,7 @@ function newUiObject () {
thisObject.circularProgressBar = undefined
}
thisObject.isRunning = false
lastHeartBeat = undefined
}
}
@@ -38,6 +38,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt
let uiStartDate = new Date(bot.uiStartDate)
let fisrtTimeThisProcessRun = false
let limit = 1000 // This is the default value
let hostname
return thisObject;
@@ -54,7 +55,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt
/* Applying the parameters defined by the user at the Exchange node */
if (bot.exchangeNode.code.API !== undefined) {
for (let i = 0; i < bot.exchangeNode.code.API.length; i++) {
if (bot.exchangeNode.code.API[i].method === 'fetchOHLCVs') {
if (bot.exchangeNode.code.API[i].method === 'fetch_ohlcv') {
if (bot.exchangeNode.code.API[i].class !== undefined) {
exchangeId = bot.exchangeNode.code.API[i].class
}
@@ -69,6 +70,9 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt
if (bot.exchangeNode.code.API[i].rateLimit !== undefined) {
rateLimit = bot.exchangeNode.code.API[i].rateLimit
}
if (bot.exchangeNode.code.API[i].hostname !== undefined) {
hostname = bot.exchangeNode.code.API[i].hostname
}
}
}
}
@@ -96,6 +100,9 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt
if (rateLimit !== undefined) {
exchangeConstructorParams.rateLimit = rateLimit
}
if (hostname !== undefined) {
exchangeConstructorParams.hostname = hostname
}
exchange = new exchangeClass(exchangeConstructorParams)
@@ -313,6 +320,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt
let error
let separator
let heartBeatCounter = 0
let headOfTheMarketReached = false
let i = 0
@@ -324,7 +332,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt
let filesCreated = 0
/* Go through all possible 1 min candles of a day. */
for (let j = 0; j < 60 * 24; j++) {
for (let j = 0; j < 60 * 24; j++) {
let candle = {
begin: currentDay * ONE_DAY + ONE_MIN * j,
@@ -341,6 +349,22 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt
sell: lastVolume.sell
}
let processingDate = new Date(candle.begin)
processingDate = processingDate.getUTCFullYear() + '-' + utilities.pad(processingDate.getUTCMonth() + 1, 2) + '-' + utilities.pad(processingDate.getUTCDate(), 2);
if (candle.begin > (new Date()).valueOf()) {
/* We stop when the current candle is pointing to a time in the future.*/
headOfTheMarketReached = true
saveFile(currentDay)
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> saveOHLCVs -> Saving OHLCVs @ " + processingDate + " -> i = " + i + " -> total = " + allOHLCVs.length) }
bot.processHeartBeat("Saving " + i.toFixed(0) + " / " + allOHLCVs.length + " OHLCVs from " + bot.exchange + " " + symbol + " @ " + processingDate) // tell the world we are alive and doing well
/* We exit the loop and we aint comming back*/
return
}
let record = allOHLCVs[i]
let OHLCV = {
timestamp: record[0],
@@ -365,6 +389,11 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt
OHLCVMinute = Math.trunc(OHLCV.timestamp / ONE_MIN)
if (OHLCVMinute < candleMinute) {
if (i >= allOHLCVs.length - 1) {
/* We run out of OHLCVs, we can not move to the next OHLCV, we leave this function. */
return
}
i++
record = allOHLCVs[i]
OHLCV = {
@@ -380,9 +409,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt
}
/* Reporting we are doing well */
let processingDate = new Date(candle.begin)
processingDate = processingDate.getUTCFullYear() + '-' + utilities.pad(processingDate.getUTCMonth() + 1, 2) + '-' + utilities.pad(processingDate.getUTCDate(), 2);
heartBeatCounter--
heartBeatCounter--
if (heartBeatCounter <= 0) {
heartBeatCounter = 1440
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> saveOHLCVs -> Saving OHLCVs @ " + processingDate + " -> i = " + i + " -> total = " + allOHLCVs.length) }
@@ -397,7 +424,10 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt
candle.max = OHLCV.hight
volume.buy = OHLCV.volume / 2
volume.sell = OHLCV.volume / 2
i++
if (i < allOHLCVs.length - 1) {
i++
}
}
lastCandle = candle
@@ -413,40 +443,21 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt
candlesFileContent = candlesFileContent + separator + '[' + candle.min + "," + candle.max + "," + candle.open + "," + candle.close + "," + candle.begin + "," + candle.end + "]";
volumesFileContent = volumesFileContent + separator + '[' + volume.buy + "," + volume.sell + "," + volume.begin + "," + volume.end + "]";
if (i === allOHLCVs.length) {
/* This was the last OHLCV, so we save the file.*/
saveFile(currentDay)
/* It might happen that there are several days after the last OHLCV without OHLCVs. We need to record empty files for them.*/
if (allOHLCVs.length < MAX_OHLCVs_PER_EXECUTION) {
let currentTimeDay = Math.trunc((new Date()).valueOf() / ONE_DAY)
if (currentTimeDay - currentDay > 1) {
createMissingEmptyFiles(currentDay, currentTimeDay)
}
}
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> saveOHLCVs -> Saving OHLCVs @ " + processingDate + " -> i = " + i + " -> total = " + allOHLCVs.length) }
bot.processHeartBeat("Saving " + i.toFixed(0) + " / " + allOHLCVs.length + " OHLCVs from " + bot.exchange + " " + symbol + " @ " + processingDate) // tell the world we are alive and doing well
return
}
}
previousDay = currentDay
if (i > 0) { // Only start saving at the day of the first candle.
saveFile(currentDay)
}
previousDay = currentDay
if (error) {
callBackFunction(error);
return;
}
return
}
controlLoop()
function saveFile(day) {
candlesFileContent = candlesFileContent + ']'
volumesFileContent = volumesFileContent + ']'
if (currentDay - previousDay > 1) {
createMissingEmptyFiles(previousDay, currentDay)
}
let fileName = bot.market.baseAsset + '_' + bot.market.quotedAsset + '.json'
filesToCreate++
@@ -460,26 +471,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt
needSeparator = false
}
function createMissingEmptyFiles(begin, end) {
/*
If this range is too wide, we will consider this means that the begin is before the begining of this market at this exchange.
In that case we will change the begin and the beginingOfMarket
*/
if ((end - begin) > 7) {
begin = end
beginingOfMarket = new Date(end * ONE_DAY)
}
for (let j = begin + 1; j < end; j++) {
let fileName = bot.market.baseAsset + '_' + bot.market.quotedAsset + '.json'
filesToCreate++
fileStorage.createTextFile(getFilePath(j * ONE_DAY, CANDLES_FOLDER_NAME) + '/' + fileName, "[]" + '\n', onFileCreated);
filesToCreate++
fileStorage.createTextFile(getFilePath(j * ONE_DAY, VOLUMES_FOLDER_NAME) + '/' + fileName, "[]" + '\n', onFileCreated);
}
}
function onFileCreated(err) {
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
logger.write(MODULE_NAME, "[ERROR] start -> OHLCVsReadyToBeSaved -> onFileBCreated -> err = " + JSON.stringify(err));
@@ -492,6 +484,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt
controlLoop()
}
}
function getFilePath(timestamp, folderName) {
let datetime = new Date(timestamp)
let dateForPath = datetime.getUTCFullYear() + '/' +
@@ -500,8 +493,6 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt
let filePath = bot.filePathRoot + "/Output/" + folderName + '/' + dateForPath;
return filePath
}
}
function controlLoop() {
@@ -510,8 +501,14 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt
return
}
if (error) {
callBackFunction(error);
return;
}
currentDay++
if (i < allOHLCVs.length) {
if (headOfTheMarketReached === false) {
setImmediate(loop)
} else {
writeStatusReport()
+1 -1
View File
@@ -1 +1 @@
{"type":"Workspace","name":"My Workspace","rootNodes":[{"type":"Network","name":"Superalgos","networkNodes":[{"type":"Network Node","name":"My Computer","dataStorage":{"type":"Data Storage","name":"New Data Storage","sessionIndependentData":{"type":"Session Independent Data","name":"New Session Independent Data","exchangeDataProducts":[{"type":"Exchange Data Products","name":"Binance","singleMarketData":[{"type":"Single Market Data","name":"Binance BTC/USDT","dataProducts":[{"type":"Data Product","name":"Candles","id":"592901f9-9d7e-4d02-9c3e-9941fd1cbc62","savedPayload":{"position":{"x":25504.760548571518,"y":30474.545725692617},"targetPosition":{"x":25159.58206404965,"y":30546.012914365223},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"angleToParent":2,"distanceToParent":3},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Candles","id":"fe6065ec-4d2d-47a0-bae0-8647f0e195d7"}}},{"type":"Data Product","name":"Volumes","id":"54e5d587-dae5-4901-8625-899f3b6eb361","savedPayload":{"position":{"x":25512.0152903826,"y":30539.188970481562},"targetPosition":{"x":25159.58206404965,"y":30546.012914365223},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"angleToParent":2,"distanceToParent":3},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Volumes","id":"1a366aef-efef-470e-88e0-2a6fbe4dd91f"}}},{"type":"Data Product","name":"Candle-Stairs","id":"7f5856c1-cf3a-4525-8036-69da93e57771","savedPayload":{"position":{"x":25507.268341367977,"y":30604.064596495053},"targetPosition":{"x":25159.58206404965,"y":30546.012914365223},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"angleToParent":2,"distanceToParent":3},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Candle-Stairs","id":"642474e9-da61-4168-97dc-7f7869bebc02"}}},{"type":"Data Product","name":"Volume-Stairs","id":"fad346d0-20f9-4cf4-9663-7eb54622b5f0","savedPayload":{"position":{"x":25490.681353183005,"y":30666.963342098927},"targetPosition":{"x":25159.58206404965,"y":30546.012914365223},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"angleToParent":2,"distanceToParent":3},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Volume-Stairs","id":"846e9572-c4d6-4c7e-942e-c82402c5ecea"}}},{"type":"Data Product","name":"Bollinger Bands","id":"2fc1f392-7d9b-409e-9cb7-85c14e1e7c07","savedPayload":{"position":{"x":25462.819175816425,"y":30725.74326595038},"targetPosition":{"x":25159.58206404965,"y":30546.012914365223},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"angleToParent":2,"distanceToParent":3},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Bollinger Bands","id":"29088877-8d63-4217-8d34-8742afc262f4"}}},{"type":"Data Product","name":"Percentage Bandwidth","id":"e7c4252c-3b6b-4b21-9f7a-6a6263739835","savedPayload":{"position":{"x":25424.630622301454,"y":30778.402688241396},"targetPosition":{"x":25159.58206404965,"y":30546.012914365223},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"angleToParent":2,"distanceToParent":3},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Percentage Bandwidth","id":"3b7885a0-cd72-4a3f-a38b-3dc8c47bd068"}}},{"type":"Data Product","name":"Bollinger Channels Objects","id":"3e9c58db-ca68-4089-9a02-d99f01428a41","savedPayload":{"position":{"x":25377.416158025928,"y":30823.148355503872},"targetPosition":{"x":25159.58206404965,"y":30546.012914365223},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"angleToParent":2,"distanceToParent":3},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Bollinger Channels Objects","id":"1f111f72-624f-4166-9f99-ab8d785d5267"}}},{"type":"Data Product","name":"Bollinger Sub-Channels Objects","id":"b47bf5eb-2f3e-462f-aa45-8e5c6ae784bc","savedPayload":{"position":{"x":25322.783614943237,"y":30858.456507705698},"targetPosition":{"x":25159.58206404965,"y":30546.012914365223},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"angleToParent":2,"distanceToParent":3},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Bollinger Sub-Channels Objects","id":"080c87fc-4546-4482-ab11-180a33f6d9ab"}}},{"type":"Data Product","name":"Popular SMAs","id":"67a989ee-e8da-4079-9b0a-8a7509db45a5","savedPayload":{"position":{"x":25262.59343878355,"y":30883.1247680711},"targetPosition":{"x":25159.58206404965,"y":30546.012914365223},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":3},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Popular SMAs","id":"4029d5bf-a8ad-4d80-b874-2af506e0ab34"}}},{"type":"Data Product","name":"Base7 SMAs","id":"763cde69-4a76-498f-a753-87baa3b227f3","savedPayload":{"position":{"x":25198.895333805827,"y":30896.31308857965},"targetPosition":{"x":25159.58206404965,"y":30546.012914365223},"floatingLine truncated
{"type":"Workspace","name":"My Workspace","rootNodes":[{"type":"Network","name":"Superalgos","networkNodes":[{"type":"Network Node","name":"My Computer","dataStorage":{"type":"Data Storage","name":"New Data Storage","sessionIndependentData":{"type":"Session Independent Data","name":"New Session Independent Data","exchangeDataProducts":[{"type":"Exchange Data Products","name":"Binance","singleMarketData":[{"type":"Single Market Data","name":"Binance BTC/USDT","dataProducts":[{"type":"Data Product","name":"Candles","id":"592901f9-9d7e-4d02-9c3e-9941fd1cbc62","savedPayload":{"position":{"x":25668.591222219326,"y":29993.21611788368},"targetPosition":{"x":25557.124436708455,"y":30327.627717281495},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"angleToParent":2,"distanceToParent":3},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Candles","id":"fe6065ec-4d2d-47a0-bae0-8647f0e195d7"}}},{"type":"Data Product","name":"Volumes","id":"54e5d587-dae5-4901-8625-899f3b6eb361","savedPayload":{"position":{"x":25728.141198236768,"y":30019.392075018255},"targetPosition":{"x":25557.124436708455,"y":30327.627717281495},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"angleToParent":2,"distanceToParent":3},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Volumes","id":"1a366aef-efef-470e-88e0-2a6fbe4dd91f"}}},{"type":"Data Product","name":"Candle-Stairs","id":"7f5856c1-cf3a-4525-8036-69da93e57771","savedPayload":{"position":{"x":25781.86740324687,"y":30056.06461611922},"targetPosition":{"x":25557.124436708455,"y":30327.627717281495},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"angleToParent":2,"distanceToParent":3},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Candle-Stairs","id":"642474e9-da61-4168-97dc-7f7869bebc02"}}},{"type":"Data Product","name":"Volume-Stairs","id":"fad346d0-20f9-4cf4-9663-7eb54622b5f0","savedPayload":{"position":{"x":25827.940255775495,"y":30101.98490178324},"targetPosition":{"x":25557.124436708455,"y":30327.627717281495},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"angleToParent":2,"distanceToParent":3},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Volume-Stairs","id":"846e9572-c4d6-4c7e-942e-c82402c5ecea"}}},{"type":"Data Product","name":"Bollinger Bands","id":"2fc1f392-7d9b-409e-9cb7-85c14e1e7c07","savedPayload":{"position":{"x":25864.79080008807,"y":30155.589171757336},"targetPosition":{"x":25557.124436708455,"y":30327.627717281495},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"angleToParent":2,"distanceToParent":3},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Bollinger Bands","id":"29088877-8d63-4217-8d34-8742afc262f4"}}},{"type":"Data Product","name":"Percentage Bandwidth","id":"e7c4252c-3b6b-4b21-9f7a-6a6263739835","savedPayload":{"position":{"x":25891.164135095394,"y":30215.05199691878},"targetPosition":{"x":25557.124436708455,"y":30327.627717281495},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"angleToParent":2,"distanceToParent":3},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Percentage Bandwidth","id":"3b7885a0-cd72-4a3f-a38b-3dc8c47bd068"}}},{"type":"Data Product","name":"Bollinger Channels Objects","id":"3e9c58db-ca68-4089-9a02-d99f01428a41","savedPayload":{"position":{"x":25906.16214850512,"y":30278.3484420745},"targetPosition":{"x":25557.124436708455,"y":30327.627717281495},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"angleToParent":2,"distanceToParent":3},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Bollinger Channels Objects","id":"1f111f72-624f-4166-9f99-ab8d785d5267"}}},{"type":"Data Product","name":"Bollinger Sub-Channels Objects","id":"b47bf5eb-2f3e-462f-aa45-8e5c6ae784bc","savedPayload":{"position":{"x":25909.27410095871,"y":30343.323022700435},"targetPosition":{"x":25557.124436708455,"y":30327.627717281495},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"angleToParent":2,"distanceToParent":3},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Bollinger Sub-Channels Objects","id":"080c87fc-4546-4482-ab11-180a33f6d9ab"}}},{"type":"Data Product","name":"Popular SMAs","id":"67a989ee-e8da-4079-9b0a-8a7509db45a5","savedPayload":{"position":{"x":25900.394018647734,"y":30407.763107381787},"targetPosition":{"x":25557.124436708455,"y":30327.627717281495},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":3},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Popular SMAs","id":"4029d5bf-a8ad-4d80-b874-2af506e0ab34"}}},{"type":"Data Product","name":"Base7 SMAs","id":"763cde69-4a76-498f-a753-87baa3b227f3","savedPayload":{"position":{"x":25879.824302124813,"y":30469.474266322093},"targetPosition":{"x":25557.124436708455,"y":30327.627717281495},"fLine truncated