From afb04b914bde1e9b7e791e2d1dc0d5ee18f8372d Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 16 Mar 2019 11:41:27 +0100 Subject: [PATCH] defining strategy output graphql types --- src/schema/types/Condition.js | 15 +++++++ src/schema/types/Event.js | 43 ------------------- src/schema/types/Formula.js | 15 ------- src/schema/types/Phase.js | 25 +++++++++++ src/schema/types/Plotter.js | 15 ------- src/schema/types/Prize.js | 23 ---------- src/schema/types/Situation.js | 24 +++++++++++ src/schema/types/Strategy.js | 26 ++++++++++++ src/schema/types/SubPrize.js | 14 ------ src/schema/types/SubStrategy.js | 75 +++++++++++++++++++++++++++++++++ src/schema/types/index.js | 20 ++++----- 11 files changed, 175 insertions(+), 120 deletions(-) create mode 100644 src/schema/types/Condition.js delete mode 100644 src/schema/types/Event.js delete mode 100644 src/schema/types/Formula.js create mode 100644 src/schema/types/Phase.js delete mode 100644 src/schema/types/Plotter.js delete mode 100644 src/schema/types/Prize.js create mode 100644 src/schema/types/Situation.js create mode 100644 src/schema/types/Strategy.js delete mode 100644 src/schema/types/SubPrize.js create mode 100644 src/schema/types/SubStrategy.js diff --git a/src/schema/types/Condition.js b/src/schema/types/Condition.js new file mode 100644 index 000000000..c22d2621e --- /dev/null +++ b/src/schema/types/Condition.js @@ -0,0 +1,15 @@ +import { + GraphQLObjectType, + GraphQLString, +} from 'graphql'; + +const ConditionType = new GraphQLObjectType({ + name: 'Condition', + description: 'Condition definition', + fields: () => ({ + name: { type: GraphQLString }, + code: { type: GraphQLString }, + }), +}); + +export default ConditionType; diff --git a/src/schema/types/Event.js b/src/schema/types/Event.js deleted file mode 100644 index 1d958b3d0..000000000 --- a/src/schema/types/Event.js +++ /dev/null @@ -1,43 +0,0 @@ -import { - GraphQLObjectType, - GraphQLString, - GraphQLList, - GraphQLID, -} from 'graphql'; -import { - FormulaType, - PlotterType, - PrizeType, -} from './index'; -import EventStateEnumType from './enum/EventState'; - -const EventType = new GraphQLObjectType({ - name: 'Event', - description: 'Everything you need to know about an event', - fields: () => ({ - id: { type: GraphQLID }, - state: { type: EventStateEnumType }, - name: { type: GraphQLString }, - hostId: { type: GraphQLString }, - formula: { - type: FormulaType, - resolve(parent) { - return parent.formulaId; - }, - }, - plotter: { - type: PlotterType, - resolve(parent) { - return parent.plotterId; - }, - }, - prizes: { - type: new GraphQLList(PrizeType), - resolve(parent) { - return parent.prizes; - }, - }, - }), -}); - -export default EventType; diff --git a/src/schema/types/Formula.js b/src/schema/types/Formula.js deleted file mode 100644 index 610cd517b..000000000 --- a/src/schema/types/Formula.js +++ /dev/null @@ -1,15 +0,0 @@ -import { - GraphQLObjectType, - GraphQLString, -} from 'graphql'; - -const FormulaType = new GraphQLObjectType({ - name: 'Formula', - description: 'For now it\'s simplay a named field', - fields: () => ({ - id: { type: GraphQLString }, - name: { type: GraphQLString }, - }), -}); - -export default FormulaType; diff --git a/src/schema/types/Phase.js b/src/schema/types/Phase.js new file mode 100644 index 000000000..09d80d700 --- /dev/null +++ b/src/schema/types/Phase.js @@ -0,0 +1,25 @@ +import { + GraphQLObjectType, + GraphQLString, + GraphQLList, +} from 'graphql'; +import { + SituationType, +} from './index'; + +const PhaseType = new GraphQLObjectType({ + name: 'Phase', + code: 'Phase', + description: 'Phase definition', + fields: () => ({ + name: { type: GraphQLString }, + situations: { + type: new GraphQLList(SituationType), + resolve(parent) { + return parent.situations; + }, + }, + }), +}); + +export default PhaseType; diff --git a/src/schema/types/Plotter.js b/src/schema/types/Plotter.js deleted file mode 100644 index 2d7a07952..000000000 --- a/src/schema/types/Plotter.js +++ /dev/null @@ -1,15 +0,0 @@ -import { - GraphQLObjectType, - GraphQLString, -} from 'graphql'; - -const PlotterType = new GraphQLObjectType({ - name: 'Plotter', - description: 'Will soon change in order to use contained plotter objects', - fields: () => ({ - id: { type: GraphQLString }, - name: { type: GraphQLString }, - }), -}); - -export default PlotterType; diff --git a/src/schema/types/Prize.js b/src/schema/types/Prize.js deleted file mode 100644 index c4790c230..000000000 --- a/src/schema/types/Prize.js +++ /dev/null @@ -1,23 +0,0 @@ -import { - GraphQLObjectType, - GraphQLList, - GraphQLString, - GraphQLNonNull, -} from 'graphql'; -import { SubPrizeType } from './index'; - -const PrizeType = new GraphQLObjectType({ - name: 'Prize', - description: 'Prize, by default in algos', - fields: () => ({ - rank: { type: new GraphQLNonNull(GraphQLString) }, - subPrize: { - type: new GraphQLList(SubPrizeType), - resolve(parent) { - return parent.subPrize; - }, - }, - }), -}); - -export default PrizeType; diff --git a/src/schema/types/Situation.js b/src/schema/types/Situation.js new file mode 100644 index 000000000..1c73eb2f0 --- /dev/null +++ b/src/schema/types/Situation.js @@ -0,0 +1,24 @@ +import { + GraphQLObjectType, + GraphQLString, + GraphQLList, +} from 'graphql'; +import { + ConditionType, +} from './index'; + +const SituationType = new GraphQLObjectType({ + name: 'Situation', + description: 'Situation definition', + fields: () => ({ + name: { type: GraphQLString }, + conditions: { + type: new GraphQLList(ConditionType), + resolve(parent) { + return parent.conditions; + }, + }, + }), +}); + +export default SituationType; diff --git a/src/schema/types/Strategy.js b/src/schema/types/Strategy.js new file mode 100644 index 000000000..d95ec3102 --- /dev/null +++ b/src/schema/types/Strategy.js @@ -0,0 +1,26 @@ +import { + GraphQLObjectType, + GraphQLString, + GraphQLList, + GraphQLID, +} from 'graphql'; +import { + SubStrategyType, +} from './index'; + +const EventType = new GraphQLObjectType({ + name: 'Event', + description: 'Everything you need to know about an event', + fields: () => ({ + id: { type: GraphQLID }, + fbId: { type: GraphQLString }, + subStrategies: { + type: new GraphQLList(SubStrategyType), + resolve(parent) { + return parent.subStrategies; + }, + }, + }), +}); + +export default EventType; diff --git a/src/schema/types/SubPrize.js b/src/schema/types/SubPrize.js deleted file mode 100644 index 65b6caad5..000000000 --- a/src/schema/types/SubPrize.js +++ /dev/null @@ -1,14 +0,0 @@ -import { - GraphQLObjectType, - GraphQLString, -} from 'graphql'; - -const SubPrizeType = new GraphQLObjectType({ - name: 'SubPrize', - description: 'Prize', - fields: () => ({ - condition: { type: GraphQLString }, - }), -}); - -export default SubPrizeType; diff --git a/src/schema/types/SubStrategy.js b/src/schema/types/SubStrategy.js new file mode 100644 index 000000000..2df444d5b --- /dev/null +++ b/src/schema/types/SubStrategy.js @@ -0,0 +1,75 @@ +import { + GraphQLObjectType, + GraphQLString, + GraphQLList, +} from 'graphql'; +import { + SituationType, + PhaseType, +} from './index'; + +const SubStrategyType = new GraphQLObjectType({ + name: 'SubStrategy', + description: 'SubStrategy composing a strategy', + fields: () => ({ + name: { type: GraphQLString }, + entryPoint: { + situations: { + type: new GraphQLList(SituationType), + resolve(parent) { + return parent.situations; + }, + }, + }, + exitPoint: { + situations: { + type: new GraphQLList(SituationType), + resolve(parent) { + return parent.situations; + }, + }, + }, + sellPoint: { + situations: { + type: new GraphQLList(SituationType), + resolve(parent) { + return parent.situations; + }, + }, + }, + buyPoint: { + situations: { + type: new GraphQLList(SituationType), + resolve(parent) { + return parent.situations; + }, + }, + }, + stopLoss: { + phases: { + type: new GraphQLList(PhaseType), + resolve(parent) { + return parent.phases; + }, + }, + }, + buyOrder: { + phases: { + type: new GraphQLList(PhaseType), + resolve(parent) { + return parent.phases; + }, + }, + }, + sellOrder: { + phases: { + type: new GraphQLList(PhaseType), + resolve(parent) { + return parent.phases; + }, + }, + }, + }), +}); + +export default SubStrategyType; diff --git a/src/schema/types/index.js b/src/schema/types/index.js index 6eb04985d..d2715104d 100644 --- a/src/schema/types/index.js +++ b/src/schema/types/index.js @@ -1,13 +1,13 @@ -import PlotterType from './Plotter'; -import SubPrizeType from './SubPrize'; -import PrizeType from './Prize'; -import FormulaType from './Formula'; -import EventType from './Event'; +import StrategyType from './Strategy'; +import SubStrategyType from './SubStrategy'; +import ConditionType from './Condition'; +import SituationType from './Situation'; +import PhaseType from './Phase'; export { - PlotterType, - SubPrizeType, - PrizeType, - FormulaType, - EventType, + StrategyType, + SubStrategyType, + ConditionType, + SituationType, + PhaseType, };