Exchange and Market as global variables.
This commit is contained in:
1 parent
91dfa45b61
commit
1d00aaf6d2
6 files changed
+40
-26
No files matched your search
Binary file not shown.
+2
-9
@@ -29,13 +29,6 @@
|
||||
let processDatetime;
|
||||
let exchangeAPI;
|
||||
|
||||
/* The current bots trades only at one market: USDT_BTC. */
|
||||
|
||||
const MARKET = {
|
||||
assetA: "USDT",
|
||||
assetB: "BTC",
|
||||
};
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(pProcessDatetime, pBotContext, pExchangeAPI, callBackFunction) {
|
||||
@@ -99,7 +92,7 @@
|
||||
|
||||
*/
|
||||
|
||||
exchangeAPI.getOpenPositions(MARKET, onResponse);
|
||||
exchangeAPI.getOpenPositions(global.MARKET, onResponse);
|
||||
|
||||
function onResponse(err, pExchangePositions) {
|
||||
|
||||
@@ -432,7 +425,7 @@
|
||||
function putPositionAtExchange(pType, pRate, pAmountA, pAmountB, callBack) {
|
||||
|
||||
try {
|
||||
exchangeAPI.putPosition(MARKET, pType, pRate, pAmountA, pAmountB, onResponse);
|
||||
exchangeAPI.putPosition(global.MARKET, pType, pRate, pAmountA, pAmountB, onResponse);
|
||||
|
||||
function onResponse(err, pPositionId) {
|
||||
|
||||
|
||||
+8
-8
@@ -66,8 +66,6 @@
|
||||
|
||||
let processDatetime;
|
||||
|
||||
const EXCHANGE_NAME = "Poloniex";
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(pProcessDatetime, callBackFunction) {
|
||||
@@ -109,6 +107,7 @@
|
||||
|
||||
switch (err.result) {
|
||||
case global.DEFAULT_OK_RESPONSE.result: {
|
||||
logger.write("[INFO] initialize -> onDone -> Execution finished well. :-)");
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
return;
|
||||
}
|
||||
@@ -140,7 +139,7 @@
|
||||
if (FULL_LOG === true) { logger.write("[INFO] initialize -> getStatusReport -> Entering function."); }
|
||||
|
||||
let fileName = "Status.Report.json"
|
||||
let filePath = bot.devTeam + "/" + bot.codeName + "/" + bot.version + "/" + bot.dataSetVersion + "/Processes/" + bot.process + "/" + EXCHANGE_NAME;
|
||||
let filePath = bot.devTeam + "/" + bot.codeName + "/" + bot.version + "/" + bot.dataSetVersion + "/Processes/" + bot.process + "/" + global.EXCHANGE_NAME;
|
||||
|
||||
cloudStorage.getTextFile(filePath, fileName, onFileReceived);
|
||||
|
||||
@@ -194,7 +193,7 @@
|
||||
if (FULL_LOG === true) { logger.write("[INFO] initialize -> getExecutionHistory -> Entering function."); }
|
||||
|
||||
let fileName = "Execution.History.json"
|
||||
let filePath = bot.devTeam + "/" + bot.codeName + "/" + bot.version + "/" + bot.dataSetVersion + "/Output/" + bot.process + "/" + EXCHANGE_NAME;
|
||||
let filePath = bot.devTeam + "/" + bot.codeName + "/" + bot.version + "/" + bot.dataSetVersion + "/Output/" + bot.process + "/" + global.EXCHANGE_NAME;
|
||||
|
||||
cloudStorage.getTextFile(filePath, fileName, onFileReceived);
|
||||
|
||||
@@ -245,7 +244,7 @@
|
||||
|
||||
let fileName = "Execution.Context.json"
|
||||
let dateForPath = date.getUTCFullYear() + '/' + utilities.pad(date.getUTCMonth() + 1, 2) + '/' + utilities.pad(date.getUTCDate(), 2) + '/' + utilities.pad(date.getUTCHours(), 2) + '/' + utilities.pad(date.getUTCMinutes(), 2);
|
||||
let filePath = bot.devTeam + "/" + bot.codeName + "/" + bot.version + "/" + bot.dataSetVersion + "/Output/" + bot.process + "/" + EXCHANGE_NAME + "/" + dateForPath;
|
||||
let filePath = bot.devTeam + "/" + bot.codeName + "/" + bot.version + "/" + bot.dataSetVersion + "/Output/" + bot.process + "/" + global.EXCHANGE_NAME + "/" + dateForPath;
|
||||
|
||||
cloudStorage.getTextFile(filePath, fileName, onFileReceived);
|
||||
|
||||
@@ -339,6 +338,7 @@
|
||||
|
||||
switch (err.result) {
|
||||
case global.DEFAULT_OK_RESPONSE.result: {
|
||||
logger.write("[INFO] initialize -> onDone -> Execution finished well. :-)");
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
return;
|
||||
}
|
||||
@@ -373,7 +373,7 @@
|
||||
|
||||
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 = bot.devTeam + "/" + bot.codeName + "/" + bot.version + "/" + bot.dataSetVersion + "/Output/" + bot.process + "/" + EXCHANGE_NAME + "/" + dateForPath;
|
||||
let filePath = bot.devTeam + "/" + bot.codeName + "/" + bot.version + "/" + bot.dataSetVersion + "/Output/" + bot.process + "/" + global.EXCHANGE_NAME + "/" + dateForPath;
|
||||
|
||||
utilities.createFolderIfNeeded(filePath, cloudStorage, onFolderCreated);
|
||||
|
||||
@@ -428,7 +428,7 @@
|
||||
try {
|
||||
|
||||
let fileName = "Execution.History.json"
|
||||
let filePath = bot.devTeam + "/" + bot.codeName + "/" + bot.version + "/" + bot.dataSetVersion + "/Output/" + bot.process + "/" + EXCHANGE_NAME;
|
||||
let filePath = bot.devTeam + "/" + bot.codeName + "/" + bot.version + "/" + bot.dataSetVersion + "/Output/" + bot.process + "/" + global.EXCHANGE_NAME;
|
||||
|
||||
utilities.createFolderIfNeeded(filePath, cloudStorage, onFolderCreated);
|
||||
|
||||
@@ -493,7 +493,7 @@
|
||||
try {
|
||||
|
||||
let fileName = "Status.Report.json"
|
||||
let filePath = bot.devTeam + "/" + bot.codeName + "/" + bot.version + "/" + bot.dataSetVersion + "/Processes/" + bot.process + "/" + EXCHANGE_NAME;
|
||||
let filePath = bot.devTeam + "/" + bot.codeName + "/" + bot.version + "/" + bot.dataSetVersion + "/Processes/" + bot.process + "/" + global.EXCHANGE_NAME;
|
||||
|
||||
utilities.createFolderIfNeeded(filePath, cloudStorage, onFolderCreated);
|
||||
|
||||
|
||||
+14
-6
@@ -99,6 +99,7 @@
|
||||
|
||||
switch (err.result) {
|
||||
case global.DEFAULT_OK_RESPONSE.result: {
|
||||
logger.write("[INFO] initialize -> onDone -> Execution finished well. :-)");
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
return;
|
||||
}
|
||||
@@ -400,12 +401,19 @@
|
||||
}
|
||||
}
|
||||
|
||||
function getFile(pFileService, pFileName, pFilePath, pPeriodName, pDatetime, innerCallBack, outerCallBack) {
|
||||
try {
|
||||
pFileName = pFileName.replace("@AssetA", market.assetA);
|
||||
pFileName = pFileName.replace("@AssetB", market.assetB);
|
||||
function getFile(pFileStorage, pFileName, pFilePath, pPeriodName, pDatetime, innerCallBack, outerCallBack) {
|
||||
|
||||
pFilePath = pFilePath.replace("@Exchange", EXCHANGE_NAME);
|
||||
try {
|
||||
if (FULL_LOG === true) { logger.write("[INFO] initialize -> getFile -> Entering function."); }
|
||||
if (FULL_LOG === true) { logger.write("[INFO] initialize -> getFile -> pFileName = " + pFileName); }
|
||||
if (FULL_LOG === true) { logger.write("[INFO] initialize -> getFile -> pFilePath = " + pFilePath); }
|
||||
if (FULL_LOG === true) { logger.write("[INFO] initialize -> getFile -> pPeriodName = " + pPeriodName); }
|
||||
if (FULL_LOG === true) { logger.write("[INFO] initialize -> getFile -> pDatetime = " + pDatetime); }
|
||||
|
||||
pFileName = pFileName.replace("@AssetA", MARKET.assetA);
|
||||
pFileName = pFileName.replace("@AssetB", MARKET.assetB);
|
||||
|
||||
pFilePath = pFilePath.replace("@Exchange", global.EXCHANGE_NAME);
|
||||
pFilePath = pFilePath.replace("@Period", pPeriodName);
|
||||
|
||||
if (pDatetime !== undefined) {
|
||||
@@ -416,7 +424,7 @@
|
||||
|
||||
}
|
||||
|
||||
pFileService.getTextFile(pFilePath, pFileName, onFileReceived);
|
||||
pFileStorage.getTextFile(pFilePath, pFileName, onFileReceived);
|
||||
|
||||
function onFileReceived(err, text) {
|
||||
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@
|
||||
|
||||
try {
|
||||
let fs = require('fs');
|
||||
let filePath = '../' + 'API-Keys' + '/' + bot.codeName + '.' + EXCHANGE_NAME + '.json';
|
||||
let filePath = '../' + 'API-Keys' + '/' + bot.codeName + '.' + global.EXCHANGE_NAME + '.json';
|
||||
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
||||
}
|
||||
catch (err) {
|
||||
|
||||
@@ -66,21 +66,34 @@ process.on('exit', function (code) {
|
||||
logger.write('About to exit with code:' + code);
|
||||
});
|
||||
|
||||
/* Global constants definitions. */
|
||||
|
||||
/* Callbacks default responses. */
|
||||
|
||||
global.DEFAULT_OK_RESPONSE = {
|
||||
result: "Ok",
|
||||
message: "Operation Succeeded"
|
||||
};
|
||||
|
||||
global.global.DEFAULT_FAIL_RESPONSE = {
|
||||
global.DEFAULT_FAIL_RESPONSE = {
|
||||
result: "Fail",
|
||||
message: "Operation Failed"
|
||||
};
|
||||
|
||||
global.global.DEFAULT_RETRY_RESPONSE = {
|
||||
global.DEFAULT_RETRY_RESPONSE = {
|
||||
result: "Retry",
|
||||
message: "Retry Later"
|
||||
};
|
||||
|
||||
/* Current state of the art fixed parameters */
|
||||
|
||||
global.MARKET = {
|
||||
assetA: "USDT",
|
||||
assetB: "BTC",
|
||||
};
|
||||
|
||||
global.EXCHANGE_NAME = "Poloniex";
|
||||
|
||||
|
||||
|
||||
const START_ALL_MONTHS = false;
|
||||
|
||||
Reference in new issue
Block a user