Merge pull request #100 from AAVikings/master

Add and remove clones from ecosystem
This commit is contained in:
benme authored and GitHub committed 2019-07-03 20:13:48 -03:00
commit b0f90f27dd
6 files changed
+197 -44

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
import logger from '../config/logger'
import axios from 'axios'
const addBotMutation = async (authorization, bot) => {
logger.debug('addBotMutation -> Entering function.')
let response = await axios({
url: process.env.GATEWAY_ENDPOINT,
method: 'post',
data: {
query: `
mutation web_AddBot($bot: web_BotInput){
web_AddBot(bot: $bot){
codeName
cloneId
}
}
`,
variables: {
bot
}
},
headers: {
authorization: authorization
}
})
if (response.data.errors) {
throw response.data.errors
}
return response.data.data.web_AddBot
}
export default addBotMutation
+1 -1
View File
@@ -31,7 +31,7 @@ const ecosystemQuery = async (authorization) => {
})
if (response.data.errors) {
throw error
throw response.data.errors
}
return response.data.data.web_GetEcosystem
@@ -0,0 +1,35 @@
import logger from '../config/logger'
import axios from 'axios'
const removeBotMutation = async (authorization, bot) => {
logger.debug('removeBotMutation -> Entering function.')
let response = await axios({
url: process.env.GATEWAY_ENDPOINT,
method: 'post',
data: {
query: `
mutation web_RemoveBot($bot: web_BotInput){
web_RemoveBot(bot: $bot){
codeName
cloneId
}
}
`,
variables: {
bot
}
},
headers: {
authorization: authorization
}
})
if (response.data.errors) {
throw response.data.errors
}
return response.data.data.web_RemoveBot
}
export default removeBotMutation
@@ -1,10 +1,10 @@
import { CloneInputType } from '../types/input'
import { CloneType } from '../types'
import { Clone } from '../../models'
import { CloneModeEnum } from '../../enums/CloneMode'
import { BotTypesEnum } from '../../enums/BotTypes'
import teamQuery from '../../graphQLCalls/teamQuery'
import authorizeKey from '../../graphQLCalls/authorizeKey'
import addBotMutation from '../../graphQLCalls/addBotMutation'
import cloneDetails from '../cloneDetails'
import {
AuthenticationError,
@@ -15,7 +15,8 @@ import {
import logger from '../../config/logger'
import createKubernetesClone from '../../kubernetes/createClone'
import { isDefined } from '../../config/utils'
import { LIVE, COMPETITION } from '../../enums/CloneMode'
import { CloneModeEnum, LIVE, COMPETITION, BACKTEST } from '../../enums/CloneMode'
import { Trading } from '../../enums/BotTypes'
const args = {
clone: { type: CloneInputType }
@@ -93,6 +94,28 @@ const resolve = async (parent, { clone }, context) => {
await createKubernetesClone(clone)
if(clone.botType === Trading){
let productCodeName
if(clone.mode === LIVE){
productCodeName = 'Live Trading History'
}
if(clone.mode === COMPETITION){
productCodeName = 'Competition Trading History'
}
if(clone.mode === BACKTEST){
productCodeName = 'Backtest Trading History'
}
let newEcosystemBot = {
devTeam: clone.teamSlug,
codeName: clone.botSlug,
cloneId: clone.id,
productCodeName
}
await addBotMutation(context.authorization, newEcosystemBot)
}
logger.debug('addClone -> Clone created sucessfully.')
return savedClone
} catch (err) {
@@ -7,11 +7,11 @@ import teamQuery from '../../graphQLCalls/teamQuery'
import { isDefined } from '../../config/utils'
import cloneDetails from '../cloneDetails'
import authorizeKey from '../../graphQLCalls/authorizeKey'
import { LIVE, COMPETITION } from '../../enums/CloneMode'
import { LIVE, COMPETITION, BACKTEST } from '../../enums/CloneMode'
import { Trading } from '../../enums/BotTypes'
import removeBotMutation from '../../graphQLCalls/removeBotMutation'
const args = {
id: { type: new GraphQLNonNull(GraphQLID) }
}
const args = { id: { type: new GraphQLNonNull(GraphQLID) } }
const resolve = async (parent, { id }, context) => {
logger.debug('removeClone -> Entering Fuction.')
@@ -42,6 +42,28 @@ const resolve = async (parent, { id }, context) => {
logger.debug('removeClone -> Removing Clone from Kubernates.')
await removeKuberneteClone(clone.id)
if (clone.botType === Trading) {
let productCodeName
if (clone.mode === LIVE) {
productCodeName = 'Live Trading History'
}
if (clone.mode === COMPETITION) {
productCodeName = 'Competition Trading History'
}
if (clone.mode === BACKTEST) {
productCodeName = 'Backtest Trading History'
}
let newEcosystemBot = {
devTeam: clone.teamSlug,
codeName: clone.botSlug,
cloneId: clone.id,
productCodeName
}
await removeBotMutation(context.authorization, newEcosystemBot)
}
const query = {
_id: id,
authId: context.userId
+75 -37
View File
@@ -2,49 +2,87 @@ var assert = require('chai').assert
const axios = require('axios')
const { activeCloneList } = require('./activeCloneList')
require('dotenv').config()
var cloneList = activeCloneList("Poloniex")
describe('Admin clones Clones', function () {
it('Remove clones', async function () {
this.timeout(300000)
var error
try {
var clones = await getClones()
for (let clone of clones) {
await removeClone(clone.id, clone.botName)
}
} catch (err) {
console.log('Error: ' + err)
error = err
var clones = await getClones()
for (let clone of clones) {
await removeClone(clone.id, clone.botName)
}
assert.equal(error, undefined)
assert.isOk('everything', 'everything is ok')
})
it('Add COSS Live Indicator Clones', async function () {
this.timeout(300000)
var error
var clones = activeCloneList("Coss")
try {
for (let clone of clones) {
await createClone(clone)
}
} catch (err) {
console.log('Error: ' + err)
error = err
}
assert.equal(error, undefined)
})
it('Add POLONIEX Live Indicator Clones', async function () {
this.timeout(300000)
var error
var clones = activeCloneList("Poloniex")
try {
for (let clone of clones) {
await createClone(clone)
}
} catch (err) {
console.log('Error: ' + err)
error = err
}
assert.equal(error, undefined)
// it('Add COSS Live Indicator Clones', async function () {
// this.timeout(300000)
// var error
// var clones = activeCloneList("Coss")
// try {
// for (let clone of clones) {
// await createClone(clone)
// }
// } catch (err) {
// console.log('Error: ' + err)
// error = err
// }
// assert.equal(error, undefined)
// })
// it('Add POLONIEX Live Indicator Clones', async function () {
// this.timeout(300000)
// var error
// var clones = activeCloneList("Poloniex")
// try {
// for (let clone of clones) {
// await createClone(clone)
// }
// } catch (err) {
// console.log('Error: ' + err)
// error = err
// }
// assert.equal(error, undefined)
// })
describe('Poloniex clones', function () {
it('Add Charly', async function () {
this.timeout(3000)
await createClone(cloneList[0])
await createClone(cloneList[1])
assert.isOk('everything', 'everything is ok')
})
it('Add Bruce', async function () {
this.timeout(3000)
await createClone(cloneList[2])
assert.isOk('everything', 'everything is ok')
})
it('Add Olivia', async function () {
this.timeout(3000)
await createClone(cloneList[3])
await createClone(cloneList[4])
assert.isOk('everything', 'everything is ok')
})
it('Add Tom', async function () {
this.timeout(3000)
await createClone(cloneList[5])
await createClone(cloneList[6])
assert.isOk('everything', 'everything is ok')
})
it('Add Chris', async function () {
this.timeout(3000)
await createClone(cloneList[7])
await createClone(cloneList[8])
assert.isOk('everything', 'everything is ok')
})
it('Add Paula', async function () {
this.timeout(3000)
await createClone(cloneList[9])
await createClone(cloneList[10])
assert.isOk('everything', 'everything is ok')
})
it('Add Gauss', async function () {
this.timeout(6000)
await createClone(cloneList[11])
await createClone(cloneList[12])
assert.isOk('everything', 'everything is ok')
})
})
})