@barchart/portfolio-api-common 1.2.9 → 1.2.13

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.
@@ -235,6 +235,17 @@ module.exports = (() => {
235
235
  return distributionFund;
236
236
  }
237
237
 
238
+ /**
239
+ * A mutual fund distribution in cash, reinvested.
240
+ *
241
+ * @public
242
+ * @static
243
+ * @returns {TransactionType}
244
+ */
245
+ static get DISTRIBUTION_REINVEST() {
246
+ return distributionReinvest;
247
+ }
248
+
238
249
  /**
239
250
  * A split.
240
251
  *
@@ -351,6 +362,7 @@ module.exports = (() => {
351
362
  const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', false, false, false, false, true, false, false);
352
363
 
353
364
  const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', false, false, true, false, false, false, true);
365
+ const distributionReinvest = new TransactionType('DY', 'Distribution (Reinvested)', 'Distribution Reinvest', false, false, false, true, false, false, true);
354
366
  const distributionFund = new TransactionType('DF', 'Distribution (Units)', 'Unit Distribution', false, false, false, true, false, false, true);
355
367
 
356
368
  const deposit = new TransactionType('D', 'Deposit', 'Deposit', false, false, false, false, false, false, false);
@@ -73,6 +73,28 @@ module.exports = (() => {
73
73
  return valid.map(d => d.type);
74
74
  }
75
75
 
76
+ /**
77
+ * Returns transaction types which can be initiated by the user, regardless
78
+ * of instrument type.
79
+ *
80
+ * @public
81
+ * @static
82
+ * @return {Array.<TransactionType>}
83
+ */
84
+ static getUserInitiatedTransactionTypes() {
85
+ return array.unique(Object.keys(validTransactionTypes).reduce((types, key) => {
86
+ const instrumentTypes = validTransactionTypes[key];
87
+
88
+ instrumentTypes.forEach((data) => {
89
+ if (data.user) {
90
+ types.push(data.type);
91
+ }
92
+ });
93
+
94
+ return types;
95
+ }, [ ]));
96
+ }
97
+
76
98
  /**
77
99
  * Checks to see if an transaction type is applicable to an instrument type.
78
100
  *
@@ -155,6 +177,7 @@ module.exports = (() => {
155
177
  associateTypes(InstrumentType.FUND, TransactionType.FEE, true, [ PositionDirection.LONG ]);
156
178
  associateTypes(InstrumentType.FUND, TransactionType.FEE_UNITS, false);
157
179
  associateTypes(InstrumentType.FUND, TransactionType.DISTRIBUTION_CASH, false);
180
+ associateTypes(InstrumentType.FUND, TransactionType.DISTRIBUTION_REINVEST, false);
158
181
  associateTypes(InstrumentType.FUND, TransactionType.DISTRIBUTION_FUND, false);
159
182
 
160
183
  associateTypes(InstrumentType.OTHER, TransactionType.BUY, true, [ PositionDirection.LONG, PositionDirection.EVEN ]);
@@ -125,16 +125,25 @@ module.exports = (() => {
125
125
  });
126
126
 
127
127
  formatters.set(TransactionType.DIVIDEND_STOCK, (t) => {
128
- const shares = t.snapshot.open.subtract(t.quantity);
129
128
  const rate = (is.object(t.dividend) && is.string(t.dividend.rate)) || '';
130
129
 
131
130
  return {
132
131
  boughtSold: t.quantity,
133
- shares: shares,
132
+ shares: t.snapshot.open.subtract(t.quantity),
134
133
  rate: rate
135
134
  };
136
135
  });
137
136
 
137
+ formatters.set(TransactionType.DIVIDEND_REINVEST, (t) => {
138
+ return {
139
+ boughtSold: t.quantity,
140
+ shares: t.snapshot.open.subtract(t.quantity),
141
+ price: t.dividend.price,
142
+ fee: t.fee,
143
+ rate: t.dividend.rate
144
+ };
145
+ });
146
+
138
147
  formatters.set(TransactionType.DISTRIBUTION_CASH, (t) => {
139
148
  return {
140
149
  shares: t.snapshot.open,
@@ -143,20 +152,20 @@ module.exports = (() => {
143
152
  };
144
153
  });
145
154
 
146
- formatters.set(TransactionType.DIVIDEND_REINVEST, (t) => {
155
+ formatters.set(TransactionType.DISTRIBUTION_FUND, (t) => {
147
156
  return {
148
157
  shares: t.snapshot.open.subtract(t.quantity),
149
- price: t.dividend.price,
150
- fee: t.fee,
151
- total: t.quantity,
152
- rate: t.dividend.rate
158
+ fee: t.fee
153
159
  };
154
160
  });
155
161
 
156
- formatters.set(TransactionType.DISTRIBUTION_FUND, (t) => {
162
+ formatters.set(TransactionType.DISTRIBUTION_REINVEST, (t) => {
157
163
  return {
164
+ boughtSold: t.quantity,
158
165
  shares: t.snapshot.open.subtract(t.quantity),
159
- fee: t.fee
166
+ price: t.dividend.price,
167
+ fee: t.fee,
168
+ rate: t.dividend.rate
160
169
  };
161
170
  });
162
171
 
@@ -201,6 +201,7 @@ module.exports = (() => {
201
201
  .withField('split.reference', DataType.STRING, true)
202
202
  .withField('charge.amount', DataType.DECIMAL, true)
203
203
  .withField('income.amount', DataType.DECIMAL, true)
204
+ .withField('valuation.rate', DataType.DECIMAL, true)
204
205
  .withField('valuation.value', DataType.DECIMAL, true)
205
206
  .withField('system.sequence', DataType.NUMBER)
206
207
  .withField('system.version', DataType.STRING)
@@ -239,6 +240,7 @@ module.exports = (() => {
239
240
  .withField('split.reference', DataType.STRING, true)
240
241
  .withField('charge.amount', DataType.DECIMAL, true)
241
242
  .withField('income.amount', DataType.DECIMAL, true)
243
+ .withField('valuation.rate', DataType.DECIMAL, true)
242
244
  .withField('valuation.value', DataType.DECIMAL, true)
243
245
  .schema
244
246
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.2.9",
3
+ "version": "1.2.13",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -845,6 +845,17 @@ module.exports = (() => {
845
845
  return distributionFund;
846
846
  }
847
847
 
848
+ /**
849
+ * A mutual fund distribution in cash, reinvested.
850
+ *
851
+ * @public
852
+ * @static
853
+ * @returns {TransactionType}
854
+ */
855
+ static get DISTRIBUTION_REINVEST() {
856
+ return distributionReinvest;
857
+ }
858
+
848
859
  /**
849
860
  * A split.
850
861
  *
@@ -961,6 +972,7 @@ module.exports = (() => {
961
972
  const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', false, false, false, false, true, false, false);
962
973
 
963
974
  const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', false, false, true, false, false, false, true);
975
+ const distributionReinvest = new TransactionType('DY', 'Distribution (Reinvested)', 'Distribution Reinvest', false, false, false, true, false, false, true);
964
976
  const distributionFund = new TransactionType('DF', 'Distribution (Units)', 'Unit Distribution', false, false, false, true, false, false, true);
965
977
 
966
978
  const deposit = new TransactionType('D', 'Deposit', 'Deposit', false, false, false, false, false, false, false);
@@ -1050,6 +1062,28 @@ module.exports = (() => {
1050
1062
  return valid.map(d => d.type);
1051
1063
  }
1052
1064
 
1065
+ /**
1066
+ * Returns transaction types which can be initiated by the user, regardless
1067
+ * of instrument type.
1068
+ *
1069
+ * @public
1070
+ * @static
1071
+ * @return {Array.<TransactionType>}
1072
+ */
1073
+ static getUserInitiatedTransactionTypes() {
1074
+ return array.unique(Object.keys(validTransactionTypes).reduce((types, key) => {
1075
+ const instrumentTypes = validTransactionTypes[key];
1076
+
1077
+ instrumentTypes.forEach((data) => {
1078
+ if (data.user) {
1079
+ types.push(data.type);
1080
+ }
1081
+ });
1082
+
1083
+ return types;
1084
+ }, [ ]));
1085
+ }
1086
+
1053
1087
  /**
1054
1088
  * Checks to see if an transaction type is applicable to an instrument type.
1055
1089
  *
@@ -1132,6 +1166,7 @@ module.exports = (() => {
1132
1166
  associateTypes(InstrumentType.FUND, TransactionType.FEE, true, [ PositionDirection.LONG ]);
1133
1167
  associateTypes(InstrumentType.FUND, TransactionType.FEE_UNITS, false);
1134
1168
  associateTypes(InstrumentType.FUND, TransactionType.DISTRIBUTION_CASH, false);
1169
+ associateTypes(InstrumentType.FUND, TransactionType.DISTRIBUTION_REINVEST, false);
1135
1170
  associateTypes(InstrumentType.FUND, TransactionType.DISTRIBUTION_FUND, false);
1136
1171
 
1137
1172
  associateTypes(InstrumentType.OTHER, TransactionType.BUY, true, [ PositionDirection.LONG, PositionDirection.EVEN ]);
@@ -9213,6 +9248,20 @@ describe('When validating transaction order', () => {
9213
9248
  });
9214
9249
  });
9215
9250
 
9251
+ describe('When requesting all the user-initiated transaction types', () => {
9252
+ 'use strict';
9253
+
9254
+ let userInitiated;
9255
+
9256
+ beforeEach(() => {
9257
+ userInitiated = TransactionValidator.getUserInitiatedTransactionTypes();
9258
+ });
9259
+
9260
+ it('Only nine types should be returned', () => {
9261
+ expect(userInitiated.length).toEqual(9);
9262
+ });
9263
+ });
9264
+
9216
9265
  },{"./../../../lib/data/TransactionValidator":5,"@barchart/common-js/lang/Day":18}],37:[function(require,module,exports){
9217
9266
  const Currency = require('@barchart/common-js/lang/Currency'),
9218
9267
  Decimal = require('@barchart/common-js/lang/Decimal');
@@ -41,3 +41,17 @@ describe('When validating transaction order', () => {
41
41
  expect(TransactionValidator.validateOrder([ build(1, '2018-05-02'), build(2, '2018-05-01'), build(3, '2018-04-30') ])).toEqual(false);
42
42
  });
43
43
  });
44
+
45
+ describe('When requesting all the user-initiated transaction types', () => {
46
+ 'use strict';
47
+
48
+ let userInitiated;
49
+
50
+ beforeEach(() => {
51
+ userInitiated = TransactionValidator.getUserInitiatedTransactionTypes();
52
+ });
53
+
54
+ it('Only nine types should be returned', () => {
55
+ expect(userInitiated.length).toEqual(9);
56
+ });
57
+ });