171 lines
4.9 KiB
JavaScript
171 lines
4.9 KiB
JavaScript
|
|
global.CURRENT_ENVIRONMENT = "Develop";
|
|
global.CURRENT_EXECUTION_AT = "Cloud";
|
|
global.SHALL_BOT_STOP = false;
|
|
global.AT_BREAKPOINT = false; // This is used only when running at the browser.
|
|
|
|
/* Default parameters can be changed by the execution configuration */
|
|
global.EXCHANGE_NAME = "Poloniex";
|
|
global.MARKET = {
|
|
assetA: "USDT",
|
|
assetB: "BTC"
|
|
};
|
|
|
|
process.on('uncaughtException', function (err) {
|
|
console.log('[INFO] Run -> uncaughtException -> err.message = ' + err.message);
|
|
return;
|
|
});
|
|
|
|
process.on('unhandledRejection', (reason, p) => {
|
|
console.log('[INFO] Run -> unhandledRejection -> reason = ' + reason);
|
|
console.log('[INFO] Run -> unhandledRejection -> p = ' + JSON.stringify(p));
|
|
return;
|
|
});
|
|
|
|
process.on('exit', function (code) {
|
|
try {
|
|
console.log('[INFO] Run -> process.on.exit -> About to exit -> code = ' + code);
|
|
return;
|
|
}
|
|
catch (err) {
|
|
console.log("[ERROR] Run -> process.on.exit -> Error Logging Error Code.");
|
|
console.log("[ERROR] Run -> process.on.exit -> err.message = " + err.message);
|
|
return;
|
|
}
|
|
});
|
|
|
|
global.USER_PROFILE = {};
|
|
global.EMAIL_CONFIG = {};
|
|
|
|
readStoragePermissions();
|
|
|
|
function readStoragePermissions() {
|
|
|
|
let filePath;
|
|
|
|
try {
|
|
console.log( "[INFO] Run -> readStoragePermissions -> Entering function. ");
|
|
|
|
let fs = require('fs');
|
|
filePath = './' + 'configs' + '/' + 'User.Profile.json';
|
|
global.USER_PROFILE = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
|
|
|
|
/* Here we will rearrange the storage permissions array into a map, so that it can be easily consumed when needed. */
|
|
|
|
let permissionsMap = new Map;
|
|
|
|
for (i = 0; i < global.USER_PROFILE.storagePermissions.length; i++) {
|
|
|
|
let permission = global.USER_PROFILE.storagePermissions[i];
|
|
|
|
permissionsMap.set(permission[0], permission[1]);
|
|
|
|
}
|
|
|
|
global.USER_PROFILE.storagePermissions = permissionsMap;
|
|
|
|
readEmailConfiguration();
|
|
}
|
|
catch (err) {
|
|
console.log("[ERROR] Run -> readStoragePermissions -> err = " + err.message);
|
|
console.log("[HINT] Run -> readStoragePermissions -> You need to have a file at this path -> " + filePath);
|
|
}
|
|
}
|
|
|
|
function readEmailConfiguration() {
|
|
|
|
let filePath;
|
|
|
|
try {
|
|
console.log( "Run : [INFO] readEmailConfiguration -> Entering function. ");
|
|
|
|
let fs = require('fs');
|
|
filePath = './' + 'configs' + '/' + 'Email.Config.json';
|
|
global.EMAIL_CONFIG = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
|
|
readExecutionConfiguration();
|
|
}
|
|
catch (err) {
|
|
console.log("[ERROR] Run -> readEmailConfiguration -> err = " + err.message);
|
|
console.log("[HINT] Run -> You need to have a file at this path -> " + filePath);
|
|
}
|
|
}
|
|
|
|
function readExecutionConfiguration() {
|
|
let filePath;
|
|
try {
|
|
let fs = require('fs');
|
|
filePath = './configs/Execution.Config.json';
|
|
let executionProperties = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
global.DEV_TEAM = executionProperties.devTeam;
|
|
global.USER_LOGGED_IN = executionProperties.userName;
|
|
global.EXCHANGE_NAME = executionProperties.exchangeName;
|
|
global.MARKET = executionProperties.market;
|
|
global.EXECUTION_CONFIG = {
|
|
executionList: executionProperties.executionList,
|
|
startMode: executionProperties.startMode
|
|
};
|
|
|
|
readExchangeAPIKey();
|
|
}
|
|
catch (err) {
|
|
console.log("[ERROR] readExecutionConfiguration -> err = " + err.message);
|
|
console.log("[HINT] You need to have a file at this path -> " + filePath);
|
|
}
|
|
}
|
|
|
|
//TODO Move this method inside ExchangeAPI
|
|
function readExchangeAPIKey() {
|
|
|
|
try {
|
|
console.log( "[INFO] Run -> readExchangeAPIKey -> Entering function. ");
|
|
|
|
let fs = require('fs');
|
|
let filePath = './configs/Secret.Keys' + '.json';
|
|
|
|
global.EXCHANGE_KEYS = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
startRoot();
|
|
}
|
|
catch (err) {
|
|
console.log("[ERROR] Run -> readExchangeAPIKey -> err = " + err.message);
|
|
console.log("[HINT] Run -> You need to have a file at this path -> " + filePath);
|
|
|
|
global.EXCHANGE_KEYS = {
|
|
Poloniex: [{
|
|
Key: "",
|
|
Secret: ""
|
|
}]
|
|
}
|
|
|
|
startRoot();
|
|
}
|
|
}
|
|
|
|
function startRoot() {
|
|
|
|
console.log( "[INFO] Run -> startRoot -> Entering function. ");
|
|
|
|
const ROOT_DIR = './';
|
|
const ROOT_MODULE = require(ROOT_DIR + 'Root');
|
|
let root = ROOT_MODULE.newRoot();
|
|
|
|
let UI_COMMANDS = {
|
|
beginDatetime: undefined,
|
|
endDatetime: undefined,
|
|
timePeriod: undefined,
|
|
startMode: undefined,
|
|
eventHandler: undefined
|
|
};
|
|
|
|
root.initialize(UI_COMMANDS, onInitialized);
|
|
|
|
function onInitialized() {
|
|
|
|
console.log( "[INFO] Run -> startRoot -> onInitialized -> Entering function. ");
|
|
|
|
root.start();
|
|
}
|
|
}
|
|
|