Integration with saweb

This commit is contained in:
Matias committed 2019-06-17 21:07:03 -03:00
1 parent b2f3990edf
commit a4dbcfd25c
4 files changed
+35 -129

No files matched your search

+2 -46
View File
@@ -1,5 +1,4 @@
const axios = require('axios')
const auth = require('./utils/auth')
const strategy = require('./Integrations/Strategy')
exports.newCommons = function newCommons(bot, logger, UTILITIES) {
@@ -70,7 +69,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) {
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> Entering function."); }
let tradingSystem = await getTradingSystem();
let tradingSystem = await strategy.getStrategy();
/* Initial Default Values */
@@ -1837,49 +1836,6 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) {
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
async function getTradingSystem() {
try {
const accessToken = await auth.authenticate()
let fbSlug = bot.codeName
if (process.env.TEST_FB !== undefined) {
fbSlug = process.env.TEST_FB
}
const strategizerResponse = await axios({
url: process.env.GATEWAY_ENDPOINT,
method: 'post',
data: {
query: `
query($fbSlug: String!){
strategizer_TradingSystemByFb(fbSlug: $fbSlug){
id
fbSlug
data
}
}
`,
variables: {
fbSlug: fbSlug
},
},
headers: {
authorization: 'Bearer ' + accessToken
}
})
if (strategizerResponse.data.errors)
throw new Error(strategizerResponse.data.errors[0].message)
return strategizerResponse.data.data.strategizer_TradingSystemByFb.data;
} catch (error) {
throw new Error('There has been an error getting the strategy to run on the simulator. Error: ' + error)
}
}
};
+17 -22
View File
@@ -1,4 +1,4 @@
exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, BLOB_STORAGE, FILE_STORAGE) {
exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES) {
const FULL_LOG = true;
const LOG_FILE_CONTENT = false;
@@ -18,7 +18,9 @@
};
let utilities = UTILITIES.newCloudUtilities(bot, logger);
let thisBotStorage = BLOB_STORAGE.newBlobStorage(bot, logger);
const FILE_STORAGE = require('./Integrations/FileStorage.js');
let botStorage = FILE_STORAGE.newFileStorage();
let dataDependencies;
@@ -35,19 +37,8 @@
dataDependencies = pDataDependencies;
thisBotStorage.initialize(bot.devTeam, onStorageInizialized);
callBackFunction(global.DEFAULT_OK_RESPONSE);
function onStorageInizialized(err) {
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
callBackFunction(global.DEFAULT_OK_RESPONSE);
} else {
logger.write(MODULE_NAME, "[ERROR] initializeStorage -> onStorageInizialized -> err = " + err.stack);
callBackFunction(err);
}
}
} catch (err) {
logger.write(MODULE_NAME, "[ERROR] initialize -> err = " + err.stack);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
@@ -190,10 +181,11 @@
let dateForPath = currentDay.getUTCFullYear() + '/' + utilities.pad(currentDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(currentDay.getUTCDate(), 2);
let fileName = '' + market.assetA + '_' + market.assetB + '.json';
let filePathRoot = bot.devTeam + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.PLATFORM_CONFIG.codeName + "." + global.PLATFORM_CONFIG.version.major + "." + global.PLATFORM_CONFIG.version.minor + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion;
let filePathRoot = bot.devTeam + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion;
let filePath = filePathRoot + "/Output/" + SIMULATED_RECORDS_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + outputPeriodLabel + "/" + dateForPath;
filePath += '/' + fileName
thisBotStorage.createTextFile(filePath, fileName, fileContent + '\n', onFileCreated);
botStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated);
function onFileCreated(err) {
@@ -277,10 +269,11 @@
let dateForPath = currentDay.getUTCFullYear() + '/' + utilities.pad(currentDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(currentDay.getUTCDate(), 2);
let fileName = '' + market.assetA + '_' + market.assetB + '.json';
let filePathRoot = bot.devTeam + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.PLATFORM_CONFIG.codeName + "." + global.PLATFORM_CONFIG.version.major + "." + global.PLATFORM_CONFIG.version.minor + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion;
let filePathRoot = bot.devTeam + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion;
let filePath = filePathRoot + "/Output/" + CONDITIONS_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + outputPeriodLabel + "/" + dateForPath;
filePath += '/' + fileName
thisBotStorage.createTextFile(filePath, fileName, fileContent + '\n', onFileCreated);
botStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated);
function onFileCreated(err) {
@@ -353,10 +346,11 @@
let dateForPath = currentDay.getUTCFullYear() + '/' + utilities.pad(currentDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(currentDay.getUTCDate(), 2);
let fileName = '' + market.assetA + '_' + market.assetB + '.json';
let filePathRoot = bot.devTeam + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.PLATFORM_CONFIG.codeName + "." + global.PLATFORM_CONFIG.version.major + "." + global.PLATFORM_CONFIG.version.minor + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion;
let filePathRoot = bot.devTeam + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion;
let filePath = filePathRoot + "/Output/" + STRATEGIES_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + outputPeriodLabel + "/" + dateForPath;
filePath += '/' + fileName
thisBotStorage.createTextFile(filePath, fileName, fileContent + '\n', onFileCreated);
botStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated);
function onFileCreated(err) {
@@ -432,10 +426,11 @@
let dateForPath = currentDay.getUTCFullYear() + '/' + utilities.pad(currentDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(currentDay.getUTCDate(), 2);
let fileName = '' + market.assetA + '_' + market.assetB + '.json';
let filePathRoot = bot.devTeam + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.PLATFORM_CONFIG.codeName + "." + global.PLATFORM_CONFIG.version.major + "." + global.PLATFORM_CONFIG.version.minor + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion;
let filePathRoot = bot.devTeam + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion;
let filePath = filePathRoot + "/Output/" + TRADES_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + outputPeriodLabel + "/" + dateForPath;
filePath += '/' + fileName
thisBotStorage.createTextFile(filePath, fileName, fileContent + '\n', onFileCreated);
botStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated);
function onFileCreated(err) {
+16 -23
View File
@@ -1,4 +1,4 @@
exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, BLOB_STORAGE, FILE_STORAGE) {
exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES) {
const FULL_LOG = true;
const LOG_FILE_CONTENT = false;
@@ -17,8 +17,8 @@
start: start
};
let utilities = UTILITIES.newCloudUtilities(bot, logger);
let thisBotStorage = BLOB_STORAGE.newBlobStorage(bot, logger);
const FILE_STORAGE = require('./Integrations/FileStorage.js');
let botStorage = FILE_STORAGE.newFileStorage();
let dataDependencies;
@@ -35,19 +35,8 @@
dataDependencies = pDataDependencies;
thisBotStorage.initialize(bot.devTeam, onStorageInizialized);
callBackFunction(global.DEFAULT_OK_RESPONSE);
function onStorageInizialized(err) {
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
callBackFunction(global.DEFAULT_OK_RESPONSE);
} else {
logger.write(MODULE_NAME, "[ERROR] initializeStorage -> onStorageInizialized -> err = " + err.stack);
callBackFunction(err);
}
}
} catch (err) {
logger.write(MODULE_NAME, "[ERROR] initialize -> err = " + err.stack);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
@@ -187,10 +176,11 @@
let fileName = '' + market.assetA + '_' + market.assetB + '.json';
let filePathRoot = bot.devTeam + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.PLATFORM_CONFIG.codeName + "." + global.PLATFORM_CONFIG.version.major + "." + global.PLATFORM_CONFIG.version.minor + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion;
let filePathRoot = bot.devTeam + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion;
let filePath = filePathRoot + "/Output/" + SIMULATED_RECORDS_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + outputPeriodLabel;
filePath += '/' + fileName
thisBotStorage.createTextFile(filePath, fileName, fileContent + '\n', onFileCreated);
botStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated);
function onFileCreated(err) {
@@ -264,10 +254,11 @@
fileContent = "[" + JSON.stringify(tradingSystem) + "," + JSON.stringify(lastObjectsArray) + "," + fileContent + "]";
let fileName = '' + market.assetA + '_' + market.assetB + '.json';
let filePathRoot = bot.devTeam + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.PLATFORM_CONFIG.codeName + "." + global.PLATFORM_CONFIG.version.major + "." + global.PLATFORM_CONFIG.version.minor + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion;
let filePathRoot = bot.devTeam + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion;
let filePath = filePathRoot + "/Output/" + CONDITIONS_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + outputPeriodLabel;
filePath += '/' + fileName
thisBotStorage.createTextFile(filePath, fileName, fileContent + '\n', onFileCreated);
botStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated);
function onFileCreated(err) {
@@ -333,10 +324,11 @@
fileContent = "[" + fileContent + "]";
let fileName = '' + market.assetA + '_' + market.assetB + '.json';
let filePathRoot = bot.devTeam + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.PLATFORM_CONFIG.codeName + "." + global.PLATFORM_CONFIG.version.major + "." + global.PLATFORM_CONFIG.version.minor + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion;
let filePathRoot = bot.devTeam + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion;
let filePath = filePathRoot + "/Output/" + STRATEGIES_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + outputPeriodLabel;
filePath += '/' + fileName
thisBotStorage.createTextFile(filePath, fileName, fileContent + '\n', onFileCreated);
botStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated);
function onFileCreated(err) {
@@ -405,10 +397,11 @@
fileContent = "[" + fileContent + "]";
let fileName = '' + market.assetA + '_' + market.assetB + '.json';
let filePathRoot = bot.devTeam + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.PLATFORM_CONFIG.codeName + "." + global.PLATFORM_CONFIG.version.major + "." + global.PLATFORM_CONFIG.version.minor + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion;
let filePathRoot = bot.devTeam + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion;
let filePath = filePathRoot + "/Output/" + TRADES_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + outputPeriodLabel;
filePath += '/' + fileName
thisBotStorage.createTextFile(filePath, fileName, fileContent + '\n', onFileCreated);
botStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated);
function onFileCreated(err) {
-38
View File
@@ -14,25 +14,6 @@
{
"name": "Multi-Period-Market",
"description": "Produces a single file for each time period covering all the market.",
"startMode": {
"allMonths": {
"run": "false",
"minYear": "",
"maxYear": ""
},
"oneMonth": {
"run": "false",
"year": "",
"month": ""
},
"noTime": {
"run": "true"
},
"fixedInterval": {
"run": "false",
"interval": 0
}
},
"normalWaitTime": 60000,
"retryWaitTime": 10000,
"sleepWaitTime": 3600000,
@@ -129,25 +110,6 @@
{
"name": "Multi-Period-Daily",
"description": "Produces a Daily File at each time period.",
"startMode": {
"allMonths": {
"run": "false",
"minYear": "",
"maxYear": ""
},
"oneMonth": {
"run": "false",
"year": "",
"month": ""
},
"noTime": {
"run": "true"
},
"fixedInterval": {
"run": "false",
"interval": 0
}
},
"normalWaitTime": 60000,
"retryWaitTime": 10000,
"sleepWaitTime": 3600000,