@barchart/portfolio-api-common 1.3.7 → 1.3.11

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.
@@ -18,58 +18,58 @@ module.exports = (() => {
18
18
  }
19
19
 
20
20
  /**
21
- * If true, the corporate action is fictitious -- used only for internal
22
- * system purposes.
21
+ * A split.
23
22
  *
24
23
  * @public
25
- * @returns {Boolean}
24
+ * @static
25
+ * @returns {CorporateActionType}
26
26
  */
27
- get internal() {
28
- return this._internal;
27
+ static get SPLIT() {
28
+ return split;
29
29
  }
30
30
 
31
31
  /**
32
- * A symbol change.
32
+ * A dividend.
33
33
  *
34
34
  * @public
35
35
  * @static
36
36
  * @returns {CorporateActionType}
37
37
  */
38
- static get SYMBOL_CHANGE() {
39
- return symbolChange;
38
+ static get DIVIDEND() {
39
+ return dividend;
40
40
  }
41
41
 
42
42
  /**
43
- * A name change.
43
+ * A stock dividend.
44
44
  *
45
45
  * @public
46
46
  * @static
47
47
  * @returns {CorporateActionType}
48
48
  */
49
- static get NAME_CHANGE() {
50
- return nameChange;
49
+ static get STOCK_DIVIDEND() {
50
+ return stockDividend;
51
51
  }
52
52
 
53
53
  /**
54
- * A dividend.
54
+ * A symbol change.
55
55
  *
56
56
  * @public
57
57
  * @static
58
58
  * @returns {CorporateActionType}
59
59
  */
60
- static get DIVIDEND() {
61
- return dividend;
60
+ static get SYMBOL_CHANGE() {
61
+ return symbolChange;
62
62
  }
63
63
 
64
64
  /**
65
- * A split.
65
+ * A name change.
66
66
  *
67
67
  * @public
68
68
  * @static
69
69
  * @returns {CorporateActionType}
70
70
  */
71
- static get SPLIT() {
72
- return split;
71
+ static get NAME_CHANGE() {
72
+ return nameChange;
73
73
  }
74
74
 
75
75
  /**
@@ -84,10 +84,11 @@ module.exports = (() => {
84
84
  }
85
85
  }
86
86
 
87
+ const split = new CorporateActionType('SPLIT', 'Split', false);
88
+ const dividend = new CorporateActionType('DIVIDEND', 'Dividend', false);
89
+ const stockDividend = new CorporateActionType('STOCK_DIVIDEND', 'Stock Dividend', false);
87
90
  const symbolChange = new CorporateActionType('SYMBOL_CHANGE', 'Symbol Change', false);
88
91
  const nameChange = new CorporateActionType('NAME_CHANGE', 'Name Change', false);
89
- const dividend = new CorporateActionType('DIVIDEND', 'Dividend', false);
90
- const split = new CorporateActionType('SPLIT', 'Split', false);
91
92
  const delist = new CorporateActionType('DELIST', 'Delist', false);
92
93
 
93
94
  return CorporateActionType;
@@ -236,7 +236,7 @@ module.exports = (() => {
236
236
  *
237
237
  * @public
238
238
  * @static
239
- * @param code
239
+ * @param {Number} code
240
240
  * @returns {InstrumentType}
241
241
  */
242
242
  static fromSymbolType(code) {
@@ -126,6 +126,7 @@ module.exports = (() => {
126
126
  f.code = t.type.code;
127
127
  f.sequence = t.sequence;
128
128
  f.position = t.position;
129
+ f.open = t.snapshot.open;
129
130
  };
130
131
 
131
132
  const averageCostFormatter = (t, f) => {
@@ -151,53 +152,87 @@ module.exports = (() => {
151
152
  };
152
153
 
153
154
  const dividendFormatter = (t, f) => {
154
- f.shares = t.snapshot.open;
155
155
  f.total = t.dividend.amount;
156
156
  f.rate = t.dividend.rate;
157
+
158
+ f.shares = t.dividend.amount.divide(t.dividend.rate);
157
159
  };
158
160
 
159
- const dividendStockFormatter = (t, f) => {
160
- f.boughtSold = t.quantity;
161
- f.fee = t.fee;
161
+ const distributionCashFormatter = (t, f) => {
162
+ f.total = t.dividend.amount;
163
+ f.rate = t.dividend.rate;
162
164
 
163
- if (t.dividend && t.dividend.rate && t.dividend.price) {
164
- f.shares = t.snapshot.open.subtract(t.quantity);
165
- f.price = t.dividend.price;
166
- f.rate = t.dividend.rate;
167
- }
165
+ f.shares = t.dividend.amount.divide(t.dividend.rate);
168
166
  };
169
167
 
170
168
  const dividendReinvestFormatter = (t, f) => {
171
169
  f.boughtSold = t.quantity;
172
- f.shares = t.snapshot.open.subtract(t.quantity);
170
+
171
+ if (f.fee && !f.fee.getIsZero()) {
172
+ f.fee = t.fee;
173
+ }
174
+
173
175
  f.price = t.dividend.price;
174
- f.fee = t.fee;
175
176
  f.rate = t.dividend.rate;
177
+
178
+ f.shares = t.snapshot.open.subtract(t.quantity);
176
179
  };
177
180
 
178
- const distributionCashFormatter = (t, f) => {
179
- f.shares = t.snapshot.open;
180
- f.total = t.dividend.amount;
181
+ const distributionReinvestFormatter = (t, f) => {
182
+ f.boughtSold = t.quantity;
183
+
184
+ if (f.fee && !f.fee.getIsZero()) {
185
+ f.fee = t.fee;
186
+ }
187
+
188
+ f.price = t.dividend.price;
181
189
  f.rate = t.dividend.rate;
190
+
191
+ f.shares = t.snapshot.open.subtract(t.quantity);
182
192
  };
183
193
 
184
- const distributionFundFormatter = (t, f) => {
185
- f.boughtSold =t.quantity;
186
- f.fee = t.fee;
194
+ const dividendStockFormatter = (t, f) => {
195
+ f.boughtSold = t.quantity;
187
196
 
188
- if (t.dividend && t.dividend.rate && t.dividend.price) {
189
- f.shares = t.snapshot.open.subtract(t.quantity);
190
- f.price = t.dividend.price;
191
- f.rate = t.dividend.rate;
197
+ if (f.fee && !f.fee.getIsZero()) {
198
+ f.fee = t.fee;
192
199
  }
200
+
201
+ if (t.dividend) {
202
+ if (t.dividend.numerator && t.dividend.denominator) {
203
+ f.rate = t.dividend.numerator.divide(t.dividend.denominator);
204
+ } else if (t.dividend.rate) {
205
+ f.rate = t.dividend.rate;
206
+ }
207
+
208
+ if (t.dividend.price) {
209
+ f.price = t.dividend.price;
210
+ }
211
+ }
212
+
213
+ f.shares = t.snapshot.open.subtract(t.quantity);
193
214
  };
194
215
 
195
- const distributionReinvestFormatter = (t, f) => {
216
+ const distributionFundFormatter = (t, f) => {
196
217
  f.boughtSold = t.quantity;
218
+
219
+ if (f.fee && !f.fee.getIsZero()) {
220
+ f.fee = t.fee;
221
+ }
222
+
223
+ if (t.dividend) {
224
+ if (t.dividend.numerator && t.dividend.denominator) {
225
+ f.rate = t.dividend.numerator.divide(t.dividend.denominator);
226
+ } else if (t.dividend.rate) {
227
+ f.rate = t.dividend.rate;
228
+ }
229
+
230
+ if (t.dividend.price) {
231
+ f.price = t.dividend.price;
232
+ }
233
+ }
234
+
197
235
  f.shares = t.snapshot.open.subtract(t.quantity);
198
- f.price = t.dividend.price;
199
- f.fee = t.fee;
200
- f.rate = t.dividend.rate;
201
236
  };
202
237
 
203
238
  const incomeFormatter = (t, f) => {
@@ -214,8 +249,9 @@ module.exports = (() => {
214
249
  };
215
250
 
216
251
  const splitFormatter = (t, f) => {
217
- f.shares = t.quantity;
218
252
  f.rate = t.split.numerator.divide(t.split.denominator);
253
+
254
+ f.shares = t.snapshot.open.subtract(t.quantity);
219
255
  };
220
256
 
221
257
  const valuationFormatter = (t, f) => {
@@ -41,8 +41,8 @@ module.exports = (() => {
41
41
  * @public
42
42
  * @param {PositionTreeDefinition[]} definitions
43
43
  * @param {Object[]} portfolios - The portfolios.
44
- * @param {Object[]} positions - The positions (for all of the portfolios).
45
- * @param {Object[]} summaries - The positions summaries (for all of the positions).
44
+ * @param {Object[]} positions - The positions (for all of portfolios).
45
+ * @param {Object[]} summaries - The positions summaries (for all of positions).
46
46
  * @param {PositionSummaryFrame=} reportFrame - If specified, locks the current (and previous) periods to a specific frame, use for reporting.
47
47
  * @param {Day=} reportDate - The end date for the report frame.
48
48
  */
@@ -933,7 +933,6 @@ module.exports = (() => {
933
933
  });
934
934
  }
935
935
 
936
-
937
936
  function updateEmptyPortfolioGroups(portfolio) {
938
937
  Object.keys(this._trees).forEach((key) => {
939
938
  this._trees[key].walk((group) => {
@@ -74,7 +74,7 @@ module.exports = (() => {
74
74
  }
75
75
 
76
76
  /**
77
- * A function, when given a {@link PositionItem} returns a string that is used
77
+ * A function, when given a {@link PositionItem}, returns a string that is used
78
78
  * to group {@link PositionItem} instances into different groups.
79
79
  *
80
80
  * @public
@@ -85,7 +85,7 @@ module.exports = (() => {
85
85
  }
86
86
 
87
87
  /**
88
- * A function, when given a {@link PositionItem} returns a string used to describe the
88
+ * A function, when given a {@link PositionItem}, returns a string used to describe the
89
89
  * group.
90
90
  *
91
91
  * @public
@@ -96,7 +96,7 @@ module.exports = (() => {
96
96
  }
97
97
 
98
98
  /**
99
- * A function, when given a {@link PositionItem} returns the {@link Currency} used to
99
+ * A function, when given a {@link PositionItem}, returns the {@link Currency} used to
100
100
  * display values for the group.
101
101
  *
102
102
  * @public
@@ -111,7 +111,7 @@ module.exports = (() => {
111
111
  * groups.
112
112
  *
113
113
  * @public
114
- * @returns {Array<String>}
114
+ * @returns {String[]}
115
115
  */
116
116
  get requiredGroups() {
117
117
  return this._requiredGroups;
@@ -3,19 +3,49 @@ const Enum = require('@barchart/common-js/lang/Enum');
3
3
  module.exports = (() => {
4
4
  'use strict';
5
5
 
6
+ /**
7
+ * Describes the contents of a grouping level within a tree of positions.
8
+ * This is an attribute of a {@link PositionLevelDefinition}.
9
+ *
10
+ * @public
11
+ * @extends {Enum}
12
+ */
6
13
  class PositionLevelType extends Enum {
7
14
  constructor(code) {
8
15
  super(code, code);
9
16
  }
10
17
 
18
+ /**
19
+ * A level of grouping that represents an entire portfolio's contents.
20
+ *
21
+ * @public
22
+ * @static
23
+ * @returns {PositionLevelType}
24
+ */
11
25
  static get PORTFOLIO() {
12
26
  return portfolio;
13
27
  }
14
28
 
29
+ /**
30
+ * A level of grouping that represents a single positions (i.e. guaranteed to
31
+ * be a leaf node in a grouping tree).
32
+ *
33
+ * @public
34
+ * @static
35
+ * @return {PositionLevelType}
36
+ */
15
37
  static get POSITION() {
16
38
  return position;
17
39
  }
18
40
 
41
+ /**
42
+ * A level of grouping that is neither a portfolio or a position. This could be an
43
+ * intermediate level of grouping (e.g. an asset class within a portfolio).
44
+ *
45
+ * @public
46
+ * @static
47
+ * @return {PositionLevelType}
48
+ */
19
49
  static get OTHER() {
20
50
  return other;
21
51
  }
@@ -11,7 +11,7 @@ module.exports = (() => {
11
11
  * @public
12
12
  * @param {String} name
13
13
  * @param {PositionLevelDefinition[]} definitions
14
- * @oaram {String[]=} exclusionDependencies
14
+ * @param {String[]=} exclusionDependencies
15
15
  */
16
16
  class PositionTreeDefinitions {
17
17
  constructor(name, definitions, exclusionDependencies) {
@@ -44,7 +44,7 @@ module.exports = (() => {
44
44
  * bottom-most level of the tree (i.e. leaf nodes).
45
45
  *
46
46
  * @public
47
- * @returns {PositionLevelDefinitions>[]}
47
+ * @returns {PositionLevelDefinitions[]}
48
48
  */
49
49
  get definitions() {
50
50
  return this._definitions;
@@ -0,0 +1,148 @@
1
+ const assert = require('@barchart/common-js/lang/assert'),
2
+ Enum = require('@barchart/common-js/lang/Enum');
3
+
4
+ module.exports = (() => {
5
+ 'use strict';
6
+
7
+ /**
8
+ * Types of websocket response actions.
9
+ *
10
+ * @public
11
+ * @extends {Enum}
12
+ * @param {String} code
13
+ * @param {String} description
14
+ * @param {String} action
15
+ */
16
+ class WebsocketActionType extends Enum {
17
+ constructor(code, description, action) {
18
+ super(code, description);
19
+
20
+ assert.argumentIsRequired(action, 'action', String);
21
+
22
+ this._action = action;
23
+ }
24
+
25
+ /**
26
+ * An action of websocket response
27
+ *
28
+ * @public
29
+ * @returns {String}
30
+ */
31
+ get action() {
32
+ return this._action;
33
+ }
34
+
35
+ /**
36
+ * Action type for creating new portfolio.
37
+ *
38
+ * @public
39
+ * @static
40
+ * @returns {WebsocketActionType}
41
+ */
42
+ static get PORTFOLIO_CREATE() {
43
+ return portfolioCreate;
44
+ }
45
+
46
+ /**
47
+ * Action type for deleting portfolio.
48
+ *
49
+ * @public
50
+ * @static
51
+ * @returns {WebsocketActionType}
52
+ */
53
+ static get PORTFOLIO_DELETE() {
54
+ return portfolioDelete;
55
+ }
56
+
57
+ /**
58
+ * Action type for updating new portfolio.
59
+ *
60
+ * @public
61
+ * @static
62
+ * @returns {WebsocketActionType}
63
+ */
64
+ static get PORTFOLIO_UPDATE() {
65
+ return portfolioUpdate;
66
+ }
67
+
68
+ /**
69
+ * Action type for creating new transaction.
70
+ *
71
+ * @public
72
+ * @static
73
+ * @returns {WebsocketActionType}
74
+ */
75
+ static get TRANSACTION_CREATE() {
76
+ return transactionCreate;
77
+ }
78
+
79
+ /**
80
+ * Action type for deleting transaction.
81
+ *
82
+ * @public
83
+ * @static
84
+ * @returns {WebsocketActionType}
85
+ */
86
+ static get TRANSACTION_DELETE() {
87
+ return transactionDelete;
88
+ }
89
+
90
+ /**
91
+ * Action type for editing transaction.
92
+ *
93
+ * @public
94
+ * @static
95
+ * @returns {WebsocketActionType}
96
+ */
97
+ static get TRANSACTION_EDIT() {
98
+ return transactionEdit;
99
+ }
100
+
101
+ /**
102
+ * Action type for batching transaction.
103
+ *
104
+ * @public
105
+ * @static
106
+ * @returns {WebsocketActionType}
107
+ */
108
+ static get TRANSACTION_BATCH() {
109
+ return transactionBatch;
110
+ }
111
+
112
+ /**
113
+ * Action type for deleting position.
114
+ *
115
+ * @public
116
+ * @static
117
+ * @returns {WebsocketActionType}
118
+ */
119
+ static get POSITION_DELETE() {
120
+ return positionDelete;
121
+ }
122
+
123
+ /**
124
+ * Action type for updating position.
125
+ *
126
+ * @public
127
+ * @static
128
+ * @returns {WebsocketActionType}
129
+ */
130
+ static get POSITION_UPDATE() {
131
+ return positionUpdate;
132
+ }
133
+ }
134
+
135
+ const portfolioCreate = new WebsocketActionType('PORTFOLIO_CREATE', 'Create portfolio action', 'portfolio/create');
136
+ const portfolioDelete = new WebsocketActionType('PORTFOLIO_DELETE', 'Delete portfolio action', 'portfolio/delete');
137
+ const portfolioUpdate = new WebsocketActionType('PORTFOLIO_UPDATE', 'Update portfolio action', 'portfolio/update');
138
+
139
+ const transactionCreate = new WebsocketActionType('TRANSACTION_CREATE', 'Create transaction action', 'transaction/create');
140
+ const transactionDelete = new WebsocketActionType('TRANSACTION_DELETE', 'Delete transaction action', 'transaction/delete');
141
+ const transactionEdit = new WebsocketActionType('TRANSACTION_EDIT', 'Edit transaction action', 'transaction/edit');
142
+ const transactionBatch = new WebsocketActionType('TRANSACTION_BATCH', 'Batch transaction action', 'transaction/batch');
143
+
144
+ const positionDelete = new WebsocketActionType('POSITION_DELETE', 'Delete position action', 'position/delete');
145
+ const positionUpdate = new WebsocketActionType('POSITION_UPDATE', 'Update position action', 'position/update');
146
+
147
+ return WebsocketActionType;
148
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.3.7",
3
+ "version": "1.3.11",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",