diff --git a/.env b/.env deleted file mode 100644 index 5f94ea3bd..000000000 --- a/.env +++ /dev/null @@ -1,33 +0,0 @@ - -#PORT NUMBERS: If any of these ports are already in use by a different app, please pick a new number between 1 and 50000. -HTTP_INTERFACE_PORT=34248 -WEB_SOCKETS_INTERFACE_PORT=18041 - - -# TASK MANAGER VARIABLES: - -TASK_SERVER_PATH=./TaskServer - -# TASK SERVER VARIABLES: - -STORAGE_PATH=./Data-Storage - -WRITE_LOGS_TO_FILES=true -LOG_PATH=./Log-Files -WEB_SERVER_URL=localhost - -# WEB SERVER VARIABLES: - -#Log options -CONSOLE_LOG=false -CONSOLE_ERROR_LOG=true -LOG_FILE_CONTENT=false - -PROJECTS_PATH=./Projects -PATH_TO_UI=./UI -PATH_TO_DATA_FILES=./UI/Data-Files/src -PATH_TO_CLIENT=./Client/ - -DEFAULT_WORKSPACE_PATH=./Projects/Superalgos/Plugins/Workspaces -MY_WORKSPACES_PATH=./My-Workspaces -PATH_TO_FONTS=./Client/WebServer/Fonts \ No newline at end of file diff --git a/Client/.env b/Client/.env deleted file mode 100644 index ccfd1e3ba..000000000 --- a/Client/.env +++ /dev/null @@ -1,11 +0,0 @@ - -INTER_PROCESS_FILES_PATH=../Inter-Process-Files -STORAGE_PATH=../Data-Storage - -USE_KEYVAULT=false -WRITE_LOGS_TO_FILES=true -LOG_PATH=../Log-Files - -WEB_SOCKETS_INTERFACE_PORT=18041 -WEB_SERVER_PORT=34248 -WEB_SERVER_URL=localhost diff --git a/Client/client.js b/Client/client.js index 211837145..33fac1b5a 100644 --- a/Client/client.js +++ b/Client/client.js @@ -1,4 +1,9 @@ +/* Load Environment Variables */ +let ENVIRONMENT = require('../Environment.js'); +let ENVIRONMENT_MODULE = ENVIRONMENT.newEnvironment() +global.env = ENVIRONMENT_MODULE + process.on('uncaughtException', function (err) { if (err.message.indexOf("EADDRINUSE") > 0) { console.log("A Superalgos Client cannot be started. Reason: the port " + port + " is already in use by another application.") @@ -113,12 +118,12 @@ try { WEB_SOCKETS_INTERFACE = WEB_SOCKETS_INTERFACE.newWebSocketsInterface(EVENT_SERVER) WEB_SOCKETS_INTERFACE.initialize() WEB_SOCKETS_INTERFACE.run() - console.log('Web Sockets Interface .............. Listening at port ' + process.env.WEB_SOCKETS_INTERFACE_PORT) + console.log('Web Sockets Interface .............. Listening at port ' + global.env.WEB_SOCKETS_INTERFACE_PORT) HTTP_INTERFACE = HTTP_INTERFACE.newHttpInterface(WEB_SERVER, DATA_FILE_SERVER, PROJECT_FILE_SERVER, UI_FILE_SERVER, PLUGIN_SERVER, CCXT_SERVER, WEB3_SERVER) HTTP_INTERFACE.initialize() HTTP_INTERFACE.run() - console.log('Http Interface ..................... Listening at port ' + process.env.HTTP_INTERFACE_PORT) + console.log('Http Interface ..................... Listening at port ' + global.env.HTTP_INTERFACE_PORT) console.log('') console.log("You are running Superalgos Beta 7 SP 1") diff --git a/Client/httpInterface.js b/Client/httpInterface.js index 8080c094f..7f3925ad5 100644 --- a/Client/httpInterface.js +++ b/Client/httpInterface.js @@ -9,11 +9,7 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE require('dotenv').config() const open = require('open') - CONSOLE_LOG = process.env.CONSOLE_LOG === 'true' - CONSOLE_ERROR_LOG = process.env.CONSOLE_ERROR_LOG === 'true' - LOG_FILE_CONTENT = process.env.LOG_FILE_CONTENT === 'true' - - let port = process.env.HTTP_INTERFACE_PORT + let port = global.env.HTTP_INTERFACE_PORT let http = require('http') let isHttpServerStarted = false @@ -35,7 +31,6 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE } function startHtttpServer() { - if (CONSOLE_LOG === true) { console.log('[INFO] httpInterface -> startHtttpServer -> Entering function.') } try { if (isHttpServerStarted === false) { @@ -55,7 +50,6 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE } function onBrowserRequest(httpRequest, httpResponse) { - if (CONSOLE_LOG === true && httpRequest.url.indexOf('NO-LOG') === -1) { console.log('[INFO] httpInterface -> onBrowserRequest -> httpRequest.url = ' + httpRequest.url) } function getBody(callback) { // Gets the de body from a POST httpRequest to the web server try { @@ -75,11 +69,11 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE }) httpRequest.on('error', function (err) { - if (CONSOLE_LOG === true) { console.log('[INFO] httpInterface -> onBrowserRequest -> getBody -> err = ' + err.stack) } + console.log('[INFO] httpInterface -> onBrowserRequest -> getBody -> err = ' + err.stack) respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse) }) } catch (err) { - if (CONSOLE_LOG === true) { console.log('[INFO] httpInterface -> onBrowserRequest -> getBody -> err = ' + err.stack) } + console.log('[INFO] httpInterface -> onBrowserRequest -> getBody -> err = ' + err.stack) respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse) } } @@ -137,9 +131,9 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE } } } catch (err) { - if (CONSOLE_ERROR_LOG === true) { console.log('[ERROR] httpInterface -> WEB3s -> Method call produced an error.') } - if (CONSOLE_ERROR_LOG === true) { console.log('[ERROR] httpInterface -> WEB3s -> err.stack = ' + err.stack) } - if (CONSOLE_ERROR_LOG === true) { console.log('[ERROR] httpInterface -> WEB3s -> Params Received = ' + body) } + console.log('[ERROR] httpInterface -> WEB3s -> Method call produced an error.') + console.log('[ERROR] httpInterface -> WEB3s -> err.stack = ' + err.stack) + console.log('[ERROR] httpInterface -> WEB3s -> Params Received = ' + body) let error = { result: 'Fail Because', @@ -219,7 +213,7 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE err: global.DEFAULT_FAIL_RESPONSE // method not supported } } catch (err) { - if (CONSOLE_LOG === true) { console.log('[INFO] httpInterface -> CCXT FetchMarkets -> Could not fetch markets.') } + console.log('[INFO] httpInterface -> CCXT FetchMarkets -> Could not fetch markets.') let error = { result: 'Fail Because', message: err.message @@ -310,19 +304,19 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE case 'LegacyPlotter.js': { - respondWithFile(process.env.PATH_TO_CLIENT + 'WebServer/LegacyPlotter.js', httpResponse) + respondWithFile(global.env.PATH_TO_CLIENT + 'WebServer/LegacyPlotter.js', httpResponse) } break case 'PlotterPanel.js': { - respondWithFile(process.env.PATH_TO_CLIENT + 'WebServer/PlotterPanel.js', httpResponse) + respondWithFile(global.env.PATH_TO_CLIENT + 'WebServer/PlotterPanel.js', httpResponse) } break case 'Images': // This means the Images folder. { - let path = process.env.PATH_TO_CLIENT + 'WebServer/Images/' + requestParameters[2] + let path = global.env.PATH_TO_CLIENT + 'WebServer/Images/' + requestParameters[2] if (requestParameters[3] !== undefined) { path = path + '/' + requestParameters[3] @@ -344,7 +338,7 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE case 'Icons': // This means the Icons folder under Projects. { - let path = process.env.PROJECTS_PATH + '/' + requestParameters[2] + '/Icons' + let path = global.env.PATH_TO_PROJECTS + '/' + requestParameters[2] + '/Icons' if (requestParameters[3] !== undefined) { path = path + '/' + requestParameters[3] @@ -365,7 +359,7 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE case 'Gifs': // This means the Gifs folder under Projects. { - let path = process.env.PROJECTS_PATH + '/' + requestParameters[2] + '/Gifs' + let path = global.env.PATH_TO_PROJECTS + '/' + requestParameters[2] + '/Gifs' if (requestParameters[3] !== undefined) { path = path + '/' + requestParameters[3] @@ -386,19 +380,19 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE case 'favicon.ico': // This means the Scripts folder. { - respondWithImage(process.env.PATH_TO_CLIENT + 'WebServer/Images/' + 'favicon.ico', httpResponse) + respondWithImage(global.env.PATH_TO_CLIENT + 'WebServer/Images/' + 'favicon.ico', httpResponse) } break case 'WebServer': // This means the WebServer folder. { - respondWithFile(process.env.PATH_TO_CLIENT + 'WebServer/' + requestParameters[2], httpResponse) + respondWithFile(global.env.PATH_TO_CLIENT + 'WebServer/' + requestParameters[2], httpResponse) } break case 'externalScripts': // This means the WebServer folder. { - respondWithFile(process.env.PATH_TO_CLIENT + 'WebServer/externalScripts/' + requestParameters[2], httpResponse) + respondWithFile(global.env.PATH_TO_CLIENT + 'WebServer/externalScripts/' + requestParameters[2], httpResponse) } break @@ -408,45 +402,45 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE let dataMine = requestParameters[3] let codeName = requestParameters[4] let moduleName = requestParameters[5] - let filePath = process.env.PROJECTS_PATH + '/' + project + '/' + 'Bots-Plotters-Code' + '/' + dataMine + '/plotters/' + codeName + '/' + moduleName + let filePath = global.env.PATH_TO_PROJECTS + '/' + project + '/' + 'Bots-Plotters-Code' + '/' + dataMine + '/plotters/' + codeName + '/' + moduleName respondWithFile(filePath, httpResponse) } break case 'ChartLayers': { - respondWithFile(process.env.PATH_TO_UI + '/' + requestParameters[1] + '/' + requestParameters[2], httpResponse) + respondWithFile(global.env.PATH_TO_UI + '/' + requestParameters[1] + '/' + requestParameters[2], httpResponse) } break case 'Files': { - respondWithFile(process.env.PATH_TO_DATA_FILES + '/' + requestParameters[2], httpResponse) + respondWithFile(global.env.PATH_TO_DATA_FILES + '/' + requestParameters[2], httpResponse) } break case 'Fonts': { - respondWithFont(process.env.PATH_TO_FONTS + '/' + requestParameters[2], httpResponse) + respondWithFont(global.env.PATH_TO_FONTS + '/' + requestParameters[2], httpResponse) } break case 'ProjectNames': { - let projects = getDirectories(process.env.PROJECTS_PATH) + let projects = getDirectories(global.env.PATH_TO_PROJECTS) respondWithContent(JSON.stringify(projects), httpResponse) } break case 'Schema': { - sendSchema(process.env.PROJECTS_PATH + '/' + requestParameters[2] + '/Schemas/', requestParameters[3] + '.json') + sendSchema(global.env.PATH_TO_PROJECTS + '/' + requestParameters[2] + '/Schemas/', requestParameters[3] + '.json') } break case 'IconNames': { - let projects = getDirectories(process.env.PROJECTS_PATH) + let projects = getDirectories(global.env.PATH_TO_PROJECTS) const fs = require('fs') let icons = [] @@ -456,7 +450,7 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE for (let i = 0; i < projects.length; i++) { let project = projects[i] - const folder = process.env.PROJECTS_PATH + '/' + project + '/Icons/' + const folder = global.env.PATH_TO_PROJECTS + '/' + project + '/Icons/' fs.readdir(folder, (err, files) => { for (let j = 0; j < files.length; j++) { @@ -479,7 +473,7 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE let pluginType = unescape(requestParameters[3]) const fs = require('fs') - let folder = process.env.PROJECTS_PATH + '/' + project + '/Plugins/' + pluginType + let folder = global.env.PATH_TO_PROJECTS + '/' + project + '/Plugins/' + pluginType fs.readdir(folder, (err, files) => { respondWithContent(JSON.stringify(files), httpResponse) @@ -492,7 +486,7 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE let project = unescape(requestParameters[2]) let pluginType = unescape(requestParameters[3]) let fileName = unescape(requestParameters[4]) - let filePath = process.env.PROJECTS_PATH + '/' + project + '/Plugins/' + pluginType + '/' + fileName + let filePath = global.env.PATH_TO_PROJECTS + '/' + project + '/Plugins/' + pluginType + '/' + fileName respondWithFile(filePath, httpResponse) } break @@ -502,7 +496,7 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE let fs = require('fs') try { - let filePath = process.env.DEFAULT_WORKSPACE_PATH + '/Getting-Started.json' + let filePath = global.env.PATH_TO_DEFAULT_WORKSPACE + '/Getting-Started.json' fs.readFile(filePath, onFileRead) } catch (e) { console.log('[ERROR] Error reading the Workspace.', e) @@ -522,21 +516,21 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE case 'ListWorkspaces': { let allWorkspaces = [] - let projects = getDirectories(process.env.PROJECTS_PATH) + let projects = getDirectories(global.env.PATH_TO_PROJECTS) let projectsCount = 0 for (let i = 0; i < projects.length; i++) { let project = projects[i] readPluginWorkspaces() function readPluginWorkspaces() { - let dirPath = process.env.PROJECTS_PATH + '/' + project + '/Plugins/Workspaces' + let dirPath = global.env.PATH_TO_PROJECTS + '/' + project + '/Plugins/Workspaces' try { let fs = require('fs') fs.readdir(dirPath, onDirRead) function onDirRead(err, fileList) { if (err) { - if (CONSOLE_ERROR_LOG === true) { console.log('[WARN] Error reading a directory content. filePath = ' + dirPath) } + console.log('[WARN] Error reading a directory content. filePath = ' + dirPath) respondWithContent(JSON.stringify(global.DEFAULT_FAIL_RESPONSE), httpResponse) return } else { @@ -554,8 +548,8 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE } } } catch (err) { - if (CONSOLE_ERROR_LOG === true) { console.log('[ERROR] Error reading a directory content. filePath = ' + dirPath) } - if (CONSOLE_ERROR_LOG === true) { console.log('[ERROR] err.stack = ' + err.stack) } + console.log('[ERROR] Error reading a directory content. filePath = ' + dirPath) + console.log('[ERROR] err.stack = ' + err.stack) respondWithContent(JSON.stringify(global.DEFAULT_FAIL_RESPONSE), httpResponse) return } @@ -563,14 +557,14 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE } function readMyWorkspaces() { - let dirPath = process.env.MY_WORKSPACES_PATH + let dirPath = global.env.PATH_TO_MY_WORKSPACES try { let fs = require('fs') fs.readdir(dirPath, onDirRead) function onDirRead(err, fileList) { if (err) { - if (CONSOLE_ERROR_LOG === true) { console.log('[WARN] Could not read this directory content. filePath = ' + dirPath) } + console.log('[WARN] Could not read this directory content. filePath = ' + dirPath) respondWithContent(JSON.stringify(global.DEFAULT_FAIL_RESPONSE), httpResponse) return } else { @@ -585,8 +579,8 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE } } } catch (err) { - if (CONSOLE_ERROR_LOG === true) { console.log('[ERROR] Error reading a directory content. filePath = ' + dirPath) } - if (CONSOLE_ERROR_LOG === true) { console.log('[ERROR] err.stack = ' + err.stack) } + console.log('[ERROR] Error reading a directory content. filePath = ' + dirPath) + console.log('[ERROR] err.stack = ' + err.stack) respondWithContent(JSON.stringify(global.DEFAULT_FAIL_RESPONSE), httpResponse) return } @@ -597,7 +591,7 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE case 'LoadMyWorkspace': { let fileName = unescape(requestParameters[2]) - let filePath = process.env.MY_WORKSPACES_PATH + '/' + fileName + '.json' + let filePath = global.env.PATH_TO_MY_WORKSPACES + '/' + fileName + '.json' respondWithFile(filePath, httpResponse) } break @@ -610,11 +604,11 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE let fileContent = body let fileName = unescape(requestParameters[2]) - let filePath = process.env.MY_WORKSPACES_PATH + '/' + fileName + '.json' + let filePath = global.env.PATH_TO_MY_WORKSPACES + '/' + fileName + '.json' try { let fs = require('fs') - let dir = process.env.MY_WORKSPACES_PATH; + let dir = global.env.PATH_TO_MY_WORKSPACES; /* Create Dir if it does not exist */ if (!fs.existsSync(dir)) { @@ -660,7 +654,7 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE case 'ProjectsSchema': { - let path = process.env.PROJECTS_PATH + '/' + 'ProjectsSchema.json' + let path = global.env.PATH_TO_PROJECTS + '/' + 'ProjectsSchema.json' respondWithFile(path, httpResponse) } break @@ -669,7 +663,7 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE { let fs = require('fs') let allFiles = [] - let projects = getDirectories(process.env.PROJECTS_PATH) + let projects = getDirectories(global.env.PATH_TO_PROJECTS) let dirCount = 0 let totalDirs = 0 @@ -677,7 +671,7 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE let project = projects[i] let dirPath = project + '/UI/Spaces' - let spaces = getDirectories(process.env.PROJECTS_PATH + '/' + dirPath) + let spaces = getDirectories(global.env.PATH_TO_PROJECTS + '/' + dirPath) for (let j = 0; j < spaces.length; j++) { let space = spaces[j] @@ -688,9 +682,9 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE try { totalDirs++ - fs.readdir(process.env.PROJECTS_PATH + '/' + path, onDirRead) + fs.readdir(global.env.PATH_TO_PROJECTS + '/' + path, onDirRead) - let otherDirs = getDirectories(process.env.PROJECTS_PATH + '/' + path) + let otherDirs = getDirectories(global.env.PATH_TO_PROJECTS + '/' + path) for (let m = 0; m < otherDirs.length; m++) { let otherDir = otherDirs[m] readDirectory(path + '/' + otherDir) @@ -715,9 +709,7 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE } } catch (err) { console.log('[ERROR] Error reading a directory content. filePath = ' + path) - if (CONSOLE_ERROR_LOG === true) { console.log('[ERROR] err.stack = ' + err.stack) } - - console.log(err.stack) + console.log('[ERROR] err.stack = ' + err.stack) respondWithContent(JSON.stringify(global.DEFAULT_FAIL_RESPONSE), httpResponse) return } @@ -748,14 +740,14 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE } } - let filePath = process.env.PROJECTS_PATH + path + let filePath = global.env.PATH_TO_PROJECTS + path respondWithFile(filePath, httpResponse) } break case 'Storage': { - respondWithFile(process.env.STORAGE_PATH + '/' + httpRequest.url.substring(9), httpResponse) + respondWithFile(global.env.PATH_TO_DATA_STORAGE + '/' + httpRequest.url.substring(9), httpResponse) } break @@ -785,21 +777,20 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE function returnProjectFolderFileList(projectFolderName) { { let allLibraries = [] - let projects = getDirectories(process.env.PROJECTS_PATH) + let projects = getDirectories(global.env.PATH_TO_PROJECTS) let projectsCount = 0 for (let i = 0; i < projects.length; i++) { let project = projects[i] - let dirPath = process.env.PROJECTS_PATH + '/' + project + '/' + 'UI' + '/' + projectFolderName + let dirPath = global.env.PATH_TO_PROJECTS + '/' + project + '/' + 'UI' + '/' + projectFolderName try { let fs = require('fs') fs.readdir(dirPath, onDirRead) function onDirRead(err, fileList) { if (err) { - if (CONSOLE_ERROR_LOG === true) { console.log('[WARN] Error reading a directory content. filePath = ' + dirPath) } - if (CONSOLE_ERROR_LOG === true) { console.log(err.stack) } + console.log('[WARN] Error reading a directory content. filePath = ' + dirPath) return } else { let updatedFileList = [] @@ -816,8 +807,8 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE } } } catch (err) { - if (CONSOLE_ERROR_LOG === true) { console.log('[ERROR] Error reading a directory content. filePath = ' + dirPath) } - if (CONSOLE_ERROR_LOG === true) { console.log('[ERROR] err.stack = ' + err.stack) } + console.log('[ERROR] Error reading a directory content. filePath = ' + dirPath) + console.log('[ERROR] err.stack = ' + err.stack) respondWithContent(JSON.stringify(global.DEFAULT_FAIL_RESPONSE), httpResponse) return @@ -863,16 +854,16 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE function sendStyleSheet(fileName) { let fs = require('fs') try { - let filePath = process.env.PATH_TO_CLIENT + 'WebServer/' + fileName + let filePath = global.env.PATH_TO_CLIENT + 'WebServer/' + fileName fs.readFile(filePath, onFileRead) function onFileRead(err, file) { try { let fileContent = file.toString() - fileContent = fileContent.replace('HTTP_INTERFACE_PORT', process.env.HTTP_INTERFACE_PORT) - fileContent = fileContent.replace('HTTP_INTERFACE_PORT', process.env.HTTP_INTERFACE_PORT) - fileContent = fileContent.replace('HTTP_INTERFACE_PORT', process.env.HTTP_INTERFACE_PORT) + fileContent = fileContent.replace('HTTP_INTERFACE_PORT', global.env.HTTP_INTERFACE_PORT) + fileContent = fileContent.replace('HTTP_INTERFACE_PORT', global.env.HTTP_INTERFACE_PORT) + fileContent = fileContent.replace('HTTP_INTERFACE_PORT', global.env.HTTP_INTERFACE_PORT) respondWithContent(fileContent, httpResponse, 'text/css') } catch (err) { console.log('[ERROR] httpInterface -> mainCSS -> File Not Found: ' + fileName + ' or Error = ' + err.stack) @@ -887,14 +878,14 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE if (requestParameters[1] === '') { let fs = require('fs') try { - let fileName = process.env.PATH_TO_CLIENT + 'WebServer/index.html' + let fileName = global.env.PATH_TO_CLIENT + 'WebServer/index.html' fs.readFile(fileName, onFileRead) function onFileRead(err, file) { try { let fileContent = file.toString() - fileContent = fileContent.replace('HTTP_INTERFACE_PORT', process.env.HTTP_INTERFACE_PORT) + fileContent = fileContent.replace('HTTP_INTERFACE_PORT', global.env.HTTP_INTERFACE_PORT) respondWithContent(fileContent, httpResponse) } catch (err) { console.log('[ERROR] httpInterface -> homePage -> File Not Found: ' + fileName + ' or Error = ' + err.stack) @@ -904,7 +895,7 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE console.log(err) } } else { - respondWithFile(process.env.PATH_TO_UI + '/' + requestParameters[1], httpResponse) + respondWithFile(global.env.PATH_TO_UI + '/' + requestParameters[1], httpResponse) } } } @@ -919,7 +910,6 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE fs.readFile(fileName, onFileRead) function onFileRead(err, file) { - if (CONSOLE_LOG === true) { console.log('[INFO] httpInterface -> respondWithFile -> onFileRead -> Entering function.') } if (!err) { respondWithContent(file.toString(), httpResponse) } else { @@ -934,8 +924,6 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE } function respondWithContent(content, httpResponse, contentType) { - if (CONSOLE_LOG === true) { console.log('[INFO] httpInterface -> respondWithContent -> Entering function.') } - try { httpResponse.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate') // HTTP 1.1. httpResponse.setHeader('Pragma', 'no-cache') // HTTP 1.0. @@ -960,8 +948,6 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE } function respondWithImage(fileName, httpResponse) { - if (CONSOLE_LOG === true) { console.log('[INFO] httpInterface -> respondWithImage -> Entering function.') } - let fs = require('fs') try { fs.readFile(fileName, onFileRead) @@ -989,15 +975,11 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE } function respondWithFont(fileName, httpResponse) { - if (CONSOLE_LOG === true) { console.log('[INFO] httpInterface -> respondWithBinary -> Entering function.') } - let fs = require('fs') try { fs.readFile(fileName, onFileRead) function onFileRead(err, file) { - if (CONSOLE_LOG === true) { console.log('[INFO] httpInterface -> respondWithBinary -> onFileRead -> Entering function.') } - try { if (err) { console.log('[ERROR] httpInterface -> respondWithBinary -> onFileRead -> File Not Found: ' + fileName + ' or Error = ' + err.stack) @@ -1025,7 +1007,6 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE function returnEmptyArray(httpResponse) { try { - if (CONSOLE_LOG === true) { console.log('[INFO] httpInterface -> returnEmptyArray -> Entering function.') } httpResponse.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate') // HTTP 1.1. httpResponse.setHeader('Pragma', 'no-cache') // HTTP 1.0. httpResponse.setHeader('Expires', '0') // Proxies. diff --git a/Client/taskManagerServer.js b/Client/taskManagerServer.js index 22185d53b..770849e2b 100644 --- a/Client/taskManagerServer.js +++ b/Client/taskManagerServer.js @@ -64,7 +64,7 @@ //console.log('[INFO] Client -> Task Manager Server -> runTask -> Task Name = ' + message.event.taskName) //console.log('[INFO] Client -> Task Manager Server -> runTask -> Task Id = ' + message.event.taskId) - let path = process.env.TASK_SERVER_PATH + '/Task.js' + let path = global.env.PATH_TO_TASK_SERVER + '/Task.js' /* Workarround to avoid having the same debug port at the forked process which makes it crash. */ for (let i = 0; i < process.execArgv.length; i++) { diff --git a/Client/webSocketsServer.js b/Client/webSocketsServer.js index 23ef8170a..4208f8913 100644 --- a/Client/webSocketsServer.js +++ b/Client/webSocketsServer.js @@ -12,7 +12,7 @@ require('dotenv').config() const WEB_SOCKET = require('ws') let socketServer - let port = process.env.WEB_SOCKETS_INTERFACE_PORT + let port = global.env.WEB_SOCKETS_INTERFACE_PORT return thisObject diff --git a/Environment.js b/Environment.js new file mode 100644 index 000000000..496e8c53c --- /dev/null +++ b/Environment.js @@ -0,0 +1,21 @@ +exports.newEnvironment = function () { + + let thisObject = { + WEB_SERVER_URL: 'localhost', + WEB_SOCKETS_INTERFACE_PORT: 18041, + HTTP_INTERFACE_PORT: 34248, + PATH_TO_TASK_SERVER: './TaskServer', + PATH_TO_DATA_STORAGE: './Data-Storage', + PATH_TO_PROJECTS: './Projects', + PATH_TO_LOG_FILES: './Log-Files', + PATH_TO_PROJECTS_REQUIRED: '../Projects', + PATH_TO_UI: './UI', + PATH_TO_DATA_FILES: './UI/Data-Files/src', + PATH_TO_CLIENT: './Client/', + PATH_TO_DEFAULT_WORKSPACE: './Projects/Superalgos/Plugins/Workspaces', + PATH_TO_MY_WORKSPACES: './My-Workspaces', + PATH_TO_FONTS: './Client/WebServer/Fonts' + } + + return thisObject; +} \ No newline at end of file diff --git a/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Exchange-Raw-Data-Sensor-Bot/Historic-OHLCVs/User.Bot.js b/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Exchange-Raw-Data-Sensor-Bot/Historic-OHLCVs/User.Bot.js index f130e76de..522697914 100644 --- a/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Exchange-Raw-Data-Sensor-Bot/Historic-OHLCVs/User.Bot.js +++ b/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Exchange-Raw-Data-Sensor-Bot/Historic-OHLCVs/User.Bot.js @@ -88,12 +88,8 @@ exports.newUserBot = function (processIndex, bot, logger, COMMONS, UTILITIES, FI limit = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.config.fetchLimit } - let key = process.env.KEY - let secret = process.env.SECRET - - if (key === "undefined") { key = undefined } - if (secret === "undefined") { secret = undefined } - + let key + let secret exchangeClass = ccxt[exchangeId] const exchangeConstructorParams = { diff --git a/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Exchange-Raw-Data-Sensor-Bot/Historic-Trades/User.Bot.js b/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Exchange-Raw-Data-Sensor-Bot/Historic-Trades/User.Bot.js index b9048d1e2..529c76368 100644 --- a/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Exchange-Raw-Data-Sensor-Bot/Historic-Trades/User.Bot.js +++ b/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Exchange-Raw-Data-Sensor-Bot/Historic-Trades/User.Bot.js @@ -76,12 +76,8 @@ exports.newUserBot = function (processIndex, bot, logger, COMMONS, UTILITIES, FI } } - let key = process.env.KEY - let secret = process.env.SECRET - - if (key === "undefined") { key = undefined } - if (secret === "undefined") { secret = undefined } - + let key + let secret const exchangeClass = ccxt[exchangeId] const exchangeConstructorParams = { diff --git a/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Webhooks-Sensor-Bot/Check-Webhook/User.Bot.js b/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Webhooks-Sensor-Bot/Check-Webhook/User.Bot.js index aca175216..2077d5ccc 100644 --- a/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Webhooks-Sensor-Bot/Check-Webhook/User.Bot.js +++ b/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Webhooks-Sensor-Bot/Check-Webhook/User.Bot.js @@ -98,8 +98,8 @@ exports.newUserBot = function (processIndex, bot, logger, COMMONS, UTILITIES, FI try { let http = require('http'); - let url = 'http://' + process.env.WEB_SERVER_URL + - ':' + process.env.HTTP_INTERFACE_PORT + + let url = 'http://' + global.env.WEB_SERVER_URL + + ':' + global.env.HTTP_INTERFACE_PORT + '/Webhook/Fetch-Messages/' + TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.parentNode.parentNode.name + "/" + TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.baseAsset.referenceParent.config.codeName + "-" + TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.quotedAsset.referenceParent.config.codeName diff --git a/TaskServer/Environment.js b/TaskServer/Environment.js deleted file mode 100644 index ddeb5be1e..000000000 --- a/TaskServer/Environment.js +++ /dev/null @@ -1,12 +0,0 @@ -exports.newEnvironment = function () { - - let thisObject = { - WEB_SOCKETS_INTERFACE_PORT: 18041, - STORAGE_PATH: './Data-Storage', - PROJECTS_PATH: './Projects', - LOG_PATH: './Log-Files', - PROJECTS_REQUIRED_PATH: '../Projects' - } - - return thisObject; -} \ No newline at end of file diff --git a/TaskServer/FileStorage.js b/TaskServer/FileStorage.js index 772d8afdc..9afd0197c 100644 --- a/TaskServer/FileStorage.js +++ b/TaskServer/FileStorage.js @@ -74,10 +74,10 @@ exports.newFileStorage = function newFileStorage(logger, host, port) { let fileLocation let mustBeJason if (filePath.indexOf("/bots/") > 0) { - fileLocation = global.env.PROJECTS_PATH + '/' + filePath + fileLocation = global.env.PATH_TO_PROJECTS + '/' + filePath mustBeJason = false } else { - fileLocation = global.env.STORAGE_PATH + '/' + filePath + fileLocation = global.env.PATH_TO_DATA_STORAGE + '/' + filePath mustBeJason = true } @@ -234,9 +234,9 @@ exports.newFileStorage = function newFileStorage(logger, host, port) { /* Choose path for either logs or data */ let fileLocation if (filePath.indexOf("/Logs/") > 0) { - fileLocation = global.env.LOG_PATH + '/' + filePath + fileLocation = global.env.PATH_TO_LOG_FILES + '/' + filePath } else { - fileLocation = global.env.STORAGE_PATH + '/' + filePath + fileLocation = global.env.PATH_TO_DATA_STORAGE + '/' + filePath } try { @@ -391,9 +391,9 @@ exports.newFileStorage = function newFileStorage(logger, host, port) { /* Choose path for either logs or data */ let fileLocation if (filePath.indexOf("/Logs/") > 0) { - fileLocation = global.env.LOG_PATH + '/' + filePath + fileLocation = global.env.PATH_TO_LOG_FILES + '/' + filePath } else { - fileLocation = global.env.STORAGE_PATH + '/' + filePath + fileLocation = global.env.PATH_TO_DATA_STORAGE + '/' + filePath } try { diff --git a/TaskServer/LearningSession.js b/TaskServer/LearningSession.js index a885d3cf3..49935203d 100644 --- a/TaskServer/LearningSession.js +++ b/TaskServer/LearningSession.js @@ -165,7 +165,7 @@ exports.newLearningSession = function (processIndex, bot, parentLogger) { socialBotsModule.finalize() bot.STOP_SESSION = true parentLogger.write(MODULE_NAME, '[IMPORTANT] stopSession -> Stopping the Session now. ') - sessionInfo(processIndex, bot.LEARNING_SESSION, commandOrigin, parentLogger) + TS.projects.superalgos.functionLibraries.sessionFunctions.sessionInfo(processIndex, bot.LEARNING_SESSION, commandOrigin, parentLogger) } function setUpSessionFolderName() { diff --git a/TaskServer/LowFrequencyTrading/ExchangeAPI.js b/TaskServer/LowFrequencyTrading/ExchangeAPI.js index 71ef4f473..18af1f71f 100644 --- a/TaskServer/LowFrequencyTrading/ExchangeAPI.js +++ b/TaskServer/LowFrequencyTrading/ExchangeAPI.js @@ -24,11 +24,20 @@ tradingSystem = bot.simulationState.tradingSystem exchangeId = TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.parentNode.parentNode.name.toLowerCase() - + + let key + let secret + + if (TS.projects.superalgos.globals.taskConstants.TASK_NODE.keyReference !== undefined) { + if (TS.projects.superalgos.globals.taskConstants.TASK_NODE.keyReference.referenceParent !== undefined) { + key = TS.projects.superalgos.globals.taskConstants.TASK_NODE.keyReference.referenceParent.config.codeName + secret = TS.projects.superalgos.globals.taskConstants.TASK_NODE.keyReference.referenceParent.config.secret + } + } const exchangeClass = ccxt[exchangeId] const exchangeConstructorParams = { - 'apiKey': TS.projects.superalgos.globals.taskConstants.TASK_NODE.keyReference.referenceParent.config.codeName, - 'secret': TS.projects.superalgos.globals.taskConstants.TASK_NODE.keyReference.referenceParent.config.secret, + 'apiKey': key, + 'secret': secret, 'timeout': 30000, 'enableRateLimit': true, verbose: false, diff --git a/TaskServer/MultiProject.js b/TaskServer/MultiProject.js index 31edfb496..2236172b0 100644 --- a/TaskServer/MultiProject.js +++ b/TaskServer/MultiProject.js @@ -27,7 +27,7 @@ exports.newMultiProject = function () { if (projectDefinition.TS.utilities !== undefined) { for (let j = 0; j < projectDefinition.TS.utilities.length; j++) { let utilityDefinition = projectDefinition.TS.utilities[j] - let path = global.env.PROJECTS_REQUIRED_PATH + '/' + projectDefinition.name + '/' + 'TS' + '/' + 'Utilities' + '/' + utilityDefinition.fileName + let path = global.env.PATH_TO_PROJECTS_REQUIRED + '/' + projectDefinition.name + '/' + 'TS' + '/' + 'Utilities' + '/' + utilityDefinition.fileName let requiredObject = require(path) let requiredFunction = requiredObject[utilityDefinition.functionName] @@ -39,7 +39,7 @@ exports.newMultiProject = function () { if (projectDefinition.TS.globals !== undefined) { for (let j = 0; j < projectDefinition.TS.globals.length; j++) { let globalDefinition = projectDefinition.TS.globals[j] - let path = global.env.PROJECTS_REQUIRED_PATH + '/' + projectDefinition.name + '/' + 'TS' + '/' + 'Globals' + '/' + globalDefinition.fileName + let path = global.env.PATH_TO_PROJECTS_REQUIRED + '/' + projectDefinition.name + '/' + 'TS' + '/' + 'Globals' + '/' + globalDefinition.fileName let requiredObject = require(path) let requiredFunction = requiredObject[globalDefinition.functionName] @@ -51,7 +51,7 @@ exports.newMultiProject = function () { if (projectDefinition.TS.functionLibraries !== undefined) { for (let j = 0; j < projectDefinition.TS.functionLibraries.length; j++) { let functionLibraryDefinition = projectDefinition.TS.functionLibraries[j] - let path = global.env.PROJECTS_REQUIRED_PATH + '/' + projectDefinition.name + '/' + 'TS' + '/' + 'Function-Libraries' + '/' + functionLibraryDefinition.fileName + let path = global.env.PATH_TO_PROJECTS_REQUIRED + '/' + projectDefinition.name + '/' + 'TS' + '/' + 'Function-Libraries' + '/' + functionLibraryDefinition.fileName let requiredObject = require(path) let requiredFunction = requiredObject[functionLibraryDefinition.functionName] @@ -63,7 +63,7 @@ exports.newMultiProject = function () { if (projectDefinition.TS.botClasses !== undefined) { for (let j = 0; j < projectDefinition.TS.botClasses.length; j++) { let botClassDefinition = projectDefinition.TS.botClasses[j] - let path = global.env.PROJECTS_REQUIRED_PATH + '/' + projectDefinition.name + '/' + 'TS' + '/' + 'Bot-Classes' + '/' + botClassDefinition.fileName + let path = global.env.PATH_TO_PROJECTS_REQUIRED + '/' + projectDefinition.name + '/' + 'TS' + '/' + 'Bot-Classes' + '/' + botClassDefinition.fileName let requiredObject = require(path) let requiredFunction = requiredObject[botClassDefinition.functionName] diff --git a/TaskServer/Task.js b/TaskServer/Task.js index 032dee1a2..fe76fbec4 100644 --- a/TaskServer/Task.js +++ b/TaskServer/Task.js @@ -1,5 +1,5 @@ /* Load Environment Variables */ -let ENVIRONMENT = require('./Environment.js'); +let ENVIRONMENT = require('../Environment.js'); let ENVIRONMENT_MODULE = ENVIRONMENT.newEnvironment() global.env = ENVIRONMENT_MODULE @@ -52,9 +52,9 @@ function preLoader() { But before that, we need to change the path of these env variables since the home directory now is TaskServer and not its parent. */ - global.env.STORAGE_PATH = '.' + global.env.STORAGE_PATH - global.env.PROJECTS_PATH = '.' + global.env.PROJECTS_PATH - global.env.LOG_PATH = '.' + global.env.LOG_PATH + global.env.PATH_TO_DATA_STORAGE = '.' + global.env.PATH_TO_DATA_STORAGE + global.env.PATH_TO_PROJECTS = '.' + global.env.PATH_TO_PROJECTS + global.env.PATH_TO_LOG_FILES = '.' + global.env.PATH_TO_LOG_FILES try { global.EVENT_SERVER_CLIENT_MODULE.listenToEvent('Task Server', 'Debug Task Started', undefined, 'Task Server', undefined, startDebugging) diff --git a/TaskServer/TradingSession.js b/TaskServer/TradingSession.js index 16dbac9ad..2757f834d 100644 --- a/TaskServer/TradingSession.js +++ b/TaskServer/TradingSession.js @@ -166,7 +166,7 @@ socialBotsModule.finalize() bot.STOP_SESSION = true parentLogger.write(MODULE_NAME, '[IMPORTANT] stopSession -> Stopping the Session now. ') - sessionInfo(processIndex, bot.TRADING_SESSION, commandOrigin, parentLogger) + TS.projects.superalgos.functionLibraries.sessionFunctions.sessionInfo(processIndex, bot.TRADING_SESSION, commandOrigin, parentLogger) } function setUpSessionFolderName() {