@barchart/portfolio-api-common 1.0.140 → 1.0.144

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.
@@ -4,6 +4,7 @@ const array = require('@barchart/common-js/lang/array'),
4
4
  comparators = require('@barchart/common-js/collections/sorting/comparators'),
5
5
  Currency = require('@barchart/common-js/lang/Currency'),
6
6
  Decimal = require('@barchart/common-js/lang/Decimal'),
7
+ DisposableStack = require('@barchart/common-js/collections/specialized/DisposableStack'),
7
8
  is = require('@barchart/common-js/lang/is'),
8
9
  Rate = require('@barchart/common-js/lang/Rate'),
9
10
  Tree = require('@barchart/common-js/collections/Tree');
@@ -47,6 +48,18 @@ module.exports = (() => {
47
48
  const currentSummaryFrame = PositionSummaryFrame.YTD;
48
49
  const currentSummaryRange = array.last(currentSummaryFrame.getRecentRanges(0));
49
50
 
51
+ this._groupBindings = { };
52
+
53
+ const addGroupBinding = (group, dispoable) => {
54
+ const id = group.id;
55
+
56
+ if (!this._groupBindings.hasOwnProperty(id)) {
57
+ this._groupBindings[id] = new DisposableStack();
58
+ }
59
+
60
+ this._groupBindings[id].push(dispoable);
61
+ };
62
+
50
63
  this._portfolios = portfolios.reduce((map, portfolio) => {
51
64
  map[portfolio.portfolio] = portfolio;
52
65
 
@@ -214,12 +227,30 @@ module.exports = (() => {
214
227
 
215
228
  compositeGroups.sort(builder.toComparator());
216
229
 
230
+ const initializeGroupObservers = (group, groupTree) => {
231
+ addGroupBinding(group, group.registerGroupExcludedChangeHandler((excluded, sender) => {
232
+ groupTree.climb((parentGroup, parentTree) => {
233
+ let excludedItems = [ ];
234
+
235
+ currentTree.walk((childGroup, childTree) => {
236
+ if (childGroup.excluded) {
237
+ excludedItems = excludedItems.concat(childGroup.items);
238
+ }
239
+ }, false, false);
240
+
241
+ parentGroup.setExcludedItems(array.unique(excludedItems));
242
+ }, false);
243
+ }));
244
+ };
245
+
217
246
  compositeGroups.forEach((group) => {
218
247
  const childTree = currentTree.addChild(group);
219
248
 
220
- group.registerMarketPercentChangeHandler(() => {
249
+ initializeGroupObservers(group, childTree);
250
+
251
+ addGroupBinding(group, group.registerMarketPercentChangeHandler(() => {
221
252
  currentTree.walk((childGroup) => childGroup.refreshMarketPercent());
222
- });
253
+ }));
223
254
 
224
255
  createGroups(childTree, group.items, array.dropLeft(levelDefinitions));
225
256
  });
@@ -332,12 +363,21 @@ module.exports = (() => {
332
363
  * @param {String} symbol
333
364
  * @param {Object} data
334
365
  */
335
- setPositionFundamentalData(symbol, data) {
366
+ setPositionFundamentalData(symbol, display, data) {
336
367
  assert.argumentIsRequired(symbol, 'symbol', String);
368
+ assert.argumentIsRequired(display, 'display', Boolean);
337
369
  assert.argumentIsRequired(data, 'data', Object);
338
370
 
339
- if (this._symbols.hasOwnProperty(symbol)) {
340
- this._symbols[symbol].forEach(item => item.setPositionFundamentalData(data));
371
+ let map;
372
+
373
+ if (display) {
374
+ map = this._symbolsDisplay;
375
+ } else {
376
+ map = this._symbols;
377
+ }
378
+
379
+ if (map.hasOwnProperty(symbol)) {
380
+ map[symbol].forEach(item => item.setPositionFundamentalData(data));
341
381
  }
342
382
  }
343
383
 
@@ -370,6 +410,7 @@ module.exports = (() => {
370
410
  /**
371
411
  * Returns a single level of grouping from one of the internal trees.
372
412
  *
413
+ * @public
373
414
  * @param {String} name
374
415
  * @param {Array.<String> keys
375
416
  * @returns {PositionGroup}
@@ -385,6 +426,7 @@ module.exports = (() => {
385
426
  * Returns all child groups from a level of grouping within one of
386
427
  * the internal trees.
387
428
  *
429
+ * @public
388
430
  * @param {String} name
389
431
  * @param {Array.<String> keys
390
432
  * @returns {Array.<PositionGroup>}
@@ -396,6 +438,13 @@ module.exports = (() => {
396
438
  return findNode(this._trees[name], keys).getChildren().map(node => node.getValue());
397
439
  }
398
440
 
441
+ /**
442
+ * Returns all positions for the given portfolio.
443
+ *
444
+ * @public
445
+ * @param {String} portfolio
446
+ * @return {Array.<Object>}
447
+ */
399
448
  getPositions(portfolio) {
400
449
  return this._items.reduce((positions, item) => {
401
450
  if (item.position.portfolio === portfolio) {
@@ -1,6 +1,8 @@
1
- const assert = require('@barchart/common-js/lang/assert'),
1
+ const array = require('@barchart/common-js/lang/array'),
2
+ assert = require('@barchart/common-js/lang/assert'),
2
3
  Currency = require('@barchart/common-js/lang/Currency'),
3
4
  Decimal = require('@barchart/common-js/lang/Decimal'),
5
+ DisposableStack = require('@barchart/common-js/collections/specialized/DisposableStack'),
4
6
  Event = require('@barchart/common-js/messaging/Event'),
5
7
  formatter = require('@barchart/common-js/lang/formatter'),
6
8
  is = require('@barchart/common-js/lang/is'),
@@ -9,6 +11,8 @@ const assert = require('@barchart/common-js/lang/assert'),
9
11
  module.exports = (() => {
10
12
  'use strict';
11
13
 
14
+ let counter = 0;
15
+
12
16
  /**
13
17
  * A grouping of {@link PositionItem} instances. The group aggregates from across
14
18
  * all the positions and performs currency translation, as necessary.
@@ -24,6 +28,7 @@ module.exports = (() => {
24
28
  */
25
29
  class PositionGroup {
26
30
  constructor(container, parent, items, currency, key, description, single) {
31
+ this._id = counter++;
27
32
  this._container = container;
28
33
  this._parent = parent || null;
29
34
 
@@ -41,9 +46,15 @@ module.exports = (() => {
41
46
  this._showClosedPositions = false;
42
47
 
43
48
  this._marketPercentChangeEvent = new Event(this);
44
- this._excludedChangeEvent = new Event(this);
49
+ this._groupExcludedChangeEvent = new Event(this);
45
50
  this._showClosedPositionsChangeEvent = new Event(this);
46
51
 
52
+ this._disposeStack = new DisposableStack();
53
+
54
+ this._excludedItems = [ ];
55
+ this._excludedItemMap = { };
56
+ this._consideredItems = this._items;
57
+
47
58
  this._dataFormat = { };
48
59
  this._dataActual = { };
49
60
 
@@ -74,6 +85,15 @@ module.exports = (() => {
74
85
  this._dataFormat.fundamental = { };
75
86
  }
76
87
 
88
+ this._dataActual.quoteLast = null;
89
+ this._dataActual.quoteOpen = null;
90
+ this._dataActual.quoteHigh = null;
91
+ this._dataActual.quoteLow = null;
92
+ this._dataActual.quoteChange = null;
93
+ this._dataActual.quoteChangePercent = null;
94
+ this._dataActual.quoteTime = null;
95
+ this._dataActual.quoteVolume = null;
96
+
77
97
  this._dataFormat.quoteLast = null;
78
98
  this._dataFormat.quoteOpen = null;
79
99
  this._dataFormat.quoteHigh = null;
@@ -117,44 +137,63 @@ module.exports = (() => {
117
137
  this._dataFormat.summaryTotalPreviousNegative = false;
118
138
 
119
139
  this._items.forEach((item) => {
120
- item.registerQuoteChangeHandler((quote, sender) => {
140
+ this._disposeStack.push(item.registerQuoteChangeHandler((quote, sender) => {
121
141
  if (this._single) {
122
142
  const precision = sender.position.instrument.currency.precision;
123
143
 
124
144
  this._dataActual.currentPrice = quote.lastPrice;
125
145
  this._dataFormat.currentPrice = formatNumber(this._dataActual.currentPrice, precision);
126
146
 
127
- this._dataFormat.quoteLast = formatNumber(quote.previousPrice, precision);
128
- this._dataFormat.quoteOpen = formatNumber(quote.openPrice, precision);
129
- this._dataFormat.quoteHigh = formatNumber(quote.highPrice, precision);
130
- this._dataFormat.quoteLow = formatNumber(quote.lowPrice, precision);
131
- this._dataFormat.quoteChange = formatNumber(quote.priceChange, precision);
132
- this._dataFormat.quoteChangePercent = formatPercent(new Decimal(quote.percentChange || 0), 2);
133
- this._dataFormat.quoteTime = quote.timeDisplay;
134
- this._dataFormat.quoteVolume = formatNumber(quote.volume, 0);
147
+ this._dataActual.quoteLast = quote.previousPrice;
148
+ this._dataActual.quoteOpen = quote.openPrice;
149
+ this._dataActual.quoteHigh = quote.highPrice;
150
+ this._dataActual.quoteLow = quote.lowPrice;
151
+ this._dataActual.quoteChange = quote.priceChange;
152
+ this._dataActual.quoteChangePercent = quote.percentChange;
153
+ this._dataActual.quoteTime = quote.timeDisplay;
154
+ this._dataActual.quoteVolume = quote.volume;
155
+
156
+ this._dataFormat.quoteLast = formatNumber(this._dataActual.quoteLast , precision);
157
+ this._dataFormat.quoteOpen = formatNumber(this._dataActual.quoteOpen, precision);
158
+ this._dataFormat.quoteHigh = formatNumber(this._dataActual.quoteHigh, precision);
159
+ this._dataFormat.quoteLow = formatNumber(this._dataActual.quoteLow, precision);
160
+ this._dataFormat.quoteChange = formatNumber(this._dataActual.quoteChange, precision);
161
+ this._dataFormat.quoteChangePercent = formatPercent(new Decimal(this._dataActual.quoteChangePercent || 0), 2);
162
+ this._dataFormat.quoteTime = this._dataActual.quoteTime;
163
+ this._dataFormat.quoteVolume = formatNumber(this._dataActual.quoteVolume, 0);
135
164
  } else {
136
165
  this._dataActual.currentPrice = null;
137
166
  this._dataFormat.currentPrice = null;
138
167
  }
139
168
 
140
169
  calculatePriceData(this, this._container.getForexQuotes(), sender, false);
141
- });
170
+ }));
142
171
 
143
172
  if (this._single) {
144
- item.registerNewsExistsChangeHandler((exists, sender) => {
173
+ this._disposeStack.push(item.registerNewsExistsChangeHandler((exists, sender) => {
145
174
  this._dataActual.newsExists = exists;
146
175
  this._dataFormat.newsExists = exists;
147
- });
176
+ }));
148
177
 
149
- item.registerFundamentalDataChangeHandler((data, sender) => {
178
+ this._disposeStack.push(item.registerFundamentalDataChangeHandler((data, sender) => {
150
179
  this._dataFormat.fundamental = data;
151
- });
180
+ }));
152
181
  }
153
182
  });
154
183
 
155
184
  this.refresh();
156
185
  }
157
186
 
187
+ /**
188
+ * A unique (and otherwise meaningless) idenfitifer for the group.
189
+ *
190
+ * @public
191
+ * @returns {Number}
192
+ */
193
+ get id() {
194
+ return this._id;
195
+ }
196
+
158
197
  /**
159
198
  * The key of the group.
160
199
  *
@@ -240,6 +279,25 @@ module.exports = (() => {
240
279
  return this._excluded;
241
280
  }
242
281
 
282
+ /**
283
+ * Sets the list of items which are excluded from group aggregation calculations.
284
+ *
285
+ * @public
286
+ * @param {Array.<Object>} items
287
+ */
288
+ setExcludedItems(items) {
289
+ this._excludedItems = items;
290
+ this._consideredItems = array.difference(this._items, this._excludedItems);
291
+
292
+ this._excludedItemMap = this._excludedItems.reduce((map, item) => {
293
+ const key = item.position.position;
294
+
295
+ map[key] = item;
296
+ }, { });
297
+
298
+ this.refresh();
299
+ }
300
+
243
301
  /**
244
302
  * Causes aggregated data to be recalculated using a new exchange rate.
245
303
  *
@@ -256,7 +314,7 @@ module.exports = (() => {
256
314
  assert.argumentIsRequired(value, 'value', Boolean);
257
315
 
258
316
  if (this._excluded !== value) {
259
- this._excludedChangeEvent(this._excluded = value);
317
+ this._groupExcludedChangeEvent.fire(this._excluded = value);
260
318
  }
261
319
  }
262
320
 
@@ -300,8 +358,27 @@ module.exports = (() => {
300
358
  calculateMarketPercent(this, this._container.getForexQuotes(), true);
301
359
  }
302
360
 
361
+ /**
362
+ * Adds an observer for change in the market percentage of the group.
363
+ *
364
+ * @public
365
+ * @param {Function} handler
366
+ * @return {Disposable}
367
+ */
303
368
  registerMarketPercentChangeHandler(handler) {
304
- this._marketPercentChangeEvent.register(handler);
369
+ return this._marketPercentChangeEvent.register(handler);
370
+ }
371
+
372
+ /**
373
+ * Adds an observer for changes to the exclusion of the group
374
+ * from higher level aggregations.
375
+ *
376
+ * @public
377
+ * @param {Function} handler
378
+ * @return {Disposable}
379
+ */
380
+ registerGroupExcludedChangeHandler(handler) {
381
+ return this._groupExcludedChangeEvent.register(handler);
305
382
  }
306
383
 
307
384
  toString() {
@@ -347,7 +424,7 @@ module.exports = (() => {
347
424
 
348
425
  const currency = group.currency;
349
426
 
350
- const items = group._items;
427
+ const items = group._consideredItems;
351
428
 
352
429
  group._bypassCurrencyTranslation = items.every(item => item.currency === currency);
353
430
 
@@ -415,11 +492,16 @@ module.exports = (() => {
415
492
  }
416
493
 
417
494
  const parent = group._parent;
495
+ const currency = group.currency;
418
496
 
419
497
  const actual = group._dataActual;
420
498
  const format = group._dataFormat;
421
499
 
422
- const currency = group.currency;
500
+ const refresh = (is.boolean(forceRefresh) && forceRefresh) || (actual.market === null || actual.unrealizedToday === null || actual.total === null);
501
+
502
+ if (!refresh && group._excludedItemMap.hasOwnProperty(item.position.position)) {
503
+ return;
504
+ }
423
505
 
424
506
  const translate = (item, value) => {
425
507
  let translated;
@@ -433,12 +515,10 @@ module.exports = (() => {
433
515
  return translated;
434
516
  };
435
517
 
436
- const refresh = (is.boolean(forceRefresh) && forceRefresh) || (actual.market === null || actual.unrealizedToday === null || actual.total === null);
437
-
438
518
  let updates;
439
519
 
440
520
  if (refresh) {
441
- const items = group._items;
521
+ const items = group._consideredItems;
442
522
 
443
523
  updates = items.reduce((updates, item) => {
444
524
  updates.market = updates.market.add(translate(item, item.data.market));
@@ -453,7 +533,6 @@ module.exports = (() => {
453
533
  unrealized: Decimal.ZERO,
454
534
  unrealizedToday: Decimal.ZERO,
455
535
  summaryTotalCurrent: Decimal.ZERO
456
-
457
536
  });
458
537
  } else {
459
538
  updates = {
@@ -196,9 +196,10 @@ module.exports = (() => {
196
196
  *
197
197
  * @public
198
198
  * @param {Function} handler
199
+ * @returns {Disposable}
199
200
  */
200
201
  registerQuoteChangeHandler(handler) {
201
- this._quoteChangedEvent.register(handler);
202
+ return this._quoteChangedEvent.register(handler);
202
203
  }
203
204
 
204
205
  /**
@@ -206,9 +207,10 @@ module.exports = (() => {
206
207
  *
207
208
  * @public
208
209
  * @param {Function} handler
210
+ * @returns {Disposable}
209
211
  */
210
212
  registerFundamentalDataChangeHandler(handler) {
211
- this._fundamentalDataChangeEvent.register(handler);
213
+ return this._fundamentalDataChangeEvent.register(handler);
212
214
  }
213
215
 
214
216
  /**
@@ -216,9 +218,10 @@ module.exports = (() => {
216
218
  *
217
219
  * @public
218
220
  * @param {Function} handler
221
+ * @returns {Disposable}
219
222
  */
220
223
  registerNewsExistsChangeHandler(handler) {
221
- this._newsExistsChangedEvent.register(handler);
224
+ return this._newsExistsChangedEvent.register(handler);
222
225
  }
223
226
 
224
227
  toString() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.0.140",
3
+ "version": "1.0.144",
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":16,"@barchart/common-js/lang/assert":19}],2:[function(require,module,exports){
119
+ },{"@barchart/common-js/lang/Enum":18,"@barchart/common-js/lang/assert":21}],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":13,"@barchart/common-js/lang/Decimal":14,"@barchart/common-js/lang/Enum":16,"@barchart/common-js/lang/array":18,"@barchart/common-js/lang/assert":19,"@barchart/common-js/lang/is":21}],3:[function(require,module,exports){
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){
377
377
  const assert = require('@barchart/common-js/lang/assert'),
378
378
  Enum = require('@barchart/common-js/lang/Enum');
379
379
 
@@ -713,13 +713,14 @@ module.exports = (() => {
713
713
  return TransactionType;
714
714
  })();
715
715
 
716
- },{"@barchart/common-js/lang/Enum":16,"@barchart/common-js/lang/assert":19}],4:[function(require,module,exports){
716
+ },{"@barchart/common-js/lang/Enum":18,"@barchart/common-js/lang/assert":21}],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'),
720
720
  comparators = require('@barchart/common-js/collections/sorting/comparators'),
721
721
  Currency = require('@barchart/common-js/lang/Currency'),
722
722
  Decimal = require('@barchart/common-js/lang/Decimal'),
723
+ DisposableStack = require('@barchart/common-js/collections/specialized/DisposableStack'),
723
724
  is = require('@barchart/common-js/lang/is'),
724
725
  Rate = require('@barchart/common-js/lang/Rate'),
725
726
  Tree = require('@barchart/common-js/collections/Tree');
@@ -763,6 +764,18 @@ module.exports = (() => {
763
764
  const currentSummaryFrame = PositionSummaryFrame.YTD;
764
765
  const currentSummaryRange = array.last(currentSummaryFrame.getRecentRanges(0));
765
766
 
767
+ this._groupBindings = { };
768
+
769
+ const addGroupBinding = (group, dispoable) => {
770
+ const id = group.id;
771
+
772
+ if (!this._groupBindings.hasOwnProperty(id)) {
773
+ this._groupBindings[id] = new DisposableStack();
774
+ }
775
+
776
+ this._groupBindings[id].push(dispoable);
777
+ };
778
+
766
779
  this._portfolios = portfolios.reduce((map, portfolio) => {
767
780
  map[portfolio.portfolio] = portfolio;
768
781
 
@@ -930,12 +943,30 @@ module.exports = (() => {
930
943
 
931
944
  compositeGroups.sort(builder.toComparator());
932
945
 
946
+ const initializeGroupObservers = (group, groupTree) => {
947
+ addGroupBinding(group, group.registerGroupExcludedChangeHandler((excluded, sender) => {
948
+ groupTree.climb((parentGroup, parentTree) => {
949
+ let excludedItems = [ ];
950
+
951
+ currentTree.walk((childGroup, childTree) => {
952
+ if (childGroup.excluded) {
953
+ excludedItems = excludedItems.concat(childGroup.items);
954
+ }
955
+ }, false, false);
956
+
957
+ parentGroup.setExcludedItems(array.unique(excludedItems));
958
+ }, false);
959
+ }));
960
+ };
961
+
933
962
  compositeGroups.forEach((group) => {
934
963
  const childTree = currentTree.addChild(group);
935
964
 
936
- group.registerMarketPercentChangeHandler(() => {
965
+ initializeGroupObservers(group, childTree);
966
+
967
+ addGroupBinding(group, group.registerMarketPercentChangeHandler(() => {
937
968
  currentTree.walk((childGroup) => childGroup.refreshMarketPercent());
938
- });
969
+ }));
939
970
 
940
971
  createGroups(childTree, group.items, array.dropLeft(levelDefinitions));
941
972
  });
@@ -1048,12 +1079,21 @@ module.exports = (() => {
1048
1079
  * @param {String} symbol
1049
1080
  * @param {Object} data
1050
1081
  */
1051
- setPositionFundamentalData(symbol, data) {
1082
+ setPositionFundamentalData(symbol, display, data) {
1052
1083
  assert.argumentIsRequired(symbol, 'symbol', String);
1084
+ assert.argumentIsRequired(display, 'display', Boolean);
1053
1085
  assert.argumentIsRequired(data, 'data', Object);
1054
1086
 
1055
- if (this._symbols.hasOwnProperty(symbol)) {
1056
- this._symbols[symbol].forEach(item => item.setPositionFundamentalData(data));
1087
+ let map;
1088
+
1089
+ if (display) {
1090
+ map = this._symbolsDisplay;
1091
+ } else {
1092
+ map = this._symbols;
1093
+ }
1094
+
1095
+ if (map.hasOwnProperty(symbol)) {
1096
+ map[symbol].forEach(item => item.setPositionFundamentalData(data));
1057
1097
  }
1058
1098
  }
1059
1099
 
@@ -1086,6 +1126,7 @@ module.exports = (() => {
1086
1126
  /**
1087
1127
  * Returns a single level of grouping from one of the internal trees.
1088
1128
  *
1129
+ * @public
1089
1130
  * @param {String} name
1090
1131
  * @param {Array.<String> keys
1091
1132
  * @returns {PositionGroup}
@@ -1101,6 +1142,7 @@ module.exports = (() => {
1101
1142
  * Returns all child groups from a level of grouping within one of
1102
1143
  * the internal trees.
1103
1144
  *
1145
+ * @public
1104
1146
  * @param {String} name
1105
1147
  * @param {Array.<String> keys
1106
1148
  * @returns {Array.<PositionGroup>}
@@ -1112,6 +1154,13 @@ module.exports = (() => {
1112
1154
  return findNode(this._trees[name], keys).getChildren().map(node => node.getValue());
1113
1155
  }
1114
1156
 
1157
+ /**
1158
+ * Returns all positions for the given portfolio.
1159
+ *
1160
+ * @public
1161
+ * @param {String} portfolio
1162
+ * @return {Array.<Object>}
1163
+ */
1115
1164
  getPositions(portfolio) {
1116
1165
  return this._items.reduce((positions, item) => {
1117
1166
  if (item.position.portfolio === portfolio) {
@@ -1166,10 +1215,12 @@ module.exports = (() => {
1166
1215
  return PositionContainer;
1167
1216
  })();
1168
1217
 
1169
- },{"./../data/PositionSummaryFrame":2,"./PositionGroup":5,"./PositionItem":6,"./definitions/PositionTreeDefinition":8,"@barchart/common-js/collections/Tree":9,"@barchart/common-js/collections/sorting/ComparatorBuilder":10,"@barchart/common-js/collections/sorting/comparators":11,"@barchart/common-js/lang/Currency":12,"@barchart/common-js/lang/Decimal":14,"@barchart/common-js/lang/Rate":17,"@barchart/common-js/lang/array":18,"@barchart/common-js/lang/assert":19,"@barchart/common-js/lang/is":21}],5:[function(require,module,exports){
1170
- const assert = require('@barchart/common-js/lang/assert'),
1218
+ },{"./../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){
1219
+ const array = require('@barchart/common-js/lang/array'),
1220
+ assert = require('@barchart/common-js/lang/assert'),
1171
1221
  Currency = require('@barchart/common-js/lang/Currency'),
1172
1222
  Decimal = require('@barchart/common-js/lang/Decimal'),
1223
+ DisposableStack = require('@barchart/common-js/collections/specialized/DisposableStack'),
1173
1224
  Event = require('@barchart/common-js/messaging/Event'),
1174
1225
  formatter = require('@barchart/common-js/lang/formatter'),
1175
1226
  is = require('@barchart/common-js/lang/is'),
@@ -1178,6 +1229,8 @@ const assert = require('@barchart/common-js/lang/assert'),
1178
1229
  module.exports = (() => {
1179
1230
  'use strict';
1180
1231
 
1232
+ let counter = 0;
1233
+
1181
1234
  /**
1182
1235
  * A grouping of {@link PositionItem} instances. The group aggregates from across
1183
1236
  * all the positions and performs currency translation, as necessary.
@@ -1193,6 +1246,7 @@ module.exports = (() => {
1193
1246
  */
1194
1247
  class PositionGroup {
1195
1248
  constructor(container, parent, items, currency, key, description, single) {
1249
+ this._id = counter++;
1196
1250
  this._container = container;
1197
1251
  this._parent = parent || null;
1198
1252
 
@@ -1210,9 +1264,15 @@ module.exports = (() => {
1210
1264
  this._showClosedPositions = false;
1211
1265
 
1212
1266
  this._marketPercentChangeEvent = new Event(this);
1213
- this._excludedChangeEvent = new Event(this);
1267
+ this._groupExcludedChangeEvent = new Event(this);
1214
1268
  this._showClosedPositionsChangeEvent = new Event(this);
1215
1269
 
1270
+ this._disposeStack = new DisposableStack();
1271
+
1272
+ this._excludedItems = [ ];
1273
+ this._excludedItemMap = { };
1274
+ this._consideredItems = this._items;
1275
+
1216
1276
  this._dataFormat = { };
1217
1277
  this._dataActual = { };
1218
1278
 
@@ -1243,6 +1303,15 @@ module.exports = (() => {
1243
1303
  this._dataFormat.fundamental = { };
1244
1304
  }
1245
1305
 
1306
+ this._dataActual.quoteLast = null;
1307
+ this._dataActual.quoteOpen = null;
1308
+ this._dataActual.quoteHigh = null;
1309
+ this._dataActual.quoteLow = null;
1310
+ this._dataActual.quoteChange = null;
1311
+ this._dataActual.quoteChangePercent = null;
1312
+ this._dataActual.quoteTime = null;
1313
+ this._dataActual.quoteVolume = null;
1314
+
1246
1315
  this._dataFormat.quoteLast = null;
1247
1316
  this._dataFormat.quoteOpen = null;
1248
1317
  this._dataFormat.quoteHigh = null;
@@ -1286,44 +1355,63 @@ module.exports = (() => {
1286
1355
  this._dataFormat.summaryTotalPreviousNegative = false;
1287
1356
 
1288
1357
  this._items.forEach((item) => {
1289
- item.registerQuoteChangeHandler((quote, sender) => {
1358
+ this._disposeStack.push(item.registerQuoteChangeHandler((quote, sender) => {
1290
1359
  if (this._single) {
1291
1360
  const precision = sender.position.instrument.currency.precision;
1292
1361
 
1293
1362
  this._dataActual.currentPrice = quote.lastPrice;
1294
1363
  this._dataFormat.currentPrice = formatNumber(this._dataActual.currentPrice, precision);
1295
1364
 
1296
- this._dataFormat.quoteLast = formatNumber(quote.previousPrice, precision);
1297
- this._dataFormat.quoteOpen = formatNumber(quote.openPrice, precision);
1298
- this._dataFormat.quoteHigh = formatNumber(quote.highPrice, precision);
1299
- this._dataFormat.quoteLow = formatNumber(quote.lowPrice, precision);
1300
- this._dataFormat.quoteChange = formatNumber(quote.priceChange, precision);
1301
- this._dataFormat.quoteChangePercent = formatPercent(new Decimal(quote.percentChange || 0), 2);
1302
- this._dataFormat.quoteTime = quote.timeDisplay;
1303
- this._dataFormat.quoteVolume = formatNumber(quote.volume, 0);
1365
+ this._dataActual.quoteLast = quote.previousPrice;
1366
+ this._dataActual.quoteOpen = quote.openPrice;
1367
+ this._dataActual.quoteHigh = quote.highPrice;
1368
+ this._dataActual.quoteLow = quote.lowPrice;
1369
+ this._dataActual.quoteChange = quote.priceChange;
1370
+ this._dataActual.quoteChangePercent = quote.percentChange;
1371
+ this._dataActual.quoteTime = quote.timeDisplay;
1372
+ this._dataActual.quoteVolume = quote.volume;
1373
+
1374
+ this._dataFormat.quoteLast = formatNumber(this._dataActual.quoteLast , precision);
1375
+ this._dataFormat.quoteOpen = formatNumber(this._dataActual.quoteOpen, precision);
1376
+ this._dataFormat.quoteHigh = formatNumber(this._dataActual.quoteHigh, precision);
1377
+ this._dataFormat.quoteLow = formatNumber(this._dataActual.quoteLow, precision);
1378
+ this._dataFormat.quoteChange = formatNumber(this._dataActual.quoteChange, precision);
1379
+ this._dataFormat.quoteChangePercent = formatPercent(new Decimal(this._dataActual.quoteChangePercent || 0), 2);
1380
+ this._dataFormat.quoteTime = this._dataActual.quoteTime;
1381
+ this._dataFormat.quoteVolume = formatNumber(this._dataActual.quoteVolume, 0);
1304
1382
  } else {
1305
1383
  this._dataActual.currentPrice = null;
1306
1384
  this._dataFormat.currentPrice = null;
1307
1385
  }
1308
1386
 
1309
1387
  calculatePriceData(this, this._container.getForexQuotes(), sender, false);
1310
- });
1388
+ }));
1311
1389
 
1312
1390
  if (this._single) {
1313
- item.registerNewsExistsChangeHandler((exists, sender) => {
1391
+ this._disposeStack.push(item.registerNewsExistsChangeHandler((exists, sender) => {
1314
1392
  this._dataActual.newsExists = exists;
1315
1393
  this._dataFormat.newsExists = exists;
1316
- });
1394
+ }));
1317
1395
 
1318
- item.registerFundamentalDataChangeHandler((data, sender) => {
1396
+ this._disposeStack.push(item.registerFundamentalDataChangeHandler((data, sender) => {
1319
1397
  this._dataFormat.fundamental = data;
1320
- });
1398
+ }));
1321
1399
  }
1322
1400
  });
1323
1401
 
1324
1402
  this.refresh();
1325
1403
  }
1326
1404
 
1405
+ /**
1406
+ * A unique (and otherwise meaningless) idenfitifer for the group.
1407
+ *
1408
+ * @public
1409
+ * @returns {Number}
1410
+ */
1411
+ get id() {
1412
+ return this._id;
1413
+ }
1414
+
1327
1415
  /**
1328
1416
  * The key of the group.
1329
1417
  *
@@ -1409,6 +1497,25 @@ module.exports = (() => {
1409
1497
  return this._excluded;
1410
1498
  }
1411
1499
 
1500
+ /**
1501
+ * Sets the list of items which are excluded from group aggregation calculations.
1502
+ *
1503
+ * @public
1504
+ * @param {Array.<Object>} items
1505
+ */
1506
+ setExcludedItems(items) {
1507
+ this._excludedItems = items;
1508
+ this._consideredItems = array.difference(this._items, this._excludedItems);
1509
+
1510
+ this._excludedItemMap = this._excludedItems.reduce((map, item) => {
1511
+ const key = item.position.position;
1512
+
1513
+ map[key] = item;
1514
+ }, { });
1515
+
1516
+ this.refresh();
1517
+ }
1518
+
1412
1519
  /**
1413
1520
  * Causes aggregated data to be recalculated using a new exchange rate.
1414
1521
  *
@@ -1425,7 +1532,7 @@ module.exports = (() => {
1425
1532
  assert.argumentIsRequired(value, 'value', Boolean);
1426
1533
 
1427
1534
  if (this._excluded !== value) {
1428
- this._excludedChangeEvent(this._excluded = value);
1535
+ this._groupExcludedChangeEvent.fire(this._excluded = value);
1429
1536
  }
1430
1537
  }
1431
1538
 
@@ -1469,8 +1576,27 @@ module.exports = (() => {
1469
1576
  calculateMarketPercent(this, this._container.getForexQuotes(), true);
1470
1577
  }
1471
1578
 
1579
+ /**
1580
+ * Adds an observer for change in the market percentage of the group.
1581
+ *
1582
+ * @public
1583
+ * @param {Function} handler
1584
+ * @return {Disposable}
1585
+ */
1472
1586
  registerMarketPercentChangeHandler(handler) {
1473
- this._marketPercentChangeEvent.register(handler);
1587
+ return this._marketPercentChangeEvent.register(handler);
1588
+ }
1589
+
1590
+ /**
1591
+ * Adds an observer for changes to the exclusion of the group
1592
+ * from higher level aggregations.
1593
+ *
1594
+ * @public
1595
+ * @param {Function} handler
1596
+ * @return {Disposable}
1597
+ */
1598
+ registerGroupExcludedChangeHandler(handler) {
1599
+ return this._groupExcludedChangeEvent.register(handler);
1474
1600
  }
1475
1601
 
1476
1602
  toString() {
@@ -1516,7 +1642,7 @@ module.exports = (() => {
1516
1642
 
1517
1643
  const currency = group.currency;
1518
1644
 
1519
- const items = group._items;
1645
+ const items = group._consideredItems;
1520
1646
 
1521
1647
  group._bypassCurrencyTranslation = items.every(item => item.currency === currency);
1522
1648
 
@@ -1584,11 +1710,16 @@ module.exports = (() => {
1584
1710
  }
1585
1711
 
1586
1712
  const parent = group._parent;
1713
+ const currency = group.currency;
1587
1714
 
1588
1715
  const actual = group._dataActual;
1589
1716
  const format = group._dataFormat;
1590
1717
 
1591
- const currency = group.currency;
1718
+ const refresh = (is.boolean(forceRefresh) && forceRefresh) || (actual.market === null || actual.unrealizedToday === null || actual.total === null);
1719
+
1720
+ if (!refresh && group._excludedItemMap.hasOwnProperty(item.position.position)) {
1721
+ return;
1722
+ }
1592
1723
 
1593
1724
  const translate = (item, value) => {
1594
1725
  let translated;
@@ -1602,12 +1733,10 @@ module.exports = (() => {
1602
1733
  return translated;
1603
1734
  };
1604
1735
 
1605
- const refresh = (is.boolean(forceRefresh) && forceRefresh) || (actual.market === null || actual.unrealizedToday === null || actual.total === null);
1606
-
1607
1736
  let updates;
1608
1737
 
1609
1738
  if (refresh) {
1610
- const items = group._items;
1739
+ const items = group._consideredItems;
1611
1740
 
1612
1741
  updates = items.reduce((updates, item) => {
1613
1742
  updates.market = updates.market.add(translate(item, item.data.market));
@@ -1622,7 +1751,6 @@ module.exports = (() => {
1622
1751
  unrealized: Decimal.ZERO,
1623
1752
  unrealizedToday: Decimal.ZERO,
1624
1753
  summaryTotalCurrent: Decimal.ZERO
1625
-
1626
1754
  });
1627
1755
  } else {
1628
1756
  updates = {
@@ -1734,7 +1862,7 @@ module.exports = (() => {
1734
1862
  return PositionGroup;
1735
1863
  })();
1736
1864
 
1737
- },{"@barchart/common-js/lang/Currency":12,"@barchart/common-js/lang/Decimal":14,"@barchart/common-js/lang/Rate":17,"@barchart/common-js/lang/assert":19,"@barchart/common-js/lang/formatter":20,"@barchart/common-js/lang/is":21,"@barchart/common-js/messaging/Event":23}],6:[function(require,module,exports){
1865
+ },{"@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){
1738
1866
  const array = require('@barchart/common-js/lang/array'),
1739
1867
  assert = require('@barchart/common-js/lang/assert'),
1740
1868
  Currency = require('@barchart/common-js/lang/Currency'),
@@ -1933,9 +2061,10 @@ module.exports = (() => {
1933
2061
  *
1934
2062
  * @public
1935
2063
  * @param {Function} handler
2064
+ * @returns {Disposable}
1936
2065
  */
1937
2066
  registerQuoteChangeHandler(handler) {
1938
- this._quoteChangedEvent.register(handler);
2067
+ return this._quoteChangedEvent.register(handler);
1939
2068
  }
1940
2069
 
1941
2070
  /**
@@ -1943,9 +2072,10 @@ module.exports = (() => {
1943
2072
  *
1944
2073
  * @public
1945
2074
  * @param {Function} handler
2075
+ * @returns {Disposable}
1946
2076
  */
1947
2077
  registerFundamentalDataChangeHandler(handler) {
1948
- this._fundamentalDataChangeEvent.register(handler);
2078
+ return this._fundamentalDataChangeEvent.register(handler);
1949
2079
  }
1950
2080
 
1951
2081
  /**
@@ -1953,9 +2083,10 @@ module.exports = (() => {
1953
2083
  *
1954
2084
  * @public
1955
2085
  * @param {Function} handler
2086
+ * @returns {Disposable}
1956
2087
  */
1957
2088
  registerNewsExistsChangeHandler(handler) {
1958
- this._newsExistsChangedEvent.register(handler);
2089
+ return this._newsExistsChangedEvent.register(handler);
1959
2090
  }
1960
2091
 
1961
2092
  toString() {
@@ -2100,7 +2231,7 @@ module.exports = (() => {
2100
2231
  return PositionItem;
2101
2232
  })();
2102
2233
 
2103
- },{"./../data/InstrumentType":1,"@barchart/common-js/lang/Currency":12,"@barchart/common-js/lang/Decimal":14,"@barchart/common-js/lang/array":18,"@barchart/common-js/lang/assert":19,"@barchart/common-js/lang/is":21,"@barchart/common-js/messaging/Event":23}],7:[function(require,module,exports){
2234
+ },{"./../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){
2104
2235
  const assert = require('@barchart/common-js/lang/assert'),
2105
2236
  is = require('@barchart/common-js/lang/is');
2106
2237
 
@@ -2256,7 +2387,7 @@ module.exports = (() => {
2256
2387
  return PositionLevelDefinition;
2257
2388
  })();
2258
2389
 
2259
- },{"@barchart/common-js/lang/assert":19,"@barchart/common-js/lang/is":21}],8:[function(require,module,exports){
2390
+ },{"@barchart/common-js/lang/assert":21,"@barchart/common-js/lang/is":23}],8:[function(require,module,exports){
2260
2391
  const assert = require('@barchart/common-js/lang/assert');
2261
2392
 
2262
2393
  const PositionLevelDefinition = require('./PositionLevelDefinition');
@@ -2310,7 +2441,139 @@ module.exports = (() => {
2310
2441
  return PositionTreeDefinitions;
2311
2442
  })();
2312
2443
 
2313
- },{"./PositionLevelDefinition":7,"@barchart/common-js/lang/assert":19}],9:[function(require,module,exports){
2444
+ },{"./PositionLevelDefinition":7,"@barchart/common-js/lang/assert":21}],9:[function(require,module,exports){
2445
+ 'use strict';
2446
+
2447
+ 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; }; }();
2448
+
2449
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2450
+
2451
+ var assert = require('./../lang/assert');
2452
+
2453
+ module.exports = function () {
2454
+ 'use strict';
2455
+
2456
+ /**
2457
+ * A stack collection (supports LIFO operations).
2458
+ *
2459
+ * @public
2460
+ */
2461
+
2462
+ var Stack = function () {
2463
+ function Stack() {
2464
+ _classCallCheck(this, Stack);
2465
+
2466
+ this._array = [];
2467
+ }
2468
+
2469
+ /**
2470
+ * Adds an item to the stack.
2471
+ *
2472
+ * @public
2473
+ * @param {object} item
2474
+ * @returns {object} - The item added to the stack.
2475
+ */
2476
+
2477
+
2478
+ _createClass(Stack, [{
2479
+ key: 'push',
2480
+ value: function push(item) {
2481
+ this._array.unshift(item);
2482
+
2483
+ return item;
2484
+ }
2485
+
2486
+ /**
2487
+ * Removes and returns an item from the stack. Throws if the stack is empty.
2488
+ *
2489
+ * @public
2490
+ * @returns {object} - The removed from the stack.
2491
+ */
2492
+
2493
+ }, {
2494
+ key: 'pop',
2495
+ value: function pop() {
2496
+ if (this.empty()) {
2497
+ throw new Error('Stack is empty');
2498
+ }
2499
+
2500
+ return this._array.shift();
2501
+ }
2502
+
2503
+ /**
2504
+ * Returns the next item in the stack (without removing it). Throws if the stack is empty.
2505
+ *
2506
+ * @public
2507
+ * @returns {object} - The item added to the queue.
2508
+ */
2509
+
2510
+ }, {
2511
+ key: 'peek',
2512
+ value: function peek() {
2513
+ if (this.empty()) {
2514
+ throw new Error('Stack is empty');
2515
+ }
2516
+
2517
+ return this._array[0];
2518
+ }
2519
+
2520
+ /**
2521
+ * Returns true if the queue is empty; otherwise false.
2522
+ *
2523
+ * @public
2524
+ * @returns {boolean}
2525
+ */
2526
+
2527
+ }, {
2528
+ key: 'empty',
2529
+ value: function empty() {
2530
+ return this._array.length === 0;
2531
+ }
2532
+
2533
+ /**
2534
+ * Runs an action on each item in the stack.
2535
+ *
2536
+ * @public
2537
+ * @param {Function} action - The action to run.
2538
+ */
2539
+
2540
+ }, {
2541
+ key: 'scan',
2542
+ value: function scan(action) {
2543
+ assert.argumentIsRequired(action, 'action', Function);
2544
+
2545
+ this._array.forEach(function (x) {
2546
+ return action(x);
2547
+ });
2548
+ }
2549
+
2550
+ /**
2551
+ * Outputs an array of the stacks's items; without affecting the
2552
+ * queue's internal state;
2553
+ *
2554
+ * @public
2555
+ * @returns {Array}
2556
+ */
2557
+
2558
+ }, {
2559
+ key: 'toArray',
2560
+ value: function toArray() {
2561
+ return this._array.slice(0);
2562
+ }
2563
+ }, {
2564
+ key: 'toString',
2565
+ value: function toString() {
2566
+ return '[Stack]';
2567
+ }
2568
+ }]);
2569
+
2570
+ return Stack;
2571
+ }();
2572
+
2573
+ return Stack;
2574
+ }();
2575
+
2576
+ },{"./../lang/assert":21}],10:[function(require,module,exports){
2314
2577
  'use strict';
2315
2578
 
2316
2579
  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; }; }();
@@ -2619,7 +2882,7 @@ module.exports = function () {
2619
2882
  return Tree;
2620
2883
  }();
2621
2884
 
2622
- },{"./../lang/is":21}],10:[function(require,module,exports){
2885
+ },{"./../lang/is":23}],11:[function(require,module,exports){
2623
2886
  'use strict';
2624
2887
 
2625
2888
  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; }; }();
@@ -2763,7 +3026,7 @@ module.exports = function () {
2763
3026
  return ComparatorBuilder;
2764
3027
  }();
2765
3028
 
2766
- },{"./../../lang/assert":19,"./comparators":11}],11:[function(require,module,exports){
3029
+ },{"./../../lang/assert":21,"./comparators":12}],12:[function(require,module,exports){
2767
3030
  'use strict';
2768
3031
 
2769
3032
  var assert = require('./../../lang/assert');
@@ -2838,7 +3101,115 @@ module.exports = function () {
2838
3101
  };
2839
3102
  }();
2840
3103
 
2841
- },{"./../../lang/assert":19}],12:[function(require,module,exports){
3104
+ },{"./../../lang/assert":21}],13:[function(require,module,exports){
3105
+ 'use strict';
3106
+
3107
+ 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; }; }();
3108
+
3109
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3110
+
3111
+ function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
3112
+
3113
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
3114
+
3115
+ var Stack = require('./../Stack');
3116
+
3117
+ var assert = require('./../../lang/assert'),
3118
+ Disposable = require('./../../lang/Disposable'),
3119
+ is = require('./../../lang/is');
3120
+
3121
+ module.exports = function () {
3122
+ 'use strict';
3123
+
3124
+ /**
3125
+ * A stack of {@link Disposable} instances which itself inherits {@Disposable}.
3126
+ * When {@link DisposableStack#dispose} is called, then each item in the collection
3127
+ * is disposed in order.
3128
+ *
3129
+ * @public
3130
+ * @extends {Disposable}
3131
+ */
3132
+
3133
+ var DisposableStack = function (_Disposable) {
3134
+ _inherits(DisposableStack, _Disposable);
3135
+
3136
+ function DisposableStack() {
3137
+ _classCallCheck(this, DisposableStack);
3138
+
3139
+ var _this = _possibleConstructorReturn(this, (DisposableStack.__proto__ || Object.getPrototypeOf(DisposableStack)).call(this));
3140
+
3141
+ _this._stack = new Stack();
3142
+ return _this;
3143
+ }
3144
+
3145
+ /**
3146
+ * Adds a new {@link Disposable} instance to the stack.
3147
+ *
3148
+ * @public
3149
+ * @param {Disposable} disposable - The item to add.
3150
+ */
3151
+
3152
+
3153
+ _createClass(DisposableStack, [{
3154
+ key: 'push',
3155
+ value: function push(disposable) {
3156
+ assert.argumentIsRequired(disposable, 'disposable', Disposable, 'Disposable');
3157
+
3158
+ if (this.getIsDisposed()) {
3159
+ throw new Error('Unable to push item onto DisposableStack because it has been disposed.');
3160
+ }
3161
+
3162
+ this._stack.push(disposable);
3163
+ }
3164
+ }, {
3165
+ key: '_onDispose',
3166
+ value: function _onDispose() {
3167
+ while (!this._stack.empty()) {
3168
+ this._stack.pop().dispose();
3169
+ }
3170
+ }
3171
+ }], [{
3172
+ key: 'fromArray',
3173
+ value: function fromArray(bindings) {
3174
+ assert.argumentIsArray(bindings, 'bindings', Disposable, 'Disposable');
3175
+
3176
+ var returnRef = new DisposableStack();
3177
+
3178
+ for (var i = 0; i < bindings.length; i++) {
3179
+ returnRef.push(bindings[i]);
3180
+ }
3181
+
3182
+ return returnRef;
3183
+ }
3184
+ }, {
3185
+ key: 'pushPromise',
3186
+ value: function pushPromise(stack, promise) {
3187
+ assert.argumentIsRequired(stack, 'stack', DisposableStack, 'DisposableStack');
3188
+ assert.argumentIsRequired(promise, 'promise');
3189
+
3190
+ return promise.then(function (b) {
3191
+ var bindings = void 0;
3192
+
3193
+ if (is.array(b)) {
3194
+ bindings = b;
3195
+ } else {
3196
+ bindings = [b];
3197
+ }
3198
+
3199
+ bindings.forEach(function (binding) {
3200
+ return stack.push(binding);
3201
+ });
3202
+ });
3203
+ }
3204
+ }]);
3205
+
3206
+ return DisposableStack;
3207
+ }(Disposable);
3208
+
3209
+ return DisposableStack;
3210
+ }();
3211
+
3212
+ },{"./../../lang/Disposable":17,"./../../lang/assert":21,"./../../lang/is":23,"./../Stack":9}],14:[function(require,module,exports){
2842
3213
  'use strict';
2843
3214
 
2844
3215
  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; }; }();
@@ -2869,7 +3240,7 @@ module.exports = function () {
2869
3240
  var Currency = function (_Enum) {
2870
3241
  _inherits(Currency, _Enum);
2871
3242
 
2872
- function Currency(code, description, precision) {
3243
+ function Currency(code, description, precision, alternateDescription) {
2873
3244
  _classCallCheck(this, Currency);
2874
3245
 
2875
3246
  var _this = _possibleConstructorReturn(this, (Currency.__proto__ || Object.getPrototypeOf(Currency)).call(this, code, description));
@@ -2877,7 +3248,11 @@ module.exports = function () {
2877
3248
  assert.argumentIsRequired(precision, 'precision', Number);
2878
3249
  assert.argumentIsValid(precision, 'precision', is.integer, 'is an integer');
2879
3250
 
3251
+ assert.argumentIsOptional(alternateDescription, 'alternateDescription', String);
3252
+
2880
3253
  _this._precision = precision;
3254
+
3255
+ _this._alternateDescription = alternateDescription || description;
2881
3256
  return _this;
2882
3257
  }
2883
3258
 
@@ -2900,6 +3275,19 @@ module.exports = function () {
2900
3275
  return this._precision;
2901
3276
  }
2902
3277
 
3278
+ /**
3279
+ * An alternate human-readable description.
3280
+ *
3281
+ * @public
3282
+ * @returns {String}
3283
+ */
3284
+
3285
+ }, {
3286
+ key: 'alternateDescription',
3287
+ get: function get() {
3288
+ return this._alternateDescription;
3289
+ }
3290
+
2903
3291
  /**
2904
3292
  * Given a code, returns the enumeration item.
2905
3293
  *
@@ -2957,14 +3345,14 @@ module.exports = function () {
2957
3345
  return Currency;
2958
3346
  }(Enum);
2959
3347
 
2960
- var cad = new Currency('CAD', 'Canadian Dollar', 2);
2961
- var eur = new Currency('EUR', 'Euro', 2);
2962
- var usd = new Currency('USD', 'US Dollar', 2);
3348
+ var cad = new Currency('CAD', 'Canadian Dollar', 2, 'CAD$');
3349
+ var eur = new Currency('EUR', 'Euro', 2, 'EUR');
3350
+ var usd = new Currency('USD', 'US Dollar', 2, 'US$');
2963
3351
 
2964
3352
  return Currency;
2965
3353
  }();
2966
3354
 
2967
- },{"./Enum":16,"./assert":19,"./is":21}],13:[function(require,module,exports){
3355
+ },{"./Enum":18,"./assert":21,"./is":23}],15:[function(require,module,exports){
2968
3356
  'use strict';
2969
3357
 
2970
3358
  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; }; }();
@@ -3517,7 +3905,7 @@ module.exports = function () {
3517
3905
  return Day;
3518
3906
  }();
3519
3907
 
3520
- },{"./../collections/sorting/ComparatorBuilder":10,"./../collections/sorting/comparators":11,"./assert":19,"./is":21}],14:[function(require,module,exports){
3908
+ },{"./../collections/sorting/ComparatorBuilder":11,"./../collections/sorting/comparators":12,"./assert":21,"./is":23}],16:[function(require,module,exports){
3521
3909
  'use strict';
3522
3910
 
3523
3911
  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; }; }();
@@ -3933,9 +4321,9 @@ module.exports = function () {
3933
4321
  assert.argumentIsRequired(a, 'a', Decimal, 'Decimal');
3934
4322
  assert.argumentIsRequired(b, 'b', Decimal, 'Decimal');
3935
4323
 
3936
- if (a._big.gt(b)) {
4324
+ if (a._big.gt(b._big)) {
3937
4325
  return 1;
3938
- } else if (a._big.lt(b)) {
4326
+ } else if (a._big.lt(b._big)) {
3939
4327
  return -1;
3940
4328
  } else {
3941
4329
  return 0;
@@ -4097,7 +4485,7 @@ module.exports = function () {
4097
4485
  return Decimal;
4098
4486
  }();
4099
4487
 
4100
- },{"./Enum":16,"./assert":19,"./is":21,"big.js":24}],15:[function(require,module,exports){
4488
+ },{"./Enum":18,"./assert":21,"./is":23,"big.js":26}],17:[function(require,module,exports){
4101
4489
  'use strict';
4102
4490
 
4103
4491
  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; }; }();
@@ -4246,7 +4634,7 @@ module.exports = function () {
4246
4634
  return Disposable;
4247
4635
  }();
4248
4636
 
4249
- },{"./assert":19}],16:[function(require,module,exports){
4637
+ },{"./assert":21}],18:[function(require,module,exports){
4250
4638
  'use strict';
4251
4639
 
4252
4640
  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; }; }();
@@ -4388,7 +4776,7 @@ module.exports = function () {
4388
4776
  return Enum;
4389
4777
  }();
4390
4778
 
4391
- },{"./assert":19}],17:[function(require,module,exports){
4779
+ },{"./assert":21}],19:[function(require,module,exports){
4392
4780
  'use strict';
4393
4781
 
4394
4782
  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; }; }();
@@ -4396,12 +4784,10 @@ var _createClass = function () { function defineProperties(target, props) { for
4396
4784
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4397
4785
 
4398
4786
  var assert = require('./assert'),
4399
- is = require('./is'),
4400
4787
  memoize = require('./memoize');
4401
4788
 
4402
4789
  var Currency = require('./Currency'),
4403
- Decimal = require('./Decimal'),
4404
- Enum = require('./Enum');
4790
+ Decimal = require('./Decimal');
4405
4791
 
4406
4792
  module.exports = function () {
4407
4793
  'use strict';
@@ -4581,12 +4967,7 @@ module.exports = function () {
4581
4967
  assert.argumentIsRequired(amount, 'amount', Decimal, 'Decimal');
4582
4968
  assert.argumentIsRequired(currency, 'currency', Currency, 'Currency');
4583
4969
  assert.argumentIsRequired(desiredCurrency, 'desiredCurrency', Currency, 'Currency');
4584
-
4585
- for (var _len = arguments.length, rates = Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
4586
- rates[_key - 3] = arguments[_key];
4587
- }
4588
-
4589
- assert.argumentIsArray(rates, 'rates', Rate, 'Rate');
4970
+ //assert.argumentIsArray(rates, 'rates', Rate, 'Rate');
4590
4971
 
4591
4972
  var converted = void 0;
4592
4973
 
@@ -4596,6 +4977,10 @@ module.exports = function () {
4596
4977
  var numerator = desiredCurrency;
4597
4978
  var denominator = currency;
4598
4979
 
4980
+ for (var _len = arguments.length, rates = Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
4981
+ rates[_key - 3] = arguments[_key];
4982
+ }
4983
+
4599
4984
  var rate = rates.find(function (r) {
4600
4985
  return r.numerator === numerator && r.denominator === denominator || r.numerator === denominator && r.denominator === numerator;
4601
4986
  });
@@ -4646,7 +5031,7 @@ module.exports = function () {
4646
5031
  return Rate;
4647
5032
  }();
4648
5033
 
4649
- },{"./Currency":12,"./Decimal":14,"./Enum":16,"./assert":19,"./is":21,"./memoize":22}],18:[function(require,module,exports){
5034
+ },{"./Currency":14,"./Decimal":16,"./assert":21,"./memoize":24}],20:[function(require,module,exports){
4650
5035
  'use strict';
4651
5036
 
4652
5037
  var assert = require('./assert'),
@@ -5027,7 +5412,7 @@ module.exports = function () {
5027
5412
  };
5028
5413
  }();
5029
5414
 
5030
- },{"./assert":19,"./is":21}],19:[function(require,module,exports){
5415
+ },{"./assert":21,"./is":23}],21:[function(require,module,exports){
5031
5416
  'use strict';
5032
5417
 
5033
5418
  var is = require('./is');
@@ -5175,7 +5560,7 @@ module.exports = function () {
5175
5560
  };
5176
5561
  }();
5177
5562
 
5178
- },{"./is":21}],20:[function(require,module,exports){
5563
+ },{"./is":23}],22:[function(require,module,exports){
5179
5564
  'use strict';
5180
5565
 
5181
5566
  module.exports = function () {
@@ -5240,7 +5625,7 @@ module.exports = function () {
5240
5625
  };
5241
5626
  }();
5242
5627
 
5243
- },{}],21:[function(require,module,exports){
5628
+ },{}],23:[function(require,module,exports){
5244
5629
  'use strict';
5245
5630
 
5246
5631
  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; };
@@ -5463,7 +5848,7 @@ module.exports = function () {
5463
5848
  };
5464
5849
  }();
5465
5850
 
5466
- },{}],22:[function(require,module,exports){
5851
+ },{}],24:[function(require,module,exports){
5467
5852
  'use strict';
5468
5853
 
5469
5854
  var assert = require('./assert'),
@@ -5536,7 +5921,7 @@ module.exports = function () {
5536
5921
  };
5537
5922
  }();
5538
5923
 
5539
- },{"./assert":19,"./is":21}],23:[function(require,module,exports){
5924
+ },{"./assert":21,"./is":23}],25:[function(require,module,exports){
5540
5925
  'use strict';
5541
5926
 
5542
5927
  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; }; }();
@@ -5708,7 +6093,7 @@ module.exports = function () {
5708
6093
  return Event;
5709
6094
  }();
5710
6095
 
5711
- },{"./../lang/Disposable":15,"./../lang/assert":19}],24:[function(require,module,exports){
6096
+ },{"./../lang/Disposable":17,"./../lang/assert":21}],26:[function(require,module,exports){
5712
6097
  /*
5713
6098
  * big.js v5.0.3
5714
6099
  * A small, fast, easy-to-use library for arbitrary-precision decimal arithmetic.
@@ -6649,7 +7034,7 @@ module.exports = function () {
6649
7034
  }
6650
7035
  })(this);
6651
7036
 
6652
- },{}],25:[function(require,module,exports){
7037
+ },{}],27:[function(require,module,exports){
6653
7038
  const Day = require('@barchart/common-js/lang/Day'),
6654
7039
  Decimal = require('@barchart/common-js/lang/Decimal');
6655
7040
 
@@ -7006,7 +7391,7 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
7006
7391
  });
7007
7392
  });
7008
7393
 
7009
- },{"./../../../lib/data/PositionSummaryFrame":2,"./../../../lib/data/TransactionType":3,"@barchart/common-js/lang/Day":13,"@barchart/common-js/lang/Decimal":14}],26:[function(require,module,exports){
7394
+ },{"./../../../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){
7010
7395
  const Currency = require('@barchart/common-js/lang/Currency'),
7011
7396
  Decimal = require('@barchart/common-js/lang/Decimal');
7012
7397
 
@@ -7115,4 +7500,4 @@ describe('When a position container data is gathered', () => {
7115
7500
  });
7116
7501
  });
7117
7502
 
7118
- },{"./../../../lib/data/InstrumentType":1,"./../../../lib/processing/PositionContainer":4,"./../../../lib/processing/definitions/PositionLevelDefinition":7,"./../../../lib/processing/definitions/PositionTreeDefinition":8,"@barchart/common-js/lang/Currency":12,"@barchart/common-js/lang/Decimal":14}]},{},[25,26]);
7503
+ },{"./../../../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]);