@barchart/portfolio-api-common 1.0.163 → 1.0.167

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.
@@ -167,6 +167,13 @@ module.exports = (() => {
167
167
  }, { });
168
168
  }
169
169
 
170
+ /**
171
+ * Adds a new portfolio to the container, injecting it into aggregation
172
+ * trees, as necessary.
173
+ *
174
+ * @public
175
+ * @param {Object} portfolio
176
+ */
170
177
  addPortfolio(portfolio) {
171
178
  assert.argumentIsRequired(portfolio, 'portfolio', Object);
172
179
  assert.argumentIsRequired(portfolio.portfolio, 'portfolio.portfolio', String);
@@ -179,20 +186,68 @@ module.exports = (() => {
179
186
 
180
187
  this._definitions.forEach((treeDefinition) => {
181
188
  const tree = this._trees[treeDefinition.name];
189
+ const levelDefinitions = treeDefinition.definitions;
182
190
 
183
- treeDefinition.definitions.forEach((levelDefinition) => {
184
- const requiredGroup = levelDefinition.generateRequiredGroup(portfolio);
191
+ let portfolioRequiredGroup = null;
185
192
 
186
- if (requiredGroup !== null) {
193
+ let portfolioLevelDefinition = null;
194
+ let portfolioLevelDefinitionIndex = null;
187
195
 
196
+ levelDefinitions.forEach((levelDefinition, i) => {
197
+ if (portfolioRequiredGroup === null) {
198
+ portfolioRequiredGroup = levelDefinition.generateRequiredGroup(portfolio);
199
+
200
+ if (portfolioRequiredGroup !== null) {
201
+ portfolioLevelDefinition = levelDefinition;
202
+ portfolioLevelDefinitionIndex = i;
203
+ }
188
204
  }
189
205
  });
206
+
207
+ if (portfolioRequiredGroup !== null) {
208
+ let parentTrees = [ ];
209
+
210
+ if (portfolioLevelDefinitionIndex === 0) {
211
+ parentTrees.push(tree);
212
+ } else {
213
+ const parentLevelDefinition = levelDefinitions[ portfolioLevelDefinitionIndex - 1 ];
214
+
215
+ tree.walk((group, groupTree) => {
216
+ if (group.definition === parentLevelDefinition) {
217
+ parentTrees.push(groupTree);
218
+ }
219
+ }, false, false);
220
+ }
221
+
222
+ const overrideRequiredGroups = [ portfolioRequiredGroup ];
223
+
224
+ parentTrees.forEach((t) => {
225
+ createGroups.call(this, tree, t, [ ], treeDefinition, levelDefinitions.slice(portfolioLevelDefinitionIndex), overrideRequiredGroups);
226
+ });
227
+ }
190
228
  });
191
229
  }
192
230
  }
193
231
 
232
+ /**
233
+ * Removes an existing portfolio, and all of it's positions, from the container. This
234
+ * also triggers removal of the portfolio and it's positions from any applicable
235
+ * aggregation trees.
236
+ *
237
+ * @public
238
+ * @param {Object} portfolio
239
+ */
194
240
  removePortfolio(portfolio) {
241
+ assert.argumentIsRequired(portfolio, 'portfolio', Object);
242
+ assert.argumentIsRequired(portfolio.portfolio, 'portfolio.portfolio', String);
243
+
244
+ this.startTransaction(() => {
245
+ const itemsToRemove = getPositionItemsForPortfolio(this._items, portfolio.portfolio).forEach(i => removePositionItem.call(this, i));
195
246
 
247
+ itemsToRemove.forEach(item => removePositionItem.call(this, item));
248
+
249
+
250
+ });
196
251
  }
197
252
 
198
253
  mutatePosition(position, summary) {
@@ -200,7 +255,7 @@ module.exports = (() => {
200
255
  }
201
256
 
202
257
  removePosition(position) {
203
-
258
+ removePositionItem.call(this, this._items.find((item) => item.position.position === position));
204
259
  }
205
260
 
206
261
  /**
@@ -377,6 +432,16 @@ module.exports = (() => {
377
432
  return findNode(this._trees[name], keys).getChildren().map(node => node.getValue());
378
433
  }
379
434
 
435
+ /**
436
+ * Returns all portfolios in the container.
437
+ *
438
+ * @public
439
+ * @return {Array.<Object>}
440
+ */
441
+ getPortfolios() {
442
+ return Object.keys(this._portfolios).map(id => this._portfolios[id]);
443
+ }
444
+
380
445
  /**
381
446
  * Returns all positions for the given portfolio.
382
447
  *
@@ -385,24 +450,42 @@ module.exports = (() => {
385
450
  * @return {Array.<Object>}
386
451
  */
387
452
  getPositions(portfolio) {
388
- return this._items.reduce((positions, item) => {
389
- if (item.position.portfolio === portfolio) {
390
- positions.push(item);
391
- }
453
+ assert.argumentIsRequired(portfolio, 'portfolio', String);
392
454
 
393
- return positions;
394
- }, []);
455
+ return getPositionItemsForPortfolio(this._items, portfolio).map(item => item.position);
395
456
  }
396
457
 
397
- startTransaction(name, executor) {
398
- assert.argumentIsRequired(name, 'name', String);
458
+ /**
459
+ * Pauses aggregation calculations during the processing of an action.
460
+ *
461
+ * @public
462
+ * @param {Function} executor
463
+ * @param {String=|Array.<String>=} names
464
+ */
465
+ startTransaction(executor, names) {
466
+ let namesToUse;
467
+
468
+ if (is.array(names)) {
469
+ assert.argumentIsArray(names, 'names', String);
470
+
471
+ namesToUse = names;
472
+ } else {
473
+ assert.argumentIsOptional(names, 'names', String);
474
+
475
+ if (names) {
476
+ namesToUse = [ names ];
477
+ } else {
478
+ namesToUse = Object.keys(this._trees);
479
+ }
480
+ }
481
+
399
482
  assert.argumentIsRequired(executor, 'executor', Function);
400
483
 
401
- this._trees[name].walk(group => group.setSuspended(true), false, false);
484
+ namesToUse.forEach((name) => this._trees[name].walk(group => group.setSuspended(true), false, false));
402
485
 
403
486
  executor(this);
404
487
 
405
- this._trees[name].walk(group => group.setSuspended(false), false, false);
488
+ namesToUse.forEach((name) => this._trees[name].walk(group => group.setSuspended(false), false, false));
406
489
  }
407
490
 
408
491
  toString() {
@@ -444,7 +527,7 @@ module.exports = (() => {
444
527
  this._groupBindings[id].push(dispoable);
445
528
  }
446
529
 
447
- function createGroups(parentTree, currentTree, items, treeDefinition, levelDefinitions) {
530
+ function createGroups(parentTree, currentTree, items, treeDefinition, levelDefinitions, overrideRequiredGroups) {
448
531
  if (levelDefinitions.length === 0) {
449
532
  return;
450
533
  }
@@ -458,26 +541,28 @@ module.exports = (() => {
458
541
  const items = populatedObjects[key];
459
542
  const first = items[0];
460
543
 
461
- list.push(new PositionGroup(this, parent, items, levelDefinition.currencySelector(first), key, levelDefinition.descriptionSelector(first), levelDefinition.single && items.length === 1, levelDefinition.aggregateCash));
544
+ list.push(new PositionGroup(this, parent, levelDefinition, items, levelDefinition.currencySelector(first), key, levelDefinition.descriptionSelector(first), levelDefinition.single && items.length === 1, levelDefinition.aggregateCash));
462
545
 
463
546
  return list;
464
547
  }, [ ]);
465
548
 
466
- const missingGroups = array.difference(levelDefinition.requiredGroups.map(group => group.key), populatedGroups.map(group => group.key))
549
+ const requiredGroupsToUse = overrideRequiredGroups || levelDefinition.requiredGroups;
550
+
551
+ const missingGroups = array.difference(requiredGroupsToUse.map(group => group.key), populatedGroups.map(group => group.key))
467
552
  .map((key) => {
468
- return levelDefinition.requiredGroups.find(g => g.key === key);
553
+ return requiredGroupsToUse.find(g => g.key === key);
469
554
  });
470
555
 
471
556
  const empty = missingGroups.map((group) => {
472
- return new PositionGroup(this, parent, [ ], group.currency, group.key, group.description);
557
+ return new PositionGroup(this, parent, levelDefinition, [ ], group.currency, group.key, group.description);
473
558
  });
474
559
 
475
560
  const compositeGroups = populatedGroups.concat(empty);
476
561
 
477
562
  let builder;
478
563
 
479
- if (levelDefinition.requiredGroups.length !== 0) {
480
- const ordering = levelDefinition.requiredGroups.reduce((map, group, index) => {
564
+ if (requiredGroupsToUse.length !== 0) {
565
+ const ordering = requiredGroupsToUse.reduce((map, group, index) => {
481
566
  map[group.description] = index;
482
567
 
483
568
  return map;
@@ -561,5 +646,23 @@ module.exports = (() => {
561
646
  });
562
647
  }
563
648
 
649
+ function getPositionItemsForPortfolio(items, portfolio) {
650
+ return items.reduce((positionItems, item) => {
651
+ if (item.position.portfolio === portfolio) {
652
+ positionItems.push(item.position);
653
+ }
654
+
655
+ return positionItems;
656
+ }, [ ]);
657
+ }
658
+
659
+ function removePositionItem(positionItem) {
660
+ if (!positionItem) {
661
+ return;
662
+ }
663
+
664
+ positionItem.dispose();
665
+ }
666
+
564
667
  return PositionContainer;
565
668
  })();
@@ -22,6 +22,7 @@ module.exports = (() => {
22
22
  * @public
23
23
  * @param {PositionContainer} container
24
24
  * @param {PositionGroup|null} parent
25
+ * @param {LevelDefinition} definition
25
26
  * @param {Array.<PositionItem>} items
26
27
  * @param {Currency} currency
27
28
  * @param {String} key
@@ -30,8 +31,10 @@ module.exports = (() => {
30
31
  * @param {Boolean=} aggregateCash
31
32
  */
32
33
  class PositionGroup {
33
- constructor(container, parent, items, currency, key, description, single, aggregateCash) {
34
+ constructor(container, parent, definition, items, currency, key, description, single, aggregateCash) {
34
35
  this._id = counter++;
36
+
37
+ this._definition = definition;
35
38
  this._container = container;
36
39
  this._parent = parent || null;
37
40
 
@@ -209,6 +212,16 @@ module.exports = (() => {
209
212
  return this._id;
210
213
  }
211
214
 
215
+ /**
216
+ * The {@link LevelDefinition} which was used to generate this group.
217
+ *
218
+ * @public
219
+ * @returns {LevelDefinition}
220
+ */
221
+ get definition() {
222
+ return this._definition;
223
+ }
224
+
212
225
  /**
213
226
  * The key of the group.
214
227
  *
@@ -360,11 +373,19 @@ module.exports = (() => {
360
373
  }
361
374
  }
362
375
 
376
+ /**
377
+ * Stops (or starts) group-level aggregation calculations.
378
+ *
379
+ * @public
380
+ * @param {Boolean} value
381
+ */
363
382
  setSuspended(value) {
364
383
  assert.argumentIsRequired(value, 'value', Boolean);
365
384
 
366
385
  if (this._suspended !== value) {
367
- if (this._suspended = value) {
386
+ this._suspended = value;
387
+
388
+ if (!this._suspended) {
368
389
  this.refresh();
369
390
  }
370
391
  }
@@ -2,6 +2,7 @@ const array = require('@barchart/common-js/lang/array'),
2
2
  assert = require('@barchart/common-js/lang/assert'),
3
3
  Currency = require('@barchart/common-js/lang/Currency'),
4
4
  Decimal = require('@barchart/common-js/lang/Decimal'),
5
+ Disposable = require('@barchart/common-js/lang/Disposable'),
5
6
  Event = require('@barchart/common-js/messaging/Event'),
6
7
  is = require('@barchart/common-js/lang/is');
7
8
 
@@ -21,8 +22,10 @@ module.exports = (() => {
21
22
  * @param {Object} currentSummary
22
23
  * @param {Array.<Object>} previousSummaries
23
24
  */
24
- class PositionItem {
25
+ class PositionItem extends Disposable {
25
26
  constructor(portfolio, position, currentSummary, previousSummaries) {
27
+ super();
28
+
26
29
  this._portfolio = portfolio;
27
30
  this._position = position;
28
31
  this._currency = position.instrument.currency || Currency.CAD;
@@ -67,6 +70,7 @@ module.exports = (() => {
67
70
  this._quoteChangedEvent = new Event(this);
68
71
  this._newsExistsChangedEvent = new Event(this);
69
72
  this._fundamentalDataChangeEvent = new Event(this);
73
+ this._positionItemDisposeEvent = new Event(this);
70
74
  }
71
75
 
72
76
  /**
@@ -149,6 +153,10 @@ module.exports = (() => {
149
153
  setQuote(quote) {
150
154
  assert.argumentIsRequired(quote, 'quote', Object);
151
155
 
156
+ if (this.getIsDisposed()) {
157
+ return;
158
+ }
159
+
152
160
  if (this._currentPricePrevious !== quote.lastPrice) {
153
161
  calculatePriceData(this, quote.lastPrice);
154
162
 
@@ -170,6 +178,10 @@ module.exports = (() => {
170
178
  setPositionFundamentalData(data) {
171
179
  assert.argumentIsRequired(data, 'data', Object);
172
180
 
181
+ if (this.getIsDisposed()) {
182
+ return;
183
+ }
184
+
173
185
  this._fundamentalDataChangeEvent.fire(this._data.fundamental = data);
174
186
  }
175
187
 
@@ -183,6 +195,10 @@ module.exports = (() => {
183
195
  setNewsArticleExists(value) {
184
196
  assert.argumentIsRequired(value, 'value', Boolean);
185
197
 
198
+ if (this.getIsDisposed()) {
199
+ return;
200
+ }
201
+
186
202
  if (this._data.newsExists !== value) {
187
203
  this._newsExistsChangedEvent.fire(this._data.newsExists = value);
188
204
  }
@@ -222,6 +238,26 @@ module.exports = (() => {
222
238
  return this._newsExistsChangedEvent.register(handler);
223
239
  }
224
240
 
241
+ /**
242
+ * Registers an observer for object disposal.
243
+ *
244
+ * @public
245
+ * @param {Function} handler
246
+ * @returns {Disposable}
247
+ */
248
+ registerPositionItemDisposeHandler(handler) {
249
+ return this._positionItemDisposeEvent.register(handler);
250
+ }
251
+
252
+ _onDispose() {
253
+ this._positionItemDisposeEvent.fire(this);
254
+
255
+ this._quoteChangedEvent.clear();
256
+ this._newsExistsChangedEvent.clear();
257
+ this._fundamentalDataChangeEvent.clear();
258
+ this._positionItemDisposeEvent.clear();
259
+ }
260
+
225
261
  toString() {
226
262
  return '[PositionItem]';
227
263
  }
@@ -4,6 +4,8 @@ const assert = require('@barchart/common-js/lang/assert'),
4
4
 
5
5
  const InstrumentType = require('./../../data/InstrumentType');
6
6
 
7
+ const PositionLevelType = require('./PositionLevelType');
8
+
7
9
  module.exports = (() => {
8
10
  'use strict';
9
11
 
@@ -20,11 +22,12 @@ module.exports = (() => {
20
22
  * @param {Array.<PositionLevelDefinition~RequiredGroup>=} requiredGroups
21
23
  * @param {Boolean=} single
22
24
  * @param {Boolean=} aggregateCash
23
- * @param {Function=} injectPositions
25
+ * @param {Function=} requiredGroupGenerator
24
26
  */
25
27
  class PositionLevelDefinition {
26
- constructor(name, keySelector, descriptionSelector, currencySelector, requiredGroups, single, aggregateCash, requiredGroupGenerator) {
28
+ constructor(name, type, keySelector, descriptionSelector, currencySelector, requiredGroups, single, aggregateCash, requiredGroupGenerator) {
27
29
  assert.argumentIsRequired(name, 'name', String);
30
+ assert.argumentIsRequired(type, 'type', PositionLevelType, 'PositionLevelType');
28
31
  assert.argumentIsRequired(keySelector, 'keySelector', Function);
29
32
  assert.argumentIsRequired(descriptionSelector, 'descriptionSelector', Function);
30
33
  assert.argumentIsRequired(currencySelector, 'currencySelector', Function);
@@ -38,6 +41,7 @@ module.exports = (() => {
38
41
  assert.argumentIsOptional(requiredGroupGenerator, 'requiredGroupGenerator', Function);
39
42
 
40
43
  this._name = name;
44
+ this._type = type;
41
45
 
42
46
  this._keySelector = keySelector;
43
47
  this._descriptionSelector = descriptionSelector;
@@ -61,6 +65,16 @@ module.exports = (() => {
61
65
  return this._name;
62
66
  }
63
67
 
68
+ /**
69
+ * A general description of the type of items grouped together.
70
+ *
71
+ * @public
72
+ * @return {PositionLevelType}
73
+ */
74
+ get type() {
75
+ return this._type;
76
+ }
77
+
64
78
  /**
65
79
  * A function, when given a {@link PositionItem} returns a string that is used
66
80
  * to group {@link PositionItem} instances into different groups.
@@ -0,0 +1,29 @@
1
+ const Enum = require('@barchart/common-js/lang/Enum');
2
+
3
+ module.exports = (() => {
4
+ 'use strict';
5
+
6
+ class PositionLevelType extends Enum {
7
+ constructor(code) {
8
+ super(code, code);
9
+ }
10
+
11
+ static get PORTFOLIO() {
12
+ return portfolio;
13
+ }
14
+
15
+ static get POSITION() {
16
+ return position;
17
+ }
18
+
19
+ static get OTHER() {
20
+ return other;
21
+ }
22
+ }
23
+
24
+ const portfolio = new PositionLevelType('PORTFOLIO');
25
+ const position = new PositionLevelType('POSITION');
26
+ const other = new PositionLevelType('OTHER');
27
+
28
+ return PositionLevelType;
29
+ })();
@@ -43,7 +43,7 @@ module.exports = (() => {
43
43
  * bottom-most level of the tree (i.e. leaf nodes).
44
44
  *
45
45
  * @public
46
- * @returns {Array.<PositionTreeDefinition>}
46
+ * @returns {Array.<PositionLevelDefinitions>}
47
47
  */
48
48
  get definitions() {
49
49
  return this._definitions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.0.163",
3
+ "version": "1.0.167",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -116,7 +116,7 @@ module.exports = (() => {
116
116
  return InstrumentType;
117
117
  })();
118
118
 
119
- },{"@barchart/common-js/lang/Enum":18,"@barchart/common-js/lang/assert":21}],2:[function(require,module,exports){
119
+ },{"@barchart/common-js/lang/Enum":19,"@barchart/common-js/lang/assert":22}],2:[function(require,module,exports){
120
120
  const array = require('@barchart/common-js/lang/array'),
121
121
  assert = require('@barchart/common-js/lang/assert'),
122
122
  Day = require('@barchart/common-js/lang/Day'),
@@ -373,7 +373,7 @@ module.exports = (() => {
373
373
  return PositionSummaryFrame;
374
374
  })();
375
375
 
376
- },{"@barchart/common-js/lang/Day":15,"@barchart/common-js/lang/Decimal":16,"@barchart/common-js/lang/Enum":18,"@barchart/common-js/lang/array":20,"@barchart/common-js/lang/assert":21,"@barchart/common-js/lang/is":23}],3:[function(require,module,exports){
376
+ },{"@barchart/common-js/lang/Day":16,"@barchart/common-js/lang/Decimal":17,"@barchart/common-js/lang/Enum":19,"@barchart/common-js/lang/array":21,"@barchart/common-js/lang/assert":22,"@barchart/common-js/lang/is":24}],3:[function(require,module,exports){
377
377
  const assert = require('@barchart/common-js/lang/assert'),
378
378
  Enum = require('@barchart/common-js/lang/Enum');
379
379
 
@@ -713,7 +713,7 @@ module.exports = (() => {
713
713
  return TransactionType;
714
714
  })();
715
715
 
716
- },{"@barchart/common-js/lang/Enum":18,"@barchart/common-js/lang/assert":21}],4:[function(require,module,exports){
716
+ },{"@barchart/common-js/lang/Enum":19,"@barchart/common-js/lang/assert":22}],4:[function(require,module,exports){
717
717
  const array = require('@barchart/common-js/lang/array'),
718
718
  assert = require('@barchart/common-js/lang/assert'),
719
719
  ComparatorBuilder = require('@barchart/common-js/collections/sorting/ComparatorBuilder'),
@@ -883,6 +883,13 @@ module.exports = (() => {
883
883
  }, { });
884
884
  }
885
885
 
886
+ /**
887
+ * Adds a new portfolio to the container, injecting it into aggregation
888
+ * trees, as necessary.
889
+ *
890
+ * @public
891
+ * @param {Object} portfolio
892
+ */
886
893
  addPortfolio(portfolio) {
887
894
  assert.argumentIsRequired(portfolio, 'portfolio', Object);
888
895
  assert.argumentIsRequired(portfolio.portfolio, 'portfolio.portfolio', String);
@@ -895,20 +902,68 @@ module.exports = (() => {
895
902
 
896
903
  this._definitions.forEach((treeDefinition) => {
897
904
  const tree = this._trees[treeDefinition.name];
905
+ const levelDefinitions = treeDefinition.definitions;
906
+
907
+ let portfolioRequiredGroup = null;
898
908
 
899
- treeDefinition.definitions.forEach((levelDefinition) => {
900
- const requiredGroup = levelDefinition.generateRequiredGroup(portfolio);
909
+ let portfolioLevelDefinition = null;
910
+ let portfolioLevelDefinitionIndex = null;
901
911
 
902
- if (requiredGroup !== null) {
912
+ levelDefinitions.forEach((levelDefinition, i) => {
913
+ if (portfolioRequiredGroup === null) {
914
+ portfolioRequiredGroup = levelDefinition.generateRequiredGroup(portfolio);
903
915
 
916
+ if (portfolioRequiredGroup !== null) {
917
+ portfolioLevelDefinition = levelDefinition;
918
+ portfolioLevelDefinitionIndex = i;
919
+ }
904
920
  }
905
921
  });
922
+
923
+ if (portfolioRequiredGroup !== null) {
924
+ let parentTrees = [ ];
925
+
926
+ if (portfolioLevelDefinitionIndex === 0) {
927
+ parentTrees.push(tree);
928
+ } else {
929
+ const parentLevelDefinition = levelDefinitions[ portfolioLevelDefinitionIndex - 1 ];
930
+
931
+ tree.walk((group, groupTree) => {
932
+ if (group.definition === parentLevelDefinition) {
933
+ parentTrees.push(groupTree);
934
+ }
935
+ }, false, false);
936
+ }
937
+
938
+ const overrideRequiredGroups = [ portfolioRequiredGroup ];
939
+
940
+ parentTrees.forEach((t) => {
941
+ createGroups.call(this, tree, t, [ ], treeDefinition, levelDefinitions.slice(portfolioLevelDefinitionIndex), overrideRequiredGroups);
942
+ });
943
+ }
906
944
  });
907
945
  }
908
946
  }
909
947
 
948
+ /**
949
+ * Removes an existing portfolio, and all of it's positions, from the container. This
950
+ * also triggers removal of the portfolio and it's positions from any applicable
951
+ * aggregation trees.
952
+ *
953
+ * @public
954
+ * @param {Object} portfolio
955
+ */
910
956
  removePortfolio(portfolio) {
957
+ assert.argumentIsRequired(portfolio, 'portfolio', Object);
958
+ assert.argumentIsRequired(portfolio.portfolio, 'portfolio.portfolio', String);
911
959
 
960
+ this.startTransaction(() => {
961
+ const itemsToRemove = getPositionItemsForPortfolio(this._items, portfolio.portfolio).forEach(i => removePositionItem.call(this, i));
962
+
963
+ itemsToRemove.forEach(item => removePositionItem.call(this, item));
964
+
965
+
966
+ });
912
967
  }
913
968
 
914
969
  mutatePosition(position, summary) {
@@ -916,7 +971,7 @@ module.exports = (() => {
916
971
  }
917
972
 
918
973
  removePosition(position) {
919
-
974
+ removePositionItem.call(this, this._items.find((item) => item.position.position === position));
920
975
  }
921
976
 
922
977
  /**
@@ -1093,6 +1148,16 @@ module.exports = (() => {
1093
1148
  return findNode(this._trees[name], keys).getChildren().map(node => node.getValue());
1094
1149
  }
1095
1150
 
1151
+ /**
1152
+ * Returns all portfolios in the container.
1153
+ *
1154
+ * @public
1155
+ * @return {Array.<Object>}
1156
+ */
1157
+ getPortfolios() {
1158
+ return Object.keys(this._portfolios).map(id => this._portfolios[id]);
1159
+ }
1160
+
1096
1161
  /**
1097
1162
  * Returns all positions for the given portfolio.
1098
1163
  *
@@ -1101,24 +1166,42 @@ module.exports = (() => {
1101
1166
  * @return {Array.<Object>}
1102
1167
  */
1103
1168
  getPositions(portfolio) {
1104
- return this._items.reduce((positions, item) => {
1105
- if (item.position.portfolio === portfolio) {
1106
- positions.push(item);
1107
- }
1169
+ assert.argumentIsRequired(portfolio, 'portfolio', String);
1108
1170
 
1109
- return positions;
1110
- }, []);
1171
+ return getPositionItemsForPortfolio(this._items, portfolio).map(item => item.position);
1111
1172
  }
1112
1173
 
1113
- startTransaction(name, executor) {
1114
- assert.argumentIsRequired(name, 'name', String);
1174
+ /**
1175
+ * Pauses aggregation calculations during the processing of an action.
1176
+ *
1177
+ * @public
1178
+ * @param {Function} executor
1179
+ * @param {String=|Array.<String>=} names
1180
+ */
1181
+ startTransaction(executor, names) {
1182
+ let namesToUse;
1183
+
1184
+ if (is.array(names)) {
1185
+ assert.argumentIsArray(names, 'names', String);
1186
+
1187
+ namesToUse = names;
1188
+ } else {
1189
+ assert.argumentIsOptional(names, 'names', String);
1190
+
1191
+ if (names) {
1192
+ namesToUse = [ names ];
1193
+ } else {
1194
+ namesToUse = Object.keys(this._trees);
1195
+ }
1196
+ }
1197
+
1115
1198
  assert.argumentIsRequired(executor, 'executor', Function);
1116
1199
 
1117
- this._trees[name].walk(group => group.setSuspended(true), false, false);
1200
+ namesToUse.forEach((name) => this._trees[name].walk(group => group.setSuspended(true), false, false));
1118
1201
 
1119
1202
  executor(this);
1120
1203
 
1121
- this._trees[name].walk(group => group.setSuspended(false), false, false);
1204
+ namesToUse.forEach((name) => this._trees[name].walk(group => group.setSuspended(false), false, false));
1122
1205
  }
1123
1206
 
1124
1207
  toString() {
@@ -1160,7 +1243,7 @@ module.exports = (() => {
1160
1243
  this._groupBindings[id].push(dispoable);
1161
1244
  }
1162
1245
 
1163
- function createGroups(parentTree, currentTree, items, treeDefinition, levelDefinitions) {
1246
+ function createGroups(parentTree, currentTree, items, treeDefinition, levelDefinitions, overrideRequiredGroups) {
1164
1247
  if (levelDefinitions.length === 0) {
1165
1248
  return;
1166
1249
  }
@@ -1174,26 +1257,28 @@ module.exports = (() => {
1174
1257
  const items = populatedObjects[key];
1175
1258
  const first = items[0];
1176
1259
 
1177
- list.push(new PositionGroup(this, parent, items, levelDefinition.currencySelector(first), key, levelDefinition.descriptionSelector(first), levelDefinition.single && items.length === 1, levelDefinition.aggregateCash));
1260
+ list.push(new PositionGroup(this, parent, levelDefinition, items, levelDefinition.currencySelector(first), key, levelDefinition.descriptionSelector(first), levelDefinition.single && items.length === 1, levelDefinition.aggregateCash));
1178
1261
 
1179
1262
  return list;
1180
1263
  }, [ ]);
1181
1264
 
1182
- const missingGroups = array.difference(levelDefinition.requiredGroups.map(group => group.key), populatedGroups.map(group => group.key))
1265
+ const requiredGroupsToUse = overrideRequiredGroups || levelDefinition.requiredGroups;
1266
+
1267
+ const missingGroups = array.difference(requiredGroupsToUse.map(group => group.key), populatedGroups.map(group => group.key))
1183
1268
  .map((key) => {
1184
- return levelDefinition.requiredGroups.find(g => g.key === key);
1269
+ return requiredGroupsToUse.find(g => g.key === key);
1185
1270
  });
1186
1271
 
1187
1272
  const empty = missingGroups.map((group) => {
1188
- return new PositionGroup(this, parent, [ ], group.currency, group.key, group.description);
1273
+ return new PositionGroup(this, parent, levelDefinition, [ ], group.currency, group.key, group.description);
1189
1274
  });
1190
1275
 
1191
1276
  const compositeGroups = populatedGroups.concat(empty);
1192
1277
 
1193
1278
  let builder;
1194
1279
 
1195
- if (levelDefinition.requiredGroups.length !== 0) {
1196
- const ordering = levelDefinition.requiredGroups.reduce((map, group, index) => {
1280
+ if (requiredGroupsToUse.length !== 0) {
1281
+ const ordering = requiredGroupsToUse.reduce((map, group, index) => {
1197
1282
  map[group.description] = index;
1198
1283
 
1199
1284
  return map;
@@ -1277,10 +1362,28 @@ module.exports = (() => {
1277
1362
  });
1278
1363
  }
1279
1364
 
1365
+ function getPositionItemsForPortfolio(items, portfolio) {
1366
+ return items.reduce((positionItems, item) => {
1367
+ if (item.position.portfolio === portfolio) {
1368
+ positionItems.push(item.position);
1369
+ }
1370
+
1371
+ return positionItems;
1372
+ }, [ ]);
1373
+ }
1374
+
1375
+ function removePositionItem(positionItem) {
1376
+ if (!positionItem) {
1377
+ return;
1378
+ }
1379
+
1380
+ positionItem.dispose();
1381
+ }
1382
+
1280
1383
  return PositionContainer;
1281
1384
  })();
1282
1385
 
1283
- },{"./../data/PositionSummaryFrame":2,"./PositionGroup":5,"./PositionItem":6,"./definitions/PositionTreeDefinition":8,"@barchart/common-js/collections/Tree":10,"@barchart/common-js/collections/sorting/ComparatorBuilder":11,"@barchart/common-js/collections/sorting/comparators":12,"@barchart/common-js/collections/specialized/DisposableStack":13,"@barchart/common-js/lang/Currency":14,"@barchart/common-js/lang/Decimal":16,"@barchart/common-js/lang/Rate":19,"@barchart/common-js/lang/array":20,"@barchart/common-js/lang/assert":21,"@barchart/common-js/lang/is":23}],5:[function(require,module,exports){
1386
+ },{"./../data/PositionSummaryFrame":2,"./PositionGroup":5,"./PositionItem":6,"./definitions/PositionTreeDefinition":9,"@barchart/common-js/collections/Tree":11,"@barchart/common-js/collections/sorting/ComparatorBuilder":12,"@barchart/common-js/collections/sorting/comparators":13,"@barchart/common-js/collections/specialized/DisposableStack":14,"@barchart/common-js/lang/Currency":15,"@barchart/common-js/lang/Decimal":17,"@barchart/common-js/lang/Rate":20,"@barchart/common-js/lang/array":21,"@barchart/common-js/lang/assert":22,"@barchart/common-js/lang/is":24}],5:[function(require,module,exports){
1284
1387
  const array = require('@barchart/common-js/lang/array'),
1285
1388
  assert = require('@barchart/common-js/lang/assert'),
1286
1389
  Currency = require('@barchart/common-js/lang/Currency'),
@@ -1305,6 +1408,7 @@ module.exports = (() => {
1305
1408
  * @public
1306
1409
  * @param {PositionContainer} container
1307
1410
  * @param {PositionGroup|null} parent
1411
+ * @param {LevelDefinition} definition
1308
1412
  * @param {Array.<PositionItem>} items
1309
1413
  * @param {Currency} currency
1310
1414
  * @param {String} key
@@ -1313,8 +1417,10 @@ module.exports = (() => {
1313
1417
  * @param {Boolean=} aggregateCash
1314
1418
  */
1315
1419
  class PositionGroup {
1316
- constructor(container, parent, items, currency, key, description, single, aggregateCash) {
1420
+ constructor(container, parent, definition, items, currency, key, description, single, aggregateCash) {
1317
1421
  this._id = counter++;
1422
+
1423
+ this._definition = definition;
1318
1424
  this._container = container;
1319
1425
  this._parent = parent || null;
1320
1426
 
@@ -1492,6 +1598,16 @@ module.exports = (() => {
1492
1598
  return this._id;
1493
1599
  }
1494
1600
 
1601
+ /**
1602
+ * The {@link LevelDefinition} which was used to generate this group.
1603
+ *
1604
+ * @public
1605
+ * @returns {LevelDefinition}
1606
+ */
1607
+ get definition() {
1608
+ return this._definition;
1609
+ }
1610
+
1495
1611
  /**
1496
1612
  * The key of the group.
1497
1613
  *
@@ -1643,11 +1759,19 @@ module.exports = (() => {
1643
1759
  }
1644
1760
  }
1645
1761
 
1762
+ /**
1763
+ * Stops (or starts) group-level aggregation calculations.
1764
+ *
1765
+ * @public
1766
+ * @param {Boolean} value
1767
+ */
1646
1768
  setSuspended(value) {
1647
1769
  assert.argumentIsRequired(value, 'value', Boolean);
1648
1770
 
1649
1771
  if (this._suspended !== value) {
1650
- if (this._suspended = value) {
1772
+ this._suspended = value;
1773
+
1774
+ if (!this._suspended) {
1651
1775
  this.refresh();
1652
1776
  }
1653
1777
  }
@@ -1973,11 +2097,12 @@ module.exports = (() => {
1973
2097
  return PositionGroup;
1974
2098
  })();
1975
2099
 
1976
- },{"./../data/InstrumentType":1,"@barchart/common-js/collections/specialized/DisposableStack":13,"@barchart/common-js/lang/Currency":14,"@barchart/common-js/lang/Decimal":16,"@barchart/common-js/lang/Rate":19,"@barchart/common-js/lang/array":20,"@barchart/common-js/lang/assert":21,"@barchart/common-js/lang/formatter":22,"@barchart/common-js/lang/is":23,"@barchart/common-js/messaging/Event":25}],6:[function(require,module,exports){
2100
+ },{"./../data/InstrumentType":1,"@barchart/common-js/collections/specialized/DisposableStack":14,"@barchart/common-js/lang/Currency":15,"@barchart/common-js/lang/Decimal":17,"@barchart/common-js/lang/Rate":20,"@barchart/common-js/lang/array":21,"@barchart/common-js/lang/assert":22,"@barchart/common-js/lang/formatter":23,"@barchart/common-js/lang/is":24,"@barchart/common-js/messaging/Event":26}],6:[function(require,module,exports){
1977
2101
  const array = require('@barchart/common-js/lang/array'),
1978
2102
  assert = require('@barchart/common-js/lang/assert'),
1979
2103
  Currency = require('@barchart/common-js/lang/Currency'),
1980
2104
  Decimal = require('@barchart/common-js/lang/Decimal'),
2105
+ Disposable = require('@barchart/common-js/lang/Disposable'),
1981
2106
  Event = require('@barchart/common-js/messaging/Event'),
1982
2107
  is = require('@barchart/common-js/lang/is');
1983
2108
 
@@ -1997,8 +2122,10 @@ module.exports = (() => {
1997
2122
  * @param {Object} currentSummary
1998
2123
  * @param {Array.<Object>} previousSummaries
1999
2124
  */
2000
- class PositionItem {
2125
+ class PositionItem extends Disposable {
2001
2126
  constructor(portfolio, position, currentSummary, previousSummaries) {
2127
+ super();
2128
+
2002
2129
  this._portfolio = portfolio;
2003
2130
  this._position = position;
2004
2131
  this._currency = position.instrument.currency || Currency.CAD;
@@ -2043,6 +2170,7 @@ module.exports = (() => {
2043
2170
  this._quoteChangedEvent = new Event(this);
2044
2171
  this._newsExistsChangedEvent = new Event(this);
2045
2172
  this._fundamentalDataChangeEvent = new Event(this);
2173
+ this._positionItemDisposeEvent = new Event(this);
2046
2174
  }
2047
2175
 
2048
2176
  /**
@@ -2125,6 +2253,10 @@ module.exports = (() => {
2125
2253
  setQuote(quote) {
2126
2254
  assert.argumentIsRequired(quote, 'quote', Object);
2127
2255
 
2256
+ if (this.getIsDisposed()) {
2257
+ return;
2258
+ }
2259
+
2128
2260
  if (this._currentPricePrevious !== quote.lastPrice) {
2129
2261
  calculatePriceData(this, quote.lastPrice);
2130
2262
 
@@ -2146,6 +2278,10 @@ module.exports = (() => {
2146
2278
  setPositionFundamentalData(data) {
2147
2279
  assert.argumentIsRequired(data, 'data', Object);
2148
2280
 
2281
+ if (this.getIsDisposed()) {
2282
+ return;
2283
+ }
2284
+
2149
2285
  this._fundamentalDataChangeEvent.fire(this._data.fundamental = data);
2150
2286
  }
2151
2287
 
@@ -2159,6 +2295,10 @@ module.exports = (() => {
2159
2295
  setNewsArticleExists(value) {
2160
2296
  assert.argumentIsRequired(value, 'value', Boolean);
2161
2297
 
2298
+ if (this.getIsDisposed()) {
2299
+ return;
2300
+ }
2301
+
2162
2302
  if (this._data.newsExists !== value) {
2163
2303
  this._newsExistsChangedEvent.fire(this._data.newsExists = value);
2164
2304
  }
@@ -2198,6 +2338,26 @@ module.exports = (() => {
2198
2338
  return this._newsExistsChangedEvent.register(handler);
2199
2339
  }
2200
2340
 
2341
+ /**
2342
+ * Registers an observer for object disposal.
2343
+ *
2344
+ * @public
2345
+ * @param {Function} handler
2346
+ * @returns {Disposable}
2347
+ */
2348
+ registerPositionItemDisposeHandler(handler) {
2349
+ return this._positionItemDisposeEvent.register(handler);
2350
+ }
2351
+
2352
+ _onDispose() {
2353
+ this._positionItemDisposeEvent.fire(this);
2354
+
2355
+ this._quoteChangedEvent.clear();
2356
+ this._newsExistsChangedEvent.clear();
2357
+ this._fundamentalDataChangeEvent.clear();
2358
+ this._positionItemDisposeEvent.clear();
2359
+ }
2360
+
2201
2361
  toString() {
2202
2362
  return '[PositionItem]';
2203
2363
  }
@@ -2341,13 +2501,15 @@ module.exports = (() => {
2341
2501
  return PositionItem;
2342
2502
  })();
2343
2503
 
2344
- },{"./../data/InstrumentType":1,"@barchart/common-js/lang/Currency":14,"@barchart/common-js/lang/Decimal":16,"@barchart/common-js/lang/array":20,"@barchart/common-js/lang/assert":21,"@barchart/common-js/lang/is":23,"@barchart/common-js/messaging/Event":25}],7:[function(require,module,exports){
2504
+ },{"./../data/InstrumentType":1,"@barchart/common-js/lang/Currency":15,"@barchart/common-js/lang/Decimal":17,"@barchart/common-js/lang/Disposable":18,"@barchart/common-js/lang/array":21,"@barchart/common-js/lang/assert":22,"@barchart/common-js/lang/is":24,"@barchart/common-js/messaging/Event":26}],7:[function(require,module,exports){
2345
2505
  const assert = require('@barchart/common-js/lang/assert'),
2346
2506
  Currency = require('@barchart/common-js/lang/Currency'),
2347
2507
  is = require('@barchart/common-js/lang/is');
2348
2508
 
2349
2509
  const InstrumentType = require('./../../data/InstrumentType');
2350
2510
 
2511
+ const PositionLevelType = require('./PositionLevelType');
2512
+
2351
2513
  module.exports = (() => {
2352
2514
  'use strict';
2353
2515
 
@@ -2364,11 +2526,12 @@ module.exports = (() => {
2364
2526
  * @param {Array.<PositionLevelDefinition~RequiredGroup>=} requiredGroups
2365
2527
  * @param {Boolean=} single
2366
2528
  * @param {Boolean=} aggregateCash
2367
- * @param {Function=} injectPositions
2529
+ * @param {Function=} requiredGroupGenerator
2368
2530
  */
2369
2531
  class PositionLevelDefinition {
2370
- constructor(name, keySelector, descriptionSelector, currencySelector, requiredGroups, single, aggregateCash, requiredGroupGenerator) {
2532
+ constructor(name, type, keySelector, descriptionSelector, currencySelector, requiredGroups, single, aggregateCash, requiredGroupGenerator) {
2371
2533
  assert.argumentIsRequired(name, 'name', String);
2534
+ assert.argumentIsRequired(type, 'type', PositionLevelType, 'PositionLevelType');
2372
2535
  assert.argumentIsRequired(keySelector, 'keySelector', Function);
2373
2536
  assert.argumentIsRequired(descriptionSelector, 'descriptionSelector', Function);
2374
2537
  assert.argumentIsRequired(currencySelector, 'currencySelector', Function);
@@ -2382,6 +2545,7 @@ module.exports = (() => {
2382
2545
  assert.argumentIsOptional(requiredGroupGenerator, 'requiredGroupGenerator', Function);
2383
2546
 
2384
2547
  this._name = name;
2548
+ this._type = type;
2385
2549
 
2386
2550
  this._keySelector = keySelector;
2387
2551
  this._descriptionSelector = descriptionSelector;
@@ -2405,6 +2569,16 @@ module.exports = (() => {
2405
2569
  return this._name;
2406
2570
  }
2407
2571
 
2572
+ /**
2573
+ * A general description of the type of items grouped together.
2574
+ *
2575
+ * @public
2576
+ * @return {PositionLevelType}
2577
+ */
2578
+ get type() {
2579
+ return this._type;
2580
+ }
2581
+
2408
2582
  /**
2409
2583
  * A function, when given a {@link PositionItem} returns a string that is used
2410
2584
  * to group {@link PositionItem} instances into different groups.
@@ -2608,7 +2782,38 @@ module.exports = (() => {
2608
2782
  return PositionLevelDefinition;
2609
2783
  })();
2610
2784
 
2611
- },{"./../../data/InstrumentType":1,"@barchart/common-js/lang/Currency":14,"@barchart/common-js/lang/assert":21,"@barchart/common-js/lang/is":23}],8:[function(require,module,exports){
2785
+ },{"./../../data/InstrumentType":1,"./PositionLevelType":8,"@barchart/common-js/lang/Currency":15,"@barchart/common-js/lang/assert":22,"@barchart/common-js/lang/is":24}],8:[function(require,module,exports){
2786
+ const Enum = require('@barchart/common-js/lang/Enum');
2787
+
2788
+ module.exports = (() => {
2789
+ 'use strict';
2790
+
2791
+ class PositionLevelType extends Enum {
2792
+ constructor(code) {
2793
+ super(code, code);
2794
+ }
2795
+
2796
+ static get PORTFOLIO() {
2797
+ return portfolio;
2798
+ }
2799
+
2800
+ static get POSITION() {
2801
+ return position;
2802
+ }
2803
+
2804
+ static get OTHER() {
2805
+ return other;
2806
+ }
2807
+ }
2808
+
2809
+ const portfolio = new PositionLevelType('PORTFOLIO');
2810
+ const position = new PositionLevelType('POSITION');
2811
+ const other = new PositionLevelType('OTHER');
2812
+
2813
+ return PositionLevelType;
2814
+ })();
2815
+
2816
+ },{"@barchart/common-js/lang/Enum":19}],9:[function(require,module,exports){
2612
2817
  const assert = require('@barchart/common-js/lang/assert');
2613
2818
 
2614
2819
  const PositionLevelDefinition = require('./PositionLevelDefinition');
@@ -2654,7 +2859,7 @@ module.exports = (() => {
2654
2859
  * bottom-most level of the tree (i.e. leaf nodes).
2655
2860
  *
2656
2861
  * @public
2657
- * @returns {Array.<PositionTreeDefinition>}
2862
+ * @returns {Array.<PositionLevelDefinitions>}
2658
2863
  */
2659
2864
  get definitions() {
2660
2865
  return this._definitions;
@@ -2679,7 +2884,7 @@ module.exports = (() => {
2679
2884
  return PositionTreeDefinitions;
2680
2885
  })();
2681
2886
 
2682
- },{"./PositionLevelDefinition":7,"@barchart/common-js/lang/assert":21}],9:[function(require,module,exports){
2887
+ },{"./PositionLevelDefinition":7,"@barchart/common-js/lang/assert":22}],10:[function(require,module,exports){
2683
2888
  'use strict';
2684
2889
 
2685
2890
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
@@ -2811,7 +3016,7 @@ module.exports = function () {
2811
3016
  return Stack;
2812
3017
  }();
2813
3018
 
2814
- },{"./../lang/assert":21}],10:[function(require,module,exports){
3019
+ },{"./../lang/assert":22}],11:[function(require,module,exports){
2815
3020
  'use strict';
2816
3021
 
2817
3022
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
@@ -3120,7 +3325,7 @@ module.exports = function () {
3120
3325
  return Tree;
3121
3326
  }();
3122
3327
 
3123
- },{"./../lang/is":23}],11:[function(require,module,exports){
3328
+ },{"./../lang/is":24}],12:[function(require,module,exports){
3124
3329
  'use strict';
3125
3330
 
3126
3331
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
@@ -3264,7 +3469,7 @@ module.exports = function () {
3264
3469
  return ComparatorBuilder;
3265
3470
  }();
3266
3471
 
3267
- },{"./../../lang/assert":21,"./comparators":12}],12:[function(require,module,exports){
3472
+ },{"./../../lang/assert":22,"./comparators":13}],13:[function(require,module,exports){
3268
3473
  'use strict';
3269
3474
 
3270
3475
  var assert = require('./../../lang/assert');
@@ -3339,7 +3544,7 @@ module.exports = function () {
3339
3544
  };
3340
3545
  }();
3341
3546
 
3342
- },{"./../../lang/assert":21}],13:[function(require,module,exports){
3547
+ },{"./../../lang/assert":22}],14:[function(require,module,exports){
3343
3548
  'use strict';
3344
3549
 
3345
3550
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
@@ -3447,7 +3652,7 @@ module.exports = function () {
3447
3652
  return DisposableStack;
3448
3653
  }();
3449
3654
 
3450
- },{"./../../lang/Disposable":17,"./../../lang/assert":21,"./../../lang/is":23,"./../Stack":9}],14:[function(require,module,exports){
3655
+ },{"./../../lang/Disposable":18,"./../../lang/assert":22,"./../../lang/is":24,"./../Stack":10}],15:[function(require,module,exports){
3451
3656
  'use strict';
3452
3657
 
3453
3658
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
@@ -3590,7 +3795,7 @@ module.exports = function () {
3590
3795
  return Currency;
3591
3796
  }();
3592
3797
 
3593
- },{"./Enum":18,"./assert":21,"./is":23}],15:[function(require,module,exports){
3798
+ },{"./Enum":19,"./assert":22,"./is":24}],16:[function(require,module,exports){
3594
3799
  'use strict';
3595
3800
 
3596
3801
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
@@ -4143,7 +4348,7 @@ module.exports = function () {
4143
4348
  return Day;
4144
4349
  }();
4145
4350
 
4146
- },{"./../collections/sorting/ComparatorBuilder":11,"./../collections/sorting/comparators":12,"./assert":21,"./is":23}],16:[function(require,module,exports){
4351
+ },{"./../collections/sorting/ComparatorBuilder":12,"./../collections/sorting/comparators":13,"./assert":22,"./is":24}],17:[function(require,module,exports){
4147
4352
  'use strict';
4148
4353
 
4149
4354
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
@@ -4723,7 +4928,7 @@ module.exports = function () {
4723
4928
  return Decimal;
4724
4929
  }();
4725
4930
 
4726
- },{"./Enum":18,"./assert":21,"./is":23,"big.js":26}],17:[function(require,module,exports){
4931
+ },{"./Enum":19,"./assert":22,"./is":24,"big.js":27}],18:[function(require,module,exports){
4727
4932
  'use strict';
4728
4933
 
4729
4934
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
@@ -4872,7 +5077,7 @@ module.exports = function () {
4872
5077
  return Disposable;
4873
5078
  }();
4874
5079
 
4875
- },{"./assert":21}],18:[function(require,module,exports){
5080
+ },{"./assert":22}],19:[function(require,module,exports){
4876
5081
  'use strict';
4877
5082
 
4878
5083
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
@@ -5014,7 +5219,7 @@ module.exports = function () {
5014
5219
  return Enum;
5015
5220
  }();
5016
5221
 
5017
- },{"./assert":21}],19:[function(require,module,exports){
5222
+ },{"./assert":22}],20:[function(require,module,exports){
5018
5223
  'use strict';
5019
5224
 
5020
5225
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
@@ -5269,7 +5474,7 @@ module.exports = function () {
5269
5474
  return Rate;
5270
5475
  }();
5271
5476
 
5272
- },{"./Currency":14,"./Decimal":16,"./assert":21,"./memoize":24}],20:[function(require,module,exports){
5477
+ },{"./Currency":15,"./Decimal":17,"./assert":22,"./memoize":25}],21:[function(require,module,exports){
5273
5478
  'use strict';
5274
5479
 
5275
5480
  var assert = require('./assert'),
@@ -5650,7 +5855,7 @@ module.exports = function () {
5650
5855
  };
5651
5856
  }();
5652
5857
 
5653
- },{"./assert":21,"./is":23}],21:[function(require,module,exports){
5858
+ },{"./assert":22,"./is":24}],22:[function(require,module,exports){
5654
5859
  'use strict';
5655
5860
 
5656
5861
  var is = require('./is');
@@ -5798,7 +6003,7 @@ module.exports = function () {
5798
6003
  };
5799
6004
  }();
5800
6005
 
5801
- },{"./is":23}],22:[function(require,module,exports){
6006
+ },{"./is":24}],23:[function(require,module,exports){
5802
6007
  'use strict';
5803
6008
 
5804
6009
  module.exports = function () {
@@ -5863,7 +6068,7 @@ module.exports = function () {
5863
6068
  };
5864
6069
  }();
5865
6070
 
5866
- },{}],23:[function(require,module,exports){
6071
+ },{}],24:[function(require,module,exports){
5867
6072
  'use strict';
5868
6073
 
5869
6074
  var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
@@ -6086,7 +6291,7 @@ module.exports = function () {
6086
6291
  };
6087
6292
  }();
6088
6293
 
6089
- },{}],24:[function(require,module,exports){
6294
+ },{}],25:[function(require,module,exports){
6090
6295
  'use strict';
6091
6296
 
6092
6297
  var assert = require('./assert'),
@@ -6159,7 +6364,7 @@ module.exports = function () {
6159
6364
  };
6160
6365
  }();
6161
6366
 
6162
- },{"./assert":21,"./is":23}],25:[function(require,module,exports){
6367
+ },{"./assert":22,"./is":24}],26:[function(require,module,exports){
6163
6368
  'use strict';
6164
6369
 
6165
6370
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
@@ -6331,7 +6536,7 @@ module.exports = function () {
6331
6536
  return Event;
6332
6537
  }();
6333
6538
 
6334
- },{"./../lang/Disposable":17,"./../lang/assert":21}],26:[function(require,module,exports){
6539
+ },{"./../lang/Disposable":18,"./../lang/assert":22}],27:[function(require,module,exports){
6335
6540
  /*
6336
6541
  * big.js v5.0.3
6337
6542
  * A small, fast, easy-to-use library for arbitrary-precision decimal arithmetic.
@@ -7272,7 +7477,7 @@ module.exports = function () {
7272
7477
  }
7273
7478
  })(this);
7274
7479
 
7275
- },{}],27:[function(require,module,exports){
7480
+ },{}],28:[function(require,module,exports){
7276
7481
  const Day = require('@barchart/common-js/lang/Day'),
7277
7482
  Decimal = require('@barchart/common-js/lang/Decimal');
7278
7483
 
@@ -7629,7 +7834,7 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
7629
7834
  });
7630
7835
  });
7631
7836
 
7632
- },{"./../../../lib/data/PositionSummaryFrame":2,"./../../../lib/data/TransactionType":3,"@barchart/common-js/lang/Day":15,"@barchart/common-js/lang/Decimal":16}],28:[function(require,module,exports){
7837
+ },{"./../../../lib/data/PositionSummaryFrame":2,"./../../../lib/data/TransactionType":3,"@barchart/common-js/lang/Day":16,"@barchart/common-js/lang/Decimal":17}],29:[function(require,module,exports){
7633
7838
  const Currency = require('@barchart/common-js/lang/Currency'),
7634
7839
  Decimal = require('@barchart/common-js/lang/Decimal');
7635
7840
 
@@ -7637,6 +7842,7 @@ const InstrumentType = require('./../../../lib/data/InstrumentType');
7637
7842
 
7638
7843
  const PositionContainer = require('./../../../lib/processing/PositionContainer'),
7639
7844
  PositionLevelDefinition = require('./../../../lib/processing/definitions/PositionLevelDefinition'),
7845
+ PositionLevelType = require('./../../../lib/processing/definitions/PositionLevelType'),
7640
7846
  PositionTreeDefinition = require('./../../../lib/processing/definitions/PositionTreeDefinition');
7641
7847
 
7642
7848
  describe('When a position container data is gathered', () => {
@@ -7698,9 +7904,9 @@ describe('When a position container data is gathered', () => {
7698
7904
  beforeEach(() => {
7699
7905
  definitions = [
7700
7906
  new PositionTreeDefinition(name = 'the only tree', [
7701
- new PositionLevelDefinition('Total', x => 'totals', x => 'Total', x => Currency.CAD),
7702
- new PositionLevelDefinition('Portfolio', x => x.portfolio.portfolio, x => x.portfolio.name, x => Currency.CAD),
7703
- new PositionLevelDefinition('Position', x => x.position.position, x => x.position.instrument.symbol.barchart, x => x.position.instrument.currency)
7907
+ new PositionLevelDefinition('Total', PositionLevelType.OTHER, x => 'totals', x => 'Total', x => Currency.CAD),
7908
+ new PositionLevelDefinition('Portfolio', PositionLevelType.PORTFOLIO, x => x.portfolio.portfolio, x => x.portfolio.name, x => Currency.CAD),
7909
+ new PositionLevelDefinition('Position', PositionLevelType.POSITION, x => x.position.position, x => x.position.instrument.symbol.barchart, x => x.position.instrument.currency)
7704
7910
  ])
7705
7911
  ];
7706
7912
 
@@ -7738,4 +7944,4 @@ describe('When a position container data is gathered', () => {
7738
7944
  });
7739
7945
  });
7740
7946
 
7741
- },{"./../../../lib/data/InstrumentType":1,"./../../../lib/processing/PositionContainer":4,"./../../../lib/processing/definitions/PositionLevelDefinition":7,"./../../../lib/processing/definitions/PositionTreeDefinition":8,"@barchart/common-js/lang/Currency":14,"@barchart/common-js/lang/Decimal":16}]},{},[27,28]);
7947
+ },{"./../../../lib/data/InstrumentType":1,"./../../../lib/processing/PositionContainer":4,"./../../../lib/processing/definitions/PositionLevelDefinition":7,"./../../../lib/processing/definitions/PositionLevelType":8,"./../../../lib/processing/definitions/PositionTreeDefinition":9,"@barchart/common-js/lang/Currency":15,"@barchart/common-js/lang/Decimal":17}]},{},[28,29]);
@@ -5,6 +5,7 @@ const InstrumentType = require('./../../../lib/data/InstrumentType');
5
5
 
6
6
  const PositionContainer = require('./../../../lib/processing/PositionContainer'),
7
7
  PositionLevelDefinition = require('./../../../lib/processing/definitions/PositionLevelDefinition'),
8
+ PositionLevelType = require('./../../../lib/processing/definitions/PositionLevelType'),
8
9
  PositionTreeDefinition = require('./../../../lib/processing/definitions/PositionTreeDefinition');
9
10
 
10
11
  describe('When a position container data is gathered', () => {
@@ -66,9 +67,9 @@ describe('When a position container data is gathered', () => {
66
67
  beforeEach(() => {
67
68
  definitions = [
68
69
  new PositionTreeDefinition(name = 'the only tree', [
69
- new PositionLevelDefinition('Total', x => 'totals', x => 'Total', x => Currency.CAD),
70
- new PositionLevelDefinition('Portfolio', x => x.portfolio.portfolio, x => x.portfolio.name, x => Currency.CAD),
71
- new PositionLevelDefinition('Position', x => x.position.position, x => x.position.instrument.symbol.barchart, x => x.position.instrument.currency)
70
+ new PositionLevelDefinition('Total', PositionLevelType.OTHER, x => 'totals', x => 'Total', x => Currency.CAD),
71
+ new PositionLevelDefinition('Portfolio', PositionLevelType.PORTFOLIO, x => x.portfolio.portfolio, x => x.portfolio.name, x => Currency.CAD),
72
+ new PositionLevelDefinition('Position', PositionLevelType.POSITION, x => x.position.position, x => x.position.instrument.symbol.barchart, x => x.position.instrument.currency)
72
73
  ])
73
74
  ];
74
75