Merge branch 'master' into 'develop'

Adding the copy of the simulator

See merge request advancedalgos/aaweb!5
This commit is contained in:
benme committed 2019-03-19 15:43:12 +00:00
commit 20e7a857da
6 files changed
+745 -33

No files matched your search

+188
View File
@@ -0,0 +1,188 @@
// let financialBeingsCopy = newFinancialBeingClone()
// const simulatorTemplatePath = "aaplatform/AATemplate/bots/AAJason-Indicator-Bot1";
// const blobName = "this.bot.config.json";
// financialBeingsCopy.copySimulator("team-a", "team a", "matias", "bot-a", "bot a")
// async function copySimulator(pTeamCodeName, pTeamDisplayName, pUserName, pBotCodeName, pBotDisplayName, pUserId) {
const {
Aborter,
BlobURL,
BlockBlobURL,
ContainerURL,
ServiceURL,
StorageURL,
SharedKeyCredential
} = require("@azure/storage-blob")
const beautify = require("json-beautify");
const { logger } = require('../logs/logger')
exports.newCopySimulator = function newCopySimulator() {
let thisObject = {
getFileContent: getFileContent,
writeFileContent: writeFileContent,
copySimulator: copySimulator,
removeSimulator: removeSimulator
}
let serviceURL = getServiceURL();
return thisObject;
function getServiceURL() {
// Enter your storage account name and shared key
const account = process.env.STORAGE_BASE_URL;
const accountKey = process.env.STORAGE_CONNECTION_STRING;
// Use SharedKeyCredential with storage account and account key
const sharedKeyCredential = new SharedKeyCredential(account, accountKey);
// Use sharedKeyCredential, tokenCredential or anonymousCredential to create a pipeline
const pipeline = StorageURL.newPipeline(sharedKeyCredential);
// List containers
const serviceURL = new ServiceURL(
// When using AnonymousCredential, following url should include a valid SAS or support public access
`https://${account}.blob.core.windows.net`,
pipeline
);
logger.info("Connected to te file Storage.")
return serviceURL
}
async function copySimulator(pTeamCodeName, pBotCodeName, pBotDisplayName) {
try {
logger.info('copySimulator started for bot %s', pBotCodeName)
let templatePath = "aaplatform/AATemplate/bots/AAJason-Indicator-Bot"
let commons = await getFileContent(templatePath, "Commons.js")
let config = await getFileContent(templatePath, "this.bot.config.json")
let codeDaily = await getFileContent(templatePath + "/Multi-Period-Daily", "User.Bot.js")
let codeMarket = await getFileContent(templatePath + "/Multi-Period-Market", "User.Bot.js")
// Change config to adapt the new indicator
let parsedConfig = JSON.parse(config)
parsedConfig.displayName = "Simulator " + pBotDisplayName;
parsedConfig.codeName = "simulator-" + pBotCodeName;
parsedConfig.devTeam = pTeamCodeName;
parsedConfig.profilePicture = pBotCodeName + ".png";
for (let i = 0; i < parsedConfig.processes[0].statusDependencies.length; i++) {
if (parsedConfig.processes[0].statusDependencies[i].devTeam === "AAMasters" &&
parsedConfig.processes[0].statusDependencies[i].bot === "AAJason") {
parsedConfig.processes[0].statusDependencies[i].devTeam = parsedConfig.devTeam;
parsedConfig.processes[0].statusDependencies[i].bot = parsedConfig.codeName;
}
}
for (let i = 0; i < parsedConfig.processes[1].statusDependencies.length; i++) {
if (parsedConfig.processes[1].statusDependencies[i].devTeam === "AAMasters" &&
parsedConfig.processes[1].statusDependencies[i].bot === "AAJason") {
parsedConfig.processes[1].statusDependencies[i].devTeam = parsedConfig.devTeam;
parsedConfig.processes[1].statusDependencies[i].bot = parsedConfig.codeName;
}
}
//Changing Indicator Output
parsedConfig.products[0].storageAccount = pTeamCodeName
parsedConfig.products[0].dataSets[0].filePath = pTeamCodeName + "/" + parsedConfig.codeName + ".1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Trading-Simulation/Multi-Period-Market/@Period"
parsedConfig.products[0].dataSets[1].filePath = pTeamCodeName + "/" + parsedConfig.codeName + ".1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Trading-Simulation/Multi-Period-Market/@Period"
parsedConfig.products[0].dataSets[1].dataRange.filePath = pTeamCodeName + "/" + parsedConfig.codeName + ".1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Trading-Simulation/Multi-Period-Market"
parsedConfig.products[1].storageAccount = pTeamCodeName
parsedConfig.products[1].dataSets[0].filePath = pTeamCodeName + "/" + parsedConfig.codeName + ".1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Conditions/Multi-Period-Market/@Period"
parsedConfig.products[1].dataSets[1].filePath = pTeamCodeName + "/" + parsedConfig.codeName + ".1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Conditions/Multi-Period-Market/@Period"
parsedConfig.products[1].dataSets[1].dataRange.filePath = pTeamCodeName + "/" + parsedConfig.codeName + ".1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Conditions/Multi-Period-Market"
// Write the new files
let newSimulatorName = pBotCodeName + "-Indicator-Bot"
let newSimulatorPath = "aaplatform/"+ pTeamCodeName + "/bots/" + newSimulatorName
await writeFileContent(newSimulatorPath, "Commons.js", commons)
await writeFileContent(newSimulatorPath, "this.bot.config.json", beautify(parsedConfig, null, 2, 80))
await writeFileContent(newSimulatorPath + "/Multi-Period-Daily", "User.Bot.js", codeDaily)
await writeFileContent(newSimulatorPath + "/Multi-Period-Market", "User.Bot.js", codeMarket)
logger.info('copySimulator completed for bot %s', pBotCodeName)
} catch (err) {
logger.error('copySimulator error for bot: %s, file: %s: %s', pBotCodeName, blobName, err)
throw err
}
}
async function removeSimulator(pTeamCodeName, pBotCodeName) {
try {
logger.info('removeSimulator started for bot %s', pBotCodeName)
// Delete simulator code
let newSimulatorName = "simulator-" + pBotCodeName + "-Indicator-Bot"
let newSimulatorPath = "aaplatform/"+ pTeamCodeName + "/bots/" + newSimulatorName
await deleteBlob(newSimulatorPath, "Commons.js")
await deleteBlob(newSimulatorPath, "this.bot.config.json")
await deleteBlob(newSimulatorPath + "/Multi-Period-Daily", "User.Bot.js")
await deleteBlob(newSimulatorPath + "/Multi-Period-Market", "User.Bot.js")
logger.info('removeSimulator completed for bot %s', pBotCodeName)
} catch (err) {
logger.error('copySimulator error for bot %s: %s', pBotCodeName, err)
throw err
}
}
async function getFileContent(containerName, blobName) {
const containerURL = ContainerURL.fromServiceURL(serviceURL, containerName)
const blockBlobURL = BlockBlobURL.fromContainerURL(containerURL, blobName)
let downloadResponse = await blockBlobURL.download(Aborter.none, 0)
return await streamToString(downloadResponse.readableStreamBody)
}
async function writeFileContent(containerName, blobName, content) {
const containerURL = ContainerURL.fromServiceURL(serviceURL, containerName)
const blobURL = BlobURL.fromContainerURL(containerURL, blobName)
const blockBlobURL = BlockBlobURL.fromBlobURL(blobURL)
await blockBlobURL.upload(
Aborter.none,
content,
content.length
)
}
async function deleteBlob(containerName, blobName) {
try{
const containerURL = ContainerURL.fromServiceURL(serviceURL, containerName)
const blockBlobURL = BlockBlobURL.fromContainerURL(containerURL, blobName)
await blockBlobURL.delete(Aborter.none)
} catch (err) {
logger.warn('Error deleting the file: %s%s', containerName, blobName)
}
}
async function deleteContainer(containerName) {
const containerURL = ContainerURL.fromServiceURL(serviceURL, containerName)
let containerRemoveResponse = await containerURL.delete(Aborter.none)
}
// A helper method used to read a Node.js readable stream into string
async function streamToString(readableStream) {
return new Promise((resolve, reject) => {
const chunks = [];
readableStream.on("data", data => {
chunks.push(data.toString());
});
readableStream.on("end", () => {
resolve(chunks.join(""));
});
readableStream.on("error", reject)
});
}
}
+50 -15
View File
@@ -2,7 +2,7 @@
let thisObject = {
newTeam: newTeam,
deleteTeam: deleteTeam,
deleteTeam: deleteTeam,
initialize: initialize
}
@@ -22,7 +22,7 @@
}
function newTeam(pTeamCodeName, pTeamDisplayName, pUserName, pBotCodeName, pBotDisplayName, pUserId, callBackFunction) {
try {
if (CONSOLE_LOG === true) { console.log("[INFO] TeamSetup -> newTeam -> Entering function."); }
@@ -203,7 +203,25 @@
botConfig.processes[0].statusDependencies[i].devTeam = pTeamCodeName;
botConfig.processes[0].statusDependencies[i].bot = pBotCodeName;
}
// Add a copy of the simulator indicator in the configuration
if ( botConfig.processes[0].statusDependencies[i].devTeam === "AAMasters" &&
botConfig.processes[0].statusDependencies[i].bot === "AAJason" ) {
botConfig.processes[0].statusDependencies[i].devTeam = pTeamCodeName;
botConfig.processes[0].statusDependencies[i].bot = "simulator-" + pBotCodeName;
}
}
for (let i = 0; i < botConfig.processes[0].dataDependencies.length; i++) {
// Add a copy of the simulator indicator in the configuration
if ( botConfig.processes[0].dataDependencies[i].devTeam === "AAMasters" &&
botConfig.processes[0].dataDependencies[i].bot === "AAJason" ) {
botConfig.processes[0].dataDependencies[i].devTeam = pTeamCodeName;
botConfig.processes[0].dataDependencies[i].bot = "simulator-" + pBotCodeName;
}
}
@@ -241,7 +259,7 @@
storage.writeData(team, filePath, fileName, fileContent, onDataWritten);
function onDataWritten(err) {
async function onDataWritten(err) {
try {
@@ -256,6 +274,10 @@
return;
}
const newCopySimulator = require("./CopySimulator")
let copySimulator = newCopySimulator.newCopySimulator()
await copySimulator.copySimulator(pTeamCodeName, pBotCodeName, pBotDisplayName)
forkAACloud();
} catch (err) {
@@ -599,6 +621,10 @@
{
"repo": pBotCodeName + "-Trading-Bot",
"configFile": "this.bot.config.json"
},
{
"repo": "simulator-"+ pBotCodeName + "-Indicator-Bot",
"configFile": "this.bot.config.json"
}
],
"plotters": []
@@ -606,6 +632,7 @@
ecosystem.devTeams.push(newTeam);
let fileContent = JSON.stringify(ecosystem);
storage.writeData("AdvancedAlgos", "AAPlatform", "ecosystem.json", fileContent, onDataWritten);
@@ -701,6 +728,8 @@
}
}
// TODO Fix-Me: this method is trying to remove from the container that was removed by the previous method.
// It must remove the files from the aaplatform/team-name folder instead
function deleteBotCode() {
try {
@@ -724,7 +753,7 @@
console.log("[ERROR] TeamSetup -> deleteTeam -> deleteBotCode -> onBlobDeleted -> Could not delete a file. ");
console.log("[ERROR] TeamSetup -> deleteTeam -> deleteBotCode -> onBlobDeleted -> err.message = " + err.message);
// Even if this failed we will try to delete the rest of the stuff related to the team.
// Even if this failed we will try to delete the rest of the stuff related to the team.
}
let team = pTeamCodeName;
@@ -744,7 +773,7 @@
console.log("[ERROR] TeamSetup -> deleteTeam -> deleteBotCode -> onBlobDeleted -> onBlobDeleted -> Could not delete a file. ");
console.log("[ERROR] TeamSetup -> deleteTeam -> deleteBotCode -> onBlobDeleted -> onBlobDeleted -> err.message = " + err.message);
// Even if this failed we will try to delete the rest of the stuff related to the team.
// Even if this failed we will try to delete the rest of the stuff related to the team.
}
deleteBotConfig();
@@ -771,11 +800,13 @@
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
// TODO Fix-Me: this method is trying to remove from the container that was removed by the previous method.
// It must remove the files from the aaplatform/team-name folder instead
function deleteBotConfig() {
try {
if (CONSOLE_LOG === true) { console.log("[INFO] TeamSetup -> deleteTeam -> deleteBotConfig -> Entering function."); }
@@ -797,7 +828,7 @@
console.log("[ERROR] TeamSetup -> deleteTeam -> deleteBotConfig -> onBlobDeleted -> Could not delete a file. ");
console.log("[ERROR] TeamSetup -> deleteTeam -> deleteBotConfig -> onBlobDeleted -> err.message = " + err.message);
// Even if this failed we will try to delete the rest of the stuff related to the team.
// Even if this failed we will try to delete the rest of the stuff related to the team.
}
let team = pTeamCodeName;
@@ -806,7 +837,7 @@
storage.deleteBlob(team, filePath, fileName, onBlobDeleted);
function onBlobDeleted(err) {
async function onBlobDeleted(err) {
try {
@@ -817,9 +848,13 @@
console.log("[ERROR] TeamSetup -> deleteTeam -> deleteBotConfig -> onBlobDeleted -> onBlobDeleted -> Could not delete a file. ");
console.log("[ERROR] TeamSetup -> deleteTeam -> deleteBotConfig -> onBlobDeleted -> onBlobDeleted -> err.message = " + err.message);
// Even if this failed we will try to delete the rest of the stuff related to the team.
// Even if this failed we will try to delete the rest of the stuff related to the team.
}
const newCopySimulator = require("./CopySimulator")
let copySimulator = newCopySimulator.newCopySimulator()
await copySimulator.removeSimulator(pTeamCodeName, pBotCodeName)
deleteAACloud();
} catch (err) {
@@ -844,7 +879,7 @@
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
function deleteAACloud() {
@@ -870,7 +905,7 @@
console.log("[ERROR] TeamSetup -> deleteTeam -> deleteAACloud -> onBlobDeleted -> Could not delete a file. ");
console.log("[ERROR] TeamSetup -> deleteTeam -> deleteAACloud -> onBlobDeleted -> err.message = " + err.message);
// Even if this failed we will try to delete the rest of the stuff related to the team.
// Even if this failed we will try to delete the rest of the stuff related to the team.
}
let team = pTeamCodeName;
@@ -890,7 +925,7 @@
console.log("[ERROR] TeamSetup -> deleteTeam -> deleteAACloud -> onBlobDeleted -> onBlobDeleted -> Could not delete a file. ");
console.log("[ERROR] TeamSetup -> deleteTeam -> deleteAACloud -> onBlobDeleted -> onBlobDeleted -> err.message = " + err.message);
// Even if this failed we will try to delete the rest of the stuff related to the team.
// Even if this failed we will try to delete the rest of the stuff related to the team.
}
removeFromSessions();
@@ -945,7 +980,7 @@
pFileContent = pFileContent.trim();
let sessions = JSON.parse(pFileContent);
for (let i = 0; i < sessions.length; i++) {
let session = sessions[i];
@@ -977,7 +1012,7 @@
console.log("[ERROR] TeamSetup -> deleteTeam -> removeFromSessions -> onDataRead -> onDataWritten -> Could not write a file. ");
console.log("[ERROR] TeamSetup -> deleteTeam -> removeFromSessions -> onDataRead -> onDataWritten -> err.message = " + err.message);
// Even if this failed we will try to delete the rest of the stuff related to the team.
// Even if this failed we will try to delete the rest of the stuff related to the team.
}
removeFromEcosystem();
+39
View File
@@ -0,0 +1,39 @@
const winston = require('winston')
const util = require('util')
const options = {
file: {
level: 'info',
filename: './logs/app.log',
handleExceptions: true,
json: true,
maxsize: 5242880, // 5MB
maxFiles: 5,
colorize: false,
timestamp: true
},
console: {
level: 'debug',
handleExceptions: true,
json: false,
colorize: true,
timestamp: true
}
}
exports.logger = winston.createLogger({
level: 'info',
format: winston.format.combine(
winston.format.colorize(),
winston.format.splat(),
winston.format.timestamp({ format: 'YY/MM/DD HH:mm' }),
winston.format.printf(
info => `${info.timestamp} - ${info.level}: ${JSON.parse(JSON.stringify(util.inspect(info.message)))}`
)
),
transports: [
// new winston.transports.File(options.file),
new winston.transports.Console(options.console)
],
exitOnError: false // do not exit on handled exceptions
})
+284
View File
@@ -4,6 +4,50 @@
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@azure/ms-rest-js": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/@azure/ms-rest-js/-/ms-rest-js-1.2.3.tgz",
"integrity": "sha512-eROQ034b+9v0Hd3wETKi/EwF5pqS3VRAk1Lm8iKVPOP8v30f6Zfzsi420MRfBMsbNCx/mE2N0L65Px7tvcGfVg==",
"requires": {
"axios": "^0.18.0",
"form-data": "^2.3.2",
"tough-cookie": "^2.4.3",
"tslib": "^1.9.2",
"uuid": "^3.2.1",
"xml2js": "^0.4.19"
},
"dependencies": {
"sax": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
"integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw=="
},
"xml2js": {
"version": "0.4.19",
"resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.19.tgz",
"integrity": "sha512-esZnJZJOiJR9wWKMyuvSE1y6Dq5LCuJanqhxslH2bxM6duahNZ+HMpCLhBQGZkbX6xRf8x1Y2eJlgt2q3qo49Q==",
"requires": {
"sax": ">=0.6.0",
"xmlbuilder": "~9.0.1"
}
},
"xmlbuilder": {
"version": "9.0.7",
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.7.tgz",
"integrity": "sha1-Ey7mPS7FVlxVfiD0wi35rKaGsQ0="
}
}
},
"@azure/storage-blob": {
"version": "10.3.0",
"resolved": "https://registry.npmjs.org/@azure/storage-blob/-/storage-blob-10.3.0.tgz",
"integrity": "sha512-KZbJ3q8RpAdeIB5Em1lgXkiq7Mll9bSHHbHavOFMepkkF7HQa3Sez9FdkAVIkVVWK5YoBlshBGZ+mtiSQiS9Fw==",
"requires": {
"@azure/ms-rest-js": "1.2.3",
"events": "3.0.0",
"tslib": "^1.9.3"
}
},
"@octokit/rest": {
"version": "14.0.9",
"resolved": "https://registry.npmjs.org/@octokit/rest/-/rest-14.0.9.tgz",
@@ -41,6 +85,14 @@
"resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz",
"integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU="
},
"async": {
"version": "2.6.2",
"resolved": "https://registry.npmjs.org/async/-/async-2.6.2.tgz",
"integrity": "sha512-H1qVYh1MYhEEFLsP97cVKqCGo7KfCyTt6uEWqsTBr9SO84oK9Uwbyd/yCW+6rKJLHksBNUVWZDAjfS+Ccx0Bbg==",
"requires": {
"lodash": "^4.17.11"
}
},
"asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
@@ -185,6 +237,56 @@
"resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz",
"integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ="
},
"color": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/color/-/color-3.0.0.tgz",
"integrity": "sha512-jCpd5+s0s0t7p3pHQKpnJ0TpQKKdleP71LWcA0aqiljpiuAkOSUFN/dyH8ZwF0hRmFlrIuRhufds1QyEP9EB+w==",
"requires": {
"color-convert": "^1.9.1",
"color-string": "^1.5.2"
}
},
"color-convert": {
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
"integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
"requires": {
"color-name": "1.1.3"
}
},
"color-name": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU="
},
"color-string": {
"version": "1.5.3",
"resolved": "https://registry.npmjs.org/color-string/-/color-string-1.5.3.tgz",
"integrity": "sha512-dC2C5qeWoYkxki5UAXapdjqO672AM4vZuPGRQfO8b5HKuKGBbKWpITyDYN7TOFKvRW7kOgAn3746clDBMDJyQw==",
"requires": {
"color-name": "^1.0.0",
"simple-swizzle": "^0.2.2"
}
},
"colornames": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/colornames/-/colornames-1.1.1.tgz",
"integrity": "sha1-+IiQMGhcfE/54qVZ9Qd+t2qBb5Y="
},
"colors": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/colors/-/colors-1.3.3.tgz",
"integrity": "sha512-mmGt/1pZqYRjMxB1axhTo16/snVZ5krrKkcmMeVKxzECMMXoCgnvTPp10QgHfcbQZw8Dq2jMNG6je4JlWU0gWg=="
},
"colorspace": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/colorspace/-/colorspace-1.1.1.tgz",
"integrity": "sha512-pI3btWyiuz7Ken0BWh9Elzsmv2bM9AhA7psXib4anUXy/orfZ/E0MbQwhSOG/9L8hLlalqrU0UhOuqxW1YjmVw==",
"requires": {
"color": "3.0.x",
"text-hex": "1.0.x"
}
},
"combined-stream": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.7.tgz",
@@ -237,6 +339,16 @@
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
},
"diagnostics": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/diagnostics/-/diagnostics-1.1.1.tgz",
"integrity": "sha512-8wn1PmdunLJ9Tqbx+Fx/ZEuHfJf4NKSN2ZBj7SJC/OWRWha843+WsTjqMe1B5E3p28jqBlp+mJ2fPVxPyNgYKQ==",
"requires": {
"colorspace": "1.1.x",
"enabled": "1.0.x",
"kuler": "1.0.x"
}
},
"dotenv": {
"version": "6.2.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-6.2.0.tgz",
@@ -252,6 +364,14 @@
"safer-buffer": "^2.1.0"
}
},
"enabled": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/enabled/-/enabled-1.0.2.tgz",
"integrity": "sha1-ll9lE9LC0cX0ZStkouM5ZGf8L5M=",
"requires": {
"env-variable": "0.0.x"
}
},
"encoding": {
"version": "0.1.12",
"resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.12.tgz",
@@ -260,6 +380,16 @@
"iconv-lite": "~0.4.13"
}
},
"env-variable": {
"version": "0.0.5",
"resolved": "https://registry.npmjs.org/env-variable/-/env-variable-0.0.5.tgz",
"integrity": "sha512-zoB603vQReOFvTg5xMl9I1P2PnHsHQQKTEowsKKD7nseUfJq6UWzK+4YtlWUO1nhiQUxe6XMkk+JleSZD1NZFA=="
},
"events": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/events/-/events-3.0.0.tgz",
"integrity": "sha512-Dc381HFWJzEOhQ+d8pkNon++bk9h6cdAoAj4iE6Q4y6xgTzySWXlKn05/TVNpjnfRqi/X0EpJEJohPjNI3zpVA=="
},
"extend": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/extend/-/extend-1.2.1.tgz",
@@ -280,6 +410,16 @@
"resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz",
"integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I="
},
"fast-safe-stringify": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.0.6.tgz",
"integrity": "sha512-q8BZ89jjc+mz08rSxROs8VsrBBcn1SIw1kq9NjolL509tkABRk9io01RAjSaEv1Xb2uFLt8VtRiZbGp5H8iDtg=="
},
"fecha": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/fecha/-/fecha-2.3.3.tgz",
"integrity": "sha512-lUGBnIamTAwk4znq5BcqsDaxSmZ9nDVJaij6NvRt/Tg4R69gERA+otPKbS86ROw9nxVMw2/mp1fnaiWqbs6Sdg=="
},
"follow-redirects": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.7.0.tgz",
@@ -419,6 +559,11 @@
"resolved": "https://registry.npmjs.org/is-array-buffer/-/is-array-buffer-1.0.0.tgz",
"integrity": "sha512-KtzJzWuC1kZQ377GJbEsoBh0LuQh1uaZnQg8oL2LcDkY/Ny8rpAzu21Ls3oph3SEKXbnrLHt3rAUVm28iuEPfw=="
},
"is-arrayish": {
"version": "0.3.2",
"resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.3.2.tgz",
"integrity": "sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ=="
},
"is-buffer": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
@@ -464,6 +609,11 @@
"integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=",
"optional": true
},
"json-beautify": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/json-beautify/-/json-beautify-1.0.1.tgz",
"integrity": "sha1-WYtQ1Mjqm4/KWru0C34svTrUwvw="
},
"json-edm-parser": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/json-edm-parser/-/json-edm-parser-0.1.2.tgz",
@@ -503,11 +653,38 @@
"verror": "1.10.0"
}
},
"kuler": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/kuler/-/kuler-1.0.1.tgz",
"integrity": "sha512-J9nVUucG1p/skKul6DU3PUZrhs0LPulNaeUOox0IyXDi8S4CztTHs1gQphhuZmzXG7VOQSf6NJfKuzteQLv9gQ==",
"requires": {
"colornames": "^1.1.1"
}
},
"lodash": {
"version": "4.17.11",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz",
"integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg=="
},
"logform": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/logform/-/logform-2.1.2.tgz",
"integrity": "sha512-+lZh4OpERDBLqjiwDLpAWNQu6KMjnlXH2ByZwCuSqVPJletw0kTWJf5CgSNAUKn1KUkv3m2cUz/LK8zyEy7wzQ==",
"requires": {
"colors": "^1.2.1",
"fast-safe-stringify": "^2.0.4",
"fecha": "^2.3.3",
"ms": "^2.1.1",
"triple-beam": "^1.3.0"
},
"dependencies": {
"ms": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz",
"integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg=="
}
}
},
"md5.js": {
"version": "1.3.4",
"resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.4.tgz",
@@ -554,6 +731,11 @@
"resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz",
"integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ=="
},
"one-time": {
"version": "0.0.4",
"resolved": "https://registry.npmjs.org/one-time/-/one-time-0.0.4.tgz",
"integrity": "sha1-+M33eISCb+Tf+T46nMN7HkSAdC4="
},
"performance-now": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
@@ -651,6 +833,14 @@
"resolved": "https://registry.npmjs.org/sax/-/sax-0.5.8.tgz",
"integrity": "sha1-1HLbIo6zMcJQaw6MFVJK25OdEsE="
},
"simple-swizzle": {
"version": "0.2.2",
"resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz",
"integrity": "sha1-pNprY1/8zMoz9w0Xy5JZLeleVXo=",
"requires": {
"is-arrayish": "^0.3.1"
}
},
"sntp": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/sntp/-/sntp-2.1.0.tgz",
@@ -675,6 +865,11 @@
"tweetnacl": "~0.14.0"
}
},
"stack-trace": {
"version": "0.0.10",
"resolved": "https://registry.npmjs.org/stack-trace/-/stack-trace-0.0.10.tgz",
"integrity": "sha1-VHxws0fo0ytOEI6hoqFZ5f3eGcA="
},
"string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
@@ -685,6 +880,11 @@
"resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.6.tgz",
"integrity": "sha512-87GEBAkegbBcweToUrdzf3eLhWNg06FJTebl4BVJz/JgWy8CvEr9dRtX5qWphiynMSQlxxi+QqN0z5T32SLlhA=="
},
"text-hex": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/text-hex/-/text-hex-1.0.0.tgz",
"integrity": "sha512-uuVGNWzgJ4yhRaNSiubPY7OjISw4sw4E5Uv0wbjp+OzcbmVU/rsT8ujgcXJhn9ypzsgr5vlzpPqP+MBBKcGvbg=="
},
"tough-cookie": {
"version": "2.4.3",
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.4.3.tgz",
@@ -694,6 +894,16 @@
"punycode": "^1.4.1"
}
},
"triple-beam": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/triple-beam/-/triple-beam-1.3.0.tgz",
"integrity": "sha512-XrHUvV5HpdLmIj4uVMxHggLbFSZYIn7HEWsqePZcI50pco+MPqJ50wMGY794X7AOOhxOBAjbkqfAbEe/QMp2Lw=="
},
"tslib": {
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz",
"integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ=="
},
"tunnel-agent": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz",
@@ -748,6 +958,80 @@
"resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.0.0.tgz",
"integrity": "sha512-9GSJUgz1D4MfyKU7KRqwOjXCXTqWdFNvEr7eUBYchQiVc744mqK/MzXPNR2WsPkmkOa4ywfg8C2n8h+13Bey1Q=="
},
"winston": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/winston/-/winston-3.2.1.tgz",
"integrity": "sha512-zU6vgnS9dAWCEKg/QYigd6cgMVVNwyTzKs81XZtTFuRwJOcDdBg7AU0mXVyNbs7O5RH2zdv+BdNZUlx7mXPuOw==",
"requires": {
"async": "^2.6.1",
"diagnostics": "^1.1.1",
"is-stream": "^1.1.0",
"logform": "^2.1.1",
"one-time": "0.0.4",
"readable-stream": "^3.1.1",
"stack-trace": "0.0.x",
"triple-beam": "^1.3.0",
"winston-transport": "^4.3.0"
},
"dependencies": {
"readable-stream": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.2.0.tgz",
"integrity": "sha512-RV20kLjdmpZuTF1INEb9IA3L68Nmi+Ri7ppZqo78wj//Pn62fCoJyV9zalccNzDD/OuJpMG4f+pfMl8+L6QdGw==",
"requires": {
"inherits": "^2.0.3",
"string_decoder": "^1.1.1",
"util-deprecate": "^1.0.1"
}
},
"string_decoder": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.2.0.tgz",
"integrity": "sha512-6YqyX6ZWEYguAxgZzHGL7SsCeGx3V2TtOTqZz1xSTSWnqsbWwbptafNyvf/ACquZUXV3DANr5BDIwNYe1mN42w==",
"requires": {
"safe-buffer": "~5.1.0"
}
}
}
},
"winston-transport": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/winston-transport/-/winston-transport-4.3.0.tgz",
"integrity": "sha512-B2wPuwUi3vhzn/51Uukcao4dIduEiPOcOt9HJ3QeaXgkJ5Z7UwpBzxS4ZGNHtrxrUvTwemsQiSys0ihOf8Mp1A==",
"requires": {
"readable-stream": "^2.3.6",
"triple-beam": "^1.2.0"
},
"dependencies": {
"process-nextick-args": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz",
"integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw=="
},
"readable-stream": {
"version": "2.3.6",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz",
"integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==",
"requires": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.3",
"isarray": "~1.0.0",
"process-nextick-args": "~2.0.0",
"safe-buffer": "~5.1.1",
"string_decoder": "~1.1.1",
"util-deprecate": "~1.0.1"
}
},
"string_decoder": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
"integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
"requires": {
"safe-buffer": "~5.1.0"
}
}
}
},
"xml2js": {
"version": "0.2.8",
"resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.2.8.tgz",
+4 -1
View File
@@ -7,6 +7,7 @@
"name": "Luis-Fernando-Molina"
},
"dependencies": {
"@azure/storage-blob": "^10.3.0",
"@octokit/rest": "^14.0.9",
"atob": "^2.1.1",
"axios": "^0.18.0",
@@ -14,9 +15,11 @@
"dotenv": "^6.2.0",
"graphql": "^14.0.2",
"graphql-client": "^2.0.1",
"json-beautify": "^1.0.1",
"lodash": "^4.17.11",
"nonce": "^1.0.4",
"request": "^2.88.0",
"retry": "^0.12.0"
"retry": "^0.12.0",
"winston": "^3.2.1"
}
}
+180 -17
View File
@@ -1,4 +1,6 @@
require('dotenv').config()
/* These 2 are global variables, that is why they do not have a let or var */
CONSOLE_LOG = true
@@ -509,8 +511,69 @@ function onBrowserRequest (request, response) {
respondWithContent(JSON.stringify(responseToBrowser), response)
}
break
}
break;
}
case "authenticateUser": {
const AABROWSER_API_USER_AUTHENTICATION = require('./AABrowserAPI/' + 'UserAuthentication');
let userAuthentication = AABROWSER_API_USER_AUTHENTICATION.newUserAuthentication();
userAuthentication.initialize(sessionManager, storageAccessManager);
userAuthentication.authenticateUser(requestParameters[3], onFinish);
function onFinish(err, pUserProfile) {
let responseToBrowser = {
err: err,
userProfile: pUserProfile
};
respondWithContent(JSON.stringify(responseToBrowser), response);
}
break;
}
case "newTeam": {
const AABROWSER_API_TEAM_SETUP = require('./AABrowserAPI/' + 'TeamSetup');
let teamSetup = AABROWSER_API_TEAM_SETUP.newTeamSetup();
teamSetup.initialize(serverConfig);
let devTeamCodeName = decodeURI(requestParameters[3]);
let devTeamDisplayName = decodeURI(requestParameters[4]);
let userName = decodeURI(requestParameters[5]);
let botCodeName = decodeURI(requestParameters[6]);
let botDisplayName = decodeURI(requestParameters[7]);
let userId = decodeURI(requestParameters[8]);
let sharedSecret = decodeURI(requestParameters[9]);
if (sharedSecret !== serverConfig.newTeamSharedSecret) {
let customFailResponse = {
result: global.DEFAULT_FAIL_RESPONSE.result,
message: "The shared secret provided is incorrect"
}
respondWithContent(JSON.stringify(customFailResponse), response);
if (CONSOLE_LOG === true) { console.log("[WARN] server -> AABrowserAPI -> newTeam -> Shared Secret Received Incorrect."); }
return;
}
teamSetup.newTeam(devTeamCodeName, devTeamDisplayName, userName, botCodeName, botDisplayName, userId, onSetupFinished);
function onSetupFinished(err) {
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
/* We must re-load all the webserver caches.*/
initialize();
case 'newTeam': {
const AABROWSER_API_TEAM_SETUP = require('./AABrowserAPI/' + 'TeamSetup')
@@ -708,24 +771,124 @@ function onBrowserRequest (request, response) {
case 'ExchangeAPI': // This is trying to access this library functionality from the broser.
{
/* We are going to let access the exchange only to authenticated users, that measn that we need the a valid session token. */
let authToken = requestParameters[3]
let authToken = requestParameters[3];
if (authToken !== undefined) {
global.CURRENT_EXECUTION_AT = 'Browser'
global.GATEWAY_ENDPOINT = serverConfig.masterAppServerURL
if (authToken !== undefined) {
global.CURRENT_EXECUTION_AT = "Browser"
global.GATEWAY_ENDPOINT = serverConfig.masterAppServerURL
global.MARKET = {
assetA: 'USDT',
assetB: 'BTC'
}
global.MARKET = {
assetA: "USDT",
assetB: "BTC"
};
global.LOG_CONTROL = {
'Exchange API': {
logInfo: true,
logWarnings: false,
logErrors: true,
logContent: false,
intensiveLogging: false
global.LOG_CONTROL = {
"Exchange API": {
logInfo: true,
logWarnings: false,
logErrors: true,
logContent: false,
intensiveLogging: false
}
}
let logger = {
write: function (moduleName, message) {
console.log(moduleName + " " + message);
}
}
const EXCHANGE_API = require('./Server/Exchange/ExchangeAPI');
let exchangeAPI = EXCHANGE_API.newExchangeAPI(logger, authToken);
exchangeAPI.initialize(onInizialized);
function onInizialized(err) {
if (CONSOLE_LOG === true) { console.log("[INFO] server -> onBrowserRequest -> ExchangeAPI -> onInizialized -> Entering function."); }
switch (err.result) {
case global.DEFAULT_OK_RESPONSE.result: {
if (CONSOLE_LOG === true) { console.log("[INFO] server -> onBrowserRequest -> ExchangeAPI -> onInizialized -> Execution finished well."); }
callExchangeAPIMethod();
return;
}
case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time.
console.log("[ERROR] server -> onBrowserRequest -> ExchangeAPI -> onInizialized -> Retry Later. Requesting Execution Retry.");
respondWithContent("", response);
return;
}
case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle.
console.log("[ERROR] server -> onBrowserRequest -> ExchangeAPI -> onInizialized -> Operation Failed. Aborting the process.");
respondWithContent("", response);
return;
}
}
}
function callExchangeAPIMethod() {
switch (requestParameters[2]) {
case "getTicker": {
exchangeAPI.getTicker(global.MARKET, onExchangeResponse);
break;
}
case "getOpenPositions": {
exchangeAPI.getOpenPositions(global.MARKET, onExchangeResponse);
break;
}
case "getExecutedTrades": {
exchangeAPI.getExecutedTrades(requestParameters[4], onExchangeResponse);
break;
}
case "putPosition": {
exchangeAPI.putPosition(global.MARKET, requestParameters[4], requestParameters[5], requestParameters[6], requestParameters[7], onExchangeResponse);
break;
}
case "movePosition": {
exchangeAPI.moveOrder(requestParameters[4], requestParameters[5], requestParameters[6], onExchangeResponse);
break;
}
case "getPublicTradeHistory": {
exchangeAPI.getPublicTradeHistory(global.MARKET, requestParameters[4], requestParameters[5], requestParameters[6], onExchangeResponse);
break;
}
case "initialize": {
onExchangeResponse(global.DEFAULT_OK_RESPONSE);
break;
}
}
}
function onExchangeResponse(err, exchangeResponse) {
/* Delete these secrets before they get logged. */
requestParameters[4] = "";
if (err.result === global.DEFAULT_OK_RESPONSE.result)
respondWithContent(JSON.stringify(exchangeResponse), response);
else
respondWithContent(JSON.stringify(err), response);
}
return;
}
else {
let customResponse = {
result: global.CUSTOM_FAIL_RESPONSE.result,
message: "You are not logged in."
};
respondWithContent(JSON.stringify(customResponse), response);
}
}
}