@barchart/portfolio-api-common 1.0.23 → 1.0.27

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}
@@ -118,22 +128,19 @@ module.exports = (() => {
118
128
  const create = new PortfolioSchema(SchemaBuilder.withName('create')
119
129
  .withField('name', DataType.STRING)
120
130
  .withField('timezone', DataType.forEnum(Timezones, 'Timezone'))
121
- .withField('dates.create', DataType.DAY)
122
131
  .withField('dates.cash', DataType.DAY, true)
123
- .withField('defaults.currency', DataType.forEnum(Currency, 'Currency'))
132
+ .withField('defaults.currency', DataType.forEnum(Currency, 'Currency'), true)
124
133
  .withField('defaults.reinvest', DataType.BOOLEAN, true)
125
- .withField('defaults.valuation', DataType.forEnum(ValuationType, 'ValuationType'))
134
+ .withField('defaults.valuation', DataType.forEnum(ValuationType, 'ValuationType'), true)
126
135
  .withField('miscellany', DataType.AD_HOC, true)
127
136
  .schema
128
137
  );
129
138
 
130
139
  const update = new PortfolioSchema(SchemaBuilder.withName('update')
131
140
  .withField('name', DataType.STRING)
132
- .withField('timezone', DataType.forEnum(Timezones, 'Timezone'))
133
- .withField('dates.cash', DataType.DAY, true)
134
- .withField('defaults.currency', DataType.forEnum(Currency, 'Currency'))
141
+ .withField('timezone', DataType.forEnum(Timezones, 'Timezone'), true)
142
+ .withField('defaults.currency', DataType.forEnum(Currency, 'Currency'), true)
135
143
  .withField('defaults.reinvest', DataType.BOOLEAN, true)
136
- .withField('defaults.valuation', DataType.forEnum(ValuationType, 'ValuationType'))
137
144
  .withField('miscellany', DataType.AD_HOC, true)
138
145
  .schema
139
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
+ })();
@@ -1,4 +1,5 @@
1
1
  const assert = require('@barchart/common-js/lang/assert'),
2
+ is = require('@barchart/common-js/lang/is'),
2
3
  Currency = require('@barchart/common-js/lang/Currency'),
3
4
  DataType = require('@barchart/common-js/serialization/json/DataType'),
4
5
  Enum = require('@barchart/common-js/lang/Enum'),
@@ -11,7 +12,7 @@ module.exports = (() => {
11
12
  'use strict';
12
13
 
13
14
  /**
14
- * The schemas which can be used to represent a transaction objects.
15
+ * The schemas which can be used to represent transaction objects.
15
16
  *
16
17
  * @public
17
18
  * @extends {Enum}
@@ -24,6 +25,8 @@ module.exports = (() => {
24
25
  }
25
26
 
26
27
  /**
28
+ * The actual {@link Schema}.
29
+ *
27
30
  * @public
28
31
  * @returns {Schema}
29
32
  */
@@ -31,10 +34,57 @@ module.exports = (() => {
31
34
  return this._schema;
32
35
  }
33
36
 
37
+ /**
38
+ * Returns the appropriate schema for creating a transaction of the
39
+ * supplied type.
40
+ *
41
+ * @public
42
+ * @static
43
+ * @param {String|TransactionType} transactionType
44
+ * @returns {TransactionSchema|null}
45
+ */
46
+ static forCreate(transactionType) {
47
+ let code;
48
+
49
+ if (transactionType instanceof TransactionType) {
50
+ code = transactionType.code;
51
+ } else {
52
+ code = transactionType;
53
+ }
54
+
55
+ let schema;
56
+
57
+ if (is.string(code)) {
58
+ schema = Enum.fromCode(TransactionSchema, code);
59
+ } else {
60
+ schema = null;
61
+ }
62
+
63
+ return schema;
64
+ }
65
+
66
+ /**
67
+ * The complete transaction schema.
68
+ *
69
+ * @static
70
+ * @public
71
+ * @returns {TransactionSchema}
72
+ */
34
73
  static get COMPLETE() {
35
74
  return complete;
36
75
  }
37
76
 
77
+ /**
78
+ * Transaction data transmitted to the client, omitting some system data.
79
+ *
80
+ * @static
81
+ * @public
82
+ * @returns {TransactionSchema}
83
+ */
84
+ static get CLIENT() {
85
+ return client;
86
+ }
87
+
38
88
  static get BUY() {
39
89
  return buy;
40
90
  }
@@ -112,7 +162,7 @@ module.exports = (() => {
112
162
  }
113
163
  }
114
164
 
115
- const complete = new TransactionSchema(SchemaBuilder.withName('Complete')
165
+ const complete = new TransactionSchema(SchemaBuilder.withName('complete')
116
166
  .withField('portfolio', DataType.STRING)
117
167
  .withField('position', DataType.STRING)
118
168
  .withField('sequence', DataType.NUMBER)
@@ -149,12 +199,51 @@ module.exports = (() => {
149
199
  .withField('charge.amount', DataType.DECIMAL, true)
150
200
  .withField('income.amount', DataType.DECIMAL, true)
151
201
  .withField('valuation.value', DataType.DECIMAL, true)
202
+ .withField('system.sequence', DataType.NUMBER)
203
+ .withField('system.version', DataType.STRING)
204
+ .withField('system.timestamp', DataType.TIMESTAMP)
152
205
  .schema
153
206
  );
154
207
 
155
- const buy = new TransactionSchema(SchemaBuilder.withName('B')
208
+ const client = new TransactionSchema(SchemaBuilder.withName('client')
209
+ .withField('portfolio', DataType.STRING)
210
+ .withField('position', DataType.STRING)
211
+ .withField('sequence', DataType.NUMBER)
212
+ .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
213
+ .withField('date', DataType.DAY)
214
+ .withField('description', DataType.STRING, true)
215
+ .withField('amount', DataType.DECIMAL)
216
+ .withField('quantity', DataType.DECIMAL)
217
+ .withField('fee', DataType.DECIMAL, true)
218
+ .withField('reference.position', DataType.STRING, true)
219
+ .withField('reference.sequence', DataType.NUMBER, true)
220
+ .withField('snapshot.open', DataType.DECIMAL)
221
+ .withField('snapshot.buys', DataType.DECIMAL)
222
+ .withField('snapshot.sells', DataType.DECIMAL)
223
+ .withField('snapshot.gain', DataType.DECIMAL)
224
+ .withField('snapshot.basis', DataType.DECIMAL)
225
+ .withField('snapshot.income', DataType.DECIMAL)
226
+ .withField('snapshot.value', DataType.DECIMAL)
227
+ .withField('trade.price', DataType.DECIMAL, true)
228
+ .withField('dividend.rate', DataType.DECIMAL, true)
229
+ .withField('dividend.effective', DataType.DAY, true)
230
+ .withField('dividend.price', DataType.DECIMAL, true)
231
+ .withField('dividend.amount', DataType.DECIMAL, true)
232
+ .withField('dividend.reference', DataType.STRING, true)
233
+ .withField('split.numerator', DataType.DECIMAL, true)
234
+ .withField('split.denominator', DataType.DECIMAL, true)
235
+ .withField('split.effective', DataType.DAY, true)
236
+ .withField('split.reference', DataType.STRING, true)
237
+ .withField('charge.amount', DataType.DECIMAL, true)
238
+ .withField('income.amount', DataType.DECIMAL, true)
239
+ .withField('valuation.value', DataType.DECIMAL, true)
240
+ .schema
241
+ );
242
+
243
+ const buy = new TransactionSchema(SchemaBuilder.withName(TransactionType.BUY.code)
244
+ .withField('portfolio', DataType.STRING)
245
+ .withField('position', DataType.STRING)
156
246
  .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
157
- .withField('position', DataType.STRING, true)
158
247
  .withField('instrument.name', DataType.STRING, true)
159
248
  .withField('instrument.type', DataType.STRING, true)
160
249
  .withField('instrument.currency', DataType.forEnum(Currency, 'Currency'), true)
@@ -168,10 +257,10 @@ module.exports = (() => {
168
257
  .schema
169
258
  );
170
259
 
171
- const sell = new TransactionSchema(SchemaBuilder.withName('S')
260
+ const sell = new TransactionSchema(SchemaBuilder.withName(TransactionType.SELL.code)
261
+ .withField('portfolio', DataType.STRING)
262
+ .withField('position', DataType.STRING)
172
263
  .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
173
- .withField('position', DataType.STRING, true)
174
- .withField('currency', DataType.forEnum(Currency, 'Currency'))
175
264
  .withField('date', DataType.DAY)
176
265
  .withField('price', DataType.DECIMAL)
177
266
  .withField('quantity', DataType.DECIMAL)
@@ -179,10 +268,10 @@ module.exports = (() => {
179
268
  .schema
180
269
  );
181
270
 
182
- const buyShort = new TransactionSchema(SchemaBuilder.withName('BS')
271
+ const buyShort = new TransactionSchema(SchemaBuilder.withName(TransactionType.BUY_SHORT.code)
272
+ .withField('portfolio', DataType.STRING)
273
+ .withField('position', DataType.STRING)
183
274
  .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
184
- .withField('position', DataType.STRING, true)
185
- .withField('currency', DataType.forEnum(Currency, 'Currency'))
186
275
  .withField('date', DataType.DAY)
187
276
  .withField('price', DataType.DECIMAL)
188
277
  .withField('quantity', DataType.DECIMAL)
@@ -190,10 +279,15 @@ module.exports = (() => {
190
279
  .schema
191
280
  );
192
281
 
193
- const sellShort = new TransactionSchema(SchemaBuilder.withName('SS')
282
+ const sellShort = new TransactionSchema(SchemaBuilder.withName(TransactionType.SELL_SHORT.code)
283
+ .withField('portfolio', DataType.STRING)
284
+ .withField('position', DataType.STRING)
194
285
  .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
195
- .withField('position', DataType.STRING, true)
196
- .withField('currency', DataType.forEnum(Currency, 'Currency'))
286
+ .withField('instrument.name', DataType.STRING, true)
287
+ .withField('instrument.type', DataType.STRING, true)
288
+ .withField('instrument.currency', DataType.forEnum(Currency, 'Currency'), true)
289
+ .withField('instrument.symbol.barchart', DataType.STRING, true)
290
+ .withField('instrument.symbol.display', DataType.STRING, true)
197
291
  .withField('date', DataType.DAY)
198
292
  .withField('price', DataType.DECIMAL)
199
293
  .withField('quantity', DataType.DECIMAL)
@@ -201,10 +295,10 @@ module.exports = (() => {
201
295
  .schema
202
296
  );
203
297
 
204
- const dividend = new TransactionSchema(SchemaBuilder.withName('DV')
298
+ const dividend = new TransactionSchema(SchemaBuilder.withName(TransactionType.DIVIDEND.code)
299
+ .withField('portfolio', DataType.STRING)
300
+ .withField('position', DataType.STRING)
205
301
  .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
206
- .withField('position', DataType.STRING, true)
207
- .withField('currency', DataType.forEnum(Currency, 'Currency'))
208
302
  .withField('date', DataType.DAY)
209
303
  .withField('rate', DataType.DECIMAL)
210
304
  .withField('open', DataType.DECIMAL, true)
@@ -213,10 +307,10 @@ module.exports = (() => {
213
307
  .schema
214
308
  );
215
309
 
216
- const dividendReinvest = new TransactionSchema(SchemaBuilder.withName('DX')
310
+ const dividendReinvest = new TransactionSchema(SchemaBuilder.withName(TransactionType.DIVIDEND_REINVEST.code)
311
+ .withField('portfolio', DataType.STRING)
312
+ .withField('position', DataType.STRING)
217
313
  .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
218
- .withField('position', DataType.STRING, true)
219
- .withField('currency', DataType.forEnum(Currency, 'Currency'))
220
314
  .withField('date', DataType.DAY)
221
315
  .withField('rate', DataType.DECIMAL)
222
316
  .withField('open', DataType.DECIMAL, true)
@@ -226,10 +320,10 @@ module.exports = (() => {
226
320
  .schema
227
321
  );
228
322
 
229
- const dividendStock = new TransactionSchema(SchemaBuilder.withName('DS')
323
+ const dividendStock = new TransactionSchema(SchemaBuilder.withName(TransactionType.DIVIDEND_STOCK.code)
324
+ .withField('portfolio', DataType.STRING)
325
+ .withField('position', DataType.STRING)
230
326
  .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
231
- .withField('position', DataType.STRING, true)
232
- .withField('currency', DataType.forEnum(Currency, 'Currency'))
233
327
  .withField('date', DataType.DAY)
234
328
  .withField('rate', DataType.DECIMAL)
235
329
  .withField('open', DataType.DECIMAL, true)
@@ -239,10 +333,10 @@ module.exports = (() => {
239
333
  .schema
240
334
  );
241
335
 
242
- const distributionCash = new TransactionSchema(SchemaBuilder.withName('DC')
336
+ const distributionCash = new TransactionSchema(SchemaBuilder.withName(TransactionType.DISTRIBUTION_CASH.code)
337
+ .withField('portfolio', DataType.STRING)
338
+ .withField('position', DataType.STRING)
243
339
  .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
244
- .withField('position', DataType.STRING, true)
245
- .withField('currency', DataType.forEnum(Currency, 'Currency'))
246
340
  .withField('date', DataType.DAY)
247
341
  .withField('rate', DataType.DECIMAL)
248
342
  .withField('open', DataType.DECIMAL, true)
@@ -251,10 +345,10 @@ module.exports = (() => {
251
345
  .schema
252
346
  );
253
347
 
254
- const distributionFund = new TransactionSchema(SchemaBuilder.withName('DF')
348
+ const distributionFund = new TransactionSchema(SchemaBuilder.withName(TransactionType.DISTRIBUTION_FUND.code)
349
+ .withField('portfolio', DataType.STRING)
350
+ .withField('position', DataType.STRING)
255
351
  .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
256
- .withField('position', DataType.STRING, true)
257
- .withField('currency', DataType.forEnum(Currency, 'Currency'))
258
352
  .withField('date', DataType.DAY)
259
353
  .withField('rate', DataType.DECIMAL)
260
354
  .withField('open', DataType.DECIMAL, true)
@@ -263,10 +357,10 @@ module.exports = (() => {
263
357
  .schema
264
358
  );
265
359
 
266
- const split = new TransactionSchema(SchemaBuilder.withName('SP')
360
+ const split = new TransactionSchema(SchemaBuilder.withName(TransactionType.SPLIT.code)
361
+ .withField('portfolio', DataType.STRING)
362
+ .withField('position', DataType.STRING)
267
363
  .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
268
- .withField('position', DataType.STRING, true)
269
- .withField('currency', DataType.forEnum(Currency, 'Currency'))
270
364
  .withField('date', DataType.DAY)
271
365
  .withField('numerator', DataType.DECIMAL)
272
366
  .withField('denominator', DataType.DECIMAL)
@@ -275,85 +369,110 @@ module.exports = (() => {
275
369
  .schema
276
370
  );
277
371
 
278
- const fee = new TransactionSchema(SchemaBuilder.withName('F')
372
+ const fee = new TransactionSchema(SchemaBuilder.withName(TransactionType.FEE.code)
373
+ .withField('portfolio', DataType.STRING)
374
+ .withField('position', DataType.STRING)
279
375
  .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
280
- .withField('position', DataType.STRING, true)
281
- .withField('currency', DataType.forEnum(Currency, 'Currency'))
282
376
  .withField('date', DataType.DAY)
283
377
  .withField('fee', DataType.DECIMAL)
284
378
  .schema
285
379
  );
286
380
 
287
- const feeUnits = new TransactionSchema(SchemaBuilder.withName('FU')
381
+ const feeUnits = new TransactionSchema(SchemaBuilder.withName(TransactionType.FEE_UNITS.code)
382
+ .withField('portfolio', DataType.STRING)
383
+ .withField('position', DataType.STRING)
288
384
  .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
289
- .withField('position', DataType.STRING, true)
290
- .withField('currency', DataType.forEnum(Currency, 'Currency'))
291
385
  .withField('date', DataType.DAY)
292
386
  .withField('fee', DataType.DECIMAL)
293
387
  .withField('price', DataType.DECIMAL)
294
388
  .schema
295
389
  );
296
390
 
297
- const deposit = new TransactionSchema(SchemaBuilder.withName('D')
391
+ const deposit = new TransactionSchema(SchemaBuilder.withName(TransactionType.DEPOSIT.code)
392
+ .withField('portfolio', DataType.STRING)
393
+ .withField('position', DataType.STRING)
298
394
  .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
299
- .withField('position', DataType.STRING, true)
300
- .withField('currency', DataType.forEnum(Currency, 'Currency'))
395
+ .withField('instrument.name', DataType.STRING, true)
396
+ .withField('instrument.type', DataType.STRING, true)
397
+ .withField('instrument.currency', DataType.forEnum(Currency, 'Currency'), true)
398
+ .withField('instrument.symbol.barchart', DataType.STRING, true)
399
+ .withField('instrument.symbol.display', DataType.STRING, true)
301
400
  .withField('date', DataType.DAY)
302
401
  .withField('amount', DataType.DECIMAL)
303
402
  .withField('fee', DataType.DECIMAL, true)
304
403
  .schema
305
404
  );
306
405
 
307
- const withdrawal = new TransactionSchema(SchemaBuilder.withName('W')
406
+ const withdrawal = new TransactionSchema(SchemaBuilder.withName(TransactionType.WITHDRAWAL.code)
407
+ .withField('portfolio', DataType.STRING)
408
+ .withField('position', DataType.STRING)
308
409
  .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
309
- .withField('position', DataType.STRING, true)
310
- .withField('currency', DataType.forEnum(Currency, 'Currency'))
311
410
  .withField('date', DataType.DAY)
312
411
  .withField('amount', DataType.DECIMAL)
313
412
  .withField('fee', DataType.DECIMAL, true)
314
413
  .schema
315
414
  );
316
415
 
317
- const debit = new TransactionSchema(SchemaBuilder.withName('DR')
416
+ const debit = new TransactionSchema(SchemaBuilder.withName(TransactionType.DEBIT.code)
417
+ .withField('portfolio', DataType.STRING)
418
+ .withField('position', DataType.STRING)
318
419
  .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
319
- .withField('position', DataType.STRING, true)
320
- .withField('currency', DataType.forEnum(Currency, 'Currency'))
321
420
  .withField('date', DataType.DAY)
322
421
  .withField('amount', DataType.DECIMAL)
323
422
  .withField('fee', DataType.DECIMAL, true)
324
423
  .schema
325
424
  );
326
425
 
327
- const credit = new TransactionSchema(SchemaBuilder.withName('CR')
426
+ const credit = new TransactionSchema(SchemaBuilder.withName(TransactionType.CREDIT.code)
427
+ .withField('portfolio', DataType.STRING)
428
+ .withField('position', DataType.STRING)
328
429
  .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
329
- .withField('position', DataType.STRING, true)
330
- .withField('currency', DataType.forEnum(Currency, 'Currency'))
331
430
  .withField('date', DataType.DAY)
332
431
  .withField('amount', DataType.DECIMAL)
333
432
  .withField('fee', DataType.DECIMAL, true)
334
433
  .schema
335
434
  );
336
435
 
337
- const valuation = new TransactionSchema(SchemaBuilder.withName('V')
436
+ const valuation = new TransactionSchema(SchemaBuilder.withName(TransactionType.VALUATION.code)
437
+ .withField('portfolio', DataType.STRING)
438
+ .withField('position', DataType.STRING)
338
439
  .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
339
- .withField('position', DataType.STRING, true)
340
- .withField('currency', DataType.forEnum(Currency, 'Currency'))
341
440
  .withField('date', DataType.DAY)
342
441
  .withField('value', DataType.DECIMAL)
343
442
  .withField('fee', DataType.DECIMAL, true)
344
443
  .schema
345
444
  );
346
445
 
347
- const income = new TransactionSchema(SchemaBuilder.withName('I')
446
+ const income = new TransactionSchema(SchemaBuilder.withName(TransactionType.INCOME.code)
447
+ .withField('portfolio', DataType.STRING)
448
+ .withField('position', DataType.STRING)
348
449
  .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
349
- .withField('position', DataType.STRING, true)
350
- .withField('currency', DataType.forEnum(Currency, 'Currency'))
351
450
  .withField('date', DataType.DAY)
352
451
  .withField('income', DataType.DECIMAL)
353
452
  .withField('fee', DataType.DECIMAL, true)
354
453
  .schema
355
454
  );
356
455
 
456
+ const map = { };
457
+
458
+ function addSchemaToMap(type, schema) {
459
+ map[type.code] = schema;
460
+ }
461
+
462
+ addSchemaToMap(TransactionType.BUY, buy);
463
+ addSchemaToMap(TransactionType.SELL, sell);
464
+ addSchemaToMap(TransactionType.BUY_SHORT, buyShort);
465
+ addSchemaToMap(TransactionType.SELL_SHORT, sellShort);
466
+ addSchemaToMap(TransactionType.DIVIDEND, dividend);
467
+ addSchemaToMap(TransactionType.DIVIDEND_STOCK, dividendStock);
468
+ addSchemaToMap(TransactionType.DIVIDEND_REINVEST, dividendReinvest);
469
+ addSchemaToMap(TransactionType.SPLIT, split);
470
+ addSchemaToMap(TransactionType.FEE, fee);
471
+ addSchemaToMap(TransactionType.FEE_UNITS, feeUnits);
472
+ addSchemaToMap(TransactionType.DEPOSIT, deposit);
473
+ addSchemaToMap(TransactionType.WITHDRAWAL, withdrawal);
474
+ addSchemaToMap(TransactionType.VALUATION, valuation);
475
+ addSchemaToMap(TransactionType.INCOME, income);
357
476
 
358
477
  return TransactionSchema;
359
478
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.0.23",
3
+ "version": "1.0.27",
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
  *