Merge Complete
This commit is contained in:
1 parent
482ef7a81a
commit
dabe23d505
6483 files changed
No files matched your search
@@ -0,0 +1,58 @@
|
||||
import 'dotenv/config';
|
||||
import express from 'express';
|
||||
import { ApolloServer } from 'apollo-server-express';
|
||||
import schema from './schema';
|
||||
import wrongPreshared from './errors/notAllowed.json';
|
||||
import db from './db';
|
||||
import logger from './utils/logger'
|
||||
import bodyParser from 'body-parser'
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use(bodyParser.json({limit: '50mb'}));
|
||||
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
|
||||
|
||||
app.post('/graphql', (req, res, next) => {
|
||||
if (req.headers.preshared === process.env.PRESHARED_GATEWAY_KEY) {
|
||||
next();
|
||||
} else {
|
||||
res.send(wrongPreshared);
|
||||
}
|
||||
});
|
||||
|
||||
// Starting the graphql server
|
||||
const server = new ApolloServer({
|
||||
schema,
|
||||
playground: {
|
||||
settings: {
|
||||
'editor.theme': 'dark',
|
||||
'editor.cursorShape': 'line',
|
||||
},
|
||||
},
|
||||
context: ({ req }) => ({
|
||||
userId: req.headers.userid,
|
||||
authorization: req.headers.authorization,
|
||||
}),
|
||||
formatError: error => ({
|
||||
code: error.extensions.exception.code,
|
||||
message: error.message,
|
||||
path: error.path,
|
||||
}),
|
||||
introspection: true,
|
||||
});
|
||||
|
||||
server.applyMiddleware({
|
||||
app,
|
||||
cors: true,
|
||||
});
|
||||
|
||||
db.on('error', (err) => {
|
||||
logger.error(err);
|
||||
});
|
||||
db.once('open', () => {
|
||||
logger.info('Connected to the DB.');
|
||||
});
|
||||
|
||||
app.listen(process.env.PORT, () => {
|
||||
logger.info(`Listening on port ${process.env.PORT}`);
|
||||
});
|
||||
@@ -0,0 +1,892 @@
|
||||
{
|
||||
"authId": "",
|
||||
"devTeams": [
|
||||
{
|
||||
"codeName": "AAMasters",
|
||||
"displayName": "Masters",
|
||||
"host": {
|
||||
"url": "https://demo-api-dev.superalgos.org/",
|
||||
"storage": "localStorage",
|
||||
"container": "aamasters",
|
||||
"accessKey": "09e890b76767ede3e10f0526b5036600a6b8d3faac540336e12b493fdb2aa9ed46f86094c34652f99fb6322e5f09806412f17725807f85e4dc4169bd22dd59f0b23aba5251f5544478a1aabf5a2dea5260e6eb0c29af3a788208af85025a02f94950437d501b91fd55b9d97b3d6ac3af4e1161321f78b73ca0fda524dc3a5d03"
|
||||
},
|
||||
"bots": [
|
||||
{
|
||||
"codeName": "AAOlivia",
|
||||
"displayName": "Olivia",
|
||||
"type": "Indicator",
|
||||
"profilePicture": "Olivia.png",
|
||||
"repo": "AAOlivia-Indicator-Bot",
|
||||
"configFile": "this.bot.config.json",
|
||||
"products": [
|
||||
{
|
||||
"codeName": "Candles",
|
||||
"displayName": "Candles",
|
||||
"description": "Two sets of files per period that contains candles.",
|
||||
"dataSets": [
|
||||
{
|
||||
"codeName": "Multi-Period-Market",
|
||||
"type": "Market Files",
|
||||
"validPeriods": [
|
||||
"24-hs",
|
||||
"12-hs",
|
||||
"08-hs",
|
||||
"06-hs",
|
||||
"04-hs",
|
||||
"03-hs",
|
||||
"02-hs",
|
||||
"01-hs"
|
||||
],
|
||||
"filePath": "AAMasters/AAOlivia.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Candles/Multi-Period-Market/@Period",
|
||||
"fileName": "@AssetA_@AssetB.json"
|
||||
},
|
||||
{
|
||||
"codeName": "Multi-Period-Daily",
|
||||
"type": "Daily Files",
|
||||
"validPeriods": [
|
||||
"45-min",
|
||||
"40-min",
|
||||
"30-min",
|
||||
"20-min",
|
||||
"15-min",
|
||||
"10-min",
|
||||
"05-min",
|
||||
"04-min",
|
||||
"03-min",
|
||||
"02-min",
|
||||
"01-min"
|
||||
],
|
||||
"filePath": "AAMasters/AAOlivia.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Candles/Multi-Period-Daily/@Period/@Year/@Month/@Day",
|
||||
"fileName": "@AssetA_@AssetB.json",
|
||||
"dataRange": {
|
||||
"filePath": "AAMasters/AAOlivia.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Candles/Multi-Period-Daily",
|
||||
"fileName": "Data.Range.@AssetA_@AssetB.json"
|
||||
}
|
||||
}
|
||||
],
|
||||
"exchangeList": [
|
||||
{
|
||||
"name": "Poloniex"
|
||||
},
|
||||
{
|
||||
"name": "Coss"
|
||||
}
|
||||
],
|
||||
"plotter": {
|
||||
"devTeam": "AAMasters",
|
||||
"codeName": "PlottersCandlesVolumes",
|
||||
"moduleName": "Candles"
|
||||
}
|
||||
},
|
||||
{
|
||||
"codeName": "Volumes",
|
||||
"displayName": "Buy and Sell Volumes",
|
||||
"description": "Two sets of files per period that contains buy and sell volumes.",
|
||||
"dataSets": [
|
||||
{
|
||||
"codeName": "Multi-Period-Market",
|
||||
"type": "Market Files",
|
||||
"validPeriods": [
|
||||
"24-hs",
|
||||
"12-hs",
|
||||
"08-hs",
|
||||
"06-hs",
|
||||
"04-hs",
|
||||
"03-hs",
|
||||
"02-hs",
|
||||
"01-hs"
|
||||
],
|
||||
"filePath": "AAMasters/AAOlivia.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Volumes/Multi-Period-Market/@Period",
|
||||
"fileName": "@AssetA_@AssetB.json"
|
||||
},
|
||||
{
|
||||
"codeName": "Multi-Period-Daily",
|
||||
"type": "Daily Files",
|
||||
"validPeriods": [
|
||||
"45-min",
|
||||
"40-min",
|
||||
"30-min",
|
||||
"20-min",
|
||||
"15-min",
|
||||
"10-min",
|
||||
"05-min",
|
||||
"04-min",
|
||||
"03-min",
|
||||
"02-min",
|
||||
"01-min"
|
||||
],
|
||||
"filePath": "AAMasters/AAOlivia.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Volumes/Multi-Period-Daily/@Period/@Year/@Month/@Day",
|
||||
"fileName": "@AssetA_@AssetB.json",
|
||||
"dataRange": {
|
||||
"filePath": "AAMasters/AAOlivia.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Volumes/Multi-Period-Daily",
|
||||
"fileName": "Data.Range.@AssetA_@AssetB.json"
|
||||
}
|
||||
}
|
||||
],
|
||||
"exchangeList": [
|
||||
{
|
||||
"name": "Poloniex"
|
||||
},
|
||||
{
|
||||
"name": "Coss"
|
||||
}
|
||||
],
|
||||
"plotter": {
|
||||
"devTeam": "AAMasters",
|
||||
"codeName": "PlottersCandlesVolumes",
|
||||
"moduleName": "Volumes"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"codeName": "AATom",
|
||||
"displayName": "Tom",
|
||||
"type": "Indicator",
|
||||
"profilePicture": "Tom.png",
|
||||
"repo": "AATom-Indicator-Bot",
|
||||
"configFile": "this.bot.config.json",
|
||||
"products": [
|
||||
{
|
||||
"codeName": "Candle-Stairs",
|
||||
"displayName": "Candle-Stairs Patters",
|
||||
"description": "Two sets of files per period that contains candle-stairs patterns.",
|
||||
"dataSets": [
|
||||
{
|
||||
"codeName": "Multi-Period-Market",
|
||||
"type": "Market Files",
|
||||
"validPeriods": [
|
||||
"24-hs",
|
||||
"12-hs",
|
||||
"08-hs",
|
||||
"06-hs",
|
||||
"04-hs",
|
||||
"03-hs",
|
||||
"02-hs",
|
||||
"01-hs"
|
||||
],
|
||||
"filePath": "AAMasters/AATom.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Candle-Stairs/Multi-Period-Market/@Period",
|
||||
"fileName": "@AssetA_@AssetB.json"
|
||||
},
|
||||
{
|
||||
"codeName": "Multi-Period-Daily",
|
||||
"type": "Daily Files",
|
||||
"validPeriods": [
|
||||
"45-min",
|
||||
"40-min",
|
||||
"30-min",
|
||||
"20-min",
|
||||
"15-min",
|
||||
"10-min",
|
||||
"05-min",
|
||||
"04-min",
|
||||
"03-min",
|
||||
"02-min",
|
||||
"01-min"
|
||||
],
|
||||
"filePath": "AAMasters/AATom.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Candle-Stairs/Multi-Period-Daily/@Period/@Year/@Month/@Day",
|
||||
"fileName": "@AssetA_@AssetB.json",
|
||||
"dataRange": {
|
||||
"filePath": "AAMasters/AATom.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Candle-Stairs/Multi-Period-Daily",
|
||||
"fileName": "Data.Range.@AssetA_@AssetB.json"
|
||||
}
|
||||
}
|
||||
],
|
||||
"exchangeList": [
|
||||
{
|
||||
"name": "Poloniex"
|
||||
},
|
||||
{
|
||||
"name": "Coss"
|
||||
}
|
||||
],
|
||||
"plotter": {
|
||||
"devTeam": "AAMasters",
|
||||
"codeName": "PlottersStairsPatterns",
|
||||
"moduleName": "CandleStairs"
|
||||
}
|
||||
},
|
||||
{
|
||||
"codeName": "Volume-Stairs",
|
||||
"displayName": "Volume-Stairs Patters",
|
||||
"description": "Two sets of files per period that contains volume-stairs patterns.",
|
||||
"dataSets": [
|
||||
{
|
||||
"codeName": "Multi-Period-Market",
|
||||
"type": "Market Files",
|
||||
"validPeriods": [
|
||||
"24-hs",
|
||||
"12-hs",
|
||||
"08-hs",
|
||||
"06-hs",
|
||||
"04-hs",
|
||||
"03-hs",
|
||||
"02-hs",
|
||||
"01-hs"
|
||||
],
|
||||
"filePath": "AAMasters/AATom.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Volume-Stairs/Multi-Period-Market/@Period",
|
||||
"fileName": "@AssetA_@AssetB.json"
|
||||
},
|
||||
{
|
||||
"codeName": "Multi-Period-Daily",
|
||||
"type": "Daily Files",
|
||||
"validPeriods": [
|
||||
"45-min",
|
||||
"40-min",
|
||||
"30-min",
|
||||
"20-min",
|
||||
"15-min",
|
||||
"10-min",
|
||||
"05-min",
|
||||
"04-min",
|
||||
"03-min",
|
||||
"02-min",
|
||||
"01-min"
|
||||
],
|
||||
"filePath": "AAMasters/AATom.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Volume-Stairs/Multi-Period-Daily/@Period/@Year/@Month/@Day",
|
||||
"fileName": "@AssetA_@AssetB.json",
|
||||
"dataRange": {
|
||||
"filePath": "AAMasters/AATom.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Volume-Stairs/Multi-Period-Daily",
|
||||
"fileName": "Data.Range.@AssetA_@AssetB.json"
|
||||
}
|
||||
}
|
||||
],
|
||||
"exchangeList": [
|
||||
{
|
||||
"name": "Poloniex"
|
||||
},
|
||||
{
|
||||
"name": "Coss"
|
||||
}
|
||||
],
|
||||
"plotter": {
|
||||
"devTeam": "AAMasters",
|
||||
"codeName": "PlottersStairsPatterns",
|
||||
"moduleName": "VolumeStairs"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"codeName": "AAChris",
|
||||
"displayName": "Chris",
|
||||
"type": "Indicator",
|
||||
"profilePicture": "Chris.png",
|
||||
"repo": "AAChris-Indicator-Bot",
|
||||
"configFile": "this.bot.config.json",
|
||||
"products": [
|
||||
{
|
||||
"codeName": "Bollinger-Bands",
|
||||
"displayName": "Bollinger Bands",
|
||||
"description": "Bollinger Bands",
|
||||
"dataSets": [
|
||||
{
|
||||
"codeName": "Multi-Period-Market",
|
||||
"type": "Market Files",
|
||||
"validPeriods": [
|
||||
"24-hs",
|
||||
"12-hs",
|
||||
"08-hs",
|
||||
"06-hs",
|
||||
"04-hs",
|
||||
"03-hs",
|
||||
"02-hs",
|
||||
"01-hs"
|
||||
],
|
||||
"filePath": "AAMasters/AAChris.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Bollinger-Bands/Multi-Period-Market/@Period",
|
||||
"fileName": "@AssetA_@AssetB.json"
|
||||
},
|
||||
{
|
||||
"codeName": "Multi-Period-Daily",
|
||||
"type": "Daily Files",
|
||||
"validPeriods": [
|
||||
"45-min",
|
||||
"40-min",
|
||||
"30-min",
|
||||
"20-min",
|
||||
"15-min",
|
||||
"10-min",
|
||||
"05-min",
|
||||
"04-min",
|
||||
"03-min",
|
||||
"02-min",
|
||||
"01-min"
|
||||
],
|
||||
"filePath": "AAMasters/AAChris.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Bollinger-Bands/Multi-Period-Daily/@Period/@Year/@Month/@Day",
|
||||
"fileName": "@AssetA_@AssetB.json",
|
||||
"dataRange": {
|
||||
"filePath": "AAMasters/AAChris.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Bollinger-Bands/Multi-Period-Daily",
|
||||
"fileName": "Data.Range.@AssetA_@AssetB.json"
|
||||
}
|
||||
}
|
||||
],
|
||||
"exchangeList": [
|
||||
{
|
||||
"name": "Poloniex"
|
||||
},
|
||||
{
|
||||
"name": "Coss"
|
||||
}
|
||||
],
|
||||
"plotter": {
|
||||
"devTeam": "AAMasters",
|
||||
"codeName": "PlottersBollingerBands",
|
||||
"moduleName": "BollingerBands"
|
||||
}
|
||||
},
|
||||
{
|
||||
"codeName": "Percentage-Bandwidth",
|
||||
"displayName": "Percentage Bandwidth",
|
||||
"description": "Percentage Bandwidth",
|
||||
"dataSets": [
|
||||
{
|
||||
"codeName": "Multi-Period-Market",
|
||||
"type": "Market Files",
|
||||
"validPeriods": [
|
||||
"24-hs",
|
||||
"12-hs",
|
||||
"08-hs",
|
||||
"06-hs",
|
||||
"04-hs",
|
||||
"03-hs",
|
||||
"02-hs",
|
||||
"01-hs"
|
||||
],
|
||||
"filePath": "AAMasters/AAChris.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Percentage-Bandwidth/Multi-Period-Market/@Period",
|
||||
"fileName": "@AssetA_@AssetB.json"
|
||||
},
|
||||
{
|
||||
"codeName": "Multi-Period-Daily",
|
||||
"type": "Daily Files",
|
||||
"validPeriods": [
|
||||
"45-min",
|
||||
"40-min",
|
||||
"30-min",
|
||||
"20-min",
|
||||
"15-min",
|
||||
"10-min",
|
||||
"05-min",
|
||||
"04-min",
|
||||
"03-min",
|
||||
"02-min",
|
||||
"01-min"
|
||||
],
|
||||
"filePath": "AAMasters/AAChris.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Percentage-Bandwidth/Multi-Period-Daily/@Period/@Year/@Month/@Day",
|
||||
"fileName": "@AssetA_@AssetB.json",
|
||||
"dataRange": {
|
||||
"filePath": "AAMasters/AAChris.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Percentage-Bandwidth/Multi-Period-Daily",
|
||||
"fileName": "Data.Range.@AssetA_@AssetB.json"
|
||||
}
|
||||
}
|
||||
],
|
||||
"exchangeList": [
|
||||
{
|
||||
"name": "Poloniex"
|
||||
},
|
||||
{
|
||||
"name": "Coss"
|
||||
}
|
||||
],
|
||||
"plotter": {
|
||||
"devTeam": "AAMasters",
|
||||
"codeName": "PlottersBollingerBands",
|
||||
"moduleName": "PercentageBandwidth"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"codeName": "AAPaula",
|
||||
"displayName": "Paula",
|
||||
"type": "Indicator",
|
||||
"profilePicture": "Paula.png",
|
||||
"repo": "AAPaula-Indicator-Bot",
|
||||
"configFile": "this.bot.config.json",
|
||||
"products": [
|
||||
{
|
||||
"codeName": "Bollinger-Channels",
|
||||
"displayName": "Bollinger-Channels",
|
||||
"description": "Two sets of files per period that contains band-channel patterns.",
|
||||
"dataSets": [
|
||||
{
|
||||
"codeName": "Multi-Period-Market",
|
||||
"type": "Market Files",
|
||||
"validPeriods": [
|
||||
"24-hs",
|
||||
"12-hs",
|
||||
"08-hs",
|
||||
"06-hs",
|
||||
"04-hs",
|
||||
"03-hs",
|
||||
"02-hs",
|
||||
"01-hs"
|
||||
],
|
||||
"filePath": "AAMasters/AAPaula.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Bollinger-Channels/Multi-Period-Market/@Period",
|
||||
"fileName": "@AssetA_@AssetB.json"
|
||||
},
|
||||
{
|
||||
"codeName": "Multi-Period-Daily",
|
||||
"type": "Daily Files",
|
||||
"validPeriods": [
|
||||
"45-min",
|
||||
"40-min",
|
||||
"30-min",
|
||||
"20-min",
|
||||
"15-min",
|
||||
"10-min",
|
||||
"05-min",
|
||||
"04-min",
|
||||
"03-min",
|
||||
"02-min",
|
||||
"01-min"
|
||||
],
|
||||
"filePath": "AAMasters/AAPaula.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Bollinger-Channels/Multi-Period-Daily/@Period/@Year/@Month/@Day",
|
||||
"fileName": "@AssetA_@AssetB.json",
|
||||
"dataRange": {
|
||||
"filePath": "AAMasters/AAPaula.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Bollinger-Channels/Multi-Period-Daily",
|
||||
"fileName": "Data.Range.@AssetA_@AssetB.json"
|
||||
}
|
||||
}
|
||||
],
|
||||
"exchangeList": [
|
||||
{
|
||||
"name": "Poloniex"
|
||||
},
|
||||
{
|
||||
"name": "Coss"
|
||||
}
|
||||
],
|
||||
"plotter": {
|
||||
"devTeam": "AAMasters",
|
||||
"codeName": "PlottersBollingerChannels",
|
||||
"moduleName": "BollingerChannels"
|
||||
}
|
||||
},
|
||||
{
|
||||
"codeName": "Bollinger-Sub-Channels",
|
||||
"displayName": "Bollinger-Sub-Channels",
|
||||
"description": "Bollinger Sub Channels with slope.",
|
||||
"dataSets": [
|
||||
{
|
||||
"codeName": "Multi-Period-Market",
|
||||
"type": "Market Files",
|
||||
"validPeriods": [
|
||||
"24-hs",
|
||||
"12-hs",
|
||||
"08-hs",
|
||||
"06-hs",
|
||||
"04-hs",
|
||||
"03-hs",
|
||||
"02-hs",
|
||||
"01-hs"
|
||||
],
|
||||
"filePath": "AAMasters/AAPaula.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Bollinger-Sub-Channels/Multi-Period-Market/@Period",
|
||||
"fileName": "@AssetA_@AssetB.json"
|
||||
},
|
||||
{
|
||||
"codeName": "Multi-Period-Daily",
|
||||
"type": "Daily Files",
|
||||
"validPeriods": [
|
||||
"45-min",
|
||||
"40-min",
|
||||
"30-min",
|
||||
"20-min",
|
||||
"15-min",
|
||||
"10-min",
|
||||
"05-min",
|
||||
"04-min",
|
||||
"03-min",
|
||||
"02-min",
|
||||
"01-min"
|
||||
],
|
||||
"filePath": "AAMasters/AAPaula.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Bollinger-Sub-Channels/Multi-Period-Daily/@Period/@Year/@Month/@Day",
|
||||
"fileName": "@AssetA_@AssetB.json",
|
||||
"dataRange": {
|
||||
"filePath": "AAMasters/AAPaula.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Bollinger-Sub-Channels/Multi-Period-Daily",
|
||||
"fileName": "Data.Range.@AssetA_@AssetB.json"
|
||||
}
|
||||
}
|
||||
],
|
||||
"exchangeList": [
|
||||
{
|
||||
"name": "Poloniex"
|
||||
},
|
||||
{
|
||||
"name": "Coss"
|
||||
}
|
||||
],
|
||||
"plotter": {
|
||||
"devTeam": "AAMasters",
|
||||
"codeName": "PlottersBollingerChannels",
|
||||
"moduleName": "BollingerSubChannels"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"plotters": [
|
||||
{
|
||||
"displayName": "Plotters Candles & Volumes",
|
||||
"codeName": "PlottersCandlesVolumes",
|
||||
"devTeam": "AAMasters",
|
||||
"modules": [
|
||||
{
|
||||
"codeName": "Candles",
|
||||
"moduleName": "Candles",
|
||||
"description": "Plots traditional red and green candles.",
|
||||
"profilePicture": "Candles.png",
|
||||
"panels": [
|
||||
{
|
||||
"codeName": "CandlePanel",
|
||||
"moduleName": "CandlePanel",
|
||||
"event": "Current Candle Changed"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"codeName": "Volumes",
|
||||
"description": "Plots volumes separated in buy and sell.",
|
||||
"moduleName": "Volumes",
|
||||
"profilePicture": "Volumes.png",
|
||||
"panels": [
|
||||
{
|
||||
"codeName": "VolumePanel",
|
||||
"moduleName": "VolumePanel",
|
||||
"event": "Current Volume Changed"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"repo": "Plotters-Candles-Volumes",
|
||||
"configFile": "this.plotter.config.json"
|
||||
},
|
||||
{
|
||||
"displayName": "Plotters Stairs Patterns",
|
||||
"codeName": "PlottersStairsPatterns",
|
||||
"devTeam": "AAMasters",
|
||||
"modules": [
|
||||
{
|
||||
"codeName": "CandleStairs",
|
||||
"moduleName": "CandleStairs",
|
||||
"description": "Plots Candle Stairs patterns.",
|
||||
"profilePicture": "CandleStairs.png",
|
||||
"panels": []
|
||||
},
|
||||
{
|
||||
"codeName": "VolumeStairs",
|
||||
"description": "Plots Volume Stairs patterns.",
|
||||
"moduleName": "VolumeStairs",
|
||||
"profilePicture": "VolumeStairs.png",
|
||||
"panels": []
|
||||
}
|
||||
],
|
||||
"repo": "Plotters-Stairs-Patterns",
|
||||
"configFile": "this.plotter.config.json"
|
||||
},
|
||||
{
|
||||
"displayName": "Plotters Trading",
|
||||
"codeName": "PlottersTrading",
|
||||
"devTeam": "AAMasters",
|
||||
"modules": [
|
||||
{
|
||||
"codeName": "Details",
|
||||
"moduleName": "Details",
|
||||
"description": "Plots trading decitions in an easy to understand way.",
|
||||
"panels": []
|
||||
},
|
||||
{
|
||||
"codeName": "History",
|
||||
"moduleName": "History",
|
||||
"description": "Plots trading history.",
|
||||
"profilePicture": "History.png",
|
||||
"panels": []
|
||||
}
|
||||
],
|
||||
"repo": "Plotters-Trading",
|
||||
"configFile": "this.plotter.config.json"
|
||||
},
|
||||
{
|
||||
"displayName": "Plotters Bollinger Bands",
|
||||
"codeName": "PlottersBollingerBands",
|
||||
"devTeam": "AAMasters",
|
||||
"modules": [
|
||||
{
|
||||
"codeName": "BollingerBands",
|
||||
"moduleName": "BollingerBands",
|
||||
"description": "Plots Bollinger Bands.",
|
||||
"profilePicture": "BollingerBands.png",
|
||||
"panels": [
|
||||
{
|
||||
"codeName": "BollingerBandsPanel",
|
||||
"moduleName": "BollingerBandsPanel",
|
||||
"event": "Current Band Changed"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"codeName": "PercentageBandwidth",
|
||||
"moduleName": "PercentageBandwidth",
|
||||
"description": "Plots Bollinger Bands.",
|
||||
"profilePicture": "PercentageBandwidth.png",
|
||||
"panels": []
|
||||
}
|
||||
],
|
||||
"repo": "Plotters-Bollinger-Bands",
|
||||
"configFile": "this.plotter.config.json"
|
||||
},
|
||||
{
|
||||
"displayName": "Plotters Trading Simulation",
|
||||
"codeName": "PlottersTradingSimulation",
|
||||
"devTeam": "AAMasters",
|
||||
"modules": [
|
||||
{
|
||||
"codeName": "TradingSimulation",
|
||||
"moduleName": "TradingSimulation",
|
||||
"description": "Plots Bollinger Records.",
|
||||
"profilePicture": "TradingSimulation.png",
|
||||
"panels": [
|
||||
{
|
||||
"codeName": "TradingSimulationPanel",
|
||||
"moduleName": "TradingSimulationPanel",
|
||||
"event": "Current Record Changed"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"codeName": "Conditions",
|
||||
"moduleName": "Conditions",
|
||||
"description": "Plots Simulation Conditions.",
|
||||
"profilePicture": "Conditions.png",
|
||||
"panels": []
|
||||
},
|
||||
{
|
||||
"codeName": "Strategies",
|
||||
"moduleName": "Strategies",
|
||||
"description": "Plots Strategies.",
|
||||
"profilePicture": "Strategies.png",
|
||||
"panels": []
|
||||
},
|
||||
{
|
||||
"codeName": "Trades",
|
||||
"moduleName": "Trades",
|
||||
"description": "Plots Trades.",
|
||||
"profilePicture": "Trades.png",
|
||||
"panels": []
|
||||
},
|
||||
{
|
||||
"codeName": "SimulationExecution",
|
||||
"moduleName": "SimulationExecution",
|
||||
"description": "Plots Simulation Execution.",
|
||||
"profilePicture": "SimulationExecution.png",
|
||||
"panels": [
|
||||
{
|
||||
"codeName": "SimulationExecutionPanel",
|
||||
"moduleName": "SimulationExecutionPanel",
|
||||
"event": "Current Record Changed"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"repo": "Plotters-Trading-Simulation",
|
||||
"configFile": "this.plotter.config.json"
|
||||
},
|
||||
{
|
||||
"displayName": "Plotters Bollinger Channels",
|
||||
"codeName": "PlottersBollingerChannels",
|
||||
"devTeam": "AAMasters",
|
||||
"modules": [
|
||||
{
|
||||
"codeName": "BollingerChannels",
|
||||
"moduleName": "BollingerChannels",
|
||||
"description": "Plots Bollinger Channels.",
|
||||
"profilePicture": "BollingerChannels.png",
|
||||
"panels": [
|
||||
{
|
||||
"codeName": "ChannelPanel",
|
||||
"moduleName": "ChannelPanel",
|
||||
"event": "Current Channel Changed"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"codeName": "BollingerSubChannels",
|
||||
"moduleName": "BollingerSubChannels",
|
||||
"description": "Plots Bollinger Sub-Channels.",
|
||||
"profilePicture": "BollingerSubChannels.png",
|
||||
"panels": [
|
||||
{
|
||||
"codeName": "SubChannelPanel",
|
||||
"moduleName": "SubChannelPanel",
|
||||
"event": "Current Sub-Channel Changed"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"repo": "Plotters-Bollinger-Channels",
|
||||
"configFile": "this.plotter.config.json"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"codeName": "AAVikings",
|
||||
"displayName": "Vikings",
|
||||
"host": {
|
||||
"url": "https://demo-api-dev.superalgos.org/",
|
||||
"container": "aavikings",
|
||||
"storage": "localStorage",
|
||||
"accessKey": "0f38fea438be5adfc5873228f503c55353fb334406128b16a958851b8e47c118a08f0105dd8985d5479758fc4cc3f56c2e2364c2d7c3d0fdffba8d7e9356056a34629e3b926b1ebb940122d973db30b04fc18fab542cbc1afdc032dccf64b0fe308ee6bbc74f82bd350aaebf723428a50d8a699fa2b4b96d58716986ed24069f"
|
||||
},
|
||||
"bots": [
|
||||
{
|
||||
"codeName": "AAGauss",
|
||||
"displayName": "Gauss",
|
||||
"type": "Indicator",
|
||||
"profilePicture": "Gauss.png",
|
||||
"repo": "AAGauss-Indicator-Bot",
|
||||
"configFile": "this.bot.config.json",
|
||||
"products": [
|
||||
{
|
||||
"codeName": "LRCPoints",
|
||||
"displayName": "LRCPoints",
|
||||
"description": "Two sets of files per period that contains LRC points.",
|
||||
"dataSets": [
|
||||
{
|
||||
"codeName": "Multi-Period-Market",
|
||||
"type": "Market Files",
|
||||
"validPeriods": [
|
||||
"24-hs",
|
||||
"12-hs",
|
||||
"08-hs",
|
||||
"06-hs",
|
||||
"04-hs",
|
||||
"03-hs",
|
||||
"02-hs",
|
||||
"01-hs"
|
||||
],
|
||||
"filePath": "AAVikings/AAGauss.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/LRC-Points/Multi-Period-Market/@Period",
|
||||
"fileName": "@AssetA_@AssetB.json"
|
||||
},
|
||||
{
|
||||
"codeName": "Multi-Period-Daily",
|
||||
"type": "Daily Files",
|
||||
"validPeriods": [
|
||||
"45-min",
|
||||
"40-min",
|
||||
"30-min",
|
||||
"20-min",
|
||||
"15-min",
|
||||
"10-min",
|
||||
"05-min",
|
||||
"04-min",
|
||||
"03-min",
|
||||
"02-min",
|
||||
"01-min"
|
||||
],
|
||||
"filePath": "AAVikings/AAGauss.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/LRC-Points/Multi-Period-Daily/@Period/@Year/@Month/@Day",
|
||||
"fileName": "@AssetA_@AssetB.json",
|
||||
"dataRange": {
|
||||
"filePath": "AAVikings/AAGauss.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/LRC-Points/Multi-Period-Daily",
|
||||
"fileName": "Data.Range.@AssetA_@AssetB.json"
|
||||
}
|
||||
}
|
||||
],
|
||||
"exchangeList": [
|
||||
{
|
||||
"name": "Poloniex"
|
||||
},
|
||||
{
|
||||
"name": "Coss"
|
||||
}
|
||||
],
|
||||
"plotter": {
|
||||
"devTeam": "AAVikings",
|
||||
"codeName": "PlotterLinearRegressionCurve",
|
||||
"moduleName": "LRC"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"plotters": [
|
||||
{
|
||||
"displayName": "Plotter LRC",
|
||||
"codeName": "PlotterLinearRegressionCurve",
|
||||
"devTeam": "AAVikings",
|
||||
"modules": [
|
||||
{
|
||||
"codeName": "LRC",
|
||||
"moduleName": "LRC",
|
||||
"description": "Plots the linear regression curve.",
|
||||
"profilePicture": "LRC.png",
|
||||
"panels": [
|
||||
{
|
||||
"codeName": "ChannelPanel",
|
||||
"moduleName": "ChannelPanel",
|
||||
"event": "Current LRC Changed"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"repo": "Plotters-Linear-Regression-Curve",
|
||||
"configFile": "this.plotter.config.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"hosts": [
|
||||
{
|
||||
"codeName": "AAMasters",
|
||||
"displayName": "AA Arena",
|
||||
"host": {
|
||||
"url": "https://demo-api-dev.superalgos.org/",
|
||||
"storage": "localStorage",
|
||||
"container": "aamasters",
|
||||
"accessKey": "09e890b76767ede3e10f0526b5036600a6b8d3faac540336e12b493fdb2aa9ed46f86094c34652f99fb6322e5f09806412f17725807f85e4dc4169bd22dd59f0b23aba5251f5544478a1aabf5a2dea5260e6eb0c29af3a788208af85025a02f94950437d501b91fd55b9d97b3d6ac3af4e1161321f78b73ca0fda524dc3a5d03"
|
||||
},
|
||||
"competitions": [
|
||||
{
|
||||
"codeName": "Weekend-Deathmatch",
|
||||
"description": "First AA Internal Competition. Bots will be trading during 3 days at the USDT/BTC market of Poloniex to see who can make the gratest return over investment (ROI).",
|
||||
"displayName": "AA Internal Challenge",
|
||||
"startDatetime": "2018-01-01T16:00:00.000Z",
|
||||
"finishDatetime": "2018-01-02T16:00:00.000Z",
|
||||
"formula": "ROI",
|
||||
"plotter": {
|
||||
"devTeam": "AAMasters",
|
||||
"codeName": "PlottersROI",
|
||||
"host": {
|
||||
"url": "https://demo-api-dev.superalgos.org/",
|
||||
"storage": "localStorage",
|
||||
"container": "aamasters",
|
||||
"accessKey": ""
|
||||
},
|
||||
"moduleName": "CombinedProfits",
|
||||
"repo": "Plotters-ROI"
|
||||
},
|
||||
"rules": [],
|
||||
"prizes": [],
|
||||
"participants": [],
|
||||
"repo": "Weekend-Deathmatch",
|
||||
"configFile": "this.competition.config.json"
|
||||
}
|
||||
],
|
||||
"plotters": [
|
||||
{
|
||||
"displayName": "Plotters ROI",
|
||||
"codeName": "PlottersROI",
|
||||
"devTeam": "AAMasters",
|
||||
"modules": [
|
||||
{
|
||||
"codeName": "CombinedProfits",
|
||||
"moduleName": "CombinedProfits",
|
||||
"description": "Plots participants of a competition by the ROI each one had over time.",
|
||||
"panels": []
|
||||
}
|
||||
],
|
||||
"repo": "Plotters-ROI",
|
||||
"configFile": "this.plotter.config.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import mongoose from 'mongoose';
|
||||
|
||||
mongoose.connect(process.env.MONGO_URL, { useNewUrlParser: true })
|
||||
mongoose.set('useCreateIndex', true);
|
||||
mongoose.set('useFindAndModify', false);
|
||||
mongoose.Promise = global.Promise;
|
||||
|
||||
const db = mongoose.connection;
|
||||
|
||||
export default db;
|
||||
@@ -0,0 +1,23 @@
|
||||
export class AuthenticationError extends Error {
|
||||
constructor(message) {
|
||||
super(message)
|
||||
this.code = 401
|
||||
this.message = 'Authentication not found, you have to be authenticated to perform this action.'
|
||||
}
|
||||
}
|
||||
|
||||
export class WrongArgumentsError extends Error {
|
||||
constructor(message) {
|
||||
super(message)
|
||||
this.code = 400
|
||||
this.message = `Wrong arguments : ${this.message}`
|
||||
}
|
||||
}
|
||||
|
||||
export class ServiceUnavailableError extends Error {
|
||||
constructor(message) {
|
||||
super(message)
|
||||
this.code = 503
|
||||
this.message = `At least one service is unresponding ${this.message}`
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"errors": [
|
||||
{
|
||||
"code": 401,
|
||||
"message": "Wait, you're not supposed to be here, go through the gate as everyone else"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
require = require('esm')(module)
|
||||
module.exports = require('./app.js')
|
||||
@@ -0,0 +1,343 @@
|
||||
const mongoose = require('mongoose')
|
||||
const { Schema } = require('mongoose')
|
||||
|
||||
const ecosystemSchema = new Schema({
|
||||
authId: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
devTeams: [{
|
||||
codeName: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
displayName: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
host: {
|
||||
url: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
storage: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
container: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
accessKey: {
|
||||
type: String,
|
||||
required: false
|
||||
},
|
||||
ownerKey: {
|
||||
type: String,
|
||||
required: false
|
||||
}
|
||||
},
|
||||
bots: [{
|
||||
codeName: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
displayName: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
profilePicture: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
repo: {
|
||||
type: String,
|
||||
required: false
|
||||
},
|
||||
configFile: {
|
||||
type: String,
|
||||
required: false
|
||||
},
|
||||
cloneId: {
|
||||
type: String,
|
||||
required: false
|
||||
},
|
||||
products: [{
|
||||
codeName: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
displayName: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
dataSets: [{
|
||||
codeName: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
validPeriods: [{
|
||||
type: String,
|
||||
required: true
|
||||
}],
|
||||
filePath: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
fileName: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
dataRange: {
|
||||
filePath: {
|
||||
type: String,
|
||||
required: false
|
||||
},
|
||||
fileName: {
|
||||
type: String,
|
||||
required: false
|
||||
},
|
||||
},
|
||||
}],
|
||||
exchangeList: [{
|
||||
name: {
|
||||
type: String,
|
||||
required: true
|
||||
}
|
||||
}],
|
||||
plotter: {
|
||||
codeName: {
|
||||
type: String,
|
||||
required: false
|
||||
},
|
||||
devTeam: {
|
||||
type: String,
|
||||
required: false
|
||||
},
|
||||
moduleName: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
}
|
||||
}]
|
||||
}],
|
||||
plotters: [{
|
||||
codeName: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
displayName: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
modules: [{
|
||||
codeName: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
moduleName: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
required: false
|
||||
},
|
||||
profilePicture: {
|
||||
type: String,
|
||||
required: false
|
||||
},
|
||||
panels: [{
|
||||
codeName: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
moduleName: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
event: {
|
||||
type: String,
|
||||
required: true
|
||||
}
|
||||
}],
|
||||
}],
|
||||
repo: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
configFile: {
|
||||
type: String,
|
||||
required: true
|
||||
}
|
||||
}]
|
||||
}],
|
||||
hosts: [{
|
||||
codeName: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
displayName: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
host: {
|
||||
url: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
storage: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
container: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
accessKey: {
|
||||
type: String,
|
||||
required: false
|
||||
}
|
||||
},
|
||||
competitions: [{
|
||||
codeName: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
displayName: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
required: false
|
||||
},
|
||||
startDatetime: {
|
||||
type: String,
|
||||
required: false
|
||||
},
|
||||
finishDatetime: {
|
||||
type: String,
|
||||
required: false
|
||||
},
|
||||
formula: {
|
||||
type: String,
|
||||
required: false
|
||||
},
|
||||
plotter: {
|
||||
devTeam: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
codeName: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
host: {
|
||||
url: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
storage: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
container: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
accessKey: {
|
||||
type: String,
|
||||
required: false
|
||||
}
|
||||
},
|
||||
repo: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
moduleName: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
},
|
||||
participants: [{
|
||||
type: String,
|
||||
required: false
|
||||
}],
|
||||
repo: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
configFile: {
|
||||
type: String,
|
||||
required: true
|
||||
}
|
||||
}],
|
||||
plotters: [{
|
||||
codeName: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
displayName: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
modules: [{
|
||||
codeName: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
moduleName: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
required: false
|
||||
},
|
||||
profilePicture: {
|
||||
type: String,
|
||||
required: false
|
||||
},
|
||||
panels: [{
|
||||
codeName: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
moduleName: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
event: {
|
||||
type: String,
|
||||
required: true
|
||||
}
|
||||
}],
|
||||
}],
|
||||
repo: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
configFile: {
|
||||
type: String,
|
||||
required: true
|
||||
}
|
||||
}]
|
||||
}]
|
||||
})
|
||||
|
||||
const Ecosystem = mongoose.model('Ecosystem', ecosystemSchema);
|
||||
|
||||
export default Ecosystem;
|
||||
@@ -0,0 +1,5 @@
|
||||
import Ecosystem from './ecosystem';
|
||||
|
||||
export {
|
||||
Ecosystem
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
import {
|
||||
GraphQLSchema,
|
||||
} from 'graphql';
|
||||
import RootQuery from './queries';
|
||||
import Mutation from './mutations';
|
||||
|
||||
const Schema = new GraphQLSchema({
|
||||
query: RootQuery,
|
||||
mutation: Mutation,
|
||||
});
|
||||
|
||||
export default Schema;
|
||||
@@ -0,0 +1,71 @@
|
||||
import logger from '../../utils/logger'
|
||||
import { BotInputType, } from '../types/input'
|
||||
import { BotType, } from '../types'
|
||||
import { Ecosystem } from '../../models'
|
||||
|
||||
export const args = { bot: { type: BotInputType } }
|
||||
|
||||
const resolve = async (parent, { bot }, context) => {
|
||||
logger.debug('addBot -> Dev team: %s. Bot: %s', bot.devTeam, bot.codeName)
|
||||
try {
|
||||
|
||||
let userEcosystem = await Ecosystem.findOne({
|
||||
authId: context.userId
|
||||
})
|
||||
|
||||
if (!userEcosystem) {
|
||||
throw 'Ecosystem not found for the user.'
|
||||
}
|
||||
|
||||
let newBotClone
|
||||
for (let i = 0; i < userEcosystem.devTeams.length; i++) {
|
||||
const auxTeam = userEcosystem.devTeams[i]
|
||||
if (auxTeam.codeName === bot.devTeam) {
|
||||
for (let j = 0; j < auxTeam.bots.length; j++) {
|
||||
const auxBot = auxTeam.bots[j]
|
||||
if (auxBot.codeName === bot.codeName) {
|
||||
for (let k = 0; k < auxBot.products.length; k++) {
|
||||
const auxProduct = auxBot.products[k]
|
||||
if (auxProduct.codeName === bot.productCodeName) {
|
||||
newBotClone = {
|
||||
displayName: auxBot.displayName,
|
||||
codeName: auxBot.codeName,
|
||||
type: auxBot.type,
|
||||
profilePicture: auxBot.profilePicture,
|
||||
cloneId: bot.cloneId,
|
||||
products: [auxProduct]
|
||||
}
|
||||
auxTeam.bots.push(newBotClone)
|
||||
userEcosystem.markModified("devTeams")
|
||||
break
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (newBotClone) {
|
||||
await userEcosystem.save()
|
||||
return newBotClone
|
||||
} else {
|
||||
throw 'Algobot not found.'
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
logger.error('addBot -> Error: %s', err.message)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
const mutation = {
|
||||
addBot: {
|
||||
type: BotType,
|
||||
args,
|
||||
resolve,
|
||||
}
|
||||
}
|
||||
|
||||
export default mutation;
|
||||
@@ -0,0 +1,89 @@
|
||||
import logger from '../../utils/logger'
|
||||
import { AuthenticationError, WrongArgumentsError } from '../../errors'
|
||||
import { TeamType } from '../types'
|
||||
import { Ecosystem } from '../../models'
|
||||
import { TeamInputType } from '../types/input'
|
||||
import { copyBot } from '../../storage/CopyBot'
|
||||
import { copySimulator } from '../../storage/CopySimulator'
|
||||
import { createContainer, writeFileContent } from '../../storage/providers/MinioStorage'
|
||||
import crypto from 'crypto'
|
||||
|
||||
export const args = { team: { type: TeamInputType } }
|
||||
|
||||
const resolve = async (parent, { team }, context) => {
|
||||
logger.debug('addTeam -> Entering Function.')
|
||||
|
||||
if (!context.userId) {
|
||||
throw new AuthenticationError()
|
||||
}
|
||||
|
||||
try {
|
||||
let userEcosystem = await Ecosystem.findOne({
|
||||
authId: context.userId
|
||||
})
|
||||
|
||||
if (!userEcosystem) {
|
||||
logger.debug('addTeam -> Ecosystem not found for the user, creating a new one from default.')
|
||||
|
||||
let defaultEcosystem = require('../../config/ecosystem.json')
|
||||
userEcosystem = new Ecosystem(defaultEcosystem)
|
||||
userEcosystem.authId = context.userId
|
||||
}
|
||||
|
||||
for (let i = 0; i < userEcosystem.devTeams.length; i++) {
|
||||
const auxTeam = userEcosystem.devTeams[i];
|
||||
if (auxTeam.codeName === team.codeName) {
|
||||
throw new WrongArgumentsError("The team already exist on the user ecosystem.")
|
||||
}
|
||||
}
|
||||
|
||||
// Teams will be created on a local minio container
|
||||
let botsConfigurations = []
|
||||
try {
|
||||
await createContainer(team.codeName)
|
||||
} catch (err) {
|
||||
if (err.message !== 'Your previous request to create the named bucket succeeded and you already own it.') {
|
||||
logger.error('addTeam -> Error: %s', err.stack)
|
||||
throw err
|
||||
} else {
|
||||
logger.warn('addTeam -> %s', err.message)
|
||||
}
|
||||
}
|
||||
|
||||
let tradingBot = await copyBot(team.codeName, team.bot.codeName, team.bot.displayName, writeFileContent)
|
||||
botsConfigurations.push(tradingBot)
|
||||
let simulatorBot = await copySimulator(team.codeName, team.bot.codeName, team.bot.displayName, writeFileContent)
|
||||
botsConfigurations.push(simulatorBot)
|
||||
|
||||
team.bots = botsConfigurations
|
||||
|
||||
if (!team.host) {
|
||||
let nodeEndpoint = {
|
||||
url: process.env.NODE_ENDPOINT,
|
||||
storage: 'localStorage',
|
||||
container: team.codeName,
|
||||
accessKey: crypto.randomBytes(128).toString('hex'),
|
||||
ownerKey: crypto.randomBytes(128).toString('hex')
|
||||
}
|
||||
team.host = nodeEndpoint
|
||||
}
|
||||
|
||||
userEcosystem.devTeams.push(team)
|
||||
userEcosystem.markModified("devTeams")
|
||||
await userEcosystem.save()
|
||||
return team
|
||||
} catch (err) {
|
||||
logger.error('addTeam -> Error: %s', err.stack)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
const mutation = {
|
||||
addTeam: {
|
||||
type: TeamType,
|
||||
args,
|
||||
resolve,
|
||||
}
|
||||
}
|
||||
|
||||
export default mutation;
|
||||
@@ -0,0 +1,40 @@
|
||||
import logger from '../../utils/logger'
|
||||
import { FileInputType } from '../types/input'
|
||||
import { GraphQLString } from 'graphql'
|
||||
import { writeFileContent } from '../../storage/providers/MinioStorage'
|
||||
import { AuthenticationError, WrongArgumentsError } from '../../errors'
|
||||
import getDevTeamHost from '../../utils/getDevTeamHost'
|
||||
|
||||
export const args = { file: { type: FileInputType } }
|
||||
|
||||
const resolve = async (parent, { file }, context) => {
|
||||
try {
|
||||
if (file.accessKey === undefined || file.accessKey === null) {
|
||||
throw new WrongArgumentsError()
|
||||
}
|
||||
|
||||
let host = await getDevTeamHost(file.container, undefined, file.accessKey)
|
||||
|
||||
if (host === undefined || host === null) {
|
||||
throw new AuthenticationError()
|
||||
}
|
||||
let date = new Date()
|
||||
await writeFileContent(file.container, file.filePath, file.fileContent)
|
||||
let dateAfter = new Date()
|
||||
logger.info('createFile: ' + file.container + '/...' + file.filePath.substring(file.filePath.length -110 , file.filePath.length) + ', ' + (dateAfter - date))
|
||||
return 'File created.'
|
||||
} catch (err) {
|
||||
logger.error('createFile -> Error: %s', err.message)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
const mutation = {
|
||||
createFile: {
|
||||
type: GraphQLString,
|
||||
args,
|
||||
resolve,
|
||||
}
|
||||
}
|
||||
|
||||
export default mutation;
|
||||
@@ -0,0 +1,61 @@
|
||||
import logger from '../../utils/logger'
|
||||
import { AuthenticationError, WrongArgumentsError } from '../../errors'
|
||||
import { TeamType } from '../types'
|
||||
import { Ecosystem } from '../../models'
|
||||
import { DeleteTeamInputType } from '../types/input'
|
||||
import { deleteContainer } from '../../storage/providers/MinioStorage'
|
||||
|
||||
export const args = { team: { type: DeleteTeamInputType } }
|
||||
|
||||
const resolve = async (parent, { team }, context) => {
|
||||
logger.debug('deleteTeam -> Entering Function.')
|
||||
|
||||
if (!context.userId) {
|
||||
throw new AuthenticationError()
|
||||
}
|
||||
|
||||
try {
|
||||
let userEcosystem = await Ecosystem.findOne({
|
||||
authId: context.userId
|
||||
})
|
||||
|
||||
if (!userEcosystem) {
|
||||
logger.debug('deleteTeam -> Ecosystem not found for the user.')
|
||||
throw new WrongArgumentsError('The user does not have an ecosystem configured.')
|
||||
}
|
||||
|
||||
let teamFound = false
|
||||
for (let i = 0; i < userEcosystem.devTeams.length; i++) {
|
||||
const auxTeam = userEcosystem.devTeams[i]
|
||||
if (auxTeam.codeName === team.codeName) {
|
||||
logger.debug('deleteTeam -> Team found, removing.')
|
||||
teamFound = true
|
||||
await deleteContainer(team.codeName)
|
||||
userEcosystem.devTeams.splice(i, 1)
|
||||
userEcosystem.markModified("devTeams")
|
||||
await userEcosystem.save()
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (!teamFound) {
|
||||
throw new WrongArgumentsError('Team was not found on the user ecosystem.')
|
||||
} else {
|
||||
return team
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
logger.error('deleteTeam -> Error: %s', err.stack)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
const mutation = {
|
||||
deleteTeam: {
|
||||
type: TeamType,
|
||||
args,
|
||||
resolve,
|
||||
}
|
||||
}
|
||||
|
||||
export default mutation;
|
||||
@@ -0,0 +1,64 @@
|
||||
import logger from '../../utils/logger'
|
||||
import { BotInputType, } from '../types/input'
|
||||
import { BotType, } from '../types'
|
||||
import { Ecosystem } from '../../models'
|
||||
|
||||
export const args = { bot: { type: BotInputType } }
|
||||
|
||||
const resolve = async (parent, { bot }, context) => {
|
||||
logger.debug('removeBot -> Dev team: %s. Bot: %s', bot.devTeam, bot.codeName)
|
||||
try {
|
||||
|
||||
let userEcosystem = await Ecosystem.findOne({
|
||||
authId: context.userId
|
||||
})
|
||||
|
||||
if (!userEcosystem) {
|
||||
throw 'Ecosystem not found for the user.'
|
||||
}
|
||||
|
||||
let removedBotClone
|
||||
for (let i = 0; i < userEcosystem.devTeams.length; i++) {
|
||||
const auxTeam = userEcosystem.devTeams[i]
|
||||
if (auxTeam.codeName === bot.devTeam) {
|
||||
for (let j = 0; j < auxTeam.bots.length; j++) {
|
||||
const auxBot = auxTeam.bots[j]
|
||||
if (auxBot.codeName === bot.codeName && auxBot.cloneId === bot.cloneId) {
|
||||
for (let k = 0; k < auxBot.products.length; k++) {
|
||||
const auxProduct = auxBot.products[k]
|
||||
if (auxProduct.codeName === bot.productCodeName) {
|
||||
removedBotClone = auxBot
|
||||
auxTeam.bots.splice(j, 1)
|
||||
userEcosystem.markModified("devTeams")
|
||||
break
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (removedBotClone) {
|
||||
await userEcosystem.save()
|
||||
return removedBotClone
|
||||
} else {
|
||||
throw 'Algobot not found.'
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
logger.error('removeBot -> Error: %s', err.message)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
const mutation = {
|
||||
removeBot: {
|
||||
type: BotType,
|
||||
args,
|
||||
resolve,
|
||||
}
|
||||
}
|
||||
|
||||
export default mutation;
|
||||
@@ -0,0 +1,22 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
} from 'graphql'
|
||||
|
||||
import AddTeamMutation from './AddTeam'
|
||||
import DeleteTeamMutation from './DeleteTeam'
|
||||
import CreateFileMutation from './CreateFile'
|
||||
import AddBotMutation from './AddBot'
|
||||
import RemoveBotMutation from './RemoveBot'
|
||||
|
||||
const Mutation = new GraphQLObjectType({
|
||||
name: 'Mutation',
|
||||
fields: Object.assign(
|
||||
AddTeamMutation,
|
||||
DeleteTeamMutation,
|
||||
CreateFileMutation,
|
||||
AddBotMutation,
|
||||
RemoveBotMutation
|
||||
)
|
||||
})
|
||||
|
||||
export default Mutation
|
||||
@@ -0,0 +1,42 @@
|
||||
import logger from '../../utils/logger'
|
||||
import { Ecosystem } from '../../models'
|
||||
import { EcosystemType } from '../types'
|
||||
|
||||
const args = {}
|
||||
|
||||
const resolve = async (parent, args, context) => {
|
||||
logger.debug('getEcosystem -> Entering Function.')
|
||||
|
||||
try {
|
||||
if (!context.userId) {
|
||||
logger.debug('getEcosystem -> User not logged in, returning default ecosystem.')
|
||||
let defaultEcosystem = require('../../config/ecosystem.json')
|
||||
return defaultEcosystem
|
||||
} else {
|
||||
let userEcosystem = await Ecosystem.findOne({
|
||||
authId: context.userId
|
||||
})
|
||||
|
||||
if (!userEcosystem) {
|
||||
logger.debug('addTeam -> Ecosystem not found for the user, retrieving default.')
|
||||
let defaultEcosystem = require('../../config/ecosystem.json')
|
||||
return defaultEcosystem
|
||||
}
|
||||
|
||||
return userEcosystem
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error('getEcosystem -> Error: %s', err.stack)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
const query = {
|
||||
getEcosystem: {
|
||||
type: EcosystemType,
|
||||
args,
|
||||
resolve,
|
||||
}
|
||||
}
|
||||
|
||||
export default query
|
||||
@@ -0,0 +1,47 @@
|
||||
import logger from '../../utils/logger'
|
||||
import { FileInputType } from '../types/input'
|
||||
import { GraphQLString } from 'graphql'
|
||||
import { getFileContent } from '../../storage/providers/MinioStorage'
|
||||
import { AuthenticationError, WrongArgumentsError } from '../../errors'
|
||||
import getDevTeamHost from '../../utils/getDevTeamHost'
|
||||
|
||||
export const args = { file: { type: FileInputType } }
|
||||
|
||||
const resolve = async (parent, { file }, context) => {
|
||||
try {
|
||||
if (file.accessKey === undefined || file.accessKey === null) {
|
||||
throw new WrongArgumentsError()
|
||||
}
|
||||
|
||||
let host = await getDevTeamHost(file.container, file.accessKey)
|
||||
|
||||
if (host === undefined || host === null) {
|
||||
logger.error('Error getting file:' + JSON.stringify(file))
|
||||
throw new AuthenticationError()
|
||||
}
|
||||
|
||||
let date = new Date()
|
||||
let fileContent = await getFileContent(file.container, file.filePath)
|
||||
let dateAfter = new Date()
|
||||
logger.info('getFileContent: ' + file.container + '/...' + file.filePath.substring(file.filePath.length -110 , file.filePath.length) + ', ' + (dateAfter - date))
|
||||
return fileContent
|
||||
|
||||
} catch (err) {
|
||||
if (err.message === 'The specified key does not exist.')
|
||||
logger.debug('getFileContent -> Error: %s', err.message)
|
||||
else {
|
||||
logger.error('getFileContent -> Error: %s', err.message)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const query = {
|
||||
fileContent: {
|
||||
type: GraphQLString,
|
||||
args,
|
||||
resolve,
|
||||
}
|
||||
}
|
||||
|
||||
export default query
|
||||
@@ -0,0 +1,53 @@
|
||||
import logger from '../../utils/logger'
|
||||
import { FileInputType } from '../types/input'
|
||||
import { GraphQLString } from 'graphql'
|
||||
import { getFileContent } from '../../storage/providers/MinioStorage'
|
||||
import { getFileContentRemote } from '../../storage/providers/AzureStorage'
|
||||
|
||||
export const args = { file: { type: FileInputType } }
|
||||
|
||||
const resolve = async (parent, { file }, context) => {
|
||||
logger.debug('getPlotterCode -> Entering Function: ' + file.container + '/' + file.filePath)
|
||||
|
||||
try {
|
||||
|
||||
let fileContent
|
||||
if (file.storage === '' || file.storage === undefined) {
|
||||
//TODO Add permissions
|
||||
fileContent = await getFileContent(file.container, file.filePath)
|
||||
} else {
|
||||
// TODO Temporary fix for plotter and plotter pannels
|
||||
if (file.storage === '' && file.accessKey === '') {
|
||||
let defaultEcosystem = require('../../config/ecosystem.json')
|
||||
for (let index = 0; index < defaultEcosystem.devTeams.length; index++) {
|
||||
const devTeam = defaultEcosystem.devTeams[index];
|
||||
if (devTeam.codeName.toLowerCase() === file.container) {
|
||||
file.storage = devTeam.host.storage
|
||||
file.accessKey = devTeam.host.accessKey
|
||||
}
|
||||
}
|
||||
}
|
||||
if (file.storage === '' || file.accessKey === '') {
|
||||
throw "Wrong parameters."
|
||||
}
|
||||
fileContent = await getFileContentRemote(file.container, file.filePath, file.storage, file.accessKey)
|
||||
}
|
||||
|
||||
return fileContent
|
||||
|
||||
} catch (err) {
|
||||
logger.error('getPlotterCode -> Error: %s', err)
|
||||
logger.error('getPlotterCode -> Stack: %s', err.stack)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
const query = {
|
||||
plotterCode: {
|
||||
type: GraphQLString,
|
||||
args,
|
||||
resolve,
|
||||
}
|
||||
}
|
||||
|
||||
export default query
|
||||
@@ -0,0 +1,18 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
} from 'graphql';
|
||||
|
||||
import EcosystemQuery from './Ecosystem';
|
||||
import FileContentQuery from './FileContent';
|
||||
import PlotterCodeQuery from './PlotterCode';
|
||||
|
||||
const RootQuery = new GraphQLObjectType({
|
||||
name: 'RootQueryType',
|
||||
fields: Object.assign(
|
||||
EcosystemQuery,
|
||||
FileContentQuery,
|
||||
PlotterCodeQuery
|
||||
),
|
||||
});
|
||||
|
||||
export default RootQuery;
|
||||
@@ -0,0 +1,28 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
GraphQLString,
|
||||
GraphQLList
|
||||
} from 'graphql';
|
||||
|
||||
import { ProductType } from './index'
|
||||
|
||||
const BotType = new GraphQLObjectType({
|
||||
name: 'Bot',
|
||||
fields: () => ({
|
||||
codeName: { type: GraphQLString },
|
||||
displayName: { type: GraphQLString },
|
||||
type: { type: GraphQLString },
|
||||
profilePicture: { type: GraphQLString },
|
||||
repo: { type: GraphQLString },
|
||||
configFile: { type: GraphQLString },
|
||||
cloneId: { type: GraphQLString },
|
||||
products: {
|
||||
type: new GraphQLList(ProductType),
|
||||
resolve(parent) {
|
||||
return parent.products;
|
||||
}
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
export default BotType;
|
||||
@@ -0,0 +1,32 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
GraphQLString,
|
||||
GraphQLList
|
||||
} from 'graphql';
|
||||
|
||||
import { PlotterReferenceType } from './index';
|
||||
|
||||
const CompetitionType = new GraphQLObjectType({
|
||||
name: 'Competition',
|
||||
fields: () => ({
|
||||
codeName: { type: GraphQLString },
|
||||
displayName: { type: GraphQLString },
|
||||
description: { type: GraphQLString },
|
||||
startDatetime: { type: GraphQLString },
|
||||
finishDatetime: { type: GraphQLString },
|
||||
formula: { type: GraphQLString },
|
||||
plotter: {
|
||||
type: PlotterReferenceType,
|
||||
resolve(parent) {
|
||||
return parent.plotter;
|
||||
}
|
||||
},
|
||||
rules:{ type: new GraphQLList(GraphQLString) },
|
||||
prizes:{ type: new GraphQLList(GraphQLString) },
|
||||
participants:{ type: new GraphQLList(GraphQLString) },
|
||||
repo: { type: GraphQLString },
|
||||
configFile: { type: GraphQLString }
|
||||
}),
|
||||
});
|
||||
|
||||
export default CompetitionType;
|
||||
@@ -0,0 +1,14 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
GraphQLString
|
||||
} from 'graphql';
|
||||
|
||||
const DataRangeType = new GraphQLObjectType({
|
||||
name: 'DataRange',
|
||||
fields: () => ({
|
||||
filePath: { type: GraphQLString },
|
||||
fileName: { type: GraphQLString }
|
||||
}),
|
||||
});
|
||||
|
||||
export default DataRangeType;
|
||||
@@ -0,0 +1,21 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
GraphQLString,
|
||||
GraphQLList
|
||||
} from 'graphql';
|
||||
|
||||
import { DataRangeType } from './index'
|
||||
|
||||
const DataSetType = new GraphQLObjectType({
|
||||
name: 'DataSet',
|
||||
fields: () => ({
|
||||
codeName: { type: GraphQLString },
|
||||
type: { type: GraphQLString },
|
||||
validPeriods: { type: new GraphQLList(GraphQLString) },
|
||||
filePath: { type: GraphQLString },
|
||||
fileName: { type: GraphQLString },
|
||||
dataRange: { type: DataRangeType }
|
||||
}),
|
||||
});
|
||||
|
||||
export default DataSetType;
|
||||
@@ -0,0 +1,31 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
GraphQLString,
|
||||
GraphQLID,
|
||||
GraphQLList
|
||||
} from 'graphql';
|
||||
|
||||
import { TeamType, EventHostType } from './index';
|
||||
|
||||
const EcosystemType = new GraphQLObjectType({
|
||||
name: 'Ecosystem',
|
||||
fields: () => ({
|
||||
id: { type: GraphQLID },
|
||||
authId: { type: GraphQLString },
|
||||
userName: { type: GraphQLString }, // TODO this field is temporary, it should be used the user module query
|
||||
devTeams: {
|
||||
type: new GraphQLList(TeamType),
|
||||
resolve(parent) {
|
||||
return parent.devTeams;
|
||||
}
|
||||
},
|
||||
hosts: {
|
||||
type: new GraphQLList(EventHostType),
|
||||
resolve(parent) {
|
||||
return parent.hosts;
|
||||
}
|
||||
}
|
||||
}),
|
||||
});
|
||||
|
||||
export default EcosystemType;
|
||||
@@ -0,0 +1,37 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
GraphQLString,
|
||||
GraphQLList
|
||||
} from 'graphql';
|
||||
|
||||
import { CompetitionType, PlotterType, HostType } from './index';
|
||||
|
||||
const EventHostType = new GraphQLObjectType({
|
||||
name: 'EventHost',
|
||||
fields: () => ({
|
||||
codeName: { type: GraphQLString },
|
||||
displayName: { type: GraphQLString },
|
||||
host: {
|
||||
type: HostType,
|
||||
resolve(parent) {
|
||||
return parent.host;
|
||||
}
|
||||
},
|
||||
container: { type: GraphQLString },
|
||||
accessKey: { type: GraphQLString },
|
||||
competitions: {
|
||||
type: new GraphQLList(CompetitionType),
|
||||
resolve(parent) {
|
||||
return parent.competitions;
|
||||
}
|
||||
},
|
||||
plotters: {
|
||||
type: new GraphQLList(PlotterType),
|
||||
resolve(parent) {
|
||||
return parent.plotters;
|
||||
}
|
||||
}
|
||||
}),
|
||||
});
|
||||
|
||||
export default EventHostType;
|
||||
@@ -0,0 +1,13 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
GraphQLString
|
||||
} from 'graphql';
|
||||
|
||||
const ExchangeType = new GraphQLObjectType({
|
||||
name: 'Exchange',
|
||||
fields: () => ({
|
||||
name: { type: GraphQLString }
|
||||
}),
|
||||
});
|
||||
|
||||
export default ExchangeType;
|
||||
@@ -0,0 +1,17 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
GraphQLString
|
||||
} from 'graphql';
|
||||
|
||||
const FileType = new GraphQLObjectType({
|
||||
name: 'File',
|
||||
fields: () => ({
|
||||
container: { type: GraphQLString },
|
||||
filePath: { type: GraphQLString },
|
||||
storage: { type: GraphQLString },
|
||||
accessKey: { type: GraphQLString },
|
||||
fileContent: { type: GraphQLString }
|
||||
}),
|
||||
});
|
||||
|
||||
export default FileType;
|
||||
@@ -0,0 +1,17 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
GraphQLString
|
||||
} from 'graphql';
|
||||
|
||||
const HostType = new GraphQLObjectType({
|
||||
name: 'Host',
|
||||
fields: () => ({
|
||||
url: { type: GraphQLString },
|
||||
storage: { type: GraphQLString },
|
||||
container: { type: GraphQLString },
|
||||
accessKey: { type: GraphQLString },
|
||||
ownerKey: { type: GraphQLString }
|
||||
}),
|
||||
});
|
||||
|
||||
export default HostType;
|
||||
@@ -0,0 +1,25 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
GraphQLString,
|
||||
GraphQLList
|
||||
} from 'graphql'
|
||||
|
||||
import { PanelType } from './index'
|
||||
|
||||
const ModuleType = new GraphQLObjectType({
|
||||
name: 'Module',
|
||||
fields: () => ({
|
||||
codeName: { type: GraphQLString },
|
||||
moduleName: { type: GraphQLString },
|
||||
description: { type: GraphQLString },
|
||||
profilePicture: { type: GraphQLString },
|
||||
panels: {
|
||||
type: new GraphQLList(PanelType),
|
||||
resolve(parent) {
|
||||
return parent.panels;
|
||||
}
|
||||
}
|
||||
}),
|
||||
});
|
||||
|
||||
export default ModuleType;
|
||||
@@ -0,0 +1,15 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
GraphQLString
|
||||
} from 'graphql';
|
||||
|
||||
const PanelType = new GraphQLObjectType({
|
||||
name: 'Panel',
|
||||
fields: () => ({
|
||||
codeName: { type: GraphQLString },
|
||||
moduleName: { type: GraphQLString },
|
||||
event: { type: GraphQLString }
|
||||
}),
|
||||
});
|
||||
|
||||
export default PanelType;
|
||||
@@ -0,0 +1,26 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
GraphQLString,
|
||||
GraphQLList
|
||||
} from 'graphql';
|
||||
|
||||
import { ModuleType } from './index'
|
||||
|
||||
const PlotterType = new GraphQLObjectType({
|
||||
name: 'Plotter',
|
||||
fields: () => ({
|
||||
codeName: { type: GraphQLString },
|
||||
displayName: { type: GraphQLString },
|
||||
host: { type: GraphQLString },
|
||||
modules: {
|
||||
type: new GraphQLList(ModuleType),
|
||||
resolve(parent) {
|
||||
return parent.modules;
|
||||
}
|
||||
},
|
||||
repo: { type: GraphQLString },
|
||||
configFile: { type: GraphQLString }
|
||||
}),
|
||||
});
|
||||
|
||||
export default PlotterType;
|
||||
@@ -0,0 +1,24 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
GraphQLString
|
||||
} from 'graphql';
|
||||
|
||||
import { HostType } from './index';
|
||||
|
||||
const PlotterReferenceType = new GraphQLObjectType({
|
||||
name: 'PlotterReference',
|
||||
fields: () => ({
|
||||
devTeam: { type: GraphQLString },
|
||||
codeName: { type: GraphQLString },
|
||||
host: {
|
||||
type: HostType,
|
||||
resolve(parent) {
|
||||
return parent.host;
|
||||
}
|
||||
},
|
||||
moduleName: { type: GraphQLString },
|
||||
repo: { type: GraphQLString }
|
||||
}),
|
||||
});
|
||||
|
||||
export default PlotterReferenceType;
|
||||
@@ -0,0 +1,31 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
GraphQLString,
|
||||
GraphQLList
|
||||
} from 'graphql';
|
||||
|
||||
import { ExchangeType, DataSetType, PlotterReferenceType } from './index'
|
||||
|
||||
const ProductType = new GraphQLObjectType({
|
||||
name: 'Product',
|
||||
fields: () => ({
|
||||
codeName: { type: GraphQLString },
|
||||
displayName: { type: GraphQLString },
|
||||
description: { type: GraphQLString },
|
||||
dataSets: {
|
||||
type: new GraphQLList(DataSetType),
|
||||
resolve(parent) {
|
||||
return parent.dataSets;
|
||||
}
|
||||
},
|
||||
exchangeList: {
|
||||
type: new GraphQLList(ExchangeType),
|
||||
resolve(parent) {
|
||||
return parent.exchangeList;
|
||||
}
|
||||
},
|
||||
plotter: { type: PlotterReferenceType }
|
||||
}),
|
||||
});
|
||||
|
||||
export default ProductType;
|
||||
@@ -0,0 +1,35 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
GraphQLString,
|
||||
GraphQLList
|
||||
} from 'graphql';
|
||||
|
||||
import { BotType, PlotterType, HostType } from './index';
|
||||
|
||||
const TeamType = new GraphQLObjectType({
|
||||
name: 'Team',
|
||||
fields: () => ({
|
||||
codeName: { type: GraphQLString },
|
||||
displayName: { type: GraphQLString },
|
||||
host: {
|
||||
type: HostType,
|
||||
resolve(parent) {
|
||||
return parent.host;
|
||||
}
|
||||
},
|
||||
bots: {
|
||||
type: new GraphQLList(BotType),
|
||||
resolve(parent) {
|
||||
return parent.bots;
|
||||
}
|
||||
},
|
||||
plotters: {
|
||||
type: new GraphQLList(PlotterType),
|
||||
resolve(parent) {
|
||||
return parent.plotters;
|
||||
}
|
||||
}
|
||||
}),
|
||||
});
|
||||
|
||||
export default TeamType;
|
||||
@@ -0,0 +1,33 @@
|
||||
import TeamType from './Team';
|
||||
import BotType from './Bot';
|
||||
import EventHostType from './EventHost';
|
||||
import HostType from './Host';
|
||||
import EcosystemType from './Ecosystem';
|
||||
import FileType from './File';
|
||||
import PanelType from './Panel';
|
||||
import ModuleType from './Module';
|
||||
import PlotterType from './Plotter';
|
||||
import CompetitionType from './Competition';
|
||||
import PlotterReferenceType from './PlotterReference';
|
||||
import ProductType from './Product';
|
||||
import DataSetType from './DataSet';
|
||||
import DataRangeType from './DataRange';
|
||||
import ExchangeType from './Exchange';
|
||||
|
||||
export {
|
||||
TeamType,
|
||||
BotType,
|
||||
EventHostType,
|
||||
HostType,
|
||||
EcosystemType,
|
||||
FileType,
|
||||
PanelType,
|
||||
ModuleType,
|
||||
PlotterType,
|
||||
CompetitionType,
|
||||
PlotterReferenceType,
|
||||
ProductType,
|
||||
DataSetType,
|
||||
DataRangeType,
|
||||
ExchangeType
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
import {
|
||||
GraphQLInputObjectType,
|
||||
GraphQLString,
|
||||
GraphQLNonNull
|
||||
} from 'graphql';
|
||||
|
||||
const Type = new GraphQLInputObjectType({
|
||||
name: 'BotInput',
|
||||
description: 'Payload for bot input.',
|
||||
fields: () => ({
|
||||
codeName: { type: new GraphQLNonNull(GraphQLString) },
|
||||
productCodeName: { type: GraphQLString },
|
||||
devTeam: { type: GraphQLString},
|
||||
displayName: { type: GraphQLString },
|
||||
repo: { type: GraphQLString },
|
||||
configFile: { type: GraphQLString },
|
||||
cloneId: { type: GraphQLString },
|
||||
validPeriod: { type: GraphQLString },
|
||||
}),
|
||||
});
|
||||
|
||||
export default Type;
|
||||
@@ -0,0 +1,19 @@
|
||||
import {
|
||||
GraphQLInputObjectType,
|
||||
GraphQLString,
|
||||
GraphQLList
|
||||
} from 'graphql';
|
||||
|
||||
const Type = new GraphQLInputObjectType({
|
||||
name: 'DataSetInput',
|
||||
description: 'Payload for data set input.',
|
||||
fields: () => ({
|
||||
codeName: { type: new GraphQLNonNull(GraphQLString) },
|
||||
type: { type: new GraphQLNonNull(GraphQLString) },
|
||||
filePath: { type: new GraphQLNonNull(GraphQLString) },
|
||||
fileName: { type: new GraphQLNonNull(GraphQLString) },
|
||||
validPeriods: { type: new GraphQLList(GraphQLString) }
|
||||
}),
|
||||
});
|
||||
|
||||
export default Type;
|
||||
@@ -0,0 +1,18 @@
|
||||
import {
|
||||
GraphQLString,
|
||||
GraphQLInputObjectType,
|
||||
GraphQLNonNull
|
||||
} from 'graphql';
|
||||
|
||||
import { HostInputType } from './index';
|
||||
|
||||
const Type = new GraphQLInputObjectType({
|
||||
name: 'DeleteTeamInput',
|
||||
description: 'Payload for team input',
|
||||
fields: () => ({
|
||||
codeName: { type: new GraphQLNonNull(GraphQLString) },
|
||||
host: { type: HostInputType }
|
||||
}),
|
||||
});
|
||||
|
||||
export default Type;
|
||||
@@ -0,0 +1,15 @@
|
||||
import {
|
||||
GraphQLInputObjectType,
|
||||
GraphQLString,
|
||||
GraphQLNonNull
|
||||
} from 'graphql';
|
||||
|
||||
const Type = new GraphQLInputObjectType({
|
||||
name: 'ExchangeInput',
|
||||
description: 'Payload for exchange input.',
|
||||
fields: () => ({
|
||||
name: { type: new GraphQLNonNull(GraphQLString) }
|
||||
}),
|
||||
});
|
||||
|
||||
export default Type;
|
||||
@@ -0,0 +1,19 @@
|
||||
import {
|
||||
GraphQLInputObjectType,
|
||||
GraphQLString,
|
||||
GraphQLNonNull
|
||||
} from 'graphql';
|
||||
|
||||
const Type = new GraphQLInputObjectType({
|
||||
name: 'FileInput',
|
||||
description: 'Payload for file input.',
|
||||
fields: () => ({
|
||||
container: { type: new GraphQLNonNull(GraphQLString) },
|
||||
filePath: { type: new GraphQLNonNull(GraphQLString) },
|
||||
storage: { type: new GraphQLNonNull(GraphQLString) },
|
||||
accessKey: { type: GraphQLString },
|
||||
fileContent: { type: GraphQLString }
|
||||
}),
|
||||
});
|
||||
|
||||
export default Type;
|
||||
@@ -0,0 +1,17 @@
|
||||
import {
|
||||
GraphQLInputObjectType,
|
||||
GraphQLString
|
||||
} from 'graphql';
|
||||
|
||||
const Type = new GraphQLInputObjectType({
|
||||
name: 'HostInput',
|
||||
description: 'Payload for host input.',
|
||||
fields: () => ({
|
||||
url: { type: GraphQLString },
|
||||
storage: { type: GraphQLString },
|
||||
container: { type: GraphQLString },
|
||||
accessKey: { type: GraphQLString }
|
||||
}),
|
||||
});
|
||||
|
||||
export default Type;
|
||||
@@ -0,0 +1,17 @@
|
||||
import {
|
||||
GraphQLInputObjectType,
|
||||
GraphQLString,
|
||||
GraphQLNonNull
|
||||
} from 'graphql';
|
||||
|
||||
const Type = new GraphQLInputObjectType({
|
||||
name: 'PlotterInput',
|
||||
description: 'Payload for plotter input.',
|
||||
fields: () => ({
|
||||
devTeam: { type: new GraphQLNonNull(GraphQLString) },
|
||||
codeName: { type: new GraphQLNonNull(GraphQLString) },
|
||||
moduleName: { type: new GraphQLNonNull(GraphQLString) }
|
||||
}),
|
||||
});
|
||||
|
||||
export default Type;
|
||||
@@ -0,0 +1,24 @@
|
||||
import {
|
||||
GraphQLInputObjectType,
|
||||
GraphQLString,
|
||||
GraphQLNonNull
|
||||
} from 'graphql';
|
||||
|
||||
import { DataSetInputType } from './index';
|
||||
import { ExchangeInputType } from './index';
|
||||
import { PlotterInputType } from './index';
|
||||
|
||||
const Type = new GraphQLInputObjectType({
|
||||
name: 'ProductInput',
|
||||
description: 'Payload for product input.',
|
||||
fields: () => ({
|
||||
codeName: { type: new GraphQLNonNull(GraphQLString) },
|
||||
displayName: { type: new GraphQLNonNull(GraphQLString) },
|
||||
description: { type: GraphQLString },
|
||||
dataSets: { type: new GraphQLList(DataSetInputType) },
|
||||
exchangeList: { type: new GraphQLList(ExchangeInputType) },
|
||||
plotter: { type: PlotterInputType }
|
||||
}),
|
||||
});
|
||||
|
||||
export default Type;
|
||||
@@ -0,0 +1,21 @@
|
||||
import {
|
||||
GraphQLString,
|
||||
GraphQLInputObjectType,
|
||||
GraphQLNonNull
|
||||
} from 'graphql';
|
||||
|
||||
import { BotInputType, HostInputType } from './index';
|
||||
|
||||
const Type = new GraphQLInputObjectType({
|
||||
name: 'TeamInput',
|
||||
description: 'Payload for team input',
|
||||
fields: () => ({
|
||||
codeName: { type: new GraphQLNonNull(GraphQLString) },
|
||||
displayName: { type: new GraphQLNonNull(GraphQLString) },
|
||||
host: { type: HostInputType },
|
||||
bot: { type: new GraphQLNonNull(BotInputType) },
|
||||
plotter: { type: BotInputType }
|
||||
}),
|
||||
});
|
||||
|
||||
export default Type;
|
||||
@@ -0,0 +1,21 @@
|
||||
import TeamInputType from './Team'
|
||||
import BotInputType from './Bot'
|
||||
import HostInputType from './Host'
|
||||
import FileInputType from './File'
|
||||
import DeleteTeamInputType from './DeleteTeam'
|
||||
import DataSetInputType from './DataSet'
|
||||
import ExchangeInputType from './Exchange'
|
||||
import PlotterInputType from './Plotter'
|
||||
import ProductInputType from './Product'
|
||||
|
||||
export {
|
||||
TeamInputType,
|
||||
BotInputType,
|
||||
HostInputType,
|
||||
FileInputType,
|
||||
DeleteTeamInputType,
|
||||
DataSetInputType,
|
||||
ExchangeInputType,
|
||||
PlotterInputType,
|
||||
ProductInputType
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import beautify from 'json-beautify'
|
||||
import logger from '../utils/logger'
|
||||
import readFile from '../utils/readFile'
|
||||
|
||||
export const copyBot = async (teamCodeName, botCodeName, botDisplayName, writeFileContent) => {
|
||||
try {
|
||||
logger.debug('copyBot started for bot %s', botCodeName)
|
||||
// File imports
|
||||
const botCode = await readFile('./src/storage/templates/TradingBot/User.Bot.js')
|
||||
const config = await readFile('./src/storage/templates/TradingBot/this.bot.config.json')
|
||||
|
||||
// Change config to adapt the new indicator
|
||||
let parsedConfig = JSON.parse(config)
|
||||
parsedConfig.displayName = botDisplayName
|
||||
parsedConfig.codeName = botCodeName
|
||||
parsedConfig.devTeam = teamCodeName
|
||||
parsedConfig.profilePicture = botCodeName + '.png'
|
||||
|
||||
parsedConfig.processes[0].statusDependencies[0].devTeam = teamCodeName
|
||||
parsedConfig.processes[0].statusDependencies[0].bot = botCodeName
|
||||
parsedConfig.processes[0].statusDependencies[1].devTeam = teamCodeName
|
||||
parsedConfig.processes[0].statusDependencies[1].bot = 'simulator-' + botCodeName
|
||||
parsedConfig.processes[0].statusDependencies[2].devTeam = teamCodeName
|
||||
parsedConfig.processes[0].statusDependencies[2].bot = 'simulator-' + botCodeName
|
||||
|
||||
parsedConfig.processes[0].dataDependencies[1].devTeam = teamCodeName
|
||||
parsedConfig.processes[0].dataDependencies[1].bot = 'simulator-' + botCodeName
|
||||
parsedConfig.processes[0].dataDependencies[2].devTeam = teamCodeName
|
||||
parsedConfig.processes[0].dataDependencies[2].bot = 'simulator-' + botCodeName
|
||||
|
||||
// Creating a new trading bot
|
||||
let newBotPath = teamCodeName + '/bots/' + botCodeName + '-Trading-Bot'
|
||||
await writeFileContent(teamCodeName, newBotPath + '/Trading-Process/User.Bot.js', botCode)
|
||||
await writeFileContent(teamCodeName, newBotPath + '/this.bot.config.json', beautify(parsedConfig, null, 2, 80))
|
||||
|
||||
return parsedConfig
|
||||
} catch (err) {
|
||||
logger.error('copyBot error for bot: %s. %s', botCodeName, err)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import beautify from 'json-beautify'
|
||||
import logger from '../utils/logger'
|
||||
import readFile from '../utils/readFile'
|
||||
|
||||
export const copySimulator = async (teamCodeName, botCodeName, botDisplayName, writeFileContent) => {
|
||||
try {
|
||||
logger.debug('copySimulator started for bot %s', 'simulator-' + botCodeName)
|
||||
|
||||
// File imports
|
||||
const commons = await readFile('./src/storage/templates/Simulator/Commons.js')
|
||||
const config = await readFile('./src/storage/templates/Simulator/this.bot.config.json')
|
||||
const codeDaily = await readFile('./src/storage/templates/Simulator/User.Bot.Daily.js')
|
||||
const codeMarket = await readFile('./src/storage/templates/Simulator/User.Bot.Market.js')
|
||||
|
||||
// Change config to adapt the new indicator
|
||||
let newBotCodeName = 'simulator-' + botCodeName
|
||||
let parsedConfig = JSON.parse(config)
|
||||
parsedConfig.displayName = 'Simulator ' + botDisplayName
|
||||
parsedConfig.codeName = newBotCodeName
|
||||
parsedConfig.devTeam = teamCodeName
|
||||
parsedConfig.profilePicture = newBotCodeName + '.png'
|
||||
|
||||
parsedConfig.processes[0].statusDependencies[0].devTeam = teamCodeName
|
||||
parsedConfig.processes[0].statusDependencies[0].bot = newBotCodeName
|
||||
parsedConfig.processes[1].statusDependencies[2].devTeam = teamCodeName
|
||||
parsedConfig.processes[1].statusDependencies[2].bot = newBotCodeName
|
||||
|
||||
//Changing Indicator Output
|
||||
parsedConfig.products[0].storageAccount = teamCodeName
|
||||
parsedConfig.products[0].dataSets[0].filePath = teamCodeName + '/' + parsedConfig.codeName + '.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Trading-Simulation/Multi-Period-Market/@Period'
|
||||
parsedConfig.products[0].dataSets[1].filePath = teamCodeName + '/' + parsedConfig.codeName + '.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Trading-Simulation/Multi-Period-Daily/@Period/@Year/@Month/@Day'
|
||||
parsedConfig.products[0].dataSets[1].dataRange.filePath = teamCodeName + '/' + parsedConfig.codeName + '.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Trading-Simulation/Multi-Period-Daily'
|
||||
|
||||
parsedConfig.products[1].storageAccount = teamCodeName
|
||||
parsedConfig.products[1].dataSets[0].filePath = teamCodeName + '/' + parsedConfig.codeName + '.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Conditions/Multi-Period-Market/@Period'
|
||||
parsedConfig.products[1].dataSets[1].filePath = teamCodeName + '/' + parsedConfig.codeName + '.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Conditions/Multi-Period-Daily/@Period/@Year/@Month/@Day'
|
||||
parsedConfig.products[1].dataSets[1].dataRange.filePath = teamCodeName + '/' + parsedConfig.codeName + '.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Conditions/Multi-Period-Daily'
|
||||
|
||||
parsedConfig.products[2].storageAccount = teamCodeName
|
||||
parsedConfig.products[2].dataSets[0].filePath = teamCodeName + '/' + parsedConfig.codeName + '.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Strategies/Multi-Period-Market/@Period'
|
||||
parsedConfig.products[2].dataSets[1].filePath = teamCodeName + '/' + parsedConfig.codeName + '.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Strategies/Multi-Period-Daily/@Period/@Year/@Month/@Day'
|
||||
parsedConfig.products[2].dataSets[1].dataRange.filePath = teamCodeName + '/' + parsedConfig.codeName + '.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Strategies/Multi-Period-Daily'
|
||||
|
||||
parsedConfig.products[3].storageAccount = teamCodeName
|
||||
parsedConfig.products[3].dataSets[0].filePath = teamCodeName + '/' + parsedConfig.codeName + '.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Trades/Multi-Period-Market/@Period'
|
||||
parsedConfig.products[3].dataSets[1].filePath = teamCodeName + '/' + parsedConfig.codeName + '.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Trades/Multi-Period-Daily/@Period/@Year/@Month/@Day'
|
||||
parsedConfig.products[3].dataSets[1].dataRange.filePath = teamCodeName + '/' + parsedConfig.codeName + '.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Trades/Multi-Period-Daily'
|
||||
|
||||
// Write the new files
|
||||
let newSimulatorName = newBotCodeName + '-Indicator-Bot'
|
||||
let newSimulatorPath = teamCodeName + '/bots/' + newSimulatorName
|
||||
await writeFileContent(teamCodeName, newSimulatorPath + '/Commons.js', commons)
|
||||
await writeFileContent(teamCodeName, newSimulatorPath + '/this.bot.config.json', beautify(parsedConfig, null, 2, 80))
|
||||
await writeFileContent(teamCodeName, newSimulatorPath + '/Multi-Period-Daily/User.Bot.js', codeDaily)
|
||||
await writeFileContent(teamCodeName, newSimulatorPath + '/Multi-Period-Market/User.Bot.js', codeMarket)
|
||||
|
||||
logger.debug('copySimulator completed for bot %s', newBotCodeName)
|
||||
return parsedConfig
|
||||
} catch (err) {
|
||||
logger.error('copySimulator error for bot: %s. %s', botCodeName, err)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
export const removeSimulator = async (storage, teamCodeName, botCodeName) => {
|
||||
try {
|
||||
logger.debug('removeSimulator started for bot %s', botCodeName)
|
||||
|
||||
// Delete simulator code
|
||||
let newSimulatorName = 'simulator-' + botCodeName + '-Indicator-Bot'
|
||||
let newSimulatorPath = teamCodeName + '/bots/' + newSimulatorName
|
||||
await storage.deleteBlob(teamCodeName, newSimulatorPath + '/Commons.js')
|
||||
await storage.deleteBlob(teamCodeName, newSimulatorPath + '/this.bot.config.json')
|
||||
await storage.deleteBlob(teamCodeName, newSimulatorPath + '/Multi-Period-Daily/User.Bot.js')
|
||||
await storage.deleteBlob(teamCodeName, newSimulatorPath + '/Multi-Period-Market/User.Bot.js')
|
||||
|
||||
logger.debug('removeSimulator completed for bot %s', botCodeName)
|
||||
|
||||
} catch (err) {
|
||||
logger.error('copySimulator error for bot %s: %s', botCodeName, err)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
import {
|
||||
Aborter,
|
||||
BlobURL,
|
||||
BlockBlobURL,
|
||||
ContainerURL,
|
||||
ServiceURL,
|
||||
StorageURL,
|
||||
SharedKeyCredential,
|
||||
AnonymousCredential
|
||||
} from '@azure/storage-blob'
|
||||
|
||||
const getService = () => {
|
||||
// Use SharedKeyCredential with storage account and account key
|
||||
const sharedKeyCredential = new SharedKeyCredential(process.env.AZURE_BASE_URL, process.env.AZURE_CONNECTION_STRING);
|
||||
|
||||
// Use sharedKeyCredential, tokenCredential or anonymousCredential to create a pipeline
|
||||
const pipeline = StorageURL.newPipeline(sharedKeyCredential, {
|
||||
retryOptions: { maxTries: 10 }
|
||||
});
|
||||
|
||||
// List containers
|
||||
const serviceURL = new ServiceURL(
|
||||
// When using AnonymousCredential, following url should include a valid SAS or support public access
|
||||
`https://${process.env.AZURE_BASE_URL}.blob.core.windows.net`,
|
||||
pipeline
|
||||
)
|
||||
return serviceURL
|
||||
}
|
||||
|
||||
export const getFileContentRemote = async (containerName, blobName, storage, accessKey) => {
|
||||
const pipeline = StorageURL.newPipeline(new AnonymousCredential(), {
|
||||
retryOptions: { maxTries: 10 }
|
||||
})
|
||||
const serviceURLWithAccessKey = new ServiceURL(
|
||||
`${storage}${accessKey}`,
|
||||
pipeline
|
||||
);
|
||||
const containerURL = ContainerURL.fromServiceURL(serviceURLWithAccessKey, containerName)
|
||||
const blockBlobURL = BlockBlobURL.fromContainerURL(containerURL, blobName)
|
||||
let downloadResponse = await blockBlobURL.download(Aborter.none, 0)
|
||||
return await streamToString(downloadResponse.readableStreamBody)
|
||||
}
|
||||
|
||||
export const getFileContent = async (containerName, blobName) => {
|
||||
const containerURL = ContainerURL.fromServiceURL(getService(), containerName)
|
||||
const blockBlobURL = BlockBlobURL.fromContainerURL(containerURL, blobName)
|
||||
let downloadResponse = await blockBlobURL.download(Aborter.none, 0)
|
||||
return await streamToString(downloadResponse.readableStreamBody)
|
||||
}
|
||||
|
||||
export const writeFileContent = async (containerName, blobName, content) => {
|
||||
const containerURL = ContainerURL.fromServiceURL(getService(), containerName)
|
||||
const blobURL = BlobURL.fromContainerURL(containerURL, blobName)
|
||||
const blockBlobURL = BlockBlobURL.fromBlobURL(blobURL)
|
||||
await blockBlobURL.upload(
|
||||
Aborter.none,
|
||||
content,
|
||||
content.length
|
||||
)
|
||||
}
|
||||
|
||||
export const deleteBlob = async (containerName, blobName) => {
|
||||
const containerURL = ContainerURL.fromServiceURL(getService(), containerName)
|
||||
const blockBlobURL = BlockBlobURL.fromContainerURL(containerURL, blobName)
|
||||
await blockBlobURL.delete(Aborter.none)
|
||||
}
|
||||
|
||||
export const deleteContainer = async (containerName) => {
|
||||
const containerURL = ContainerURL.fromServiceURL(getService(), containerName)
|
||||
await containerURL.delete(Aborter.none)
|
||||
}
|
||||
|
||||
export const createContainer = async (containerName) => {
|
||||
const containerURL = ContainerURL.fromServiceURL(getService(), containerName)
|
||||
await containerURL.create(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)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
import { Client } from 'minio'
|
||||
|
||||
const getService = () => {
|
||||
let service = new Client({
|
||||
endPoint: process.env.MINIO_END_POINT,
|
||||
port: JSON.parse(process.env.MINIO_PORT),
|
||||
useSSL: JSON.parse(process.env.MINIO_USE_SSL),
|
||||
accessKey: process.env.MINIO_ACCESS_KEY,
|
||||
secretKey: process.env.MINIO_SECRET_KEY
|
||||
})
|
||||
return service
|
||||
}
|
||||
|
||||
export const getFileContent = async (containerName, blobName) => {
|
||||
let service = getService()
|
||||
let chunks = []
|
||||
let fileContent = await new Promise(function (resolve, reject) {
|
||||
service.getObject(containerName, blobName, function (error, dataStream) {
|
||||
if (error) {
|
||||
reject(error)
|
||||
}
|
||||
if (dataStream != undefined) {
|
||||
dataStream.on('data', function (chunk) {
|
||||
chunks.push(chunk.toString())
|
||||
})
|
||||
dataStream.on('end', function () {
|
||||
resolve(chunks.join(''))
|
||||
})
|
||||
dataStream.on('error', function (e) {
|
||||
reject(e)
|
||||
})
|
||||
} else {
|
||||
resolve('')
|
||||
}
|
||||
})
|
||||
})
|
||||
return fileContent
|
||||
}
|
||||
|
||||
export const writeFileContent = async (containerName, blobName, content) => {
|
||||
let service = getService()
|
||||
await new Promise(function (resolve, reject) {
|
||||
service.putObject(containerName, blobName, content, 'text/plain', function (error) {
|
||||
if (error) {
|
||||
reject(error)
|
||||
}
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const createContainer = async (containerName) => {
|
||||
let service = getService()
|
||||
await new Promise(function (resolve, reject) {
|
||||
service.makeBucket(containerName, '', function (error) {
|
||||
if (error) {
|
||||
reject(error)
|
||||
}
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const deleteContainer = async (containerName) => {
|
||||
let service = getService()
|
||||
let objectsStream = service.listObjects(containerName, '', true)
|
||||
let totalObjects = 0
|
||||
let removed = 0
|
||||
objectsStream.on('data', async function (obj) {
|
||||
totalObjects++
|
||||
await new Promise(function (resolve, reject) {
|
||||
service.removeObject(containerName, obj.name, function (e) {
|
||||
if (e) reject(e)
|
||||
removed++
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
})
|
||||
objectsStream.on('error', function (e) {
|
||||
throw e
|
||||
})
|
||||
objectsStream.on('end', async function (e) {
|
||||
await removeBucket()
|
||||
})
|
||||
|
||||
function removeBucket() {
|
||||
if (totalObjects === removed) {
|
||||
new Promise(function (resolve, reject) {
|
||||
service.removeBucket(containerName, function (e) {
|
||||
if (e) reject(e)
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
} else {
|
||||
setTimeout(removeBucket, 2000)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,553 @@
|
||||
exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileStorage) {
|
||||
|
||||
const FULL_LOG = true;
|
||||
const LOG_FILE_CONTENT = false;
|
||||
|
||||
const MODULE_NAME = "User Bot";
|
||||
|
||||
const EXECUTION_FOLDER_NAME = "Trading-Execution";
|
||||
const SIMULATED_RECORDS_FOLDER_NAME = "Trading-Simulation";
|
||||
const CONDITIONS_FOLDER_NAME = "Simulation-Conditions";
|
||||
const STRATEGIES_FOLDER_NAME = "Simulation-Strategies";
|
||||
const TRADES_FOLDER_NAME = "Simulation-Trades";
|
||||
|
||||
const commons = COMMONS.newCommons(bot, logger, UTILITIES);
|
||||
|
||||
thisObject = {
|
||||
initialize: initialize,
|
||||
start: start
|
||||
};
|
||||
|
||||
let utilities = UTILITIES.newCloudUtilities(bot, logger);
|
||||
|
||||
let dataDependencies;
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(pDataDependencies, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
logger.fileName = MODULE_NAME;
|
||||
logger.initialize();
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] initialize -> Entering function."); }
|
||||
|
||||
dataDependencies = pDataDependencies;
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
|
||||
} catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] initialize -> err = " + err.stack);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function start(dataFiles, timePeriod, outputPeriodLabel, currentDay, startDate, endDate, interExecutionMemory, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> Entering function."); }
|
||||
|
||||
let market = global.MARKET;
|
||||
let dataFile;
|
||||
|
||||
let recordsArray
|
||||
let conditionsArray
|
||||
let strategiesArray
|
||||
let tradesArray
|
||||
let lastObjectsArray
|
||||
|
||||
let tradingSystem = {};
|
||||
|
||||
commons.initializeData();
|
||||
|
||||
for (let i = 0; i < dataDependencies.config.length; i++) {
|
||||
|
||||
let dependency = dataDependencies.config[i];
|
||||
dataFile = dataFiles[i];
|
||||
|
||||
switch (i) {
|
||||
|
||||
case 0: {
|
||||
commons.buildLRC(dataFile, callBackFunction);
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
commons.buildPercentageBandwidthMap(dataFile, callBackFunction);
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
commons.buildBollingerBandsMap(dataFile, callBackFunction);
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
commons.buildBollingerChannelsArray(dataFile, callBackFunction);
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
commons.buildBollingerSubChannelsArray(dataFile, callBackFunction);
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
commons.buildCandles(dataFile, callBackFunction);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
commons.runSimulation(
|
||||
timePeriod,
|
||||
currentDay,
|
||||
startDate,
|
||||
endDate,
|
||||
interExecutionMemory,
|
||||
writeFiles,
|
||||
callBackFunction)
|
||||
|
||||
function writeFiles(pTradingSystem, pExecutionArray, pRecordsArray, pConditionsArray, pStrategiesArray, pTradesArray, pLastObjectsArray) {
|
||||
|
||||
tradingSystem = pTradingSystem
|
||||
executionArray = pExecutionArray
|
||||
recordsArray = pRecordsArray
|
||||
conditionsArray = pConditionsArray
|
||||
strategiesArray = pStrategiesArray
|
||||
tradesArray = pTradesArray
|
||||
lastObjectsArray = pLastObjectsArray
|
||||
|
||||
writeExecutionFile()
|
||||
}
|
||||
|
||||
function writeExecutionFile() {
|
||||
|
||||
try {
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeExecutionFile -> Entering function."); }
|
||||
|
||||
let separator = "";
|
||||
let fileRecordCounter = 0;
|
||||
|
||||
let fileContent = "";
|
||||
|
||||
for (let i = 0; i < executionArray.length; i++) {
|
||||
|
||||
let record = executionArray[i];
|
||||
|
||||
/* Will only add to the file the records of the current day */
|
||||
|
||||
if (record.begin < currentDay.valueOf()) { continue; }
|
||||
|
||||
fileContent = fileContent + separator + '[' +
|
||||
record.begin + "," +
|
||||
record.end + "," +
|
||||
JSON.stringify(record.executionRecord) + "]";
|
||||
|
||||
if (separator === "") { separator = ","; }
|
||||
|
||||
fileRecordCounter++;
|
||||
|
||||
}
|
||||
|
||||
fileContent = "[" + fileContent + "]";
|
||||
|
||||
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.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion;
|
||||
let filePath = filePathRoot + "/Output/" + EXECUTION_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + outputPeriodLabel + "/" + dateForPath;
|
||||
filePath += '/' + fileName
|
||||
|
||||
fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated);
|
||||
|
||||
function onFileCreated(err) {
|
||||
|
||||
try {
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeExecutionFile -> onFileCreated -> Entering function."); }
|
||||
if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> writeExecutionFile -> onFileCreated -> fileContent = " + fileContent); }
|
||||
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeExecutionFile -> onFileCreated -> err = " + err.stack);
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeExecutionFile -> onFileCreated -> filePath = " + filePath);
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeExecutionFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB);
|
||||
|
||||
callBackFunction(err);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
writeRecordsFile();
|
||||
|
||||
}
|
||||
catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeExecutionFile -> onFileCreated -> err = " + err.stack);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeExecutionFile -> err = " + err.stack);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function writeRecordsFile() {
|
||||
|
||||
try {
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeRecordsFile -> Entering function."); }
|
||||
|
||||
let separator = "";
|
||||
let fileRecordCounter = 0;
|
||||
|
||||
let fileContent = "";
|
||||
|
||||
for (let i = 0; i < recordsArray.length; i++) {
|
||||
|
||||
let record = recordsArray[i];
|
||||
|
||||
/* Will only add to the file the records of the current day */
|
||||
|
||||
if (record.begin < currentDay.valueOf()) { continue; }
|
||||
|
||||
fileContent = fileContent + separator + '[' +
|
||||
record.begin + "," +
|
||||
record.end + "," +
|
||||
record.type + "," +
|
||||
record.marketRate + "," +
|
||||
record.amount + "," +
|
||||
record.balanceA + "," +
|
||||
record.balanceB + "," +
|
||||
record.profit + "," +
|
||||
record.lastTradeProfitLoss + "," +
|
||||
record.stopLoss + "," +
|
||||
record.roundtrips + "," +
|
||||
record.hits + "," +
|
||||
record.fails + "," +
|
||||
record.hitRatio + "," +
|
||||
record.ROI + "," +
|
||||
record.periods + "," +
|
||||
record.days + "," +
|
||||
record.anualizedRateOfReturn + "," +
|
||||
record.positionRate + "," +
|
||||
record.lastTradeROI + "," +
|
||||
record.strategy + "," +
|
||||
record.strategyStageNumber + "," +
|
||||
record.takeProfit + "," +
|
||||
record.stopLossPhase + "," +
|
||||
record.takeProfitPhase + "," +
|
||||
JSON.stringify(record.executionRecord) + "," +
|
||||
record.positionSize + "," +
|
||||
record.initialBalanceA + "," +
|
||||
record.minimumBalanceA + "," +
|
||||
record.maximumBalanceA + "," +
|
||||
record.initialBalanceB + "," +
|
||||
record.minimumBalanceB + "," +
|
||||
record.maximumBalanceB + "," +
|
||||
record.baseAsset + "]";
|
||||
|
||||
if (separator === "") { separator = ","; }
|
||||
|
||||
fileRecordCounter++;
|
||||
|
||||
}
|
||||
|
||||
fileContent = "[" + fileContent + "]";
|
||||
|
||||
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.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
|
||||
|
||||
fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated);
|
||||
|
||||
function onFileCreated(err) {
|
||||
|
||||
try {
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeRecordsFile -> onFileCreated -> Entering function."); }
|
||||
if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> writeRecordsFile -> onFileCreated -> fileContent = " + fileContent); }
|
||||
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeRecordsFile -> onFileCreated -> err = " + err.stack);
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeRecordsFile -> onFileCreated -> filePath = " + filePath);
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeRecordsFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB);
|
||||
|
||||
callBackFunction(err);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
writeConditionsFile();
|
||||
|
||||
}
|
||||
catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeRecordsFile -> onFileCreated -> err = " + err.stack);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeRecordsFile -> err = " + err.stack);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function writeConditionsFile() {
|
||||
|
||||
try {
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeConditionsFile -> Entering function."); }
|
||||
|
||||
let separator = "";
|
||||
let fileRecordCounter = 0;
|
||||
|
||||
let fileContent = "";
|
||||
|
||||
for (let i = 0; i < conditionsArray.length; i++) {
|
||||
|
||||
let record = conditionsArray[i];
|
||||
|
||||
/* Will only add to the file the records of the current day */
|
||||
|
||||
if (record.begin < currentDay.valueOf()) { continue; }
|
||||
|
||||
let conditions = "";
|
||||
let conditionsSeparator = "";
|
||||
|
||||
/* Will only add to the file the records of the current day */
|
||||
|
||||
if (record.begin < currentDay.valueOf()) { continue; }
|
||||
|
||||
for (let j = 0; j < record.length - 3; j++) {
|
||||
conditions = conditions + conditionsSeparator + record[j];
|
||||
if (conditionsSeparator === "") { conditionsSeparator = ","; }
|
||||
}
|
||||
|
||||
conditions = conditions + conditionsSeparator + '[' + record[record.length - 3] + ']'; // The last item contains an Array of condition values.
|
||||
conditions = conditions + conditionsSeparator + '[' + record[record.length - 2] + ']'; // The last item contains an Array of formulaErrors.
|
||||
conditions = conditions + conditionsSeparator + '[' + record[record.length - 1] + ']'; // The last item contains an Array of formulaValues.
|
||||
|
||||
fileContent = fileContent + separator + '[' + conditions + ']';
|
||||
|
||||
if (separator === "") { separator = ","; }
|
||||
|
||||
fileRecordCounter++;
|
||||
|
||||
}
|
||||
|
||||
fileContent = "[" + fileContent + "]";
|
||||
fileContent = "[" + JSON.stringify(tradingSystem) + "," + JSON.stringify(lastObjectsArray) + "," + fileContent + "]";
|
||||
|
||||
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.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
|
||||
|
||||
fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated);
|
||||
|
||||
function onFileCreated(err) {
|
||||
|
||||
try {
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeConditionsFile -> onFileCreated -> Entering function."); }
|
||||
if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> writeConditionsFile -> onFileCreated -> fileContent = " + fileContent); }
|
||||
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeConditionsFile -> onFileCreated -> err = " + err.stack);
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeConditionsFile -> onFileCreated -> filePath = " + filePath);
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeConditionsFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB);
|
||||
|
||||
callBackFunction(err);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
writeStrategiesFile();
|
||||
|
||||
}
|
||||
catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeConditionsFile -> onFileCreated -> err = " + err.stack);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeConditionsFile -> err = " + err.stack);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function writeStrategiesFile() {
|
||||
|
||||
try {
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeStrategiesFile -> Entering function."); }
|
||||
|
||||
let separator = "";
|
||||
let fileRecordCounter = 0;
|
||||
|
||||
let fileContent = "";
|
||||
|
||||
for (let i = 0; i < strategiesArray.length; i++) {
|
||||
let record = strategiesArray[i];
|
||||
|
||||
/* Will only add to the file the records of the current day. In this case since objects can span more than one day, we add all of the objects that ends
|
||||
at the current date. */
|
||||
|
||||
if (record.end < currentDay.valueOf()) { continue; }
|
||||
|
||||
fileContent = fileContent + separator + '[' +
|
||||
record.begin + "," +
|
||||
record.end + "," +
|
||||
record.status + "," +
|
||||
record.number + "," +
|
||||
record.beginRate + "," +
|
||||
record.endRate + "]";
|
||||
|
||||
if (separator === "") { separator = ","; }
|
||||
|
||||
fileRecordCounter++;
|
||||
|
||||
}
|
||||
|
||||
fileContent = "[" + fileContent + "]";
|
||||
|
||||
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.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
|
||||
|
||||
fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated);
|
||||
|
||||
function onFileCreated(err) {
|
||||
|
||||
try {
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeStrategiesFile -> onFileCreated -> Entering function."); }
|
||||
if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> writeStrategiesFile -> onFileCreated -> fileContent = " + fileContent); }
|
||||
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> onFileCreated -> err = " + err.stack);
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> onFileCreated -> filePath = " + filePath);
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB);
|
||||
|
||||
callBackFunction(err);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
writeTradesFile();
|
||||
|
||||
}
|
||||
catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> onFileCreated -> err = " + err.stack);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> err = " + err.stack);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function writeTradesFile() {
|
||||
|
||||
try {
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeTradesFile -> Entering function."); }
|
||||
|
||||
let separator = "";
|
||||
let fileRecordCounter = 0;
|
||||
|
||||
let fileContent = "";
|
||||
|
||||
for (let i = 0; i < tradesArray.length; i++) {
|
||||
|
||||
let record = tradesArray[i];
|
||||
|
||||
/* Will only add to the file the records of the current day. In this case since objects can span more than one day, we add all of the objects that ends
|
||||
at the current date. */
|
||||
|
||||
if (record.end < currentDay.valueOf()) { continue; }
|
||||
if (record.stopRate === undefined) { record.stopRate = 0}
|
||||
|
||||
fileContent = fileContent + separator + '[' +
|
||||
record.begin + "," +
|
||||
record.end + "," +
|
||||
record.status + "," +
|
||||
record.lastTradeROI + "," +
|
||||
record.beginRate + "," +
|
||||
record.endRate + "," +
|
||||
record.exitType + "," +
|
||||
record.stopRate + "]";
|
||||
|
||||
if (separator === "") { separator = ","; }
|
||||
|
||||
fileRecordCounter++;
|
||||
|
||||
}
|
||||
|
||||
fileContent = "[" + fileContent + "]";
|
||||
|
||||
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.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
|
||||
|
||||
fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated);
|
||||
|
||||
function onFileCreated(err) {
|
||||
|
||||
try {
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeTradesFile -> onFileCreated -> Entering function."); }
|
||||
if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> writeTradesFile -> onFileCreated -> fileContent = " + fileContent); }
|
||||
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> onFileCreated -> err = " + err.stack);
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> onFileCreated -> filePath = " + filePath);
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB);
|
||||
|
||||
callBackFunction(err);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
|
||||
}
|
||||
catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> onFileCreated -> err = " + err.stack);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> err = " + err.stack);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> err = " + err.stack);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,518 @@
|
||||
exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileStorage) {
|
||||
|
||||
const FULL_LOG = true;
|
||||
const LOG_FILE_CONTENT = false;
|
||||
|
||||
const MODULE_NAME = "User Bot";
|
||||
|
||||
const EXECUTION_FOLDER_NAME = "Trading-Execution";
|
||||
const SIMULATED_RECORDS_FOLDER_NAME = "Trading-Simulation";
|
||||
const CONDITIONS_FOLDER_NAME = "Simulation-Conditions";
|
||||
const STRATEGIES_FOLDER_NAME = "Simulation-Strategies";
|
||||
const TRADES_FOLDER_NAME = "Simulation-Trades";
|
||||
|
||||
const commons = COMMONS.newCommons(bot, logger, UTILITIES);
|
||||
|
||||
thisObject = {
|
||||
initialize: initialize,
|
||||
start: start
|
||||
};
|
||||
|
||||
let dataDependencies;
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(pDataDependencies, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
logger.fileName = MODULE_NAME;
|
||||
logger.initialize();
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] initialize -> Entering function."); }
|
||||
|
||||
dataDependencies = pDataDependencies;
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
|
||||
} catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] initialize -> err = " + err.stack);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function start(dataFiles, timePeriod, outputPeriodLabel, startDate, endDate, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> Entering function."); }
|
||||
|
||||
let market = global.MARKET;
|
||||
let dataFile;
|
||||
|
||||
let recordsArray
|
||||
let conditionsArray
|
||||
let strategiesArray
|
||||
let tradesArray
|
||||
let lastObjectsArray
|
||||
|
||||
let tradingSystem = {};
|
||||
let interExecutionMemory = {};
|
||||
let currentDay = bot.processDatetime;
|
||||
|
||||
commons.initializeData();
|
||||
|
||||
for (let i = 0; i < dataDependencies.config.length; i++) {
|
||||
|
||||
let dependency = dataDependencies.config[i];
|
||||
dataFile = dataFiles[i];
|
||||
|
||||
switch (i) {
|
||||
|
||||
case 0: {
|
||||
commons.buildLRC(dataFile, callBackFunction);
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
commons.buildPercentageBandwidthMap(dataFile, callBackFunction);
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
commons.buildBollingerBandsMap(dataFile, callBackFunction);
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
commons.buildBollingerChannelsArray(dataFile, callBackFunction);
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
commons.buildBollingerSubChannelsArray(dataFile, callBackFunction);
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
commons.buildCandles(dataFile, callBackFunction);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
commons.runSimulation(
|
||||
timePeriod,
|
||||
currentDay,
|
||||
startDate,
|
||||
endDate,
|
||||
interExecutionMemory,
|
||||
writeFiles,
|
||||
callBackFunction)
|
||||
|
||||
function writeFiles(pTradingSystem, pExecutionArray, pRecordsArray, pConditionsArray, pStrategiesArray, pTradesArray, pLastObjectsArray) {
|
||||
|
||||
tradingSystem = pTradingSystem
|
||||
executionArray = pExecutionArray
|
||||
recordsArray = pRecordsArray
|
||||
conditionsArray = pConditionsArray
|
||||
strategiesArray = pStrategiesArray
|
||||
tradesArray = pTradesArray
|
||||
lastObjectsArray = pLastObjectsArray
|
||||
|
||||
writeExecutionFile()
|
||||
}
|
||||
|
||||
function writeExecutionFile() {
|
||||
|
||||
try {
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeExecutionFile -> Entering function."); }
|
||||
|
||||
let separator = "";
|
||||
let fileRecordCounter = 0;
|
||||
|
||||
let fileContent = "";
|
||||
|
||||
for (let i = 0; i < executionArray.length; i++) {
|
||||
|
||||
let record = executionArray[i];
|
||||
|
||||
fileContent = fileContent + separator + '[' +
|
||||
record.begin + "," +
|
||||
record.end + "," +
|
||||
JSON.stringify(record.executionRecord) + "]";
|
||||
|
||||
if (separator === "") { separator = ","; }
|
||||
|
||||
fileRecordCounter++;
|
||||
|
||||
}
|
||||
|
||||
fileContent = "[" + fileContent + "]";
|
||||
|
||||
let fileName = '' + market.assetA + '_' + market.assetB + '.json';
|
||||
|
||||
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/" + EXECUTION_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + outputPeriodLabel;
|
||||
filePath += '/' + fileName
|
||||
|
||||
fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated);
|
||||
|
||||
function onFileCreated(err) {
|
||||
|
||||
try {
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeExecutionFile -> onFileCreated -> Entering function."); }
|
||||
if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> writeExecutionFile -> onFileCreated -> fileContent = " + fileContent); }
|
||||
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeExecutionFile -> onFileCreated -> err = " + err.stack);
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeExecutionFile -> onFileCreated -> filePath = " + filePath);
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeExecutionFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB);
|
||||
|
||||
callBackFunction(err);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
writeRecordsFile();
|
||||
|
||||
}
|
||||
catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeExecutionFile -> onFileCreated -> err = " + err.stack);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeExecutionFile -> err = " + err.stack);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function writeRecordsFile() {
|
||||
|
||||
try {
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeRecordsFile -> Entering function."); }
|
||||
|
||||
let separator = "";
|
||||
let fileRecordCounter = 0;
|
||||
|
||||
let fileContent = "";
|
||||
|
||||
for (let i = 0; i < recordsArray.length; i++) {
|
||||
|
||||
let record = recordsArray[i];
|
||||
|
||||
fileContent = fileContent + separator + '[' +
|
||||
record.begin + "," +
|
||||
record.end + "," +
|
||||
record.type + "," +
|
||||
record.marketRate + "," +
|
||||
record.amount + "," +
|
||||
record.balanceA + "," +
|
||||
record.balanceB + "," +
|
||||
record.profit + "," +
|
||||
record.lastTradeProfitLoss + "," +
|
||||
record.stopLoss + "," +
|
||||
record.roundtrips + "," +
|
||||
record.hits + "," +
|
||||
record.fails + "," +
|
||||
record.hitRatio + "," +
|
||||
record.ROI + "," +
|
||||
record.periods + "," +
|
||||
record.days + "," +
|
||||
record.anualizedRateOfReturn + "," +
|
||||
record.positionRate + "," +
|
||||
record.lastTradeROI + "," +
|
||||
record.strategy + "," +
|
||||
record.strategyStageNumber + "," +
|
||||
record.takeProfit + "," +
|
||||
record.stopLossPhase + "," +
|
||||
record.takeProfitPhase + "," +
|
||||
JSON.stringify(record.executionRecord) + "," +
|
||||
record.positionSize + "," +
|
||||
record.initialBalanceA + "," +
|
||||
record.minimumBalanceA + "," +
|
||||
record.maximumBalanceA + "," +
|
||||
record.initialBalanceB + "," +
|
||||
record.minimumBalanceB + "," +
|
||||
record.maximumBalanceB + "," +
|
||||
record.baseAsset + "]";
|
||||
|
||||
if (separator === "") { separator = ","; }
|
||||
|
||||
fileRecordCounter++;
|
||||
|
||||
}
|
||||
|
||||
fileContent = "[" + fileContent + "]";
|
||||
|
||||
let fileName = '' + market.assetA + '_' + market.assetB + '.json';
|
||||
|
||||
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
|
||||
|
||||
fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated);
|
||||
|
||||
function onFileCreated(err) {
|
||||
|
||||
try {
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeRecordsFile -> onFileCreated -> Entering function."); }
|
||||
if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> writeRecordsFile -> onFileCreated -> fileContent = " + fileContent); }
|
||||
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeRecordsFile -> onFileCreated -> err = " + err.stack);
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeRecordsFile -> onFileCreated -> filePath = " + filePath);
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeRecordsFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB);
|
||||
|
||||
callBackFunction(err);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
writeConditionsFile();
|
||||
|
||||
}
|
||||
catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeRecordsFile -> onFileCreated -> err = " + err.stack);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeRecordsFile -> err = " + err.stack);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function writeConditionsFile() {
|
||||
|
||||
try {
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeConditionsFile -> Entering function."); }
|
||||
|
||||
let separator = "";
|
||||
let fileRecordCounter = 0;
|
||||
|
||||
let fileContent = "";
|
||||
|
||||
for (let i = 0; i < conditionsArray.length; i++) {
|
||||
|
||||
let record = conditionsArray[i];
|
||||
|
||||
let conditions = "";
|
||||
let conditionsSeparator = "";
|
||||
|
||||
for (let j = 0; j < record.length - 3; j++) {
|
||||
conditions = conditions + conditionsSeparator + record[j];
|
||||
if (conditionsSeparator === "") { conditionsSeparator = ","; }
|
||||
}
|
||||
|
||||
conditions = conditions + conditionsSeparator + '[' + record[record.length - 3] + ']'; // The last item contains an Array of condition values.
|
||||
conditions = conditions + conditionsSeparator + '[' + record[record.length - 2] + ']'; // The last item contains an Array of formulaErrors.
|
||||
conditions = conditions + conditionsSeparator + '[' + record[record.length - 1] + ']'; // The last item contains an Array of formulaValues.
|
||||
|
||||
fileContent = fileContent + separator + '[' + conditions + ']';
|
||||
|
||||
if (separator === "") { separator = ","; }
|
||||
|
||||
fileRecordCounter++;
|
||||
|
||||
}
|
||||
|
||||
fileContent = "[" + fileContent + "]";
|
||||
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.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
|
||||
|
||||
fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated);
|
||||
|
||||
function onFileCreated(err) {
|
||||
|
||||
try {
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeConditionsFile -> onFileCreated -> Entering function."); }
|
||||
if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> writeConditionsFile -> onFileCreated -> fileContent = " + fileContent); }
|
||||
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeConditionsFile -> onFileCreated -> err = " + err.stack);
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeConditionsFile -> onFileCreated -> filePath = " + filePath);
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeConditionsFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB);
|
||||
|
||||
callBackFunction(err);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
writeStrategiesFile();
|
||||
|
||||
}
|
||||
catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeConditionsFile -> onFileCreated -> err = " + err.stack);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeConditionsFile -> err = " + err.stack);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function writeStrategiesFile() {
|
||||
|
||||
try {
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeStrategiesFile -> Entering function."); }
|
||||
|
||||
let separator = "";
|
||||
let fileRecordCounter = 0;
|
||||
|
||||
let fileContent = "";
|
||||
|
||||
for (let i = 0; i < strategiesArray.length; i++) {
|
||||
let record = strategiesArray[i];
|
||||
|
||||
fileContent = fileContent + separator + '[' +
|
||||
record.begin + "," +
|
||||
record.end + "," +
|
||||
record.status + "," +
|
||||
record.number + "," +
|
||||
record.beginRate + "," +
|
||||
record.endRate + "]";
|
||||
|
||||
if (separator === "") { separator = ","; }
|
||||
|
||||
fileRecordCounter++;
|
||||
|
||||
}
|
||||
|
||||
fileContent = "[" + fileContent + "]";
|
||||
let fileName = '' + market.assetA + '_' + market.assetB + '.json';
|
||||
|
||||
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
|
||||
|
||||
fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated);
|
||||
|
||||
function onFileCreated(err) {
|
||||
|
||||
try {
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeStrategiesFile -> onFileCreated -> Entering function."); }
|
||||
if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> writeStrategiesFile -> onFileCreated -> fileContent = " + fileContent); }
|
||||
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> onFileCreated -> err = " + err.stack);
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> onFileCreated -> filePath = " + filePath);
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB);
|
||||
|
||||
callBackFunction(err);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
writeTradesFile();
|
||||
|
||||
}
|
||||
catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> onFileCreated -> err = " + err.stack);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeStrategiesFile -> err = " + err.stack);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function writeTradesFile() {
|
||||
|
||||
try {
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeTradesFile -> Entering function."); }
|
||||
|
||||
let separator = "";
|
||||
let fileRecordCounter = 0;
|
||||
|
||||
let fileContent = "";
|
||||
|
||||
for (let i = 0; i < tradesArray.length; i++) {
|
||||
|
||||
let record = tradesArray[i];
|
||||
if (record.stopRate === undefined) { record.stopRate = 0 }
|
||||
|
||||
fileContent = fileContent + separator + '[' +
|
||||
record.begin + "," +
|
||||
record.end + "," +
|
||||
record.status + "," +
|
||||
record.lastTradeROI + "," +
|
||||
record.beginRate + "," +
|
||||
record.endRate + "," +
|
||||
record.exitType + "," +
|
||||
record.stopRate + "]";
|
||||
|
||||
if (separator === "") { separator = ","; }
|
||||
|
||||
fileRecordCounter++;
|
||||
|
||||
}
|
||||
|
||||
fileContent = "[" + fileContent + "]";
|
||||
let fileName = '' + market.assetA + '_' + market.assetB + '.json';
|
||||
|
||||
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
|
||||
|
||||
fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated);
|
||||
|
||||
function onFileCreated(err) {
|
||||
|
||||
try {
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeTradesFile -> onFileCreated -> Entering function."); }
|
||||
if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> writeTradesFile -> onFileCreated -> fileContent = " + fileContent); }
|
||||
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> onFileCreated -> err = " + err.stack);
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> onFileCreated -> filePath = " + filePath);
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB);
|
||||
|
||||
callBackFunction(err);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
|
||||
}
|
||||
catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> onFileCreated -> err = " + err.stack);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> writeTradesFile -> err = " + err.stack);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> err = " + err.stack);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,387 @@
|
||||
{
|
||||
"displayName": "Jason",
|
||||
"codeName": "AAJason",
|
||||
"type": "Indicator",
|
||||
"version": {
|
||||
"major": 1,
|
||||
"minor": 0,
|
||||
"patch": 0
|
||||
},
|
||||
"devTeam": "AAMasters",
|
||||
"profilePicture": "Jason.png",
|
||||
"dataSetVersion": "dataSet.V1",
|
||||
"processes": [
|
||||
{
|
||||
"name": "Multi-Period-Market",
|
||||
"description": "Produces a single file for each time period covering all the market.",
|
||||
"normalWaitTime": 60000,
|
||||
"retryWaitTime": 10000,
|
||||
"sleepWaitTime": 3600000,
|
||||
"comaWaitTime": 86400000,
|
||||
"framework": {
|
||||
"name": "Multi-Period-Market",
|
||||
"startDate": {
|
||||
"fixedDate": "2018-07-01"
|
||||
},
|
||||
"endDate": {
|
||||
}
|
||||
},
|
||||
"statusDependencies": [
|
||||
{
|
||||
"devTeam": "AAMasters",
|
||||
"bot": "AAJason",
|
||||
"botVersion": {
|
||||
"major": 1,
|
||||
"minor": 0
|
||||
},
|
||||
"process": "Multi-Period-Market",
|
||||
"dataSetVersion": "dataSet.V1"
|
||||
}
|
||||
],
|
||||
"dataDependencies": [
|
||||
{
|
||||
"devTeam": "AAVikings",
|
||||
"bot": "AAGauss",
|
||||
"botVersion": {
|
||||
"major": 1,
|
||||
"minor": 0
|
||||
},
|
||||
"product": "LRC-Points",
|
||||
"dataSetVersion": "dataSet.V1",
|
||||
"dataSet": "Multi-Period-Market"
|
||||
},
|
||||
{
|
||||
"devTeam": "AAMasters",
|
||||
"bot": "AAChris",
|
||||
"botVersion": {
|
||||
"major": 1,
|
||||
"minor": 0
|
||||
},
|
||||
"product": "Percentage-Bandwidth",
|
||||
"dataSetVersion": "dataSet.V1",
|
||||
"dataSet": "Multi-Period-Market"
|
||||
},
|
||||
{
|
||||
"devTeam": "AAMasters",
|
||||
"bot": "AAChris",
|
||||
"botVersion": {
|
||||
"major": 1,
|
||||
"minor": 0
|
||||
},
|
||||
"product": "Bollinger-Bands",
|
||||
"dataSetVersion": "dataSet.V1",
|
||||
"dataSet": "Multi-Period-Market"
|
||||
},
|
||||
{
|
||||
"devTeam": "AAMasters",
|
||||
"bot": "AAPaula",
|
||||
"botVersion": {
|
||||
"major": 1,
|
||||
"minor": 0
|
||||
},
|
||||
"product": "Bollinger-Standard-Channels",
|
||||
"dataSetVersion": "dataSet.V1",
|
||||
"dataSet": "Multi-Period-Market"
|
||||
},
|
||||
{
|
||||
"devTeam": "AAMasters",
|
||||
"bot": "AAPaula",
|
||||
"botVersion": {
|
||||
"major": 1,
|
||||
"minor": 0
|
||||
},
|
||||
"product": "Bollinger-Standard-Sub-Channels",
|
||||
"dataSetVersion": "dataSet.V1",
|
||||
"dataSet": "Multi-Period-Market"
|
||||
},
|
||||
{
|
||||
"devTeam": "AAMasters",
|
||||
"bot": "AAOlivia",
|
||||
"botVersion": {
|
||||
"major": 1,
|
||||
"minor": 0
|
||||
},
|
||||
"product": "Candles",
|
||||
"dataSetVersion": "dataSet.V1",
|
||||
"dataSet": "Multi-Period-Market"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Multi-Period-Daily",
|
||||
"description": "Produces a Daily File at each time period.",
|
||||
"normalWaitTime": 60000,
|
||||
"retryWaitTime": 10000,
|
||||
"sleepWaitTime": 3600000,
|
||||
"comaWaitTime": 86400000,
|
||||
"framework": {
|
||||
"name": "Multi-Period-Daily",
|
||||
"validPeriods": [ "15-min", "10-min", "05-min"],
|
||||
"startDate": {
|
||||
"fixedDate": "2018-07-01"
|
||||
},
|
||||
"endDate": {
|
||||
"takeItFromStatusDependency": 1
|
||||
}
|
||||
},
|
||||
"statusDependencies": [
|
||||
{
|
||||
"devTeam": "AAMasters",
|
||||
"bot": "AACharly",
|
||||
"botVersion": {
|
||||
"major": 1,
|
||||
"minor": 0
|
||||
},
|
||||
"process": "Historic-Trades",
|
||||
"dataSetVersion": "dataSet.V1"
|
||||
},
|
||||
{
|
||||
"devTeam": "AAMasters",
|
||||
"bot": "AAOlivia",
|
||||
"botVersion": {
|
||||
"major": 1,
|
||||
"minor": 0
|
||||
},
|
||||
"process": "Multi-Period-Daily",
|
||||
"dataSetVersion": "dataSet.V1"
|
||||
},
|
||||
{
|
||||
"devTeam": "AAMasters",
|
||||
"bot": "AAJason",
|
||||
"botVersion": {
|
||||
"major": 1,
|
||||
"minor": 0
|
||||
},
|
||||
"process": "Multi-Period-Daily",
|
||||
"dataSetVersion": "dataSet.V1"
|
||||
}
|
||||
],
|
||||
"dataDependencies": [
|
||||
{
|
||||
"devTeam": "AAVikings",
|
||||
"bot": "AAGauss",
|
||||
"botVersion": {
|
||||
"major": 1,
|
||||
"minor": 0
|
||||
},
|
||||
"product": "LRC-Points",
|
||||
"dataSetVersion": "dataSet.V1",
|
||||
"dataSet": "Multi-Period-Daily"
|
||||
},
|
||||
{
|
||||
"devTeam": "AAMasters",
|
||||
"bot": "AAChris",
|
||||
"botVersion": {
|
||||
"major": 1,
|
||||
"minor": 0
|
||||
},
|
||||
"product": "Percentage-Bandwidth",
|
||||
"dataSetVersion": "dataSet.V1",
|
||||
"dataSet": "Multi-Period-Daily"
|
||||
},
|
||||
{
|
||||
"devTeam": "AAMasters",
|
||||
"bot": "AAChris",
|
||||
"botVersion": {
|
||||
"major": 1,
|
||||
"minor": 0
|
||||
},
|
||||
"product": "Bollinger-Bands",
|
||||
"dataSetVersion": "dataSet.V1",
|
||||
"dataSet": "Multi-Period-Daily"
|
||||
},
|
||||
{
|
||||
"devTeam": "AAMasters",
|
||||
"bot": "AAPaula",
|
||||
"botVersion": {
|
||||
"major": 1,
|
||||
"minor": 0
|
||||
},
|
||||
"product": "Bollinger-Standard-Channels",
|
||||
"dataSetVersion": "dataSet.V1",
|
||||
"dataSet": "Multi-Period-Daily"
|
||||
},
|
||||
{
|
||||
"devTeam": "AAMasters",
|
||||
"bot": "AAPaula",
|
||||
"botVersion": {
|
||||
"major": 1,
|
||||
"minor": 0
|
||||
},
|
||||
"product": "Bollinger-Standard-Sub-Channels",
|
||||
"dataSetVersion": "dataSet.V1",
|
||||
"dataSet": "Multi-Period-Daily"
|
||||
},
|
||||
{
|
||||
"devTeam": "AAMasters",
|
||||
"bot": "AAOlivia",
|
||||
"botVersion": {
|
||||
"major": 1,
|
||||
"minor": 0
|
||||
},
|
||||
"product": "Candles",
|
||||
"dataSetVersion": "dataSet.V1",
|
||||
"dataSet": "Multi-Period-Daily"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"products": [
|
||||
{
|
||||
"codeName": "Trading-Simulation",
|
||||
"displayName": "Trading Simulation",
|
||||
"description": "Trading Simulation",
|
||||
"storageAccount": "aajason",
|
||||
"dataSets": [
|
||||
{
|
||||
"codeName": "Multi-Period-Market",
|
||||
"type": "Market Files",
|
||||
"validPeriods": [ "24-hs", "12-hs", "08-hs", "06-hs", "04-hs", "03-hs", "02-hs", "01-hs" ],
|
||||
"filePath": "AAMasters/AAJason.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Trading-Simulation/Multi-Period-Market/@Period",
|
||||
"fileName": "@AssetA_@AssetB.json"
|
||||
},
|
||||
{
|
||||
"codeName": "Multi-Period-Daily",
|
||||
"type": "Daily Files",
|
||||
"validPeriods": [ "15-min", "10-min", "05-min" ],
|
||||
"filePath": "AAMasters/AAJason.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Trading-Simulation/Multi-Period-Daily/@Period/@Year/@Month/@Day",
|
||||
"fileName": "@AssetA_@AssetB.json",
|
||||
"dataRange": {
|
||||
"filePath": "AAMasters/AAJason.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Trading-Simulation/Multi-Period-Daily",
|
||||
"fileName": "Data.Range.@AssetA_@AssetB.json"
|
||||
}
|
||||
}
|
||||
],
|
||||
"exchangeList": [
|
||||
{
|
||||
"name": "Poloniex"
|
||||
},
|
||||
{
|
||||
"name": "Coss"
|
||||
}
|
||||
],
|
||||
"plotter": {
|
||||
"devTeam": "AAMasters",
|
||||
"codeName": "PlottersTradingSimulation",
|
||||
"moduleName": "TradingSimulation"
|
||||
}
|
||||
},
|
||||
{
|
||||
"codeName": "Simulation-Conditions",
|
||||
"displayName": "Simulation Conditions",
|
||||
"description": "Simulation Conditions",
|
||||
"storageAccount": "aajason",
|
||||
"dataSets": [
|
||||
{
|
||||
"codeName": "Multi-Period-Market",
|
||||
"type": "Market Files",
|
||||
"validPeriods": [ "24-hs", "12-hs", "08-hs", "06-hs", "04-hs", "03-hs", "02-hs", "01-hs" ],
|
||||
"filePath": "AAMasters/AAJason.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Conditions/Multi-Period-Market/@Period",
|
||||
"fileName": "@AssetA_@AssetB.json"
|
||||
},
|
||||
{
|
||||
"codeName": "Multi-Period-Daily",
|
||||
"type": "Daily Files",
|
||||
"validPeriods": [ "15-min", "10-min", "05-min" ],
|
||||
"filePath": "AAMasters/AAJason.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Conditions/Multi-Period-Daily/@Period/@Year/@Month/@Day",
|
||||
"fileName": "@AssetA_@AssetB.json",
|
||||
"dataRange": {
|
||||
"filePath": "AAMasters/AAJason.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Conditions/Multi-Period-Daily",
|
||||
"fileName": "Data.Range.@AssetA_@AssetB.json"
|
||||
}
|
||||
}
|
||||
],
|
||||
"exchangeList": [
|
||||
{
|
||||
"name": "Poloniex"
|
||||
},
|
||||
{
|
||||
"name": "Coss"
|
||||
}
|
||||
],
|
||||
"plotter": {
|
||||
"devTeam": "AAMasters",
|
||||
"codeName": "PlottersTradingSimulation",
|
||||
"moduleName": "Conditions"
|
||||
}
|
||||
},
|
||||
{
|
||||
"codeName": "Simulation-Strategies",
|
||||
"displayName": "Simulation Strategies",
|
||||
"description": "Simulation Strategies",
|
||||
"storageAccount": "aajason",
|
||||
"dataSets": [
|
||||
{
|
||||
"codeName": "Multi-Period-Market",
|
||||
"type": "Market Files",
|
||||
"validPeriods": [ "24-hs", "12-hs", "08-hs", "06-hs", "04-hs", "03-hs", "02-hs", "01-hs" ],
|
||||
"filePath": "AAMasters/AAJason.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Strategies/Multi-Period-Market/@Period",
|
||||
"fileName": "@AssetA_@AssetB.json"
|
||||
},
|
||||
{
|
||||
"codeName": "Multi-Period-Daily",
|
||||
"type": "Daily Files",
|
||||
"validPeriods": [ "15-min", "10-min", "05-min" ],
|
||||
"filePath": "AAMasters/AAJason.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Strategies/Multi-Period-Daily/@Period/@Year/@Month/@Day",
|
||||
"fileName": "@AssetA_@AssetB.json",
|
||||
"dataRange": {
|
||||
"filePath": "AAMasters/AAJason.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Strategies/Multi-Period-Daily",
|
||||
"fileName": "Data.Range.@AssetA_@AssetB.json"
|
||||
}
|
||||
}
|
||||
],
|
||||
"exchangeList": [
|
||||
{
|
||||
"name": "Poloniex"
|
||||
},
|
||||
{
|
||||
"name": "Coss"
|
||||
}
|
||||
],
|
||||
"plotter": {
|
||||
"devTeam": "AAMasters",
|
||||
"codeName": "PlottersTradingSimulation",
|
||||
"moduleName": "Strategies"
|
||||
}
|
||||
},
|
||||
{
|
||||
"codeName": "Simulation-Trades",
|
||||
"displayName": "Simulation Trades",
|
||||
"description": "Simulation Trades",
|
||||
"storageAccount": "aajason",
|
||||
"dataSets": [
|
||||
{
|
||||
"codeName": "Multi-Period-Market",
|
||||
"type": "Market Files",
|
||||
"validPeriods": [ "24-hs", "12-hs", "08-hs", "06-hs", "04-hs", "03-hs", "02-hs", "01-hs" ],
|
||||
"filePath": "AAMasters/AAJason.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Trades/Multi-Period-Market/@Period",
|
||||
"fileName": "@AssetA_@AssetB.json"
|
||||
},
|
||||
{
|
||||
"codeName": "Multi-Period-Daily",
|
||||
"type": "Daily Files",
|
||||
"validPeriods": [ "15-min", "10-min", "05-min" ],
|
||||
"filePath": "AAMasters/AAJason.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Trades/Multi-Period-Daily/@Period/@Year/@Month/@Day",
|
||||
"fileName": "@AssetA_@AssetB.json",
|
||||
"dataRange": {
|
||||
"filePath": "AAMasters/AAJason.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Trades/Multi-Period-Daily",
|
||||
"fileName": "Data.Range.@AssetA_@AssetB.json"
|
||||
}
|
||||
}
|
||||
],
|
||||
"exchangeList": [
|
||||
{
|
||||
"name": "Poloniex"
|
||||
},
|
||||
{
|
||||
"name": "Coss"
|
||||
}
|
||||
],
|
||||
"plotter": {
|
||||
"devTeam": "AAMasters",
|
||||
"codeName": "PlottersTradingSimulation",
|
||||
"moduleName": "Trades"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,915 @@
|
||||
exports.newUserBot = function newUserBot(bot, logger) {
|
||||
|
||||
// Variable used for logs, which will be passed to the logger instance
|
||||
const MODULE_NAME = 'User Bot'
|
||||
const LOG_INFO = true
|
||||
let assistant, fileStorage
|
||||
let autopilotControl = false
|
||||
|
||||
const orderMessage = require("@superalgos/mqservice/orderMessage/orderMessage")
|
||||
|
||||
const {
|
||||
MESSAGE_ENTITY, MESSAGE_TYPE, ORDER_CREATOR, ORDER_TYPE, ORDER_OWNER,
|
||||
ORDER_DIRECTION, ORDER_STATUS, ORDER_EXIT_OUTCOME, ORDER_MARGIN_ENABLED,
|
||||
getMessage, createMessageFromObject
|
||||
} = orderMessage.newOrderMessage()
|
||||
|
||||
const axios = require('axios')
|
||||
const util = require('util')
|
||||
|
||||
/*
|
||||
This objects returns two public functions that will be used to integrate with the platform.
|
||||
*/
|
||||
return {
|
||||
initialize: initialize,
|
||||
start: start,
|
||||
setAutopilot: setAutopilot,
|
||||
executorLogic: executorLogic
|
||||
}
|
||||
|
||||
function initialize(pAssistant, pGenes, callBackFunction) {
|
||||
try {
|
||||
logInfo('initialize -> Entering function.')
|
||||
|
||||
// Integration with platform logger, when running on cloud
|
||||
logger.fileName = MODULE_NAME
|
||||
assistant = pAssistant
|
||||
|
||||
if (bot.timePeriodFileStorage === undefined) {
|
||||
throw new Error("Execution Parameter Time Period not defined.")
|
||||
}
|
||||
|
||||
if (bot.dataSet === undefined) {
|
||||
throw new Error("Execution Parameter Data Set not defined.")
|
||||
}
|
||||
|
||||
let key = bot.devTeam + '-simulator-' + bot.codeName + '-Trading-Execution-' + bot.dataSet + '-dataSet.V1'
|
||||
fileStorage = assistant.dataDependencies.dataSets.get(key)
|
||||
|
||||
if (fileStorage !== undefined) {
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE)
|
||||
} else {
|
||||
logError('initialize -> Failed to initialize storage. Key not found:' + key)
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE)
|
||||
}
|
||||
} catch (error) {
|
||||
logError('initialize -> onDone -> err = ' + error.message)
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE)
|
||||
}
|
||||
}
|
||||
|
||||
function logInfo(message) {
|
||||
if (LOG_INFO === true) { logger.write(MODULE_NAME, '[INFO] ' + message) }
|
||||
}
|
||||
|
||||
function logWarn(message) {
|
||||
if (LOG_INFO === true) { logger.write(MODULE_NAME, '[WARN] ' + message) }
|
||||
}
|
||||
|
||||
function logError(message) {
|
||||
logger.write(MODULE_NAME, '[ERROR] ' + message)
|
||||
}
|
||||
|
||||
function setAutopilot(autopilot) {
|
||||
autopilotControl = autopilot
|
||||
}
|
||||
|
||||
/*
|
||||
The start function is called by the platform for executing the bot every 1 minute
|
||||
*/
|
||||
function start(callBackFunction) {
|
||||
logInfo('start -> Entering function.')
|
||||
|
||||
const callback = util.callbackify(executorLogic)
|
||||
|
||||
callback((err, ret) => {
|
||||
if (err) {
|
||||
callBackFunction(err)
|
||||
} else {
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function getValueFromPreviousExecution(key) {
|
||||
let value = assistant.remindMeOf(key)
|
||||
if (value === undefined)
|
||||
value = 0
|
||||
return value
|
||||
}
|
||||
|
||||
async function executorLogic() {
|
||||
try {
|
||||
let indicatorFileContent = await getIndicatorFile()
|
||||
let simulatorEngineMessage = getSimulatorEngineMessageFromFile(indicatorFileContent)
|
||||
|
||||
let stopLoss = getValueFromPreviousExecution('lastStopLoss')
|
||||
let takeProfit = getValueFromPreviousExecution('lastTakeProfit')
|
||||
let openTradeSimulatorMessageId = getValueFromPreviousExecution('openTradeSimulatorMessageId')
|
||||
|
||||
if (simulatorEngineMessage === undefined) {
|
||||
if (openTradeSimulatorMessageId > 0) {
|
||||
logWarn('executorLogic -> Simulator message not available. Will proceed to check if the trade needs to be closed.')
|
||||
let simulatorMessajeNotFound = -1
|
||||
await closeTrade(stopLoss, takeProfit, simulatorMessajeNotFound)
|
||||
}
|
||||
} else {
|
||||
logInfo('executorLogic -> Processing simulator record: ' + JSON.stringify(simulatorEngineMessage))
|
||||
|
||||
// Verify if there is an inconsistent state between the simulator and executor
|
||||
let isMessageAnOrder = (simulatorEngineMessage.messageType === MESSAGE_TYPE.Order)
|
||||
let isMessageAnOrderUpdate = (simulatorEngineMessage.messageType === MESSAGE_TYPE.OrderUpdate)
|
||||
let isMessageAnOrderClose = (simulatorEngineMessage.messageType === MESSAGE_TYPE.OrderClose)
|
||||
let isMessageAHeartBeat = (simulatorEngineMessage.messageType === MESSAGE_TYPE.HeartBeat)
|
||||
|
||||
let existsAnOpenTrade = (openTradeSimulatorMessageId > 0)
|
||||
if (existsAnOpenTrade) {
|
||||
let isOrderMessage = isMessageAnOrder && simulatorEngineMessage.id === openTradeSimulatorMessageId
|
||||
if (isOrderMessage || isMessageAnOrderUpdate) {
|
||||
logInfo('Moving the position because it is the same message that caused the open trade or because it is an update.')
|
||||
await openOrMoveTrade(simulatorEngineMessage)
|
||||
} else if (isMessageAnOrderClose) {
|
||||
assistant.rememberThis('closeTradeSimulatorMessageId', simulatorEngineMessage.id)
|
||||
let isStopLoss = (simulatorEngineMessage.order.exitOutcome === ORDER_EXIT_OUTCOME.StopLoss)
|
||||
let isTakeProfit = (simulatorEngineMessage.order.exitOutcome === ORDER_EXIT_OUTCOME.StopLoss)
|
||||
if (isStopLoss) {
|
||||
stopLoss = assistant.getMarketRate()
|
||||
takeProfit = 0
|
||||
} else if (isTakeProfit) {
|
||||
stopLoss = 0
|
||||
takeProfit = assistant.getMarketRate()
|
||||
}
|
||||
} else if (isMessageAHeartBeat) {
|
||||
logWarn('An inconsisten state was detected: there is an open trade and a close trade was expected.')
|
||||
let skippedSimulatorEngineMessage = getSkippedMessageOrderClose(indicatorFileContent)
|
||||
if (skippedSimulatorEngineMessage === undefined) {
|
||||
logWarn('There was not a Skipped Message Order Close. Closing the position the best possible.')
|
||||
stopLoss = assistant.getMarketRate()
|
||||
takeProfit = 0
|
||||
} else {
|
||||
if (skippedSimulatorEngineMessage.id > openTradeSimulatorMessageId) {
|
||||
logWarn('The Skipped Message Order Close was found and using it to set the SL and TP.')
|
||||
stopLoss = skippedSimulatorEngineMessage.order.stop
|
||||
takeProfit = skippedSimulatorEngineMessage.order.takeProfit
|
||||
} else {
|
||||
logWarn('One Message Order Close was found but is older than the Open Order. Closing the position the best possible.')
|
||||
stopLoss = assistant.getMarketRate()
|
||||
takeProfit = 0
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logError('Not managed condition.')
|
||||
}
|
||||
assistant.rememberThis('lastStopLoss', stopLoss)
|
||||
assistant.rememberThis('lastTakeProfit', takeProfit)
|
||||
await closeTrade(stopLoss, takeProfit, openTradeSimulatorMessageId)
|
||||
} else {
|
||||
if (isMessageAnOrder) {
|
||||
await openOrMoveTrade(simulatorEngineMessage)
|
||||
} else {
|
||||
logInfo('Nothing to do, there is not an open order.')
|
||||
}
|
||||
}
|
||||
assistant.addExtraData(simulatorEngineMessage) // Adding the record used for the execution
|
||||
}
|
||||
} catch (error) {
|
||||
logError('Error on executorLogic: ' + JSON.stringify(error))
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
async function closeTrade(stopLoss, takeProfit, openTradeSimulatorMessageId) {
|
||||
let currentRate = assistant.getMarketRate()
|
||||
let wasExecuted = false
|
||||
let tradeSize = assistant.getAvailableBalance().assetA
|
||||
let tradeDirection = ORDER_DIRECTION.Buy
|
||||
let closeTradeSimulatorMessageId = getValueFromPreviousExecution('closeTradeSimulatorMessageId')
|
||||
|
||||
if (process.env.BASE_ASSET === 'assetA') {
|
||||
wasExecuted = closeTradeSimulatorMessageId > 0 && assistant.getAvailableBalance().assetB === 0 && assistant.getAvailableBalance().assetA > 0
|
||||
tradeSize = assistant.getAvailableBalance().assetB
|
||||
tradeDirection = ORDER_DIRECTION.Sell
|
||||
} else {
|
||||
wasExecuted = closeTradeSimulatorMessageId > 0 && assistant.getAvailableBalance().assetA === 0 && assistant.getAvailableBalance().assetB > 0
|
||||
}
|
||||
|
||||
// Check completion of current positions at the exchange
|
||||
let positions = assistant.getPositions()
|
||||
let isPositionExecuted = false
|
||||
for (let i = 0; i < positions.length; i++) {
|
||||
const position = positions[i];
|
||||
if (position.id === closeTradeSimulatorMessageId && position.status === 'executed') {
|
||||
isPositionExecuted = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (isPositionExecuted || wasExecuted) {
|
||||
assistant.rememberThis('openTradeSimulatorMessageId', 0)
|
||||
assistant.rememberThis('closeTradeSimulatorMessageId', 0)
|
||||
assistant.rememberThis('openTradePositionId', 0)
|
||||
assistant.rememberThis('lastStopLoss', 0)
|
||||
assistant.rememberThis('lastTakeProfit', 0)
|
||||
|
||||
let simulatorExecutorMessage = buildBasicSimulatorExecutorMessage()
|
||||
simulatorExecutorMessage.id = openTradeSimulatorMessageId
|
||||
simulatorExecutorMessage.order.id = positions.length > 0 ? positions[0].id : 0
|
||||
simulatorExecutorMessage.order.rate = currentRate
|
||||
simulatorExecutorMessage.order.stop = stopLoss
|
||||
simulatorExecutorMessage.order.takeProfit = takeProfit
|
||||
simulatorExecutorMessage.order.direction = tradeDirection
|
||||
simulatorExecutorMessage.order.size = tradeSize
|
||||
simulatorExecutorMessage.order.status = ORDER_STATUS.Placed
|
||||
simulatorExecutorMessage.order.exitOutcome = ORDER_EXIT_OUTCOME.StopLoss
|
||||
|
||||
let message = createMessageFromObject(simulatorExecutorMessage)
|
||||
assistant.addExtraData(message)
|
||||
}
|
||||
|
||||
// Checking Stop Loss & Take Profit
|
||||
if ((takeProfit > 0 || stopLoss > 0) && closeTradeSimulatorMessageId > 0) {
|
||||
let exitOutcome
|
||||
if (takeProfit > 0) {
|
||||
logInfo('Closing trade with Take Profit.')
|
||||
exitOutcome = ORDER_EXIT_OUTCOME.TakeProfit
|
||||
} else {
|
||||
logInfo('Closing trade with Stop Loss.')
|
||||
exitOutcome = ORDER_EXIT_OUTCOME.StopLoss
|
||||
}
|
||||
|
||||
try {
|
||||
let position
|
||||
if (process.env.BASE_ASSET === 'assetA') {
|
||||
position = await createSellPosition(currentRate)
|
||||
} else {
|
||||
position = await createBuyPosition(currentRate)
|
||||
}
|
||||
assistant.rememberThis('closeTradePositionId', position.id)
|
||||
|
||||
let simulatorExecutorMessage = buildBasicSimulatorExecutorMessage()
|
||||
simulatorExecutorMessage.id = openTradeSimulatorMessageId
|
||||
simulatorExecutorMessage.order.id = position.id
|
||||
simulatorExecutorMessage.order.rate = currentRate
|
||||
simulatorExecutorMessage.order.stop = stopLoss
|
||||
simulatorExecutorMessage.order.takeProfit = takeProfit
|
||||
simulatorExecutorMessage.order.direction = tradeDirection
|
||||
simulatorExecutorMessage.order.size = tradeSize
|
||||
simulatorExecutorMessage.order.status = ORDER_STATUS.Placed
|
||||
simulatorExecutorMessage.order.exitOutcome = exitOutcome
|
||||
|
||||
let message = createMessageFromObject(simulatorExecutorMessage)
|
||||
assistant.addExtraData(message)
|
||||
|
||||
} catch (error) {
|
||||
let simulatorExecutorMessage = buildBasicSimulatorExecutorMessage()
|
||||
simulatorExecutorMessage.id = openTradeSimulatorMessageId
|
||||
simulatorExecutorMessage.from = MESSAGE_ENTITY.TradingAssistant
|
||||
simulatorExecutorMessage.to = MESSAGE_ENTITY.SimulationExecutor
|
||||
simulatorExecutorMessage.order.rate = currentRate
|
||||
simulatorExecutorMessage.order.stop = stopLoss
|
||||
simulatorExecutorMessage.order.takeProfit = takeProfit
|
||||
simulatorExecutorMessage.order.direction = tradeDirection
|
||||
simulatorExecutorMessage.order.size = tradeSize
|
||||
simulatorExecutorMessage.order.status = ORDER_STATUS.Rejected
|
||||
simulatorExecutorMessage.order.exitOutcome = exitOutcome
|
||||
simulatorExecutorMessage.order.statusDetails = error.message
|
||||
|
||||
let message = createMessageFromObject(simulatorExecutorMessage)
|
||||
assistant.addExtraData(message)
|
||||
} finally {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function openOrMoveTrade(simulatorEngineMessage) {
|
||||
autopilotControl = true // Force autopilot on for now
|
||||
if (!autopilotControl) {
|
||||
autopilotControl = await getAutopilot()
|
||||
}
|
||||
if (autopilotControl.autopilot || autopilotControl) {
|
||||
await openTradeAutopilotOn(simulatorEngineMessage)
|
||||
} else {
|
||||
await openTradeAutopilotOff(simulatorEngineMessage)
|
||||
}
|
||||
}
|
||||
|
||||
async function openTradeAutopilotOn(simulatorEngineMessage) {
|
||||
let currentRate = assistant.getMarketRate()
|
||||
let tradeSize = assistant.getAvailableBalance().assetB
|
||||
let tradeDirection = ORDER_DIRECTION.Sell
|
||||
|
||||
if (process.env.BASE_ASSET === 'assetA') {
|
||||
tradeSize = assistant.getAvailableBalance().assetA
|
||||
tradeDirection = ORDER_DIRECTION.Buy
|
||||
}
|
||||
|
||||
try {
|
||||
// Create a new position or move existing position to complete the order execution
|
||||
let position
|
||||
if (process.env.BASE_ASSET === 'assetA') {
|
||||
position = await createBuyPosition(currentRate)
|
||||
} else {
|
||||
position = await createSellPosition(currentRate)
|
||||
}
|
||||
|
||||
assistant.rememberThis('openTradePositionId', position.id)
|
||||
assistant.rememberThis('openTradeSimulatorMessageId', simulatorEngineMessage.id)
|
||||
assistant.rememberThis('lastStopLoss', simulatorEngineMessage.order.stop)
|
||||
assistant.rememberThis('lastTakeProfit', simulatorEngineMessage.order.takeProfit)
|
||||
|
||||
let simulatorExecutorMessage = buildBasicSimulatorExecutorMessage()
|
||||
simulatorExecutorMessage.id = simulatorEngineMessage.id
|
||||
simulatorExecutorMessage.order.id = position.id
|
||||
simulatorExecutorMessage.order.rate = currentRate
|
||||
simulatorExecutorMessage.order.stop = simulatorEngineMessage.order.stop
|
||||
simulatorExecutorMessage.order.takeProfit = simulatorEngineMessage.order.takeProfit
|
||||
simulatorExecutorMessage.order.direction = tradeDirection
|
||||
simulatorExecutorMessage.order.size = tradeSize
|
||||
|
||||
let message = createMessageFromObject(simulatorExecutorMessage)
|
||||
assistant.addExtraData(message)
|
||||
} catch (error) {
|
||||
let simulatorExecutorMessage = buildBasicSimulatorExecutorMessage()
|
||||
simulatorExecutorMessage.id = simulatorEngineMessage.id
|
||||
simulatorExecutorMessage.from = MESSAGE_ENTITY.TradingAssistant
|
||||
simulatorExecutorMessage.to = MESSAGE_ENTITY.SimulationExecutor
|
||||
simulatorExecutorMessage.messageType = MESSAGE_TYPE.Order
|
||||
simulatorExecutorMessage.order.rate = currentRate
|
||||
simulatorExecutorMessage.order.stop = simulatorEngineMessage.order.stop
|
||||
simulatorExecutorMessage.order.takeProfit = simulatorEngineMessage.order.takeProfit
|
||||
simulatorExecutorMessage.order.direction = tradeDirection
|
||||
simulatorExecutorMessage.order.size = tradeSize
|
||||
simulatorExecutorMessage.order.status = ORDER_STATUS.Rejected
|
||||
simulatorExecutorMessage.order.statusDetails = error.message
|
||||
|
||||
let message = createMessageFromObject(simulatorExecutorMessage)
|
||||
assistant.addExtraData(message)
|
||||
}
|
||||
}
|
||||
|
||||
async function openTradeAutopilotOff(simulatorEngineMessage) {
|
||||
/**
|
||||
* If there is a ManualAuthorized order on the cockpit we will proceed to:
|
||||
* 1) Save an audit containing what we received from the cockpit
|
||||
* 2) Execute the order in the market as received
|
||||
* 3) Save the audit of the order placed
|
||||
* 4) Update the cockpit with the result
|
||||
*/
|
||||
let acceptedSignals = await getSignalsByCloneId(ORDER_STATUS.ManualAuthorized)
|
||||
if (acceptedSignals !== undefined && acceptedSignals.length > 0) {
|
||||
for (let acceptedSignal of acceptedSignals) {
|
||||
try {
|
||||
logInfo('openTradeAutopilotOff -> Executing manual authorized signal.')
|
||||
|
||||
// 1) Save audit containing what we received from the cockpit
|
||||
let simulatorExecutorMessage = buildBasicSimulatorExecutorMessage()
|
||||
simulatorExecutorMessage.id = simulatorEngineMessage.id
|
||||
simulatorExecutorMessage.from = MESSAGE_ENTITY.TradingCokpit
|
||||
simulatorExecutorMessage.to = MESSAGE_ENTITY.SimulationExecutor
|
||||
simulatorExecutorMessage.order = acceptedSignal.orderData // we save the order as received
|
||||
simulatorExecutorMessage.order.status = ORDER_STATUS.ManualAuthorized
|
||||
let message = createMessageFromObject(simulatorExecutorMessage)
|
||||
assistant.addExtraData(message)
|
||||
|
||||
// 2) Execute the order in the market as received
|
||||
let position = await createSellPosition(acceptedSignal.orderData.rate, acceptedSignal.orderData.size)
|
||||
assistant.rememberThis('openTradePositionId', position.id)
|
||||
assistant.rememberThis('openTradeSimulatorMessageId', simulatorEngineMessage.id)
|
||||
assistant.rememberThis('lastStopLoss', simulatorEngineMessage.order.stop)
|
||||
assistant.rememberThis('lastTakeProfit', simulatorEngineMessage.order.takeProfit)
|
||||
|
||||
// 3) Save the audit of the order placed
|
||||
simulatorExecutorMessage = buildBasicSimulatorExecutorMessage()
|
||||
simulatorExecutorMessage.id = simulatorEngineMessage.id
|
||||
simulatorExecutorMessage.from = MESSAGE_ENTITY.SimulationExecutor
|
||||
simulatorExecutorMessage.to = MESSAGE_ENTITY.TradingAssistant
|
||||
simulatorExecutorMessage.dateTime = position.date
|
||||
|
||||
simulatorExecutorMessage.order = acceptedSignal.orderData
|
||||
simulatorExecutorMessage.order.id = position.id
|
||||
simulatorExecutorMessage.order.dateTime = position.date
|
||||
simulatorExecutorMessage.order.rate = position.rate
|
||||
simulatorExecutorMessage.order.size = position.amountB
|
||||
simulatorExecutorMessage.order.status = ORDER_STATUS.Placed
|
||||
simulatorExecutorMessage.order.sizeFilled = 0
|
||||
|
||||
// 4) Update the cockpit with the result
|
||||
await updateSignal(acceptedSignal.id, simulatorExecutorMessage)
|
||||
|
||||
message = createMessageFromObject(simulatorExecutorMessage)
|
||||
assistant.addExtraData(message)
|
||||
return
|
||||
} catch (error) {
|
||||
// Update the cockpit with the error
|
||||
let simulatorExecutorMessage = buildBasicSimulatorExecutorMessage()
|
||||
simulatorExecutorMessage.id = simulatorEngineMessage.id
|
||||
simulatorExecutorMessage.from = MESSAGE_ENTITY.SimulationExecutor
|
||||
simulatorExecutorMessage.to = MESSAGE_ENTITY.TradingCokpit
|
||||
simulatorExecutorMessage.messageType = MESSAGE_TYPE.Order
|
||||
simulatorExecutorMessage.dateTime = bot.processDatetime.valueOf()
|
||||
simulatorExecutorMessage.order.status = ORDER_STATUS.Rejected
|
||||
simulatorExecutorMessage.order.statusDetails = error.message
|
||||
|
||||
simulatorExecutorMessage.order = acceptedSignal.order
|
||||
|
||||
await updateSignal(acceptedSignal.id, simulatorExecutorMessage)
|
||||
|
||||
// Update the audit with the error
|
||||
let message = createMessageFromObject(simulatorExecutorMessage)
|
||||
assistant.addExtraData(message)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If there is a Placed order on the cockpit we will proceed to:
|
||||
* 1) Check order status on the market
|
||||
* 2) Save the audit of the status
|
||||
* 3) Update the cockpit with the results
|
||||
*/
|
||||
let inProcessSignals = await getSignalsByCloneId(ORDER_STATUS.Placed)
|
||||
if (inProcessSignals !== undefined && inProcessSignals.length > 0) {
|
||||
for (let inProcessSignal of inProcessSignals) {
|
||||
logInfo('openTradeAutopilotOff -> Checking in process signal.')
|
||||
// 1) Check order status on the market
|
||||
let position = checkSignalCompletion()
|
||||
if (position || position === undefined) {
|
||||
// 2) Save the audit of the status
|
||||
let simulatorExecutorMessage = buildBasicSimulatorExecutorMessage()
|
||||
simulatorExecutorMessage.id = inProcessSignal.orderData.id
|
||||
simulatorExecutorMessage.from = MESSAGE_ENTITY.SimulationExecutor
|
||||
simulatorExecutorMessage.to = MESSAGE_ENTITY.TradingCokpit
|
||||
simulatorExecutorMessage.messageType = MESSAGE_TYPE.OrderUpdate
|
||||
|
||||
simulatorExecutorMessage.order = inProcessSignal.orderData
|
||||
simulatorExecutorMessage.order.status = ORDER_STATUS.Filled
|
||||
simulatorExecutorMessage.order.sizeFilled = -1
|
||||
|
||||
// 3) Update the cockpit with the results
|
||||
await updateSignal(inProcessSignal.id, simulatorExecutorMessage)
|
||||
|
||||
let message = createMessageFromObject(simulatorExecutorMessage)
|
||||
assistant.addExtraData(message)
|
||||
} else {
|
||||
// Otherwise: Save the audit of the order status, wichs is currently saved by the trading process
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If there is any signal not yet authorized:
|
||||
* 1) Update the signal with the new indicator value on the cockpit
|
||||
* 3) Save the audit of the message sent
|
||||
*/
|
||||
let assetBBalance = assistant.getAvailableBalance().assetB
|
||||
let currentRate = assistant.getMarketRate()
|
||||
let signals = await getSignalsByCloneId(ORDER_STATUS.Signaled)
|
||||
if (signals !== undefined && signals.length > 0) {
|
||||
for (let inProcessSignal of signals) {
|
||||
logInfo('openTradeAutopilotOff -> Signal waiting for approval found, updating it with latest market data.')
|
||||
|
||||
let simulatorExecutorMessage = buildBasicSimulatorExecutorMessage()
|
||||
simulatorExecutorMessage.to = MESSAGE_ENTITY.TradingCokpit
|
||||
simulatorExecutorMessage.messageType = MESSAGE_TYPE.OrderUpdate
|
||||
simulatorExecutorMessage.order.id = 0
|
||||
simulatorExecutorMessage.order.rate = currentRate
|
||||
simulatorExecutorMessage.order.stop = simulatorEngineMessage.order.stop
|
||||
simulatorExecutorMessage.order.takeProfit = simulatorEngineMessage.order.takeProfit
|
||||
simulatorExecutorMessage.order.direction = simulatorEngineMessage.order.direction
|
||||
simulatorExecutorMessage.order.size = assetBBalance
|
||||
simulatorExecutorMessage.order.status = ORDER_STATUS.Signaled
|
||||
|
||||
await updateSignal(inProcessSignal.id, simulatorExecutorMessage)
|
||||
|
||||
let message = createMessageFromObject(simulatorExecutorMessage)
|
||||
assistant.addExtraData(message)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finally:
|
||||
* 1) Check if it's needed to create a new signal based on the indicator
|
||||
* 2) Save the audit message for the received info from Trading Simulator
|
||||
* 3) Create the signal on the cockpit
|
||||
*/
|
||||
if (simulatorEngineMessage !== undefined && simulatorEngineMessage.messageType === MESSAGE_TYPE.Order
|
||||
&& simulatorEngineMessage.order.direction === ORDER_DIRECTION.Sell) {
|
||||
logInfo('Creating new signal.')
|
||||
|
||||
// 2) Save the audit message for the received info from Trading Simulator
|
||||
let simulatorExecutorMessage = buildBasicSimulatorExecutorMessage()
|
||||
simulatorExecutorMessage.id = simulatorEngineMessage.id
|
||||
simulatorExecutorMessage.to = MESSAGE_ENTITY.TradingCokpit
|
||||
simulatorExecutorMessage.messageType = MESSAGE_TYPE.Order
|
||||
simulatorExecutorMessage.order.id = 0
|
||||
simulatorExecutorMessage.order.status = ORDER_STATUS.Signaled
|
||||
simulatorExecutorMessage.order.rate = currentRate
|
||||
simulatorExecutorMessage.order.direction = ORDER_DIRECTION.Sell
|
||||
simulatorExecutorMessage.order.takeProfit = simulatorEngineMessage.order.takeProfit
|
||||
simulatorExecutorMessage.order.stop = simulatorEngineMessage.order.stop
|
||||
simulatorExecutorMessage.order.size = assetBBalance
|
||||
|
||||
let message = createMessageFromObject(simulatorExecutorMessage)
|
||||
assistant.addExtraData(message)
|
||||
|
||||
// 3) Create the signal on the cockpit
|
||||
await createSignal(simulatorExecutorMessage)
|
||||
} else {
|
||||
logWarn("openTradeAutopilotOff -> Nothing to do, there isn't a buy or sell opportunity.")
|
||||
}
|
||||
}
|
||||
|
||||
async function createBuyPosition(currentRate, amountToBuy) {
|
||||
if (!amountToBuy) amountToBuy = assistant.getAvailableBalance().assetA
|
||||
let amountB = Number((amountToBuy / currentRate).toFixed(8))
|
||||
let positions = assistant.getPositions()
|
||||
let assetABalance = assistant.getAvailableBalance().assetA
|
||||
|
||||
if (positions.length > 0 && positions[0].type === 'buy' && positions[0].status !== 'executed') {
|
||||
logInfo('createBuyPosition -> Moving an existing BUY position to a new price: $' + Number(currentRate).toLocaleString())
|
||||
|
||||
assistant.movePosition[util.promisify.custom] = n => new Promise((resolve, reject) => {
|
||||
assistant.movePosition(positions[0], currentRate, (result, position) => {
|
||||
if (result !== global.DEFAULT_OK_RESPONSE) {
|
||||
reject(result)
|
||||
} else {
|
||||
resolve(position)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
let movePosition = util.promisify(assistant.movePosition)
|
||||
await movePosition(positions[0], currentRate)
|
||||
return positions[0]
|
||||
} else if (assetABalance > 0) {
|
||||
logInfo('createBuyPosition -> Put a new BUY position at price: $' + Number(currentRate).toLocaleString())
|
||||
|
||||
assistant.putPosition[util.promisify.custom] = n => new Promise((resolve, reject) => {
|
||||
assistant.putPosition('buy', currentRate, amountToBuy, amountB, (result, position) => {
|
||||
if (result !== global.DEFAULT_OK_RESPONSE) {
|
||||
reject(result)
|
||||
} else {
|
||||
resolve(position)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
let putPosition = util.promisify(assistant.putPosition)
|
||||
let position = await putPosition('buy', currentRate, amountToBuy, amountB)
|
||||
return position
|
||||
} else {
|
||||
logInfo('createBuyPosition -> Not enough available balance to buy.')
|
||||
throw new Error('There is not enough available balance to buy.')
|
||||
}
|
||||
}
|
||||
|
||||
async function createSellPosition(currentRate, amountToSell) {
|
||||
if (!amountToSell) amountToSell = assistant.getAvailableBalance().assetB
|
||||
let amountA = amountToSell * currentRate
|
||||
let positions = assistant.getPositions()
|
||||
|
||||
if (positions.length > 0 && positions[0].type === 'sell' && positions[0].status !== 'executed') {
|
||||
logInfo('createSellPosition -> Moving an existing SELL position to a new price: $' + Number(currentRate).toLocaleString())
|
||||
|
||||
assistant.movePosition[util.promisify.custom] = n => new Promise((resolve, reject) => {
|
||||
assistant.movePosition(positions[0], currentRate, (result, position) => {
|
||||
if (result !== global.DEFAULT_OK_RESPONSE) {
|
||||
reject(result)
|
||||
} else {
|
||||
resolve(position)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
let movePosition = util.promisify(assistant.movePosition)
|
||||
await movePosition(positions[0], currentRate)
|
||||
return positions[0]
|
||||
} else if (assistant.getAvailableBalance().assetB > 0) {
|
||||
logInfo('createSellPosition -> Put a new SELL position at price: $' + Number(currentRate).toLocaleString())
|
||||
assistant.putPosition[util.promisify.custom] = n => new Promise((resolve, reject) => {
|
||||
assistant.putPosition('sell', currentRate, amountA, amountToSell, (result, position) => {
|
||||
if (result !== global.DEFAULT_OK_RESPONSE) {
|
||||
reject(result)
|
||||
} else {
|
||||
resolve(position)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
let putPosition = util.promisify(assistant.putPosition)
|
||||
let position = await putPosition('sell', currentRate, amountA, amountToSell)
|
||||
return position
|
||||
} else {
|
||||
logInfo('createSellPosition -> There is not enough available balance to sell.')
|
||||
throw new Error('There is not enough available balance to sell.')
|
||||
}
|
||||
}
|
||||
|
||||
function checkSignalCompletion() {
|
||||
let positions = assistant.getPositions()
|
||||
if ((positions.length === 0) || (positions.length > 0 && positions[0].status === 'executed')) {
|
||||
logInfo('checkSignalCompletion -> The order was executed.')
|
||||
return positions[0]
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Storage functions
|
||||
async function getIndicatorFile() {
|
||||
logInfo('getIndicatorFile -> Entering function. ' + bot.processDatetime.toISOString())
|
||||
|
||||
let filePath
|
||||
if (bot.processes[0].timePeriod > 2700000) {
|
||||
// Market Files
|
||||
filePath = 'Trading-Execution/' + bot.dataSet + '/' + bot.timePeriodFileStorage
|
||||
} else {
|
||||
// Daily Files
|
||||
let dateTime = bot.processDatetime
|
||||
let datePath = dateTime.getUTCFullYear() + '/' + pad(dateTime.getUTCMonth() + 1, 2) + '/' + pad(dateTime.getUTCDate(), 2)
|
||||
filePath = 'Trading-Execution/' + bot.dataSet + '/' + bot.timePeriodFileStorage + '/' + datePath
|
||||
}
|
||||
|
||||
/*
|
||||
bot.botCache: allows us to keep a map (key value pairs) between executions,
|
||||
so we don't need to go to the storage to retrieve this value.
|
||||
If the value already exist on the cache we will get it from there,
|
||||
otherwise it will be retrieved from the bot storage.
|
||||
*/
|
||||
if (bot.startMode === 'Backtest' && bot.botCache.has(filePath)) {
|
||||
logInfo('getIndicatorFile -> Getting the file from local cache.')
|
||||
return bot.botCache.get(filePath)
|
||||
} else {
|
||||
let indicatorFileContent = await getFileContent(filePath, 'USDT_BTC.json')
|
||||
bot.botCache.set(filePath, JSON.parse(indicatorFileContent))
|
||||
return JSON.parse(indicatorFileContent)
|
||||
}
|
||||
}
|
||||
|
||||
function getSimulatorEngineMessageFromFile(indicatorFileContent) {
|
||||
try {
|
||||
let lastIndexIndicatorFile = indicatorFileContent.length - 1
|
||||
|
||||
if (indicatorFileContent[lastIndexIndicatorFile] === undefined) {
|
||||
logWarn('getSimulatorEngineMessageFromFile -> Recived file does not contain any record yet.')
|
||||
return
|
||||
}
|
||||
let lastAvailableDateTime = indicatorFileContent[lastIndexIndicatorFile][0]
|
||||
|
||||
if (bot.processDatetime.valueOf() <= lastAvailableDateTime || !isExecutionToday()) {
|
||||
for (let i = 0; i < indicatorFileContent.length; i++) {
|
||||
if (bot.processDatetime.valueOf() >= indicatorFileContent[i][0] && bot.processDatetime.valueOf() < indicatorFileContent[i][1]) {
|
||||
return getMessage(indicatorFileContent[i][2])
|
||||
}
|
||||
}
|
||||
|
||||
logWarn('getSimulatorEngineMessageFromFile -> The indicator message was not found at time: ' + bot.processDatetime.valueOf())
|
||||
} else {
|
||||
// Running live we will process last available Indicator Message only if it's delayed 30 minutes top
|
||||
let maxTolerance = 30 * 60 * 1000
|
||||
let lastAvailableDateTimeEnd = indicatorFileContent[lastIndexIndicatorFile][1]
|
||||
let minutesDelayed = (bot.processDatetime.valueOf() - lastAvailableDateTimeEnd) / 60 / 1000
|
||||
logWarn('getSimulatorEngineMessageFromFile -> Last available indicator is delayed: ' + minutesDelayed.toFixed(2) + ' minutes.')
|
||||
if (bot.processDatetime.valueOf() <= (lastAvailableDateTime + maxTolerance)) {
|
||||
return getMessage(indicatorFileContent[lastIndexIndicatorFile][2])
|
||||
} else {
|
||||
logWarn('getSimulatorEngineMessageFromFile -> Last available indicator older than 30 minutes: ' + JSON.stringify(indicatorFileContent[lastIndexIndicatorFile]))
|
||||
assistant.addExtraData(indicatorFileContent[lastIndexIndicatorFile]) // Adding the record used for the execution
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
logError('getSimulatorEngineMessageFromFile -> error = ' + error.message)
|
||||
throw global.DEFAULT_RETRY_RESPONSE
|
||||
}
|
||||
}
|
||||
|
||||
function getSkippedMessageOrderClose(indicatorFileContent) {
|
||||
try {
|
||||
let lastIndexIndicatorFile = indicatorFileContent.length - 1
|
||||
|
||||
for (let i = lastIndexIndicatorFile; i >= 0; i--) {
|
||||
let simulatorMessage = getMessage(indicatorFileContent[i][2])
|
||||
if (simulatorMessage.messageType === MESSAGE_TYPE.OrderClose) {
|
||||
return simulatorMessage
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
logError('getSkippedMessageOrderClose -> error = ' + error.message)
|
||||
throw global.DEFAULT_RETRY_RESPONSE
|
||||
}
|
||||
}
|
||||
|
||||
// Helper Functions
|
||||
function isExecutionToday() {
|
||||
let localDate = new Date()
|
||||
let today = new Date(Date.UTC(
|
||||
localDate.getUTCFullYear(),
|
||||
localDate.getUTCMonth(),
|
||||
localDate.getUTCDate()))
|
||||
|
||||
return (today.getUTCFullYear() === bot.processDatetime.getUTCFullYear()
|
||||
&& today.getUTCMonth() === bot.processDatetime.getUTCMonth()
|
||||
&& today.getUTCDate() === bot.processDatetime.getUTCDate())
|
||||
}
|
||||
|
||||
// Modules queries
|
||||
async function getSignalsByCloneId(orderStatus) {
|
||||
try {
|
||||
const cockPit = await axios({
|
||||
url: process.env.GATEWAY_ENDPOINT_K8S,
|
||||
method: 'post',
|
||||
data: {
|
||||
query: `
|
||||
query($cloneId: String!, $orderStatus: String){
|
||||
cockpit_SignalsByCloneId(cloneId: $cloneId, orderStatus:$orderStatus){
|
||||
id
|
||||
cloneId
|
||||
orderId
|
||||
orderCreator
|
||||
orderStatus
|
||||
orderData
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
cloneId: process.env.CLONE_ID,
|
||||
orderStatus: orderStatus
|
||||
},
|
||||
},
|
||||
headers: {
|
||||
authorization: process.env.AUTHORIZATION
|
||||
}
|
||||
})
|
||||
|
||||
logInfo("Retrieved signals in status: " + orderStatus)
|
||||
return cockPit.data.data.cockpit_SignalsByCloneId
|
||||
|
||||
} catch (error) {
|
||||
logError('getSignalsByCloneId error: ' + error.response.data.errors[0])
|
||||
throw global.DEFAULT_RETRY_RESPONSE
|
||||
}
|
||||
}
|
||||
|
||||
async function updateSignal(signalId, message) {
|
||||
try {
|
||||
const cockPit = await axios({
|
||||
url: process.env.GATEWAY_ENDPOINT_K8S,
|
||||
method: 'post',
|
||||
data: {
|
||||
query: `
|
||||
mutation ($signalId: ID!, $message:cockpit_JSON!){
|
||||
cockpit_UpdateSignal(
|
||||
id: $signalId
|
||||
message: $message
|
||||
) {
|
||||
id
|
||||
cloneId
|
||||
orderStatus
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
signalId: signalId,
|
||||
message: message
|
||||
},
|
||||
},
|
||||
headers: {
|
||||
authorization: process.env.AUTHORIZATION
|
||||
}
|
||||
})
|
||||
|
||||
logInfo('updateSignal ok.')
|
||||
return cockPit.data.data.cockpit_UpdateSignal
|
||||
} catch (error) {
|
||||
logError('updateSignal error: ' + error.response.data.errors[0])
|
||||
throw global.DEFAULT_RETRY_RESPONSE
|
||||
}
|
||||
}
|
||||
|
||||
async function createSignal(message) {
|
||||
try {
|
||||
const cockPit = await axios({
|
||||
url: process.env.GATEWAY_ENDPOINT_K8S,
|
||||
method: 'post',
|
||||
data: {
|
||||
query: `
|
||||
mutation ($cloneId: String!, $message: cockpit_JSON!){
|
||||
cockpit_CreateSignal(
|
||||
cloneId: $cloneId
|
||||
message: $message
|
||||
) {
|
||||
id
|
||||
cloneId
|
||||
orderStatus
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
cloneId: process.env.CLONE_ID,
|
||||
message: message
|
||||
},
|
||||
},
|
||||
headers: {
|
||||
authorization: process.env.AUTHORIZATION
|
||||
}
|
||||
})
|
||||
|
||||
logInfo('createSignal ok.')
|
||||
return cockPit.data.data.cockpit_CreateSignal
|
||||
} catch (error) {
|
||||
logInfo("createSignal error: " + error.response.data.errors[0])
|
||||
throw global.DEFAULT_RETRY_RESPONSE
|
||||
}
|
||||
}
|
||||
|
||||
async function getAutopilot() {
|
||||
try {
|
||||
const cockPit = await axios({
|
||||
url: process.env.GATEWAY_ENDPOINT_K8S,
|
||||
method: 'post',
|
||||
data: {
|
||||
query: `
|
||||
query($cloneId: String!){
|
||||
cockpit_CloneSettingsByCloneId(cloneId: $cloneId){
|
||||
id
|
||||
cloneId
|
||||
autopilot
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
cloneId: process.env.CLONE_ID
|
||||
},
|
||||
},
|
||||
headers: {
|
||||
authorization: process.env.AUTHORIZATION
|
||||
}
|
||||
})
|
||||
|
||||
if (cockPit.data.errors) {
|
||||
throw new Error(cockPit.data.errors[0].message)
|
||||
} else {
|
||||
logInfo('getAutopilot -> Ok.')
|
||||
return cockPit.data.data.cockpit_CloneSettingsByCloneId
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
logInfo('getAutopilot error: ' + error)
|
||||
throw global.DEFAULT_RETRY_RESPONSE
|
||||
}
|
||||
}
|
||||
|
||||
async function getFileContent(containerName, blobName) {
|
||||
fileStorage.getTextFile[util.promisify.custom] = n => new Promise((resolve, reject) => {
|
||||
fileStorage.getTextFile(containerName, blobName, (result, fileContent) => {
|
||||
if (result !== global.DEFAULT_OK_RESPONSE) {
|
||||
let errorMessage = '[WARN] getFileContent -> The indicator dependency is not ready. Will retry later.'
|
||||
console.log(errorMessage)
|
||||
logWarn(errorMessage)
|
||||
reject(global.DEFAULT_RETRY_RESPONSE)
|
||||
} else {
|
||||
resolve(fileContent)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
let getTextFile = util.promisify(fileStorage.getTextFile)
|
||||
let fileContent = await getTextFile(containerName, blobName)
|
||||
return fileContent
|
||||
}
|
||||
|
||||
function pad(str, max) {
|
||||
str = str.toString()
|
||||
return str.length < max ? pad('0' + str, max) : str
|
||||
}
|
||||
|
||||
function buildBasicSimulatorExecutorMessage() {
|
||||
var simulatorExecutorMessage = {}
|
||||
simulatorExecutorMessage.id = 0
|
||||
simulatorExecutorMessage.from = MESSAGE_ENTITY.SimulationExecutor
|
||||
simulatorExecutorMessage.to = MESSAGE_ENTITY.TradingAssistant
|
||||
simulatorExecutorMessage.messageType = MESSAGE_TYPE.Order
|
||||
simulatorExecutorMessage.dateTime = bot.processDatetime.valueOf()
|
||||
|
||||
simulatorExecutorMessage.order = {}
|
||||
simulatorExecutorMessage.order.id = 0
|
||||
simulatorExecutorMessage.order.dateTime = bot.processDatetime.valueOf()
|
||||
simulatorExecutorMessage.order.creator = ORDER_CREATOR.SimulationEngine
|
||||
simulatorExecutorMessage.order.owner = ORDER_OWNER.User
|
||||
simulatorExecutorMessage.order.exchange = global.EXCHANGE_NAME
|
||||
simulatorExecutorMessage.order.market = global.MARKET.assetA + '_' + global.MARKET.assetB
|
||||
simulatorExecutorMessage.order.marginEnabled = ORDER_MARGIN_ENABLED.False
|
||||
simulatorExecutorMessage.order.type = ORDER_TYPE.Limit
|
||||
simulatorExecutorMessage.order.status = ORDER_STATUS.Placed
|
||||
simulatorExecutorMessage.order.sizeFilled = 0
|
||||
simulatorExecutorMessage.order.exitOutcome = ''
|
||||
simulatorExecutorMessage.order.statusMessage = ''
|
||||
|
||||
return simulatorExecutorMessage
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
{
|
||||
"displayName": "Bumblebee",
|
||||
"codeName": "bumblebee",
|
||||
"type": "Trading",
|
||||
"version": {
|
||||
"major": 1,
|
||||
"minor": 0,
|
||||
"patch": 0
|
||||
},
|
||||
"devTeam": "vikings",
|
||||
"profilePicture": "bumblebee.png",
|
||||
"dataSetVersion": "dataSet.V1",
|
||||
"processes": [
|
||||
{
|
||||
"name": "Trading-Process",
|
||||
"description": "Trading strategy to be used as a template.",
|
||||
"normalWaitTime": 60000,
|
||||
"retryWaitTime": 10000,
|
||||
"sleepWaitTime": 3600000,
|
||||
"comaWaitTime": 86400000,
|
||||
"timePeriod": 3600000,
|
||||
"statusDependencies": [
|
||||
{
|
||||
"devTeam": "aavikings",
|
||||
"bot": "bumblebee",
|
||||
"botVersion": {
|
||||
"major": 1,
|
||||
"minor": 0
|
||||
},
|
||||
"process": "Trading-Process",
|
||||
"dataSetVersion": "dataSet.V1",
|
||||
"type": "Trading"
|
||||
},
|
||||
{
|
||||
"devTeam": "AAMasters",
|
||||
"bot": "AAJason",
|
||||
"botVersion": {
|
||||
"major": 1,
|
||||
"minor": 0
|
||||
},
|
||||
"process": "Multi-Period-Market",
|
||||
"dataSetVersion": "dataSet.V1",
|
||||
"type": "Indicator"
|
||||
},
|
||||
{
|
||||
"devTeam": "AAMasters",
|
||||
"bot": "AAJason",
|
||||
"botVersion": {
|
||||
"major": 1,
|
||||
"minor": 0
|
||||
},
|
||||
"process": "Multi-Period-Daily",
|
||||
"dataSetVersion": "dataSet.V1",
|
||||
"type": "Indicator"
|
||||
}
|
||||
],
|
||||
"dataDependencies": [
|
||||
{
|
||||
"devTeam": "AAMasters",
|
||||
"bot": "AABruce",
|
||||
"botVersion": {
|
||||
"major": 1,
|
||||
"minor": 0
|
||||
},
|
||||
"product": "Candles",
|
||||
"dataSetVersion": "dataSet.V1",
|
||||
"dataSet": "One-Min"
|
||||
},
|
||||
{
|
||||
"devTeam": "AAMasters",
|
||||
"bot": "AAJason",
|
||||
"botVersion": {
|
||||
"major": 1,
|
||||
"minor": 0
|
||||
},
|
||||
"product": "Trading-Execution",
|
||||
"dataSetVersion": "dataSet.V1",
|
||||
"dataSet": "Multi-Period-Market"
|
||||
},
|
||||
{
|
||||
"devTeam": "AAMasters",
|
||||
"bot": "AAJason",
|
||||
"botVersion": {
|
||||
"major": 1,
|
||||
"minor": 0
|
||||
},
|
||||
"product": "Trading-Execution",
|
||||
"dataSetVersion": "dataSet.V1",
|
||||
"dataSet": "Multi-Period-Daily"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"products": [
|
||||
{
|
||||
"codeName": "Live Trading History",
|
||||
"displayName": "Live Trading History",
|
||||
"shortDisplayName": "Live",
|
||||
"description": "General information about trading history.",
|
||||
"dataSets": [
|
||||
{
|
||||
"codeName": "Oficial History",
|
||||
"type": "File Sequence",
|
||||
"validPeriods": [ "24-hs", "12-hs", "08-hs", "06-hs", "04-hs", "03-hs", "02-hs", "01-hs", "45-min", "40-min", "30-min", "20-min", "15-min", "10-min", "05-min", "04-min", "03-min", "02-min", "01-min" ],
|
||||
"filePath": "@DevTeam/@Bot.1.0/AACloud.1.1/Poloniex/dataSet.V1/Output/Trading-Process",
|
||||
"fileName": "Execution.History.Live.@Sequence.json"
|
||||
}
|
||||
],
|
||||
"exchangeList": [
|
||||
{
|
||||
"name": "Poloniex"
|
||||
}
|
||||
],
|
||||
"plotter": {
|
||||
"devTeam": "AAMasters",
|
||||
"codeName": "PlottersTradingSimulation",
|
||||
"moduleName": "SimulationExecution"
|
||||
}
|
||||
},
|
||||
{
|
||||
"codeName": "Backtest Trading History",
|
||||
"displayName": "Backtest Trading History",
|
||||
"shortDisplayName": "Backtest",
|
||||
"description": "General information about backtest trading history.",
|
||||
"dataSets": [
|
||||
{
|
||||
"codeName": "Backtest History",
|
||||
"type": "File Sequence",
|
||||
"validPeriods": [ "24-hs", "12-hs", "08-hs", "06-hs", "04-hs", "03-hs", "02-hs", "01-hs", "45-min", "40-min", "30-min", "20-min", "15-min", "10-min", "05-min", "04-min", "03-min", "02-min", "01-min" ],
|
||||
"filePath": "@DevTeam/@Bot.1.0/AACloud.1.1/Poloniex/dataSet.V1/Output/Trading-Process",
|
||||
"fileName": "Execution.History.Backtest.@Sequence.json"
|
||||
}
|
||||
],
|
||||
"exchangeList": [
|
||||
{
|
||||
"name": "Poloniex"
|
||||
}
|
||||
],
|
||||
"plotter": {
|
||||
"devTeam": "AAMasters",
|
||||
"codeName": "PlottersTradingSimulation",
|
||||
"moduleName": "SimulationExecution"
|
||||
}
|
||||
},
|
||||
{
|
||||
"codeName": "Competition Trading History",
|
||||
"displayName": "Competition Trading History",
|
||||
"shortDisplayName": "Competition",
|
||||
"description": "General information about competition trading history.",
|
||||
"dataSets": [
|
||||
{
|
||||
"codeName": "Competition History",
|
||||
"type": "File Sequence",
|
||||
"validPeriods": [ "24-hs", "12-hs", "08-hs", "06-hs", "04-hs", "03-hs", "02-hs", "01-hs", "45-min", "40-min", "30-min", "20-min", "15-min", "10-min", "05-min", "04-min", "03-min", "02-min", "01-min" ],
|
||||
"filePath": "@DevTeam/@Bot.1.0/AACloud.1.1/Poloniex/dataSet.V1/Output/Trading-Process",
|
||||
"fileName": "Execution.History.Competition.@Sequence.json"
|
||||
}
|
||||
],
|
||||
"exchangeList": [
|
||||
{
|
||||
"name": "Poloniex"
|
||||
}
|
||||
],
|
||||
"plotter": {
|
||||
"devTeam": "AAMasters",
|
||||
"codeName": "PlottersTradingSimulation",
|
||||
"moduleName": "SimulationExecution"
|
||||
}
|
||||
}
|
||||
],
|
||||
"marketRateProvider": {
|
||||
"devTeam": "AAMasters",
|
||||
"bot": "AABruce",
|
||||
"host": {
|
||||
"url": "https://demo-dev.superalgos.org/",
|
||||
"storage": "localStorage",
|
||||
"container": "aamasters",
|
||||
"accessKey": ""
|
||||
},
|
||||
"botVersion": {
|
||||
"major": 1,
|
||||
"minor": 0
|
||||
},
|
||||
"product": "Candles",
|
||||
"dataSet": "One-Min",
|
||||
"dataSetVersion": "dataSet.V1"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { Ecosystem } from '../models'
|
||||
|
||||
let teamCache = new Map()
|
||||
export default async function getDevTeamHost(devTeamName, accessKey, ownerKey) {
|
||||
let host
|
||||
if (accessKey) {
|
||||
host = teamCache.get(devTeamName + '.accessKey')
|
||||
} else {
|
||||
host = teamCache.get(devTeamName + '.ownerKey')
|
||||
}
|
||||
if (host && (host.accessKey === accessKey || host.ownerKey === ownerKey)) {
|
||||
return host
|
||||
} else {
|
||||
let ecosystem = await Ecosystem.find()
|
||||
|
||||
for (var i = 0; i < ecosystem.length; i++) {
|
||||
for (var j = 0; j < ecosystem[i].devTeams.length; j++) {
|
||||
if (ecosystem[i].devTeams[j].codeName.toLowerCase() === devTeamName.toLowerCase()) {
|
||||
if (ecosystem[i].devTeams[j].host.accessKey === accessKey) {
|
||||
teamCache.set(devTeamName + '.accessKey', ecosystem[i].devTeams[j].host)
|
||||
return ecosystem[i].devTeams[j].host
|
||||
}
|
||||
if (ecosystem[i].devTeams[j].host.ownerKey === ownerKey) {
|
||||
teamCache.set(devTeamName + '.ownerKey', ecosystem[i].devTeams[j].host)
|
||||
return ecosystem[i].devTeams[j].host
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { createLogger, format, transports } from 'winston'
|
||||
import { inspect } from '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: process.env.LOG_LEVEL || 'debug',
|
||||
handleExceptions: true,
|
||||
json: false,
|
||||
colorize: true,
|
||||
timestamp: true
|
||||
}
|
||||
}
|
||||
|
||||
const logger = createLogger({
|
||||
level: 'info',
|
||||
format: format.combine(
|
||||
format.colorize(),
|
||||
format.splat(),
|
||||
format.timestamp({ format: 'YY/MM/DD HH:mm' }),
|
||||
format.printf(
|
||||
info => `${info.timestamp} - ${info.level}: ${JSON.parse(JSON.stringify(inspect(info.message)))}`
|
||||
)
|
||||
),
|
||||
transports: [
|
||||
// new transports.File(options.file),
|
||||
new transports.Console(options.console)
|
||||
],
|
||||
exitOnError: false // do not exit on handled exceptions
|
||||
})
|
||||
|
||||
export default logger
|
||||
@@ -0,0 +1,14 @@
|
||||
import fs from 'fs'
|
||||
|
||||
export default function readFile(fileName) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
fs.readFile(fileName, 'utf8', (err, file) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else {
|
||||
resolve(file)
|
||||
}
|
||||
})
|
||||
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user