@barchart/portfolio-api-common 1.0.153 → 1.0.154

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.
@@ -181,7 +181,7 @@ module.exports = (() => {
181
181
  const items = populatedObjects[key];
182
182
  const first = items[0];
183
183
 
184
- list.push(new PositionGroup(this, parent, items, levelDefinition.currencySelector(first), key, levelDefinition.descriptionSelector(first), levelDefinition.single && items.length === 1));
184
+ list.push(new PositionGroup(this, parent, items, levelDefinition.currencySelector(first), key, levelDefinition.descriptionSelector(first), levelDefinition.single && items.length === 1, levelDefinition.aggregateCash));
185
185
 
186
186
  return list;
187
187
  }, [ ]);
@@ -523,6 +523,5 @@ module.exports = (() => {
523
523
  }
524
524
  }
525
525
 
526
-
527
526
  return PositionContainer;
528
527
  })();
@@ -8,6 +8,8 @@ const array = require('@barchart/common-js/lang/array'),
8
8
  is = require('@barchart/common-js/lang/is'),
9
9
  Rate = require('@barchart/common-js/lang/Rate');
10
10
 
11
+ const InstrumentType = require('./../data/InstrumentType');
12
+
11
13
  module.exports = (() => {
12
14
  'use strict';
13
15
 
@@ -25,9 +27,10 @@ module.exports = (() => {
25
27
  * @param {String} key
26
28
  * @param {String} description
27
29
  * @param {Boolean=} single
30
+ * @param {Boolean=} aggregateCash
28
31
  */
29
32
  class PositionGroup {
30
- constructor(container, parent, items, currency, key, description, single) {
33
+ constructor(container, parent, items, currency, key, description, single, aggregateCash) {
31
34
  this._id = counter++;
32
35
  this._container = container;
33
36
  this._parent = parent || null;
@@ -40,6 +43,7 @@ module.exports = (() => {
40
43
  this._description = description;
41
44
 
42
45
  this._single = is.boolean(single) && single;
46
+ this._aggregateCash = is.boolean(aggregateCash) && aggregateCash;
43
47
 
44
48
  this._excluded = false;
45
49
  this._suspended = false;
@@ -117,6 +121,7 @@ module.exports = (() => {
117
121
  this._dataActual.total = null;
118
122
  this._dataActual.summaryTotalCurrent = null;
119
123
  this._dataActual.summaryTotalPrevious = null;
124
+ this._dataActual.cashTotal = null;
120
125
 
121
126
  this._dataFormat.currentPrice = null;
122
127
  this._dataFormat.previousPrice = null;
@@ -137,6 +142,7 @@ module.exports = (() => {
137
142
  this._dataActual.summaryTotalCurrentNegative = false;
138
143
  this._dataFormat.summaryTotalPrevious = null;
139
144
  this._dataFormat.summaryTotalPreviousNegative = false;
145
+ this._dataFormat.cashTotal = null;
140
146
 
141
147
  this._items.forEach((item) => {
142
148
  this._disposeStack.push(item.registerQuoteChangeHandler((quote, sender) => {
@@ -317,6 +323,13 @@ module.exports = (() => {
317
323
  }
318
324
  }
319
325
 
326
+ /**
327
+ * Set a flag to indicate if parent groups should exclude this group's
328
+ * items from their calculations.
329
+ *
330
+ * @public
331
+ * @param {Boolean} value
332
+ */
320
333
  setExcluded(value) {
321
334
  assert.argumentIsRequired(value, 'value', Boolean);
322
335
 
@@ -455,6 +468,10 @@ module.exports = (() => {
455
468
  updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrent));
456
469
  updates.summaryTotalPrevious = updates.summaryTotalPrevious.add(translate(item, item.data.summaryTotalPrevious));
457
470
 
471
+ if (item.position.type === InstrumentType.CASH) {
472
+ updates.cashTotal = updates.cashTotal.add(translate(item, item.data.market));
473
+ }
474
+
458
475
  return updates;
459
476
  }, {
460
477
  basis: Decimal.ZERO,
@@ -462,7 +479,8 @@ module.exports = (() => {
462
479
  unrealized: Decimal.ZERO,
463
480
  income: Decimal.ZERO,
464
481
  summaryTotalCurrent: Decimal.ZERO,
465
- summaryTotalPrevious: Decimal.ZERO
482
+ summaryTotalPrevious: Decimal.ZERO,
483
+ cashTotal: Decimal.ZERO
466
484
  });
467
485
 
468
486
  actual.basis = updates.basis;
@@ -471,6 +489,7 @@ module.exports = (() => {
471
489
  actual.income = updates.income;
472
490
  actual.summaryTotalCurrent = updates.summaryTotalCurrent;
473
491
  actual.summaryTotalPrevious = updates.summaryTotalPrevious;
492
+ actual.cashTotal = updates.cashTotal;
474
493
 
475
494
  format.basis = formatCurrency(actual.basis, currency);
476
495
  format.realized = formatCurrency(actual.basis, currency);
@@ -479,6 +498,7 @@ module.exports = (() => {
479
498
  format.summaryTotalCurrent = formatCurrency(updates.summaryTotalCurrent, currency);
480
499
  format.summaryTotalPrevious = formatCurrency(updates.summaryTotalPrevious, currency);
481
500
  format.summaryTotalPreviousNegative = updates.summaryTotalPrevious.getIsNegative();
501
+ format.cashTotal = formatCurrency(updates.cashTotal, currency);
482
502
 
483
503
  calculateUnrealizedPercent(group);
484
504
 
@@ -35,9 +35,7 @@ module.exports = (() => {
35
35
  this._data.basis = null;
36
36
 
37
37
  this._currentQuote = null;
38
-
39
38
  this._currentPrice = null;
40
- this._previousPrice = null;
41
39
 
42
40
  this._data.currentPrice = null;
43
41
  this._data.currentPricePrevious = null;
@@ -15,10 +15,12 @@ module.exports = (() => {
15
15
  * @param {PositionLevelDefinition~descriptionSelector} descriptionSelector
16
16
  * @param {PositionLevelDefinition~currencySelector} currencySelector
17
17
  * @param {Array.<PositionLevelDefinition~RequiredGroup>=} requiredGroups
18
+ * @param {Array.<PositionLevelDefinition~RequiredGroup>=} requiredGroups
18
19
  * @param {Boolean=} single
20
+ * @param {Boolean=} aggregateCash
19
21
  */
20
22
  class PositionLevelDefinition {
21
- constructor(name, keySelector, descriptionSelector, currencySelector, requiredGroups, single) {
23
+ constructor(name, keySelector, descriptionSelector, currencySelector, requiredGroups, single, aggregateCash) {
22
24
  assert.argumentIsRequired(name, 'name', String);
23
25
  assert.argumentIsRequired(keySelector, 'keySelector', Function);
24
26
  assert.argumentIsRequired(descriptionSelector, 'descriptionSelector', Function);
@@ -29,6 +31,7 @@ module.exports = (() => {
29
31
  }
30
32
 
31
33
  assert.argumentIsOptional(single, 'single', Boolean);
34
+ assert.argumentIsOptional(aggregateCash, 'aggregateCash', Boolean);
32
35
 
33
36
  this._name = name;
34
37
 
@@ -38,6 +41,7 @@ module.exports = (() => {
38
41
 
39
42
  this._requiredGroups = requiredGroups || [ ];
40
43
  this._single = is.boolean(single) && single;
44
+ this._aggregateCash = is.boolean(aggregateCash) && aggregateCash;
41
45
  }
42
46
 
43
47
  /**
@@ -104,6 +108,16 @@ module.exports = (() => {
104
108
  return this._single;
105
109
  }
106
110
 
111
+ /**
112
+ * Indicates if the grouping level should aggregate cash positions.
113
+ *
114
+ * @public
115
+ * @returns {Boolean}
116
+ */
117
+ get aggregateCash() {
118
+ return this._aggregateCash;
119
+ }
120
+
107
121
  toString() {
108
122
  return '[PositionLevelDefinition]';
109
123
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.0.153",
3
+ "version": "1.0.154",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -897,7 +897,7 @@ module.exports = (() => {
897
897
  const items = populatedObjects[key];
898
898
  const first = items[0];
899
899
 
900
- list.push(new PositionGroup(this, parent, items, levelDefinition.currencySelector(first), key, levelDefinition.descriptionSelector(first), levelDefinition.single && items.length === 1));
900
+ list.push(new PositionGroup(this, parent, items, levelDefinition.currencySelector(first), key, levelDefinition.descriptionSelector(first), levelDefinition.single && items.length === 1, levelDefinition.aggregateCash));
901
901
 
902
902
  return list;
903
903
  }, [ ]);
@@ -1239,7 +1239,6 @@ module.exports = (() => {
1239
1239
  }
1240
1240
  }
1241
1241
 
1242
-
1243
1242
  return PositionContainer;
1244
1243
  })();
1245
1244
 
@@ -1254,6 +1253,8 @@ const array = require('@barchart/common-js/lang/array'),
1254
1253
  is = require('@barchart/common-js/lang/is'),
1255
1254
  Rate = require('@barchart/common-js/lang/Rate');
1256
1255
 
1256
+ const InstrumentType = require('./../data/InstrumentType');
1257
+
1257
1258
  module.exports = (() => {
1258
1259
  'use strict';
1259
1260
 
@@ -1271,9 +1272,10 @@ module.exports = (() => {
1271
1272
  * @param {String} key
1272
1273
  * @param {String} description
1273
1274
  * @param {Boolean=} single
1275
+ * @param {Boolean=} aggregateCash
1274
1276
  */
1275
1277
  class PositionGroup {
1276
- constructor(container, parent, items, currency, key, description, single) {
1278
+ constructor(container, parent, items, currency, key, description, single, aggregateCash) {
1277
1279
  this._id = counter++;
1278
1280
  this._container = container;
1279
1281
  this._parent = parent || null;
@@ -1286,6 +1288,7 @@ module.exports = (() => {
1286
1288
  this._description = description;
1287
1289
 
1288
1290
  this._single = is.boolean(single) && single;
1291
+ this._aggregateCash = is.boolean(aggregateCash) && aggregateCash;
1289
1292
 
1290
1293
  this._excluded = false;
1291
1294
  this._suspended = false;
@@ -1363,6 +1366,7 @@ module.exports = (() => {
1363
1366
  this._dataActual.total = null;
1364
1367
  this._dataActual.summaryTotalCurrent = null;
1365
1368
  this._dataActual.summaryTotalPrevious = null;
1369
+ this._dataActual.cashTotal = null;
1366
1370
 
1367
1371
  this._dataFormat.currentPrice = null;
1368
1372
  this._dataFormat.previousPrice = null;
@@ -1383,6 +1387,7 @@ module.exports = (() => {
1383
1387
  this._dataActual.summaryTotalCurrentNegative = false;
1384
1388
  this._dataFormat.summaryTotalPrevious = null;
1385
1389
  this._dataFormat.summaryTotalPreviousNegative = false;
1390
+ this._dataFormat.cashTotal = null;
1386
1391
 
1387
1392
  this._items.forEach((item) => {
1388
1393
  this._disposeStack.push(item.registerQuoteChangeHandler((quote, sender) => {
@@ -1563,6 +1568,13 @@ module.exports = (() => {
1563
1568
  }
1564
1569
  }
1565
1570
 
1571
+ /**
1572
+ * Set a flag to indicate if parent groups should exclude this group's
1573
+ * items from their calculations.
1574
+ *
1575
+ * @public
1576
+ * @param {Boolean} value
1577
+ */
1566
1578
  setExcluded(value) {
1567
1579
  assert.argumentIsRequired(value, 'value', Boolean);
1568
1580
 
@@ -1701,6 +1713,10 @@ module.exports = (() => {
1701
1713
  updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrent));
1702
1714
  updates.summaryTotalPrevious = updates.summaryTotalPrevious.add(translate(item, item.data.summaryTotalPrevious));
1703
1715
 
1716
+ if (item.position.type === InstrumentType.CASH) {
1717
+ updates.cashTotal = updates.cashTotal.add(translate(item, item.data.market));
1718
+ }
1719
+
1704
1720
  return updates;
1705
1721
  }, {
1706
1722
  basis: Decimal.ZERO,
@@ -1708,7 +1724,8 @@ module.exports = (() => {
1708
1724
  unrealized: Decimal.ZERO,
1709
1725
  income: Decimal.ZERO,
1710
1726
  summaryTotalCurrent: Decimal.ZERO,
1711
- summaryTotalPrevious: Decimal.ZERO
1727
+ summaryTotalPrevious: Decimal.ZERO,
1728
+ cashTotal: Decimal.ZERO
1712
1729
  });
1713
1730
 
1714
1731
  actual.basis = updates.basis;
@@ -1717,6 +1734,7 @@ module.exports = (() => {
1717
1734
  actual.income = updates.income;
1718
1735
  actual.summaryTotalCurrent = updates.summaryTotalCurrent;
1719
1736
  actual.summaryTotalPrevious = updates.summaryTotalPrevious;
1737
+ actual.cashTotal = updates.cashTotal;
1720
1738
 
1721
1739
  format.basis = formatCurrency(actual.basis, currency);
1722
1740
  format.realized = formatCurrency(actual.basis, currency);
@@ -1725,6 +1743,7 @@ module.exports = (() => {
1725
1743
  format.summaryTotalCurrent = formatCurrency(updates.summaryTotalCurrent, currency);
1726
1744
  format.summaryTotalPrevious = formatCurrency(updates.summaryTotalPrevious, currency);
1727
1745
  format.summaryTotalPreviousNegative = updates.summaryTotalPrevious.getIsNegative();
1746
+ format.cashTotal = formatCurrency(updates.cashTotal, currency);
1728
1747
 
1729
1748
  calculateUnrealizedPercent(group);
1730
1749
 
@@ -1886,7 +1905,7 @@ module.exports = (() => {
1886
1905
  return PositionGroup;
1887
1906
  })();
1888
1907
 
1889
- },{"@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){
1908
+ },{"./../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){
1890
1909
  const array = require('@barchart/common-js/lang/array'),
1891
1910
  assert = require('@barchart/common-js/lang/assert'),
1892
1911
  Currency = require('@barchart/common-js/lang/Currency'),
@@ -1924,9 +1943,7 @@ module.exports = (() => {
1924
1943
  this._data.basis = null;
1925
1944
 
1926
1945
  this._currentQuote = null;
1927
-
1928
1946
  this._currentPrice = null;
1929
- this._previousPrice = null;
1930
1947
 
1931
1948
  this._data.currentPrice = null;
1932
1949
  this._data.currentPricePrevious = null;
@@ -2273,10 +2290,12 @@ module.exports = (() => {
2273
2290
  * @param {PositionLevelDefinition~descriptionSelector} descriptionSelector
2274
2291
  * @param {PositionLevelDefinition~currencySelector} currencySelector
2275
2292
  * @param {Array.<PositionLevelDefinition~RequiredGroup>=} requiredGroups
2293
+ * @param {Array.<PositionLevelDefinition~RequiredGroup>=} requiredGroups
2276
2294
  * @param {Boolean=} single
2295
+ * @param {Boolean=} aggregateCash
2277
2296
  */
2278
2297
  class PositionLevelDefinition {
2279
- constructor(name, keySelector, descriptionSelector, currencySelector, requiredGroups, single) {
2298
+ constructor(name, keySelector, descriptionSelector, currencySelector, requiredGroups, single, aggregateCash) {
2280
2299
  assert.argumentIsRequired(name, 'name', String);
2281
2300
  assert.argumentIsRequired(keySelector, 'keySelector', Function);
2282
2301
  assert.argumentIsRequired(descriptionSelector, 'descriptionSelector', Function);
@@ -2287,6 +2306,7 @@ module.exports = (() => {
2287
2306
  }
2288
2307
 
2289
2308
  assert.argumentIsOptional(single, 'single', Boolean);
2309
+ assert.argumentIsOptional(aggregateCash, 'aggregateCash', Boolean);
2290
2310
 
2291
2311
  this._name = name;
2292
2312
 
@@ -2296,6 +2316,7 @@ module.exports = (() => {
2296
2316
 
2297
2317
  this._requiredGroups = requiredGroups || [ ];
2298
2318
  this._single = is.boolean(single) && single;
2319
+ this._aggregateCash = is.boolean(aggregateCash) && aggregateCash;
2299
2320
  }
2300
2321
 
2301
2322
  /**
@@ -2362,6 +2383,16 @@ module.exports = (() => {
2362
2383
  return this._single;
2363
2384
  }
2364
2385
 
2386
+ /**
2387
+ * Indicates if the grouping level should aggregate cash positions.
2388
+ *
2389
+ * @public
2390
+ * @returns {Boolean}
2391
+ */
2392
+ get aggregateCash() {
2393
+ return this._aggregateCash;
2394
+ }
2395
+
2365
2396
  toString() {
2366
2397
  return '[PositionLevelDefinition]';
2367
2398
  }