From 1b4cc71f6f7d223bb295ba728c5a949b1d0384b8 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 16 Mar 2019 16:10:35 +0100 Subject: [PATCH 1/9] Last minute bugs --- src/schema/mutations/CreateStrategy.js | 8 +++++++- src/schema/types/SubStrategy.js | 15 +++++++-------- src/schema/types/input/TheSevenMonolitics.js | 6 +++--- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/schema/mutations/CreateStrategy.js b/src/schema/mutations/CreateStrategy.js index 7a0bfe720..dd4edd8a6 100644 --- a/src/schema/mutations/CreateStrategy.js +++ b/src/schema/mutations/CreateStrategy.js @@ -1,12 +1,18 @@ +import { + GraphQLNonNull, + GraphQLString, +} from 'graphql'; import { StrategyType } from '../types'; import { Strategy } from '../../models'; import { StrategyInputType } from '../types/input'; export const args = { + fbId: { type: new GraphQLNonNull(GraphQLString) }, strategy: { type: StrategyInputType }, }; -const resolve = (parent, { strategy }) => { +const resolve = (parent, { fbId, strategy }) => { + strategy.fbId = fbId; const newStrategy = new Strategy(strategy); return new Promise((res, rej) => { diff --git a/src/schema/types/SubStrategy.js b/src/schema/types/SubStrategy.js index 5d34e8caa..4d6fe80d7 100644 --- a/src/schema/types/SubStrategy.js +++ b/src/schema/types/SubStrategy.js @@ -1,7 +1,6 @@ import { GraphQLObjectType, GraphQLString, - GraphQLList, } from 'graphql'; import { EntryPointType, @@ -19,43 +18,43 @@ const Type = new GraphQLObjectType({ fields: () => ({ name: { type: GraphQLString }, entryPoint: { - type: new GraphQLList(EntryPointType), + type: EntryPointType, resolve(parent) { return parent.entryPoint; }, }, exitPoint: { - type: new GraphQLList(ExitPointType), + type: ExitPointType, resolve(parent) { return parent.exitPoint; }, }, sellPoint: { - type: new GraphQLList(SellPointType), + type: SellPointType, resolve(parent) { return parent.sellPoint; }, }, buyPoint: { - type: new GraphQLList(BuyPointType), + type: BuyPointType, resolve(parent) { return parent.buyPoint; }, }, stopLoss: { - type: new GraphQLList(StopLossType), + type: StopLossType, resolve(parent) { return parent.stopLoss; }, }, buyOrder: { - type: new GraphQLList(BuyOrderType), + type: BuyOrderType, resolve(parent) { return parent.buyOrder; }, }, sellOrder: { - type: new GraphQLList(SellOrderType), + type: SellOrderType, resolve(parent) { return parent.sellOrder; }, diff --git a/src/schema/types/input/TheSevenMonolitics.js b/src/schema/types/input/TheSevenMonolitics.js index e7e32599d..8a6b3ba37 100644 --- a/src/schema/types/input/TheSevenMonolitics.js +++ b/src/schema/types/input/TheSevenMonolitics.js @@ -44,7 +44,7 @@ const StopLossInputType = new GraphQLInputObjectType({ name: 'StopLossTypeInput', description: 'Payload for stopLossType input', fields: () => ({ - situations: { type: new GraphQLList(PhaseInputType) }, + phases: { type: new GraphQLList(PhaseInputType) }, }), }); @@ -52,7 +52,7 @@ const BuyOrderInputType = new GraphQLInputObjectType({ name: 'BuyOrderTypeInput', description: 'Payload for buyOrderType input', fields: () => ({ - situations: { type: new GraphQLList(PhaseInputType) }, + phases: { type: new GraphQLList(PhaseInputType) }, }), }); @@ -60,7 +60,7 @@ const SellOrderInputType = new GraphQLInputObjectType({ name: 'SellOrderTypeInput', description: 'Payload for sellOrderType input', fields: () => ({ - situations: { type: new GraphQLList(PhaseInputType) }, + phases: { type: new GraphQLList(PhaseInputType) }, }), }); From e6bc08516c71f441f6ea8878aa3bcef7bcab8917 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 16 Mar 2019 20:15:44 +0100 Subject: [PATCH 2/9] Renaming some arguments --- src/schema/mutations/EditStrategy.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/schema/mutations/EditStrategy.js b/src/schema/mutations/EditStrategy.js index a522b1441..f0eeaf247 100644 --- a/src/schema/mutations/EditStrategy.js +++ b/src/schema/mutations/EditStrategy.js @@ -8,16 +8,16 @@ import { StrategyInputType } from '../types/input'; const args = { id: { type: new GraphQLNonNull(GraphQLID) }, - newStrategy: { type: new GraphQLNonNull(StrategyInputType) }, + strategy: { type: new GraphQLNonNull(StrategyInputType) }, }; -const resolve = (parent, { id: _id, newStrategy }) => new Promise((res, rej) => { +const resolve = (parent, { id: _id, strategy: editedStrategy }) => new Promise((res, rej) => { Strategy.findOne({ _id }).exec((err, strategy) => { if (err) { rej(err); return; } - strategy = newStrategy; + strategy.subStrategies = editedStrategy.subStrategies; strategy.save((error) => { if (error) { rej(error); @@ -29,7 +29,7 @@ const resolve = (parent, { id: _id, newStrategy }) => new Promise((res, rej) => }); const mutation = { - editParticipant: { + editStrategy: { type: StrategyType, args, resolve, From 4f1802e4ee15fe2ffe180673a8f3dcf618811076 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 17 Mar 2019 18:46:09 +0100 Subject: [PATCH 3/9] Adding history to strategies, not showing them up yet though --- src/models/Strategy.js | 408 +++++++++++++++++++-------- src/schema/mutations/EditStrategy.js | 4 + 2 files changed, 293 insertions(+), 119 deletions(-) diff --git a/src/models/Strategy.js b/src/models/Strategy.js index 6f78bd348..f8f8f00f5 100644 --- a/src/models/Strategy.js +++ b/src/models/Strategy.js @@ -1,99 +1,19 @@ import mongoose, { Schema } from 'mongoose'; -const strategySchema = new Schema({ - fbId: { - type: String, - required: true, - unique: true, - dropDups: true, - }, - subStrategies: [{ - name: { +const strategySchema = new Schema( + { + fbId: { type: String, - default: '', + required: true, + unique: true, + dropDups: true, }, - entryPoint: { - situations: [{ - name: { - type: String, - default: '', - }, - conditions: [{ - name: { - type: String, - default: '', - }, - code: { - type: String, - default: 'false', - }, - }], - }], - }, - exitPoint: { - situations: [{ - name: { - type: String, - default: '', - }, - conditions: [{ - name: { - type: String, - default: '', - }, - code: { - type: String, - default: 'false', - }, - }], - }], - }, - sellPoint: { - situations: [{ - name: { - type: String, - default: '', - }, - conditions: [{ - name: { - type: String, - default: '', - }, - code: { - type: String, - default: 'false', - }, - }], - }], - }, - buyPoint: { - situations: [{ - name: { - type: String, - default: '', - }, - conditions: [{ - name: { - type: String, - default: '', - }, - code: { - type: String, - default: 'false', - }, - }], - }], - }, - stopLoss: { - phases: [{ - name: { - type: String, - default: '', - }, - code: { - type: String, - default: 'false', - }, + subStrategies: [{ + name: { + type: String, + default: '', + }, + entryPoint: { situations: [{ name: { type: String, @@ -110,18 +30,8 @@ const strategySchema = new Schema({ }, }], }], - }], - }, - buyOrder: { - phases: [{ - name: { - type: String, - default: '', - }, - code: { - type: String, - default: 'false', - }, + }, + exitPoint: { situations: [{ name: { type: String, @@ -138,18 +48,8 @@ const strategySchema = new Schema({ }, }], }], - }], - }, - sellOrder: { - phases: [{ - name: { - type: String, - default: '', - }, - code: { - type: String, - default: 'false', - }, + }, + sellPoint: { situations: [{ name: { type: String, @@ -166,10 +66,280 @@ const strategySchema = new Schema({ }, }], }], + }, + buyPoint: { + situations: [{ + name: { + type: String, + default: '', + }, + conditions: [{ + name: { + type: String, + default: '', + }, + code: { + type: String, + default: 'false', + }, + }], + }], + }, + stopLoss: { + phases: [{ + name: { + type: String, + default: '', + }, + code: { + type: String, + default: 'false', + }, + situations: [{ + name: { + type: String, + default: '', + }, + conditions: [{ + name: { + type: String, + default: '', + }, + code: { + type: String, + default: 'false', + }, + }], + }], + }], + }, + buyOrder: { + phases: [{ + name: { + type: String, + default: '', + }, + code: { + type: String, + default: 'false', + }, + situations: [{ + name: { + type: String, + default: '', + }, + conditions: [{ + name: { + type: String, + default: '', + }, + code: { + type: String, + default: 'false', + }, + }], + }], + }], + }, + sellOrder: { + phases: [{ + name: { + type: String, + default: '', + }, + code: { + type: String, + default: 'false', + }, + situations: [{ + name: { + type: String, + default: '', + }, + conditions: [{ + name: { + type: String, + default: '', + }, + code: { + type: String, + default: 'false', + }, + }], + }], + }], + }, + }], + history: [{ + updatedAt: Date, + subStrategies: [{ + name: { + type: String, + default: '', + }, + entryPoint: { + situations: [{ + name: { + type: String, + default: '', + }, + conditions: [{ + name: { + type: String, + default: '', + }, + code: { + type: String, + default: 'false', + }, + }], + }], + }, + exitPoint: { + situations: [{ + name: { + type: String, + default: '', + }, + conditions: [{ + name: { + type: String, + default: '', + }, + code: { + type: String, + default: 'false', + }, + }], + }], + }, + sellPoint: { + situations: [{ + name: { + type: String, + default: '', + }, + conditions: [{ + name: { + type: String, + default: '', + }, + code: { + type: String, + default: 'false', + }, + }], + }], + }, + buyPoint: { + situations: [{ + name: { + type: String, + default: '', + }, + conditions: [{ + name: { + type: String, + default: '', + }, + code: { + type: String, + default: 'false', + }, + }], + }], + }, + stopLoss: { + phases: [{ + name: { + type: String, + default: '', + }, + code: { + type: String, + default: 'false', + }, + situations: [{ + name: { + type: String, + default: '', + }, + conditions: [{ + name: { + type: String, + default: '', + }, + code: { + type: String, + default: 'false', + }, + }], + }], + }], + }, + buyOrder: { + phases: [{ + name: { + type: String, + default: '', + }, + code: { + type: String, + default: 'false', + }, + situations: [{ + name: { + type: String, + default: '', + }, + conditions: [{ + name: { + type: String, + default: '', + }, + code: { + type: String, + default: 'false', + }, + }], + }], + }], + }, + sellOrder: { + phases: [{ + name: { + type: String, + default: '', + }, + code: { + type: String, + default: 'false', + }, + situations: [{ + name: { + type: String, + default: '', + }, + conditions: [{ + name: { + type: String, + default: '', + }, + code: { + type: String, + default: 'false', + }, + }], + }], + }], + }, }], - }, - }], -}); + }], + }, + { + timestamps: true, + }, +); const Strategy = mongoose.model('Strategy', strategySchema); diff --git a/src/schema/mutations/EditStrategy.js b/src/schema/mutations/EditStrategy.js index f0eeaf247..8c864d537 100644 --- a/src/schema/mutations/EditStrategy.js +++ b/src/schema/mutations/EditStrategy.js @@ -17,6 +17,10 @@ const resolve = (parent, { id: _id, strategy: editedStrategy }) => new Promise(( rej(err); return; } + strategy.history.push({ + updatedAt: strategy.updatedAt, + subStrategies: strategy.subStrategies, + }); strategy.subStrategies = editedStrategy.subStrategies; strategy.save((error) => { if (error) { From a7cb752f1ee3a6172920321e8e8d6ce67cd20b7e Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 17 Mar 2019 20:53:51 +0100 Subject: [PATCH 4/9] Went from fbId to fbSlug --- src/models/Strategy.js | 2 +- src/schema/mutations/CreateStrategy.js | 6 +++--- src/schema/queries/StrategyByFB.js | 8 ++++---- src/schema/types/Strategy.js | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/models/Strategy.js b/src/models/Strategy.js index f8f8f00f5..504f94431 100644 --- a/src/models/Strategy.js +++ b/src/models/Strategy.js @@ -2,7 +2,7 @@ import mongoose, { Schema } from 'mongoose'; const strategySchema = new Schema( { - fbId: { + fbSlug: { type: String, required: true, unique: true, diff --git a/src/schema/mutations/CreateStrategy.js b/src/schema/mutations/CreateStrategy.js index dd4edd8a6..cbbe2bb17 100644 --- a/src/schema/mutations/CreateStrategy.js +++ b/src/schema/mutations/CreateStrategy.js @@ -7,12 +7,12 @@ import { Strategy } from '../../models'; import { StrategyInputType } from '../types/input'; export const args = { - fbId: { type: new GraphQLNonNull(GraphQLString) }, + fbSlug: { type: new GraphQLNonNull(GraphQLString) }, strategy: { type: StrategyInputType }, }; -const resolve = (parent, { fbId, strategy }) => { - strategy.fbId = fbId; +const resolve = (parent, { fbSlug, strategy }) => { + strategy.fbSlug = fbSlug; const newStrategy = new Strategy(strategy); return new Promise((res, rej) => { diff --git a/src/schema/queries/StrategyByFB.js b/src/schema/queries/StrategyByFB.js index ba752f7c2..bb68b582d 100644 --- a/src/schema/queries/StrategyByFB.js +++ b/src/schema/queries/StrategyByFB.js @@ -7,17 +7,17 @@ import { StrategyType } from '../types'; import { Strategy } from '../../models'; const args = { - fbId: { type: new GraphQLNonNull(GraphQLID) }, + fbSlug: { type: new GraphQLNonNull(GraphQLID) }, }; -const resolve = (parent, { fbId }) => new Promise((res, rej) => { - Strategy.findOne({ fbId }).exec((err, strategy) => { +const resolve = (parent, { fbSlug }) => new Promise((res, rej) => { + Strategy.findOne({ fbSlug }).exec((err, strategy) => { if (err) { rej(err); return; } if (!strategy) { - rej(new DatabaseError('None of the strategy are linked to that fbId')); + rej(new DatabaseError('None of the strategy are linked to that fbSlug')); return; } res(strategy); diff --git a/src/schema/types/Strategy.js b/src/schema/types/Strategy.js index cb6fb1f69..4a5be341d 100644 --- a/src/schema/types/Strategy.js +++ b/src/schema/types/Strategy.js @@ -13,7 +13,7 @@ const Type = new GraphQLObjectType({ description: 'Everything you need to know about a strategy', fields: () => ({ id: { type: GraphQLID }, - fbId: { type: GraphQLString }, + fbSlug: { type: GraphQLString }, subStrategies: { type: new GraphQLList(SubStrategyType), resolve(parent) { From ad3d0b303fae109d533a65443f3f651558168b6d Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 18 Mar 2019 11:33:35 +0100 Subject: [PATCH 5/9] fbSlug went from ID! to String! in the queries --- src/schema/queries/StrategyByFB.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/schema/queries/StrategyByFB.js b/src/schema/queries/StrategyByFB.js index bb68b582d..03b4005a1 100644 --- a/src/schema/queries/StrategyByFB.js +++ b/src/schema/queries/StrategyByFB.js @@ -1,13 +1,13 @@ import { GraphQLNonNull, - GraphQLID, + GraphQLString, } from 'graphql'; import { DatabaseError } from '../../errors'; import { StrategyType } from '../types'; import { Strategy } from '../../models'; const args = { - fbSlug: { type: new GraphQLNonNull(GraphQLID) }, + fbSlug: { type: new GraphQLNonNull(GraphQLString) }, }; const resolve = (parent, { fbSlug }) => new Promise((res, rej) => { From 743c1406003e8ccc5a5896044dcc83a421a82858 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 21 Mar 2019 10:56:07 +0100 Subject: [PATCH 6/9] Adding default strategy to the creation mutation --- src/schema/mutations/CreateStrategy.js | 4 + src/templates/strategyTemplate.js | 328 +++++++++++++++++++++++++ 2 files changed, 332 insertions(+) create mode 100644 src/templates/strategyTemplate.js diff --git a/src/schema/mutations/CreateStrategy.js b/src/schema/mutations/CreateStrategy.js index cbbe2bb17..0ab2216a9 100644 --- a/src/schema/mutations/CreateStrategy.js +++ b/src/schema/mutations/CreateStrategy.js @@ -5,6 +5,7 @@ import { import { StrategyType } from '../types'; import { Strategy } from '../../models'; import { StrategyInputType } from '../types/input'; +import defaultStrategy from '../../templates/strategyTemplate'; export const args = { fbSlug: { type: new GraphQLNonNull(GraphQLString) }, @@ -12,6 +13,9 @@ export const args = { }; const resolve = (parent, { fbSlug, strategy }) => { + if (strategy === undefined) { + strategy = defaultStrategy; + } strategy.fbSlug = fbSlug; const newStrategy = new Strategy(strategy); diff --git a/src/templates/strategyTemplate.js b/src/templates/strategyTemplate.js new file mode 100644 index 000000000..cbdf50876 --- /dev/null +++ b/src/templates/strategyTemplate.js @@ -0,0 +1,328 @@ +/* eslint-disable max-len */ +const strategy = { + subStrategies: [ + { + name: 'Trend Following', + entryPoint: { + situations: [ + { + name: 'Price Collapsing', + conditions: [ + { + name: '%B Moving Average going up', + code: "percentageBandwidth.previous.direction === 'down' && percentageBandwidth.direction === 'down'", + }, + { + name: '%B Bandwidth going up', + code: 'percentageBandwidth.previous.previous.bandwidth < percentageBandwidth.previous.bandwidth && percentageBandwidth.previous.bandwidth < percentageBandwidth.bandwidth', + }, + { + name: 'Candles Min going down', + code: 'candle.previous.previous.min > candle.previous.min && candle.previous.min > candle.min', + }, + ], + }, + ], + }, + exitPoint: { + situations: [ + { + name: 'Market Reversing', + conditions: [ + { + name: 'Close above Band Moving Average', + code: 'candle.close > bollingerBand.movingAverage', + }, + ], + }, + ], + }, + sellPoint: { + situations: [ + { + name: 'Min below lower bollingerBand.', + conditions: [ + { + name: '3 Candles MIN below Lower Band', + code: 'candle.previous.previous.min < bollingerBand.previous.previous.movingAverage - bollingerBand.previous.previous.deviation && candle.previous.min < bollingerBand.previous.movingAverage - bollingerBand.previous.deviation && candle.min < bollingerBand.movingAverage - bollingerBand.deviation', + }, + ], + }, + ], + }, + stopLoss: { + phases: [ + { + name: 'Following Sell Rate', + code: 'newStopLoss = sellRate + sellRate * (stopLossPercentage - stopLossDecay) / 100', + situations: [ + { + name: 'Candle below Moving Average', + conditions: [ + { + name: 'Candle fully below Band Moving Average', + code: 'candle.max < bollingerBand.movingAverage', + }, + { + name: 'Band Moving Average going down', + code: "bollingerBand.direction === 'down'", + }, + ], + }, + ], + }, + { + name: 'Above Bands Moving Average', + code: 'newStopLoss = bollingerBand.movingAverage + bollingerBand.movingAverage * (stopLossPercentage - stopLossDecay) / 100', + situations: [ + { + name: 'Candle below Moving Average', + conditions: [ + { + name: 'Candle MAX below lower band', + code: 'candle.max < bollingerBand.movingAverage - bollingerBand.deviation', + }, + ], + }, + ], + }, + { + name: 'At Bands Moving Average', + code: 'newStopLoss = bollingerBand.movingAverage', + situations: [], + }, + ], + }, + buyOrder: { + phases: [ + { + name: '12 times standard deviation', + code: 'buyOrder = bollingerBand.movingAverage - bollingerBand.standardDeviation * 12', + situations: [ + { + name: 'Candle cut by lower band', + conditions: [ + { + name: 'Max above lower band', + code: 'candle.max > bollingerBand.movingAverage - bollingerBand.deviation', + }, + { + name: 'MIN below lower band', + code: 'candle.min < bollingerBand.movingAverage - bollingerBand.deviation', + }, + { + name: 'Band Moving Average going down', + code: 'bollingerBand.previous.movingAverage > bollingerBand.movingAverage', + }, + ], + }, + ], + }, + { + name: '10 times standard deviation', + code: 'buyOrder = bollingerBand.movingAverage - bollingerBand.standardDeviation * 10', + situations: [ + { + name: '%B starting to revert', + conditions: [ + { + name: '%B Moving Average going up', + code: "percentageBandwidth.direction === 'up'", + }, + { + name: '%B Moving Average above 0', + code: 'percentageBandwidth.movingAverage > 0', + }, + ], + }, + ], + }, + { + name: '4 times standard deviation', + code: 'buyOrder = bollingerBand.movingAverage - bollingerBand.standardDeviation * 4', + situations: [ + { + name: '%B going down again', + conditions: [ + { + name: '%B Moving Average going down', + code: "percentageBandwidth.direction === 'down'", + }, + ], + }, + ], + }, + { + name: '3 times standard deviation', + code: 'buyOrder = bollingerBand.movingAverage - bollingerBand.standardDeviation * 3', + situations: [ + { + name: '%B going up and above 30', + conditions: [ + { + name: '%B Moving Average going up', + code: "percentageBandwidth.direction === 'up'", + }, + { + name: '%B Moving Average above 30', + code: 'percentageBandwidth.movingAverage > 30', + }, + ], + }, + ], + }, + { + name: 'At lower band', + code: 'buyOrder = bollingerBand.movingAverage - bollingerBand.standardDeviation * 2', + situations: [], + }, + ], + }, + }, + { + name: 'Range Trading', + entryPoint: { + situations: [ + { + name: 'Gentle Up Trend', + conditions: [ + { + name: 'Sub-Channel going up', + code: "subChannel.direction === 'up'", + }, + { + name: 'Sub-Channel Side|Gentle|Medium', + code: "subChannel.slope === 'Side' || subChannel.slope === 'Gentle' || subChannel.slope === 'Medium'", + }, + { + name: 'Candle Close above Lower Band', + code: 'candle.close > bollingerBand.movingAverage + bollingerBand.deviation', + }, + { name: 'Impossible', code: ' 1 === 2' }, + ], + }, + ], + }, + exitPoint: { + situations: [ + { + name: 'Outside Sub-Channel', + conditions: [ + { + name: 'Going down or too Steep', + code: "subChannel.direction === 'Down' || subChannel.slope === 'Steep' || subChannel.slope === 'Extreme'", + }, + ], + }, + ], + }, + sellPoint: { + situations: [ + { + name: 'Min below lower bollingerBand.', + conditions: [ + { + name: '%B Moving Average going down', + code: 'percentageBandwidth.previous.movingAverage > percentageBandwidth.movingAverage', + }, + { + name: '%B Moving Average above 90', + code: 'percentageBandwidth.previous.movingAverage > 90', + }, + ], + }, + ], + }, + stopLoss: { + phases: [ + { + name: 'Following Sell Rate', + code: 'newStopLoss = sellRate + sellRate * (stopLossPercentage - stopLossDecay) / 100', + situations: [], + }, + ], + }, + buyOrder: { + phases: [ + { + name: 'Between Band Moving Average and Lower Band', + code: 'buyOrder = bollingerBand.movingAverage - bollingerBand.standardDeviation', + situations: [], + }, + ], + }, + }, + { + name: 'LRC Strategy', + entryPoint: { + situations: [ + { + name: 'Lines in the right order', + conditions: [ + { name: '60 > 30', code: 'LRC._60 > LRC._30' }, + { name: '30 > 15', code: 'LRC._30 > LRC._15' }, + { name: 'Impossible', code: ' 1 === 2' }, + ], + }, + ], + }, + exitPoint: { + situations: [ + { + name: 'Lines out of order', + conditions: [ + { + name: '60 < 30 or 30 < 15', + code: 'LRC._60 < LRC._30 || LRC._30 < LRC._15 ', + }, + ], + }, + ], + }, + sellPoint: { + situations: [ + { + name: 'All lines going down', + conditions: [ + { name: '60 going down', code: "LRC.direction60 === 'down'" }, + { name: '30 going down', code: "LRC.direction30 === 'down'" }, + { name: '15 going down', code: "LRC.direction15 === 'down'" }, + ], + }, + ], + }, + stopLoss: { + phases: [ + { + name: 'Following Sell Rate', + code: 'newStopLoss = sellRate + sellRate * (stopLossPercentage - stopLossDecay) / 100', + situations: [ + { + name: 'Stop Loss < 60', + conditions: [ + { name: 'Stop Loss < 60', code: 'stopLoss < LRC._60' }, + ], + }, + ], + }, + { + name: 'Following 60', + code: 'newStopLoss = LRC._60', + situations: [], + }, + ], + }, + buyOrder: { + phases: [ + { + name: 'Between Band Moving Average and Lower Band', + code: 'buyOrder = bollingerBand.movingAverage - bollingerBand.standardDeviation * 4', + situations: [], + }, + ], + }, + }, + ], +}; + +export default strategy; From 5f66847dba3fe250e16de464a6ce2f3391f39e5b Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 25 Mar 2019 09:55:51 +0100 Subject: [PATCH 7/9] Adding toggleable strategy state --- src/models/Strategy.js | 5 +++++ src/schema/types/Strategy.js | 7 ++++++- src/schema/types/SubStrategy.js | 2 ++ src/schema/types/input/SubStrategy.js | 2 ++ src/templates/strategyTemplate.js | 3 +++ 5 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/models/Strategy.js b/src/models/Strategy.js index 504f94431..e0932ec67 100644 --- a/src/models/Strategy.js +++ b/src/models/Strategy.js @@ -9,6 +9,11 @@ const strategySchema = new Schema( dropDups: true, }, subStrategies: [{ + actif: { + type: Boolean, + required: true, + default: true, + }, name: { type: String, default: '', diff --git a/src/schema/types/Strategy.js b/src/schema/types/Strategy.js index 4a5be341d..8c9633146 100644 --- a/src/schema/types/Strategy.js +++ b/src/schema/types/Strategy.js @@ -2,6 +2,7 @@ import { GraphQLObjectType, GraphQLString, GraphQLList, + GraphQLBoolean, GraphQLID, } from 'graphql'; import { @@ -15,8 +16,12 @@ const Type = new GraphQLObjectType({ id: { type: GraphQLID }, fbSlug: { type: GraphQLString }, subStrategies: { + args: { actifOnly: { type: GraphQLBoolean } }, type: new GraphQLList(SubStrategyType), - resolve(parent) { + resolve(parent, { actifOnly }) { + if (actifOnly) { + return parent.subStrategies.filter(subStrategy => subStrategy.actif); + } return parent.subStrategies; }, }, diff --git a/src/schema/types/SubStrategy.js b/src/schema/types/SubStrategy.js index 4d6fe80d7..69b7ff20c 100644 --- a/src/schema/types/SubStrategy.js +++ b/src/schema/types/SubStrategy.js @@ -1,6 +1,7 @@ import { GraphQLObjectType, GraphQLString, + GraphQLBoolean, } from 'graphql'; import { EntryPointType, @@ -16,6 +17,7 @@ const Type = new GraphQLObjectType({ name: 'SubStrategy', description: 'SubStrategy composing a strategy', fields: () => ({ + actif: { type: GraphQLBoolean }, name: { type: GraphQLString }, entryPoint: { type: EntryPointType, diff --git a/src/schema/types/input/SubStrategy.js b/src/schema/types/input/SubStrategy.js index d55203ea8..737aa532b 100644 --- a/src/schema/types/input/SubStrategy.js +++ b/src/schema/types/input/SubStrategy.js @@ -1,5 +1,6 @@ import { GraphQLString, + GraphQLBoolean, GraphQLInputObjectType, } from 'graphql'; import { @@ -16,6 +17,7 @@ const Type = new GraphQLInputObjectType({ name: 'SubStrategyInput', description: 'Payload for subStrategy input', fields: () => ({ + actif: { type: GraphQLBoolean }, name: { type: GraphQLString }, entryPoint: { type: EntryPointInputType }, exitPoint: { type: ExitPointInputType }, diff --git a/src/templates/strategyTemplate.js b/src/templates/strategyTemplate.js index cbdf50876..7af2abcde 100644 --- a/src/templates/strategyTemplate.js +++ b/src/templates/strategyTemplate.js @@ -2,6 +2,7 @@ const strategy = { subStrategies: [ { + actif: true, name: 'Trend Following', entryPoint: { situations: [ @@ -180,6 +181,7 @@ const strategy = { }, }, { + actif: true, name: 'Range Trading', entryPoint: { situations: [ @@ -253,6 +255,7 @@ const strategy = { }, }, { + actif: true, name: 'LRC Strategy', entryPoint: { situations: [ From 3b8012dc994a6cf1f9e3ecf0c37bc8af97420bb7 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 26 Mar 2019 10:42:44 +0100 Subject: [PATCH 8/9] Switching from "actif" to "active" --- src/models/Strategy.js | 2 +- src/schema/types/Strategy.js | 8 ++++---- src/schema/types/SubStrategy.js | 2 +- src/schema/types/input/SubStrategy.js | 2 +- src/templates/strategyTemplate.js | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/models/Strategy.js b/src/models/Strategy.js index e0932ec67..e8116b208 100644 --- a/src/models/Strategy.js +++ b/src/models/Strategy.js @@ -9,7 +9,7 @@ const strategySchema = new Schema( dropDups: true, }, subStrategies: [{ - actif: { + active: { type: Boolean, required: true, default: true, diff --git a/src/schema/types/Strategy.js b/src/schema/types/Strategy.js index 8c9633146..034d8bcd7 100644 --- a/src/schema/types/Strategy.js +++ b/src/schema/types/Strategy.js @@ -16,11 +16,11 @@ const Type = new GraphQLObjectType({ id: { type: GraphQLID }, fbSlug: { type: GraphQLString }, subStrategies: { - args: { actifOnly: { type: GraphQLBoolean } }, + args: { activeOnly: { type: GraphQLBoolean } }, type: new GraphQLList(SubStrategyType), - resolve(parent, { actifOnly }) { - if (actifOnly) { - return parent.subStrategies.filter(subStrategy => subStrategy.actif); + resolve(parent, { activeOnly }) { + if (activeOnly) { + return parent.subStrategies.filter(subStrategy => subStrategy.active); } return parent.subStrategies; }, diff --git a/src/schema/types/SubStrategy.js b/src/schema/types/SubStrategy.js index 69b7ff20c..7facc4dc4 100644 --- a/src/schema/types/SubStrategy.js +++ b/src/schema/types/SubStrategy.js @@ -17,7 +17,7 @@ const Type = new GraphQLObjectType({ name: 'SubStrategy', description: 'SubStrategy composing a strategy', fields: () => ({ - actif: { type: GraphQLBoolean }, + active: { type: GraphQLBoolean }, name: { type: GraphQLString }, entryPoint: { type: EntryPointType, diff --git a/src/schema/types/input/SubStrategy.js b/src/schema/types/input/SubStrategy.js index 737aa532b..08a56e37b 100644 --- a/src/schema/types/input/SubStrategy.js +++ b/src/schema/types/input/SubStrategy.js @@ -17,7 +17,7 @@ const Type = new GraphQLInputObjectType({ name: 'SubStrategyInput', description: 'Payload for subStrategy input', fields: () => ({ - actif: { type: GraphQLBoolean }, + active: { type: GraphQLBoolean }, name: { type: GraphQLString }, entryPoint: { type: EntryPointInputType }, exitPoint: { type: ExitPointInputType }, diff --git a/src/templates/strategyTemplate.js b/src/templates/strategyTemplate.js index 7af2abcde..5f1031b8a 100644 --- a/src/templates/strategyTemplate.js +++ b/src/templates/strategyTemplate.js @@ -2,7 +2,7 @@ const strategy = { subStrategies: [ { - actif: true, + active: true, name: 'Trend Following', entryPoint: { situations: [ @@ -181,7 +181,7 @@ const strategy = { }, }, { - actif: true, + active: true, name: 'Range Trading', entryPoint: { situations: [ @@ -255,7 +255,7 @@ const strategy = { }, }, { - actif: true, + active: true, name: 'LRC Strategy', entryPoint: { situations: [ From 7036937586d2aad1d8643ac0f5297a1700f60bae Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 5 Apr 2019 18:03:22 +0200 Subject: [PATCH 9/9] Adapting default strategy --- src/templates/strategyTemplate.js | 72 ------------------------------- 1 file changed, 72 deletions(-) diff --git a/src/templates/strategyTemplate.js b/src/templates/strategyTemplate.js index 5f1031b8a..eb84a1325 100644 --- a/src/templates/strategyTemplate.js +++ b/src/templates/strategyTemplate.js @@ -200,7 +200,6 @@ const strategy = { name: 'Candle Close above Lower Band', code: 'candle.close > bollingerBand.movingAverage + bollingerBand.deviation', }, - { name: 'Impossible', code: ' 1 === 2' }, ], }, ], @@ -254,77 +253,6 @@ const strategy = { ], }, }, - { - active: true, - name: 'LRC Strategy', - entryPoint: { - situations: [ - { - name: 'Lines in the right order', - conditions: [ - { name: '60 > 30', code: 'LRC._60 > LRC._30' }, - { name: '30 > 15', code: 'LRC._30 > LRC._15' }, - { name: 'Impossible', code: ' 1 === 2' }, - ], - }, - ], - }, - exitPoint: { - situations: [ - { - name: 'Lines out of order', - conditions: [ - { - name: '60 < 30 or 30 < 15', - code: 'LRC._60 < LRC._30 || LRC._30 < LRC._15 ', - }, - ], - }, - ], - }, - sellPoint: { - situations: [ - { - name: 'All lines going down', - conditions: [ - { name: '60 going down', code: "LRC.direction60 === 'down'" }, - { name: '30 going down', code: "LRC.direction30 === 'down'" }, - { name: '15 going down', code: "LRC.direction15 === 'down'" }, - ], - }, - ], - }, - stopLoss: { - phases: [ - { - name: 'Following Sell Rate', - code: 'newStopLoss = sellRate + sellRate * (stopLossPercentage - stopLossDecay) / 100', - situations: [ - { - name: 'Stop Loss < 60', - conditions: [ - { name: 'Stop Loss < 60', code: 'stopLoss < LRC._60' }, - ], - }, - ], - }, - { - name: 'Following 60', - code: 'newStopLoss = LRC._60', - situations: [], - }, - ], - }, - buyOrder: { - phases: [ - { - name: 'Between Band Moving Average and Lower Band', - code: 'buyOrder = bollingerBand.movingAverage - bollingerBand.standardDeviation * 4', - situations: [], - }, - ], - }, - }, ], };