@barchart/portfolio-api-common 1.0.24 → 1.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,7 +13,7 @@ module.exports = (() => {
13
13
  'use strict';
14
14
 
15
15
  /**
16
- * The schemas which can be used to represent a portfolio objects.
16
+ * The schemas which can be used to represent portfolio objects.
17
17
  *
18
18
  * @public
19
19
  * @extends {Enum}
@@ -26,6 +26,8 @@ module.exports = (() => {
26
26
  }
27
27
 
28
28
  /**
29
+ * The actual {@link Schema}.
30
+ *
29
31
  * @public
30
32
  * @returns {Schema}
31
33
  */
@@ -34,15 +36,19 @@ module.exports = (() => {
34
36
  }
35
37
 
36
38
  /**
39
+ * The complete portfolio schema.
40
+ *
37
41
  * @static
38
42
  * @public
39
43
  * @returns {PortfolioSchema}
40
44
  */
41
- static get CREATE() {
42
- return create;
45
+ static get COMPLETE() {
46
+ return complete;
43
47
  }
44
48
 
45
49
  /**
50
+ * Portfolio data transmitted to the client, omitting some system data.
51
+ *
46
52
  * @static
47
53
  * @public
48
54
  * @returns {PortfolioSchema}
@@ -52,15 +58,19 @@ module.exports = (() => {
52
58
  }
53
59
 
54
60
  /**
61
+ * Data required to create a portfolio.
62
+ *
55
63
  * @static
56
64
  * @public
57
65
  * @returns {PortfolioSchema}
58
66
  */
59
- static get COMPLETE() {
60
- return complete;
67
+ static get CREATE() {
68
+ return create;
61
69
  }
62
70
 
63
71
  /**
72
+ * Data required to update a portfolio.
73
+ *
64
74
  * @static
65
75
  * @public
66
76
  * @returns {PortfolioSchema}
@@ -119,20 +129,18 @@ module.exports = (() => {
119
129
  .withField('name', DataType.STRING)
120
130
  .withField('timezone', DataType.forEnum(Timezones, 'Timezone'))
121
131
  .withField('dates.cash', DataType.DAY, true)
122
- .withField('defaults.currency', DataType.forEnum(Currency, 'Currency'))
132
+ .withField('defaults.currency', DataType.forEnum(Currency, 'Currency'), true)
123
133
  .withField('defaults.reinvest', DataType.BOOLEAN, true)
124
- .withField('defaults.valuation', DataType.forEnum(ValuationType, 'ValuationType'))
134
+ .withField('defaults.valuation', DataType.forEnum(ValuationType, 'ValuationType'), true)
125
135
  .withField('miscellany', DataType.AD_HOC, true)
126
136
  .schema
127
137
  );
128
138
 
129
139
  const update = new PortfolioSchema(SchemaBuilder.withName('update')
130
140
  .withField('name', DataType.STRING)
131
- .withField('timezone', DataType.forEnum(Timezones, 'Timezone'))
132
- .withField('dates.cash', DataType.DAY, true)
133
- .withField('defaults.currency', DataType.forEnum(Currency, 'Currency'))
141
+ .withField('timezone', DataType.forEnum(Timezones, 'Timezone'), true)
142
+ .withField('defaults.currency', DataType.forEnum(Currency, 'Currency'), true)
134
143
  .withField('defaults.reinvest', DataType.BOOLEAN, true)
135
- .withField('defaults.valuation', DataType.forEnum(ValuationType, 'ValuationType'))
136
144
  .withField('miscellany', DataType.AD_HOC, true)
137
145
  .schema
138
146
  );
@@ -12,7 +12,7 @@ module.exports = (() => {
12
12
  'use strict';
13
13
 
14
14
  /**
15
- * The schemas which can be used to represent a position objects.
15
+ * The schemas which can be used to represent position objects.
16
16
  *
17
17
  * @public
18
18
  * @extends {Enum}
@@ -25,6 +25,8 @@ module.exports = (() => {
25
25
  }
26
26
 
27
27
  /**
28
+ * The actual {@link Schema}.
29
+ *
28
30
  * @public
29
31
  * @returns {Schema}
30
32
  */
@@ -33,6 +35,8 @@ module.exports = (() => {
33
35
  }
34
36
 
35
37
  /**
38
+ * The complete position schema.
39
+ *
36
40
  * @static
37
41
  * @public
38
42
  * @returns {PositionSchema}
@@ -41,12 +45,23 @@ module.exports = (() => {
41
45
  return complete;
42
46
  }
43
47
 
48
+ /**
49
+ * Position data transmitted to the client, omitting some system data.
50
+ *
51
+ * @static
52
+ * @public
53
+ * @returns {PositionSchema}
54
+ */
55
+ static get CLIENT() {
56
+ return client;
57
+ }
58
+
44
59
  toString() {
45
60
  return '[PositionSchema]';
46
61
  }
47
62
  }
48
63
 
49
- const complete = new PositionSchema(SchemaBuilder.withName('Complete')
64
+ const complete = new PositionSchema(SchemaBuilder.withName('complete')
50
65
  .withField('user', DataType.STRING)
51
66
  .withField('portfolio', DataType.STRING)
52
67
  .withField('sequence', DataType.NUMBER)
@@ -78,5 +93,32 @@ module.exports = (() => {
78
93
  .schema
79
94
  );
80
95
 
96
+ const client = new PositionSchema(SchemaBuilder.withName('client')
97
+ .withField('user', DataType.STRING)
98
+ .withField('portfolio', DataType.STRING)
99
+ .withField('sequence', DataType.NUMBER)
100
+ .withField('instrument.id', DataType.STRING)
101
+ .withField('instrument.name', DataType.STRING)
102
+ .withField('instrument.type', DataType.STRING)
103
+ .withField('instrument.currency', DataType.forEnum(Currency, 'Currency'))
104
+ .withField('instrument.delist', DataType.DAY, true)
105
+ .withField('instrument.symbol.barchart', DataType.STRING, true)
106
+ .withField('instrument.symbol.display', DataType.STRING, true)
107
+ .withField('position', DataType.STRING)
108
+ .withField('open', DataType.BOOLEAN, true)
109
+ .withField('transaction', DataType.NUMBER)
110
+ .withField('valuation', DataType.forEnum(ValuationType, 'ValuationType'))
111
+ .withField('reinvest', DataType.BOOLEAN)
112
+ .withField('snapshot.date', DataType.DAY)
113
+ .withField('snapshot.open', DataType.DECIMAL)
114
+ .withField('snapshot.buys', DataType.DECIMAL)
115
+ .withField('snapshot.sells', DataType.DECIMAL)
116
+ .withField('snapshot.gain', DataType.DECIMAL)
117
+ .withField('snapshot.basis', DataType.DECIMAL)
118
+ .withField('snapshot.income', DataType.DECIMAL)
119
+ .withField('snapshot.value', DataType.DECIMAL)
120
+ .schema
121
+ );
122
+
81
123
  return PositionSchema;
82
124
  })();
@@ -0,0 +1,127 @@
1
+ const assert = require('@barchart/common-js/lang/assert'),
2
+ Currency = require('@barchart/common-js/lang/Currency'),
3
+ DataType = require('@barchart/common-js/serialization/json/DataType'),
4
+ Enum = require('@barchart/common-js/lang/Enum'),
5
+ is = require('@barchart/common-js/lang/is'),
6
+ Schema = require('@barchart/common-js/serialization/json/Schema'),
7
+ SchemaBuilder = require('@barchart/common-js/serialization/json/builders/SchemaBuilder');
8
+
9
+ const PositionSummaryFrame = require('./../data/PositionSummaryFrame');
10
+
11
+ module.exports = (() => {
12
+ 'use strict';
13
+
14
+ /**
15
+ * The schemas which can be used to represent position summary objects.
16
+ *
17
+ * @public
18
+ * @extends {Enum}
19
+ */
20
+ class PositionSummarySchema extends Enum {
21
+ constructor(schema) {
22
+ super(schema.name, schema.name);
23
+
24
+ this._schema = schema;
25
+ }
26
+
27
+ /**
28
+ * The actual {@link Schema}.
29
+ *
30
+ * @public
31
+ * @returns {Schema}
32
+ */
33
+ get schema() {
34
+ return this._schema;
35
+ }
36
+
37
+ /**
38
+ * The complete position summary schema.
39
+ *
40
+ * @static
41
+ * @public
42
+ * @returns {PositionSummarySchema}
43
+ */
44
+ static get COMPLETE() {
45
+ return complete;
46
+ }
47
+
48
+ /**
49
+ * Position summary data transmitted to the client, omitting some system data.
50
+ *
51
+ * @static
52
+ * @public
53
+ * @returns {PositionSummarySchema}
54
+ */
55
+ static get CLIENT() {
56
+ return client;
57
+ }
58
+
59
+ toString() {
60
+ return '[PositionSummarySchema]';
61
+ }
62
+ }
63
+
64
+ const complete = new PositionSummarySchema(SchemaBuilder.withName('complete')
65
+ .withField('user', DataType.STRING)
66
+ .withField('portfolio', DataType.STRING)
67
+ .withField('position', DataType.STRING)
68
+ .withField('instrument.id', DataType.STRING)
69
+ .withField('instrument.name', DataType.STRING)
70
+ .withField('instrument.type', DataType.STRING)
71
+ .withField('instrument.currency', DataType.forEnum(Currency, 'Currency'))
72
+ .withField('instrument.delist', DataType.DAY, true)
73
+ .withField('instrument.symbol.barchart', DataType.STRING, true)
74
+ .withField('instrument.symbol.display', DataType.STRING, true)
75
+ .withField('frame', DataType.forEnum(PositionSummaryFrame, 'PositionSummaryFrame'))
76
+ .withField('start.date', DataType.DAY)
77
+ .withField('start.sequence', DataType.NUMBER)
78
+ .withField('start.open', DataType.DECIMAL)
79
+ .withField('start.basis', DataType.DECIMAL)
80
+ .withField('start.value', DataType.DECIMAL)
81
+ .withField('end.date', DataType.DAY)
82
+ .withField('end.sequence', DataType.NUMBER)
83
+ .withField('end.open', DataType.DECIMAL)
84
+ .withField('end.basis', DataType.DECIMAL)
85
+ .withField('end.value', DataType.DECIMAL)
86
+ .withField('period.buys', DataType.DECIMAL)
87
+ .withField('period.sells', DataType.DECIMAL)
88
+ .withField('period.income', DataType.DECIMAL)
89
+ .withField('period.realized', DataType.DECIMAL)
90
+ .withField('period.unrealized', DataType.DECIMAL)
91
+ .withField('system.sequence', DataType.NUMBER)
92
+ .withField('system.version', DataType.STRING)
93
+ .schema
94
+ );
95
+
96
+ const client = new PositionSummarySchema(SchemaBuilder.withName('client')
97
+ .withField('user', DataType.STRING)
98
+ .withField('portfolio', DataType.STRING)
99
+ .withField('position', DataType.STRING)
100
+ .withField('instrument.id', DataType.STRING)
101
+ .withField('instrument.name', DataType.STRING)
102
+ .withField('instrument.type', DataType.STRING)
103
+ .withField('instrument.currency', DataType.forEnum(Currency, 'Currency'))
104
+ .withField('instrument.delist', DataType.DAY, true)
105
+ .withField('instrument.symbol.barchart', DataType.STRING, true)
106
+ .withField('instrument.symbol.display', DataType.STRING, true)
107
+ .withField('frame', DataType.forEnum(PositionSummaryFrame, 'PositionSummaryFrame'))
108
+ .withField('start.date', DataType.DAY)
109
+ .withField('start.sequence', DataType.NUMBER)
110
+ .withField('start.open', DataType.DECIMAL)
111
+ .withField('start.basis', DataType.DECIMAL)
112
+ .withField('start.value', DataType.DECIMAL)
113
+ .withField('end.date', DataType.DAY)
114
+ .withField('end.sequence', DataType.NUMBER)
115
+ .withField('end.open', DataType.DECIMAL)
116
+ .withField('end.basis', DataType.DECIMAL)
117
+ .withField('end.value', DataType.DECIMAL)
118
+ .withField('period.buys', DataType.DECIMAL)
119
+ .withField('period.sells', DataType.DECIMAL)
120
+ .withField('period.income', DataType.DECIMAL)
121
+ .withField('period.realized', DataType.DECIMAL)
122
+ .withField('period.unrealized', DataType.DECIMAL)
123
+ .schema
124
+ );
125
+
126
+ return PositionSummarySchema;
127
+ })();
@@ -11,7 +11,7 @@ module.exports = (() => {
11
11
  'use strict';
12
12
 
13
13
  /**
14
- * The schemas which can be used to represent a transaction objects.
14
+ * The schemas which can be used to represent transaction objects.
15
15
  *
16
16
  * @public
17
17
  * @extends {Enum}
@@ -24,6 +24,8 @@ module.exports = (() => {
24
24
  }
25
25
 
26
26
  /**
27
+ * The actual {@link Schema}.
28
+ *
27
29
  * @public
28
30
  * @returns {Schema}
29
31
  */
@@ -31,10 +33,28 @@ module.exports = (() => {
31
33
  return this._schema;
32
34
  }
33
35
 
36
+ /**
37
+ * The complete transaction schema.
38
+ *
39
+ * @static
40
+ * @public
41
+ * @returns {TransactionSchema}
42
+ */
34
43
  static get COMPLETE() {
35
44
  return complete;
36
45
  }
37
46
 
47
+ /**
48
+ * Transaction data transmitted to the client, omitting some system data.
49
+ *
50
+ * @static
51
+ * @public
52
+ * @returns {TransactionSchema}
53
+ */
54
+ static get CLIENT() {
55
+ return client;
56
+ }
57
+
38
58
  static get BUY() {
39
59
  return buy;
40
60
  }
@@ -112,7 +132,7 @@ module.exports = (() => {
112
132
  }
113
133
  }
114
134
 
115
- const complete = new TransactionSchema(SchemaBuilder.withName('Complete')
135
+ const complete = new TransactionSchema(SchemaBuilder.withName('complete')
116
136
  .withField('portfolio', DataType.STRING)
117
137
  .withField('position', DataType.STRING)
118
138
  .withField('sequence', DataType.NUMBER)
@@ -149,6 +169,44 @@ module.exports = (() => {
149
169
  .withField('charge.amount', DataType.DECIMAL, true)
150
170
  .withField('income.amount', DataType.DECIMAL, true)
151
171
  .withField('valuation.value', DataType.DECIMAL, true)
172
+ .withField('system.sequence', DataType.NUMBER)
173
+ .withField('system.version', DataType.STRING)
174
+ .withField('system.timestamp', DataType.TIMESTAMP)
175
+ .schema
176
+ );
177
+
178
+ const client = new TransactionSchema(SchemaBuilder.withName('client')
179
+ .withField('portfolio', DataType.STRING)
180
+ .withField('position', DataType.STRING)
181
+ .withField('sequence', DataType.NUMBER)
182
+ .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
183
+ .withField('date', DataType.DAY)
184
+ .withField('description', DataType.STRING, true)
185
+ .withField('amount', DataType.DECIMAL)
186
+ .withField('quantity', DataType.DECIMAL)
187
+ .withField('fee', DataType.DECIMAL, true)
188
+ .withField('reference.position', DataType.STRING, true)
189
+ .withField('reference.sequence', DataType.NUMBER, true)
190
+ .withField('snapshot.open', DataType.DECIMAL)
191
+ .withField('snapshot.buys', DataType.DECIMAL)
192
+ .withField('snapshot.sells', DataType.DECIMAL)
193
+ .withField('snapshot.gain', DataType.DECIMAL)
194
+ .withField('snapshot.basis', DataType.DECIMAL)
195
+ .withField('snapshot.income', DataType.DECIMAL)
196
+ .withField('snapshot.value', DataType.DECIMAL)
197
+ .withField('trade.price', DataType.DECIMAL, true)
198
+ .withField('dividend.rate', DataType.DECIMAL, true)
199
+ .withField('dividend.effective', DataType.DAY, true)
200
+ .withField('dividend.price', DataType.DECIMAL, true)
201
+ .withField('dividend.amount', DataType.DECIMAL, true)
202
+ .withField('dividend.reference', DataType.STRING, true)
203
+ .withField('split.numerator', DataType.DECIMAL, true)
204
+ .withField('split.denominator', DataType.DECIMAL, true)
205
+ .withField('split.effective', DataType.DAY, true)
206
+ .withField('split.reference', DataType.STRING, true)
207
+ .withField('charge.amount', DataType.DECIMAL, true)
208
+ .withField('income.amount', DataType.DECIMAL, true)
209
+ .withField('valuation.value', DataType.DECIMAL, true)
152
210
  .schema
153
211
  );
154
212
 
@@ -354,6 +412,5 @@ module.exports = (() => {
354
412
  .schema
355
413
  );
356
414
 
357
-
358
415
  return TransactionSchema;
359
416
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.0.24",
3
+ "version": "1.0.25",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -631,6 +631,37 @@ module.exports = function () {
631
631
  return Day.compareDays(this, other) > 0;
632
632
  }
633
633
 
634
+ /**
635
+ * Indicates the current day falls between two other days, inclusive
636
+ * of the range boundaries.
637
+ *
638
+ * @public
639
+ * @param {Day=} first
640
+ * @param {Day=} last
641
+ * @param {boolean=} exclusive
642
+ * @returns {boolean}
643
+ */
644
+
645
+ }, {
646
+ key: 'getIsContained',
647
+ value: function getIsContained(first, last) {
648
+ assert.argumentIsOptional(first, 'first', Day, 'Day');
649
+ assert.argumentIsOptional(last, 'last', Day, 'Day');
650
+
651
+ var notAfter = void 0;
652
+ var notBefore = void 0;
653
+
654
+ if (first && last && first.getIsAfter(last)) {
655
+ notBefore = false;
656
+ notAfter = false;
657
+ } else {
658
+ notAfter = !(last instanceof Day) || !this.getIsAfter(last);
659
+ notBefore = !(first instanceof Day) || !this.getIsBefore(first);
660
+ }
661
+
662
+ return notAfter && notBefore;
663
+ }
664
+
634
665
  /**
635
666
  * Indicates if another {@link Day} occurs after the current instance.
636
667
  *