@barchart/portfolio-api-common 1.0.130 → 1.0.131

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.
@@ -22,11 +22,11 @@ module.exports = (() => {
22
22
 
23
23
  /**
24
24
  * A container for positions which groups the positions into one or more
25
- * trees for aggregation and display purposes. For example, perhaps a positions
26
- * grouped first by asset class then by position is desired.
25
+ * trees for aggregation and display purposes. For example, positions could be
26
+ * grouped first by asset class then by position.
27
27
  *
28
28
  * Furthermore, the container performs aggregation (driven primarily by price
29
- * changes) for each level of grouping in the internal tree(s).
29
+ * changes) for each level of grouping.
30
30
  *
31
31
  * @public
32
32
  * @param {Array.<PositionTreeDefinition>} definitions
@@ -219,10 +219,14 @@ module.exports = (() => {
219
219
  }, { });
220
220
  }
221
221
 
222
- get defaultCurrency() {
223
- return this._defaultCurrency;
224
- }
225
-
222
+ /**
223
+ * Returns a distinct list of all symbols used by the positions
224
+ * within the container.
225
+ *
226
+ * @public
227
+ * @param {Boolean} display - If true, all "display" symbols are returned; otherwise Barchart symbols are returned.
228
+ * @returns {Array.<String>}
229
+ */
226
230
  getPositionSymbols(display) {
227
231
  const symbols = this._items.reduce((symbols, item) => {
228
232
  const position = item.position;
@@ -245,6 +249,14 @@ module.exports = (() => {
245
249
  return array.unique(symbols);
246
250
  }
247
251
 
252
+ /**
253
+ * Updates the quote for a single symbol; causing updates to any grouping
254
+ * level that contains the position(s) for the symbol.
255
+ *
256
+ * @public
257
+ * @param {String} symbol
258
+ * @param {Object} quote
259
+ */
248
260
  setPositionQuote(symbol, quote) {
249
261
  assert.argumentIsRequired(symbol, 'symbol', String);
250
262
  assert.argumentIsRequired(quote, 'quote', Object);
@@ -254,14 +266,34 @@ module.exports = (() => {
254
266
  }
255
267
  }
256
268
 
269
+ /**
270
+ * Returns all forex symbols that are required to do currency translations.
271
+ *
272
+ * @public
273
+ * @returns {Array.<String>}
274
+ */
257
275
  getForexSymbols() {
258
276
  return this._forexSymbols;
259
277
  }
260
278
 
279
+ /**
280
+ * Returns all current forex quotes.
281
+ *
282
+ * @public
283
+ * @returns {Array.<Object>}
284
+ */
261
285
  getForexQuotes() {
262
286
  return this._forexQuotes;
263
287
  }
264
288
 
289
+ /**
290
+ * Updates the forex quote for a single currency pair; causing updates to
291
+ * any grouping level that contains that requires translation.
292
+ *
293
+ * @public
294
+ * @param {String} symbol
295
+ * @param {Object} quote
296
+ */
265
297
  setForexQuote(symbol, quote) {
266
298
  assert.argumentIsRequired(symbol, 'symbol', String);
267
299
  assert.argumentIsRequired(quote, 'quote', Object);
@@ -279,10 +311,24 @@ module.exports = (() => {
279
311
  Object.keys(this._trees).forEach(key => this._trees[key].walk(group => group.setForexRate(rate), true, false));
280
312
  }
281
313
 
282
- setPositionFundamentals(symbol, data) {
314
+ /**
315
+ * Updates fundamental data for a single symbol.
316
+ *
317
+ * @public
318
+ * @param {String} symbol
319
+ * @param {Object} data
320
+ */
321
+ setPositionFundamentalData(symbol, data) {
283
322
  return;
284
323
  }
285
324
 
325
+ /**
326
+ * Indicates if a news article exists for a symbol.
327
+ *
328
+ * @public
329
+ * @param {String} symbol
330
+ * @param {Boolean} exists
331
+ */
286
332
  setNewsArticleExists(symbol, exists) {
287
333
  assert.argumentIsRequired(symbol, 'symbol', String);
288
334
  assert.argumentIsRequired(exists, 'exists', Boolean);
@@ -292,6 +338,13 @@ module.exports = (() => {
292
338
  }
293
339
  }
294
340
 
341
+ /**
342
+ * Returns a single level of grouping from one of the internal trees.
343
+ *
344
+ * @param {String} name
345
+ * @param {Array.<String> keys
346
+ * @returns {PositionGroup}
347
+ */
295
348
  getGroup(name, keys) {
296
349
  assert.argumentIsRequired(name, 'name', String);
297
350
  assert.argumentIsArray(keys, 'keys', Number);
@@ -299,6 +352,14 @@ module.exports = (() => {
299
352
  return findNode(this._trees[name], keys).getValue();
300
353
  }
301
354
 
355
+ /**
356
+ * Returns all child groups from a level of grouping within one of
357
+ * the internal trees.
358
+ *
359
+ * @param {String} name
360
+ * @param {Array.<String> keys
361
+ * @returns {Array.<PositionGroup>}
362
+ */
302
363
  getGroups(name, keys) {
303
364
  assert.argumentIsRequired(name, 'name', String);
304
365
  assert.argumentIsArray(keys, 'keys', Number);
@@ -310,8 +371,6 @@ module.exports = (() => {
310
371
  assert.argumentIsRequired(name, 'name', String);
311
372
  assert.argumentIsRequired(executor, 'executor', Function);
312
373
 
313
- assert.argumentIsRequired(executor, 'executor', Function);
314
-
315
374
  this._trees[name].walk(group => group.setSuspended(true), false, false);
316
375
 
317
376
  executor(this);
@@ -10,7 +10,17 @@ module.exports = (() => {
10
10
  'use strict';
11
11
 
12
12
  /**
13
+ * A grouping of {@link PositionItem} instances. The group aggregates from across
14
+ * all the positions and performs currency translation, as necessary.
15
+ *
13
16
  * @public
17
+ * @param {PositionContainer} container
18
+ * @param {PositionGroup|null} parent
19
+ * @param {Array.<PositionItem>} items
20
+ * @param {Currency} currency
21
+ * @param {String} key
22
+ * @param {String} description
23
+ * @param {Boolean=} single
14
24
  */
15
25
  class PositionGroup {
16
26
  constructor(container, parent, items, currency, key, description, single) {
@@ -135,30 +145,73 @@ module.exports = (() => {
135
145
  this.refresh();
136
146
  }
137
147
 
148
+ /**
149
+ * The key of the group.
150
+ *
151
+ * @public
152
+ * @returns {String}
153
+ */
138
154
  get key() {
139
155
  return this._key;
140
156
  }
141
157
 
158
+ /**
159
+ * The description of the group.
160
+ *
161
+ * @public
162
+ * @returns {String}
163
+ */
142
164
  get description() {
143
165
  return this._description;
144
166
  }
145
167
 
168
+ /**
169
+ * The {@link Currency} which all aggregated data is presented in.
170
+ *
171
+ * @public
172
+ * @returns {Currency}
173
+ */
146
174
  get currency() {
147
175
  return this._currency;
148
176
  }
149
177
 
178
+ /**
179
+ * The {@link PositionItem} instances which for which aggregated data is compiled.
180
+ *
181
+ * @public
182
+ * @returns {Currency}
183
+ */
150
184
  get items() {
151
185
  return this._items;
152
186
  }
153
187
 
188
+ /**
189
+ * The string-based, human-readable aggregated data for the group.
190
+ *
191
+ * @public
192
+ * @returns {Object}
193
+ */
154
194
  get data() {
155
195
  return this._dataFormat;
156
196
  }
157
197
 
198
+ /**
199
+ * The raw aggregated data for the group (typically {@link Decimal} instances).
200
+ *
201
+ * @public
202
+ * @returns {Object}
203
+ */
158
204
  get actual() {
159
205
  return this._dataActual;
160
206
  }
161
207
 
208
+ /**
209
+ * Indicates if the group will only contain one {@link PositionItem} -- that is,
210
+ * indicates if the group represents a single position.
211
+ *
212
+ * @public
213
+ * @returns {Boolean}
214
+ */
162
215
  get single() {
163
216
  return this._single;
164
217
  }
@@ -167,10 +220,22 @@ module.exports = (() => {
167
220
  return this._suspended;
168
221
  }
169
222
 
223
+ /**
224
+ * Indicates if the group should be excluded from higher-level aggregations.
225
+ *
226
+ * @public
227
+ * @returns {Boolean}
228
+ */
170
229
  get excluded() {
171
230
  return this._excluded;
172
231
  }
173
232
 
233
+ /**
234
+ * Causes aggregated data to be recalculated using a new exchange rate.
235
+ *
236
+ * @public
237
+ * @param {Rate} rate
238
+ */
174
239
  setForexRate(rate) {
175
240
  if (!this._bypassCurrencyTranslation) {
176
241
  this.refresh();
@@ -199,6 +264,11 @@ module.exports = (() => {
199
264
  }
200
265
  }
201
266
 
267
+ /**
268
+ * Causes all aggregated data to be recalculated.
269
+ *
270
+ * @public
271
+ */
202
272
  refresh() {
203
273
  const rates = this._container.getForexQuotes();
204
274
 
@@ -206,6 +276,12 @@ module.exports = (() => {
206
276
  calculatePriceData(this, rates, null, true);
207
277
  }
208
278
 
279
+ /**
280
+ * Causes the percent of the position, with respect to the parent container's
281
+ * total, to be recalculated.
282
+ *
283
+ * @public
284
+ */
209
285
  refreshMarketPercent() {
210
286
  calculateMarketPercent(this, this._container.getForexQuotes(), true);
211
287
  }
@@ -11,7 +11,15 @@ module.exports = (() => {
11
11
  'use strict';
12
12
 
13
13
  /**
14
+ * A container for a single position, which handles quote changes and
15
+ * notifies observers -- which are typically parent-level {@link PositionGroup}
16
+ * instances.
17
+ *
14
18
  * @public
19
+ * @param {Object} portfolio
20
+ * @param {Object} position
21
+ * @param {Object} currentSummary
22
+ * @param {Array.<Object>} previousSummaries
15
23
  */
16
24
  class PositionItem {
17
25
  constructor(portfolio, position, currentSummary, previousSummaries) {
@@ -27,10 +35,12 @@ module.exports = (() => {
27
35
  this._data.basis = null;
28
36
 
29
37
  this._currentQuote = null;
30
- this._previousQuote = null;
38
+
39
+ this._currentPrice = null;
40
+ this._previousPrice = null;
31
41
 
32
42
  this._data.currentPrice = null;
33
- this._data.previousPrice = null;
43
+ this._data.currentPricePrevious = null;
34
44
 
35
45
  this._data.market = null;
36
46
  this._data.marketChange = null;
@@ -62,30 +72,72 @@ module.exports = (() => {
62
72
  this._newsExistsChangedEvent = new Event(this);
63
73
  }
64
74
 
75
+ /**
76
+ * The portfolio of the encapsulated position.
77
+ *
78
+ * @public
79
+ * @returns {Object}
80
+ */
65
81
  get portfolio() {
66
82
  return this._portfolio;
67
83
  }
68
84
 
85
+ /**
86
+ * The encapsulated position.
87
+ *
88
+ * @public
89
+ * @returns {Object}
90
+ */
69
91
  get position() {
70
92
  return this._position;
71
93
  }
72
94
 
95
+ /**
96
+ * The {@link Currency} of the encapsulated position.
97
+ *
98
+ * @public
99
+ * @returns {Object}
100
+ */
73
101
  get currency() {
74
102
  return this._currency;
75
103
  }
76
104
 
105
+ /**
106
+ * The year-to-date position summary of the encapsulated position.
107
+ *
108
+ * @public
109
+ * @returns {Object}
110
+ */
77
111
  get currentSummary() {
78
112
  return this._currentSummary;
79
113
  }
80
-
114
+
115
+ /**
116
+ * Previous year's summaries for the encapsulated position.
117
+ *
118
+ * @public
119
+ * @returns {Object}
120
+ */
81
121
  get previousSummaries() {
82
122
  return this._previousSummaries;
83
123
  }
84
124
 
125
+ /**
126
+ * Various data regarding the encapsulated position.
127
+ *
128
+ * @public
129
+ * @returns {*}
130
+ */
85
131
  get data() {
86
132
  return this._data;
87
133
  }
88
134
 
135
+ /**
136
+ * The current quote for the symbol of the encapsulated position.
137
+ *
138
+ * @public
139
+ * @returns {null|{Object}}
140
+ */
89
141
  get quote() {
90
142
  return this._currentQuote;
91
143
  }
@@ -94,13 +146,22 @@ module.exports = (() => {
94
146
  return this._excluded;
95
147
  }
96
148
 
149
+ /**
150
+ * Sets the current quote -- causing position-level data (e.g. market value) to
151
+ * be recalculated.
152
+ *
153
+ * @public
154
+ * @param {Object} quote
155
+ */
97
156
  setQuote(quote) {
98
157
  assert.argumentIsRequired(quote, 'quote', Object);
99
158
 
100
- if (this._previousQuote === null || this._previousQuote.lastPrice !== quote.lastPrice) {
159
+ if (this._currentPricePrevious !== quote.lastPrice) {
101
160
  calculatePriceData(this, quote.lastPrice);
102
161
 
103
- this._previousQuote = this._currentQuote;
162
+ this._currentPricePrevious = this._currentPrice;
163
+ this._currentPrice = quote.lastPrice;
164
+
104
165
  this._currentQuote = quote;
105
166
 
106
167
  this._quoteChangedEvent.fire(this._currentQuote);
@@ -115,6 +176,13 @@ module.exports = (() => {
115
176
  }
116
177
  }
117
178
 
179
+ /**
180
+ * Sets a flag which indicates if news article(s) exist for the encapsulated position's
181
+ * symbol.
182
+ *
183
+ * @public
184
+ * @param {Boolean} value
185
+ */
118
186
  setNewsArticleExists(value) {
119
187
  assert.argumentIsRequired(value, 'value', Boolean);
120
188
 
@@ -123,6 +191,13 @@ module.exports = (() => {
123
191
  }
124
192
  }
125
193
 
194
+ /**
195
+ * Registers an observer for quote changes, which is fired after internal recalculations
196
+ * of position data are complete.
197
+ *
198
+ * @public
199
+ * @param {Function} handler
200
+ */
126
201
  registerQuoteChangeHandler(handler) {
127
202
  this._quoteChangedEvent.register(handler);
128
203
  }
@@ -131,6 +206,12 @@ module.exports = (() => {
131
206
  this._excludedChangeEvent.register(handler);
132
207
  }
133
208
 
209
+ /**
210
+ * Registers an observer changes to the status of news existence.
211
+ *
212
+ * @public
213
+ * @param {Function} handler
214
+ */
134
215
  registerNewsExistsChangeHandler(handler) {
135
216
  this._newsExistsChangedEvent.register(handler);
136
217
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.0.130",
3
+ "version": "1.0.131",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -738,11 +738,11 @@ module.exports = (() => {
738
738
 
739
739
  /**
740
740
  * A container for positions which groups the positions into one or more
741
- * trees for aggregation and display purposes. For example, perhaps a positions
742
- * grouped first by asset class then by position is desired.
741
+ * trees for aggregation and display purposes. For example, positions could be
742
+ * grouped first by asset class then by position.
743
743
  *
744
744
  * Furthermore, the container performs aggregation (driven primarily by price
745
- * changes) for each level of grouping in the internal tree(s).
745
+ * changes) for each level of grouping.
746
746
  *
747
747
  * @public
748
748
  * @param {Array.<PositionTreeDefinition>} definitions
@@ -935,10 +935,14 @@ module.exports = (() => {
935
935
  }, { });
936
936
  }
937
937
 
938
- get defaultCurrency() {
939
- return this._defaultCurrency;
940
- }
941
-
938
+ /**
939
+ * Returns a distinct list of all symbols used by the positions
940
+ * within the container.
941
+ *
942
+ * @public
943
+ * @param {Boolean} display - If true, all "display" symbols are returned; otherwise Barchart symbols are returned.
944
+ * @returns {Array.<String>}
945
+ */
942
946
  getPositionSymbols(display) {
943
947
  const symbols = this._items.reduce((symbols, item) => {
944
948
  const position = item.position;
@@ -961,6 +965,14 @@ module.exports = (() => {
961
965
  return array.unique(symbols);
962
966
  }
963
967
 
968
+ /**
969
+ * Updates the quote for a single symbol; causing updates to any grouping
970
+ * level that contains the position(s) for the symbol.
971
+ *
972
+ * @public
973
+ * @param {String} symbol
974
+ * @param {Object} quote
975
+ */
964
976
  setPositionQuote(symbol, quote) {
965
977
  assert.argumentIsRequired(symbol, 'symbol', String);
966
978
  assert.argumentIsRequired(quote, 'quote', Object);
@@ -970,14 +982,34 @@ module.exports = (() => {
970
982
  }
971
983
  }
972
984
 
985
+ /**
986
+ * Returns all forex symbols that are required to do currency translations.
987
+ *
988
+ * @public
989
+ * @returns {Array.<String>}
990
+ */
973
991
  getForexSymbols() {
974
992
  return this._forexSymbols;
975
993
  }
976
994
 
995
+ /**
996
+ * Returns all current forex quotes.
997
+ *
998
+ * @public
999
+ * @returns {Array.<Object>}
1000
+ */
977
1001
  getForexQuotes() {
978
1002
  return this._forexQuotes;
979
1003
  }
980
1004
 
1005
+ /**
1006
+ * Updates the forex quote for a single currency pair; causing updates to
1007
+ * any grouping level that contains that requires translation.
1008
+ *
1009
+ * @public
1010
+ * @param {String} symbol
1011
+ * @param {Object} quote
1012
+ */
981
1013
  setForexQuote(symbol, quote) {
982
1014
  assert.argumentIsRequired(symbol, 'symbol', String);
983
1015
  assert.argumentIsRequired(quote, 'quote', Object);
@@ -995,10 +1027,24 @@ module.exports = (() => {
995
1027
  Object.keys(this._trees).forEach(key => this._trees[key].walk(group => group.setForexRate(rate), true, false));
996
1028
  }
997
1029
 
998
- setPositionFundamentals(symbol, data) {
1030
+ /**
1031
+ * Updates fundamental data for a single symbol.
1032
+ *
1033
+ * @public
1034
+ * @param {String} symbol
1035
+ * @param {Object} data
1036
+ */
1037
+ setPositionFundamentalData(symbol, data) {
999
1038
  return;
1000
1039
  }
1001
1040
 
1041
+ /**
1042
+ * Indicates if a news article exists for a symbol.
1043
+ *
1044
+ * @public
1045
+ * @param {String} symbol
1046
+ * @param {Boolean} exists
1047
+ */
1002
1048
  setNewsArticleExists(symbol, exists) {
1003
1049
  assert.argumentIsRequired(symbol, 'symbol', String);
1004
1050
  assert.argumentIsRequired(exists, 'exists', Boolean);
@@ -1008,6 +1054,13 @@ module.exports = (() => {
1008
1054
  }
1009
1055
  }
1010
1056
 
1057
+ /**
1058
+ * Returns a single level of grouping from one of the internal trees.
1059
+ *
1060
+ * @param {String} name
1061
+ * @param {Array.<String> keys
1062
+ * @returns {PositionGroup}
1063
+ */
1011
1064
  getGroup(name, keys) {
1012
1065
  assert.argumentIsRequired(name, 'name', String);
1013
1066
  assert.argumentIsArray(keys, 'keys', Number);
@@ -1015,6 +1068,14 @@ module.exports = (() => {
1015
1068
  return findNode(this._trees[name], keys).getValue();
1016
1069
  }
1017
1070
 
1071
+ /**
1072
+ * Returns all child groups from a level of grouping within one of
1073
+ * the internal trees.
1074
+ *
1075
+ * @param {String} name
1076
+ * @param {Array.<String> keys
1077
+ * @returns {Array.<PositionGroup>}
1078
+ */
1018
1079
  getGroups(name, keys) {
1019
1080
  assert.argumentIsRequired(name, 'name', String);
1020
1081
  assert.argumentIsArray(keys, 'keys', Number);
@@ -1026,8 +1087,6 @@ module.exports = (() => {
1026
1087
  assert.argumentIsRequired(name, 'name', String);
1027
1088
  assert.argumentIsRequired(executor, 'executor', Function);
1028
1089
 
1029
- assert.argumentIsRequired(executor, 'executor', Function);
1030
-
1031
1090
  this._trees[name].walk(group => group.setSuspended(true), false, false);
1032
1091
 
1033
1092
  executor(this);
@@ -1081,7 +1140,17 @@ module.exports = (() => {
1081
1140
  'use strict';
1082
1141
 
1083
1142
  /**
1143
+ * A grouping of {@link PositionItem} instances. The group aggregates from across
1144
+ * all the positions and performs currency translation, as necessary.
1145
+ *
1084
1146
  * @public
1147
+ * @param {PositionContainer} container
1148
+ * @param {PositionGroup|null} parent
1149
+ * @param {Array.<PositionItem>} items
1150
+ * @param {Currency} currency
1151
+ * @param {String} key
1152
+ * @param {String} description
1153
+ * @param {Boolean=} single
1085
1154
  */
1086
1155
  class PositionGroup {
1087
1156
  constructor(container, parent, items, currency, key, description, single) {
@@ -1206,30 +1275,73 @@ module.exports = (() => {
1206
1275
  this.refresh();
1207
1276
  }
1208
1277
 
1278
+ /**
1279
+ * The key of the group.
1280
+ *
1281
+ * @public
1282
+ * @returns {String}
1283
+ */
1209
1284
  get key() {
1210
1285
  return this._key;
1211
1286
  }
1212
1287
 
1288
+ /**
1289
+ * The description of the group.
1290
+ *
1291
+ * @public
1292
+ * @returns {String}
1293
+ */
1213
1294
  get description() {
1214
1295
  return this._description;
1215
1296
  }
1216
1297
 
1298
+ /**
1299
+ * The {@link Currency} which all aggregated data is presented in.
1300
+ *
1301
+ * @public
1302
+ * @returns {Currency}
1303
+ */
1217
1304
  get currency() {
1218
1305
  return this._currency;
1219
1306
  }
1220
1307
 
1308
+ /**
1309
+ * The {@link PositionItem} instances which for which aggregated data is compiled.
1310
+ *
1311
+ * @public
1312
+ * @returns {Currency}
1313
+ */
1221
1314
  get items() {
1222
1315
  return this._items;
1223
1316
  }
1224
1317
 
1318
+ /**
1319
+ * The string-based, human-readable aggregated data for the group.
1320
+ *
1321
+ * @public
1322
+ * @returns {Object}
1323
+ */
1225
1324
  get data() {
1226
1325
  return this._dataFormat;
1227
1326
  }
1228
1327
 
1328
+ /**
1329
+ * The raw aggregated data for the group (typically {@link Decimal} instances).
1330
+ *
1331
+ * @public
1332
+ * @returns {Object}
1333
+ */
1229
1334
  get actual() {
1230
1335
  return this._dataActual;
1231
1336
  }
1232
1337
 
1338
+ /**
1339
+ * Indicates if the group will only contain one {@link PositionItem} -- that is,
1340
+ * indicates if the group represents a single position.
1341
+ *
1342
+ * @public
1343
+ * @returns {Boolean}
1344
+ */
1233
1345
  get single() {
1234
1346
  return this._single;
1235
1347
  }
@@ -1238,10 +1350,22 @@ module.exports = (() => {
1238
1350
  return this._suspended;
1239
1351
  }
1240
1352
 
1353
+ /**
1354
+ * Indicates if the group should be excluded from higher-level aggregations.
1355
+ *
1356
+ * @public
1357
+ * @returns {Boolean}
1358
+ */
1241
1359
  get excluded() {
1242
1360
  return this._excluded;
1243
1361
  }
1244
1362
 
1363
+ /**
1364
+ * Causes aggregated data to be recalculated using a new exchange rate.
1365
+ *
1366
+ * @public
1367
+ * @param {Rate} rate
1368
+ */
1245
1369
  setForexRate(rate) {
1246
1370
  if (!this._bypassCurrencyTranslation) {
1247
1371
  this.refresh();
@@ -1270,6 +1394,11 @@ module.exports = (() => {
1270
1394
  }
1271
1395
  }
1272
1396
 
1397
+ /**
1398
+ * Causes all aggregated data to be recalculated.
1399
+ *
1400
+ * @public
1401
+ */
1273
1402
  refresh() {
1274
1403
  const rates = this._container.getForexQuotes();
1275
1404
 
@@ -1277,6 +1406,12 @@ module.exports = (() => {
1277
1406
  calculatePriceData(this, rates, null, true);
1278
1407
  }
1279
1408
 
1409
+ /**
1410
+ * Causes the percent of the position, with respect to the parent container's
1411
+ * total, to be recalculated.
1412
+ *
1413
+ * @public
1414
+ */
1280
1415
  refreshMarketPercent() {
1281
1416
  calculateMarketPercent(this, this._container.getForexQuotes(), true);
1282
1417
  }
@@ -1560,7 +1695,15 @@ module.exports = (() => {
1560
1695
  'use strict';
1561
1696
 
1562
1697
  /**
1698
+ * A container for a single position, which handles quote changes and
1699
+ * notifies observers -- which are typically parent-level {@link PositionGroup}
1700
+ * instances.
1701
+ *
1563
1702
  * @public
1703
+ * @param {Object} portfolio
1704
+ * @param {Object} position
1705
+ * @param {Object} currentSummary
1706
+ * @param {Array.<Object>} previousSummaries
1564
1707
  */
1565
1708
  class PositionItem {
1566
1709
  constructor(portfolio, position, currentSummary, previousSummaries) {
@@ -1576,10 +1719,12 @@ module.exports = (() => {
1576
1719
  this._data.basis = null;
1577
1720
 
1578
1721
  this._currentQuote = null;
1579
- this._previousQuote = null;
1722
+
1723
+ this._currentPrice = null;
1724
+ this._previousPrice = null;
1580
1725
 
1581
1726
  this._data.currentPrice = null;
1582
- this._data.previousPrice = null;
1727
+ this._data.currentPricePrevious = null;
1583
1728
 
1584
1729
  this._data.market = null;
1585
1730
  this._data.marketChange = null;
@@ -1611,30 +1756,72 @@ module.exports = (() => {
1611
1756
  this._newsExistsChangedEvent = new Event(this);
1612
1757
  }
1613
1758
 
1759
+ /**
1760
+ * The portfolio of the encapsulated position.
1761
+ *
1762
+ * @public
1763
+ * @returns {Object}
1764
+ */
1614
1765
  get portfolio() {
1615
1766
  return this._portfolio;
1616
1767
  }
1617
1768
 
1769
+ /**
1770
+ * The encapsulated position.
1771
+ *
1772
+ * @public
1773
+ * @returns {Object}
1774
+ */
1618
1775
  get position() {
1619
1776
  return this._position;
1620
1777
  }
1621
1778
 
1779
+ /**
1780
+ * The {@link Currency} of the encapsulated position.
1781
+ *
1782
+ * @public
1783
+ * @returns {Object}
1784
+ */
1622
1785
  get currency() {
1623
1786
  return this._currency;
1624
1787
  }
1625
1788
 
1789
+ /**
1790
+ * The year-to-date position summary of the encapsulated position.
1791
+ *
1792
+ * @public
1793
+ * @returns {Object}
1794
+ */
1626
1795
  get currentSummary() {
1627
1796
  return this._currentSummary;
1628
1797
  }
1629
-
1798
+
1799
+ /**
1800
+ * Previous year's summaries for the encapsulated position.
1801
+ *
1802
+ * @public
1803
+ * @returns {Object}
1804
+ */
1630
1805
  get previousSummaries() {
1631
1806
  return this._previousSummaries;
1632
1807
  }
1633
1808
 
1809
+ /**
1810
+ * Various data regarding the encapsulated position.
1811
+ *
1812
+ * @public
1813
+ * @returns {*}
1814
+ */
1634
1815
  get data() {
1635
1816
  return this._data;
1636
1817
  }
1637
1818
 
1819
+ /**
1820
+ * The current quote for the symbol of the encapsulated position.
1821
+ *
1822
+ * @public
1823
+ * @returns {null|{Object}}
1824
+ */
1638
1825
  get quote() {
1639
1826
  return this._currentQuote;
1640
1827
  }
@@ -1643,13 +1830,22 @@ module.exports = (() => {
1643
1830
  return this._excluded;
1644
1831
  }
1645
1832
 
1833
+ /**
1834
+ * Sets the current quote -- causing position-level data (e.g. market value) to
1835
+ * be recalculated.
1836
+ *
1837
+ * @public
1838
+ * @param {Object} quote
1839
+ */
1646
1840
  setQuote(quote) {
1647
1841
  assert.argumentIsRequired(quote, 'quote', Object);
1648
1842
 
1649
- if (this._previousQuote === null || this._previousQuote.lastPrice !== quote.lastPrice) {
1843
+ if (this._currentPricePrevious !== quote.lastPrice) {
1650
1844
  calculatePriceData(this, quote.lastPrice);
1651
1845
 
1652
- this._previousQuote = this._currentQuote;
1846
+ this._currentPricePrevious = this._currentPrice;
1847
+ this._currentPrice = quote.lastPrice;
1848
+
1653
1849
  this._currentQuote = quote;
1654
1850
 
1655
1851
  this._quoteChangedEvent.fire(this._currentQuote);
@@ -1664,6 +1860,13 @@ module.exports = (() => {
1664
1860
  }
1665
1861
  }
1666
1862
 
1863
+ /**
1864
+ * Sets a flag which indicates if news article(s) exist for the encapsulated position's
1865
+ * symbol.
1866
+ *
1867
+ * @public
1868
+ * @param {Boolean} value
1869
+ */
1667
1870
  setNewsArticleExists(value) {
1668
1871
  assert.argumentIsRequired(value, 'value', Boolean);
1669
1872
 
@@ -1672,6 +1875,13 @@ module.exports = (() => {
1672
1875
  }
1673
1876
  }
1674
1877
 
1878
+ /**
1879
+ * Registers an observer for quote changes, which is fired after internal recalculations
1880
+ * of position data are complete.
1881
+ *
1882
+ * @public
1883
+ * @param {Function} handler
1884
+ */
1675
1885
  registerQuoteChangeHandler(handler) {
1676
1886
  this._quoteChangedEvent.register(handler);
1677
1887
  }
@@ -1680,6 +1890,12 @@ module.exports = (() => {
1680
1890
  this._excludedChangeEvent.register(handler);
1681
1891
  }
1682
1892
 
1893
+ /**
1894
+ * Registers an observer changes to the status of news existence.
1895
+ *
1896
+ * @public
1897
+ * @param {Function} handler
1898
+ */
1683
1899
  registerNewsExistsChangeHandler(handler) {
1684
1900
  this._newsExistsChangedEvent.register(handler);
1685
1901
  }