@barchart/portfolio-api-common 1.0.152 → 1.0.156

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) => {
@@ -164,8 +170,11 @@ module.exports = (() => {
164
170
  this._dataFormat.quoteTime = this._dataActual.quoteTime;
165
171
  this._dataFormat.quoteVolume = formatNumber(this._dataActual.quoteVolume, 0);
166
172
 
167
- setTimeout(() => this._dataFormat.quoteChangeDirection = { up: this._dataActual.quoteChange.getIsPositive(), down: this._dataActual.quoteChange.getIsNegative() });
168
- this._dataFormat.quoteChangeNegative = this._dataActual.quoteChange.getIsNegative();
173
+ const quoteChangePositive = is.number(this._dataActual.quoteChange) && this._dataActual.quoteChange > 0;
174
+ const quoteChangeNegative = is.number(this._dataActual.quoteChange) && this._dataActual.quoteChange < 0;
175
+
176
+ setTimeout(() => this._dataFormat.quoteChangeDirection = { up: quoteChangePositive, down: quoteChangeNegative }, 0);
177
+ this._dataFormat.quoteChangeNegative = quoteChangeNegative;
169
178
  } else {
170
179
  this._dataActual.currentPrice = null;
171
180
  this._dataFormat.currentPrice = null;
@@ -317,6 +326,13 @@ module.exports = (() => {
317
326
  }
318
327
  }
319
328
 
329
+ /**
330
+ * Set a flag to indicate if parent groups should exclude this group's
331
+ * items from their calculations.
332
+ *
333
+ * @public
334
+ * @param {Boolean} value
335
+ */
320
336
  setExcluded(value) {
321
337
  assert.argumentIsRequired(value, 'value', Boolean);
322
338
 
@@ -455,6 +471,10 @@ module.exports = (() => {
455
471
  updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrent));
456
472
  updates.summaryTotalPrevious = updates.summaryTotalPrevious.add(translate(item, item.data.summaryTotalPrevious));
457
473
 
474
+ if (item.position.type === InstrumentType.CASH) {
475
+ updates.cashTotal = updates.cashTotal.add(translate(item, item.data.market));
476
+ }
477
+
458
478
  return updates;
459
479
  }, {
460
480
  basis: Decimal.ZERO,
@@ -462,7 +482,8 @@ module.exports = (() => {
462
482
  unrealized: Decimal.ZERO,
463
483
  income: Decimal.ZERO,
464
484
  summaryTotalCurrent: Decimal.ZERO,
465
- summaryTotalPrevious: Decimal.ZERO
485
+ summaryTotalPrevious: Decimal.ZERO,
486
+ cashTotal: Decimal.ZERO
466
487
  });
467
488
 
468
489
  actual.basis = updates.basis;
@@ -471,6 +492,7 @@ module.exports = (() => {
471
492
  actual.income = updates.income;
472
493
  actual.summaryTotalCurrent = updates.summaryTotalCurrent;
473
494
  actual.summaryTotalPrevious = updates.summaryTotalPrevious;
495
+ actual.cashTotal = updates.cashTotal;
474
496
 
475
497
  format.basis = formatCurrency(actual.basis, currency);
476
498
  format.realized = formatCurrency(actual.basis, currency);
@@ -479,6 +501,7 @@ module.exports = (() => {
479
501
  format.summaryTotalCurrent = formatCurrency(updates.summaryTotalCurrent, currency);
480
502
  format.summaryTotalPrevious = formatCurrency(updates.summaryTotalPrevious, currency);
481
503
  format.summaryTotalPreviousNegative = updates.summaryTotalPrevious.getIsNegative();
504
+ format.cashTotal = formatCurrency(updates.cashTotal, currency);
482
505
 
483
506
  calculateUnrealizedPercent(group);
484
507
 
@@ -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.152",
3
+ "version": "1.0.156",
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) => {
@@ -1410,8 +1415,11 @@ module.exports = (() => {
1410
1415
  this._dataFormat.quoteTime = this._dataActual.quoteTime;
1411
1416
  this._dataFormat.quoteVolume = formatNumber(this._dataActual.quoteVolume, 0);
1412
1417
 
1413
- setTimeout(() => this._dataFormat.quoteChangeDirection = { up: this._dataActual.quoteChange.getIsPositive(), down: this._dataActual.quoteChange.getIsNegative() });
1414
- this._dataFormat.quoteChangeNegative = this._dataActual.quoteChange.getIsNegative();
1418
+ const quoteChangePositive = is.number(this._dataActual.quoteChange) && this._dataActual.quoteChange > 0;
1419
+ const quoteChangeNegative = is.number(this._dataActual.quoteChange) && this._dataActual.quoteChange < 0;
1420
+
1421
+ setTimeout(() => this._dataFormat.quoteChangeDirection = { up: quoteChangePositive, down: quoteChangeNegative }, 0);
1422
+ this._dataFormat.quoteChangeNegative = quoteChangeNegative;
1415
1423
  } else {
1416
1424
  this._dataActual.currentPrice = null;
1417
1425
  this._dataFormat.currentPrice = null;
@@ -1563,6 +1571,13 @@ module.exports = (() => {
1563
1571
  }
1564
1572
  }
1565
1573
 
1574
+ /**
1575
+ * Set a flag to indicate if parent groups should exclude this group's
1576
+ * items from their calculations.
1577
+ *
1578
+ * @public
1579
+ * @param {Boolean} value
1580
+ */
1566
1581
  setExcluded(value) {
1567
1582
  assert.argumentIsRequired(value, 'value', Boolean);
1568
1583
 
@@ -1701,6 +1716,10 @@ module.exports = (() => {
1701
1716
  updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrent));
1702
1717
  updates.summaryTotalPrevious = updates.summaryTotalPrevious.add(translate(item, item.data.summaryTotalPrevious));
1703
1718
 
1719
+ if (item.position.type === InstrumentType.CASH) {
1720
+ updates.cashTotal = updates.cashTotal.add(translate(item, item.data.market));
1721
+ }
1722
+
1704
1723
  return updates;
1705
1724
  }, {
1706
1725
  basis: Decimal.ZERO,
@@ -1708,7 +1727,8 @@ module.exports = (() => {
1708
1727
  unrealized: Decimal.ZERO,
1709
1728
  income: Decimal.ZERO,
1710
1729
  summaryTotalCurrent: Decimal.ZERO,
1711
- summaryTotalPrevious: Decimal.ZERO
1730
+ summaryTotalPrevious: Decimal.ZERO,
1731
+ cashTotal: Decimal.ZERO
1712
1732
  });
1713
1733
 
1714
1734
  actual.basis = updates.basis;
@@ -1717,6 +1737,7 @@ module.exports = (() => {
1717
1737
  actual.income = updates.income;
1718
1738
  actual.summaryTotalCurrent = updates.summaryTotalCurrent;
1719
1739
  actual.summaryTotalPrevious = updates.summaryTotalPrevious;
1740
+ actual.cashTotal = updates.cashTotal;
1720
1741
 
1721
1742
  format.basis = formatCurrency(actual.basis, currency);
1722
1743
  format.realized = formatCurrency(actual.basis, currency);
@@ -1725,6 +1746,7 @@ module.exports = (() => {
1725
1746
  format.summaryTotalCurrent = formatCurrency(updates.summaryTotalCurrent, currency);
1726
1747
  format.summaryTotalPrevious = formatCurrency(updates.summaryTotalPrevious, currency);
1727
1748
  format.summaryTotalPreviousNegative = updates.summaryTotalPrevious.getIsNegative();
1749
+ format.cashTotal = formatCurrency(updates.cashTotal, currency);
1728
1750
 
1729
1751
  calculateUnrealizedPercent(group);
1730
1752
 
@@ -1886,7 +1908,7 @@ module.exports = (() => {
1886
1908
  return PositionGroup;
1887
1909
  })();
1888
1910
 
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){
1911
+ },{"./../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
1912
  const array = require('@barchart/common-js/lang/array'),
1891
1913
  assert = require('@barchart/common-js/lang/assert'),
1892
1914
  Currency = require('@barchart/common-js/lang/Currency'),
@@ -1924,9 +1946,7 @@ module.exports = (() => {
1924
1946
  this._data.basis = null;
1925
1947
 
1926
1948
  this._currentQuote = null;
1927
-
1928
1949
  this._currentPrice = null;
1929
- this._previousPrice = null;
1930
1950
 
1931
1951
  this._data.currentPrice = null;
1932
1952
  this._data.currentPricePrevious = null;
@@ -2273,10 +2293,12 @@ module.exports = (() => {
2273
2293
  * @param {PositionLevelDefinition~descriptionSelector} descriptionSelector
2274
2294
  * @param {PositionLevelDefinition~currencySelector} currencySelector
2275
2295
  * @param {Array.<PositionLevelDefinition~RequiredGroup>=} requiredGroups
2296
+ * @param {Array.<PositionLevelDefinition~RequiredGroup>=} requiredGroups
2276
2297
  * @param {Boolean=} single
2298
+ * @param {Boolean=} aggregateCash
2277
2299
  */
2278
2300
  class PositionLevelDefinition {
2279
- constructor(name, keySelector, descriptionSelector, currencySelector, requiredGroups, single) {
2301
+ constructor(name, keySelector, descriptionSelector, currencySelector, requiredGroups, single, aggregateCash) {
2280
2302
  assert.argumentIsRequired(name, 'name', String);
2281
2303
  assert.argumentIsRequired(keySelector, 'keySelector', Function);
2282
2304
  assert.argumentIsRequired(descriptionSelector, 'descriptionSelector', Function);
@@ -2287,6 +2309,7 @@ module.exports = (() => {
2287
2309
  }
2288
2310
 
2289
2311
  assert.argumentIsOptional(single, 'single', Boolean);
2312
+ assert.argumentIsOptional(aggregateCash, 'aggregateCash', Boolean);
2290
2313
 
2291
2314
  this._name = name;
2292
2315
 
@@ -2296,6 +2319,7 @@ module.exports = (() => {
2296
2319
 
2297
2320
  this._requiredGroups = requiredGroups || [ ];
2298
2321
  this._single = is.boolean(single) && single;
2322
+ this._aggregateCash = is.boolean(aggregateCash) && aggregateCash;
2299
2323
  }
2300
2324
 
2301
2325
  /**
@@ -2362,6 +2386,16 @@ module.exports = (() => {
2362
2386
  return this._single;
2363
2387
  }
2364
2388
 
2389
+ /**
2390
+ * Indicates if the grouping level should aggregate cash positions.
2391
+ *
2392
+ * @public
2393
+ * @returns {Boolean}
2394
+ */
2395
+ get aggregateCash() {
2396
+ return this._aggregateCash;
2397
+ }
2398
+
2365
2399
  toString() {
2366
2400
  return '[PositionLevelDefinition]';
2367
2401
  }