@barchart/portfolio-api-common 1.0.153 → 1.0.157

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,7 +121,9 @@ 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
 
126
+ this._dataFormat.type = null;
121
127
  this._dataFormat.currentPrice = null;
122
128
  this._dataFormat.previousPrice = null;
123
129
  this._dataFormat.basis = null;
@@ -137,6 +143,7 @@ module.exports = (() => {
137
143
  this._dataActual.summaryTotalCurrentNegative = false;
138
144
  this._dataFormat.summaryTotalPrevious = null;
139
145
  this._dataFormat.summaryTotalPreviousNegative = false;
146
+ this._dataFormat.cashTotal = null;
140
147
 
141
148
  this._items.forEach((item) => {
142
149
  this._disposeStack.push(item.registerQuoteChangeHandler((quote, sender) => {
@@ -164,8 +171,11 @@ module.exports = (() => {
164
171
  this._dataFormat.quoteTime = this._dataActual.quoteTime;
165
172
  this._dataFormat.quoteVolume = formatNumber(this._dataActual.quoteVolume, 0);
166
173
 
167
- setTimeout(() => this._dataFormat.quoteChangeDirection = { up: this._dataActual.quoteChange.getIsPositive(), down: this._dataActual.quoteChange.getIsNegative() }, 0);
168
- this._dataFormat.quoteChangeNegative = this._dataActual.quoteChange.getIsNegative();
174
+ const quoteChangePositive = is.number(this._dataActual.quoteChange) && this._dataActual.quoteChange > 0;
175
+ const quoteChangeNegative = is.number(this._dataActual.quoteChange) && this._dataActual.quoteChange < 0;
176
+
177
+ setTimeout(() => this._dataFormat.quoteChangeDirection = { up: quoteChangePositive, down: quoteChangeNegative }, 0);
178
+ this._dataFormat.quoteChangeNegative = quoteChangeNegative;
169
179
  } else {
170
180
  this._dataActual.currentPrice = null;
171
181
  this._dataFormat.currentPrice = null;
@@ -317,6 +327,13 @@ module.exports = (() => {
317
327
  }
318
328
  }
319
329
 
330
+ /**
331
+ * Set a flag to indicate if parent groups should exclude this group's
332
+ * items from their calculations.
333
+ *
334
+ * @public
335
+ * @param {Boolean} value
336
+ */
320
337
  setExcluded(value) {
321
338
  assert.argumentIsRequired(value, 'value', Boolean);
322
339
 
@@ -455,6 +472,10 @@ module.exports = (() => {
455
472
  updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrent));
456
473
  updates.summaryTotalPrevious = updates.summaryTotalPrevious.add(translate(item, item.data.summaryTotalPrevious));
457
474
 
475
+ if (item.position.type === InstrumentType.CASH) {
476
+ updates.cashTotal = updates.cashTotal.add(translate(item, item.data.market));
477
+ }
478
+
458
479
  return updates;
459
480
  }, {
460
481
  basis: Decimal.ZERO,
@@ -462,7 +483,8 @@ module.exports = (() => {
462
483
  unrealized: Decimal.ZERO,
463
484
  income: Decimal.ZERO,
464
485
  summaryTotalCurrent: Decimal.ZERO,
465
- summaryTotalPrevious: Decimal.ZERO
486
+ summaryTotalPrevious: Decimal.ZERO,
487
+ cashTotal: Decimal.ZERO
466
488
  });
467
489
 
468
490
  actual.basis = updates.basis;
@@ -471,6 +493,7 @@ module.exports = (() => {
471
493
  actual.income = updates.income;
472
494
  actual.summaryTotalCurrent = updates.summaryTotalCurrent;
473
495
  actual.summaryTotalPrevious = updates.summaryTotalPrevious;
496
+ actual.cashTotal = updates.cashTotal;
474
497
 
475
498
  format.basis = formatCurrency(actual.basis, currency);
476
499
  format.realized = formatCurrency(actual.basis, currency);
@@ -479,12 +502,15 @@ module.exports = (() => {
479
502
  format.summaryTotalCurrent = formatCurrency(updates.summaryTotalCurrent, currency);
480
503
  format.summaryTotalPrevious = formatCurrency(updates.summaryTotalPrevious, currency);
481
504
  format.summaryTotalPreviousNegative = updates.summaryTotalPrevious.getIsNegative();
505
+ format.cashTotal = formatCurrency(updates.cashTotal, currency);
482
506
 
483
507
  calculateUnrealizedPercent(group);
484
508
 
485
509
  if (group.single) {
486
510
  const item = group._items[0];
487
511
 
512
+ format.type = item.data.type || null;
513
+
488
514
  actual.quantity = item.position.snapshot.open;
489
515
  actual.basisPrice = item.data.basisPrice;
490
516
 
@@ -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;
@@ -63,6 +61,8 @@ module.exports = (() => {
63
61
  this._data.newsExists = false;
64
62
  this._data.fundamental = { };
65
63
 
64
+ this._data.type = null;
65
+
66
66
  calculateStaticData(this);
67
67
  calculatePriceData(this, null);
68
68
 
@@ -236,6 +236,10 @@ module.exports = (() => {
236
236
 
237
237
  const data = item._data;
238
238
 
239
+ if (position.miscellany && position.miscellany.type && position.miscellany.type.value) {
240
+ data.type = position.miscellany.type.value;
241
+ }
242
+
239
243
  data.previousPrice = position.previous || null;
240
244
 
241
245
  let basis;
@@ -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.157",
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,7 +1366,9 @@ 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
 
1371
+ this._dataFormat.type = null;
1367
1372
  this._dataFormat.currentPrice = null;
1368
1373
  this._dataFormat.previousPrice = null;
1369
1374
  this._dataFormat.basis = null;
@@ -1383,6 +1388,7 @@ module.exports = (() => {
1383
1388
  this._dataActual.summaryTotalCurrentNegative = false;
1384
1389
  this._dataFormat.summaryTotalPrevious = null;
1385
1390
  this._dataFormat.summaryTotalPreviousNegative = false;
1391
+ this._dataFormat.cashTotal = null;
1386
1392
 
1387
1393
  this._items.forEach((item) => {
1388
1394
  this._disposeStack.push(item.registerQuoteChangeHandler((quote, sender) => {
@@ -1410,8 +1416,11 @@ module.exports = (() => {
1410
1416
  this._dataFormat.quoteTime = this._dataActual.quoteTime;
1411
1417
  this._dataFormat.quoteVolume = formatNumber(this._dataActual.quoteVolume, 0);
1412
1418
 
1413
- setTimeout(() => this._dataFormat.quoteChangeDirection = { up: this._dataActual.quoteChange.getIsPositive(), down: this._dataActual.quoteChange.getIsNegative() }, 0);
1414
- this._dataFormat.quoteChangeNegative = this._dataActual.quoteChange.getIsNegative();
1419
+ const quoteChangePositive = is.number(this._dataActual.quoteChange) && this._dataActual.quoteChange > 0;
1420
+ const quoteChangeNegative = is.number(this._dataActual.quoteChange) && this._dataActual.quoteChange < 0;
1421
+
1422
+ setTimeout(() => this._dataFormat.quoteChangeDirection = { up: quoteChangePositive, down: quoteChangeNegative }, 0);
1423
+ this._dataFormat.quoteChangeNegative = quoteChangeNegative;
1415
1424
  } else {
1416
1425
  this._dataActual.currentPrice = null;
1417
1426
  this._dataFormat.currentPrice = null;
@@ -1563,6 +1572,13 @@ module.exports = (() => {
1563
1572
  }
1564
1573
  }
1565
1574
 
1575
+ /**
1576
+ * Set a flag to indicate if parent groups should exclude this group's
1577
+ * items from their calculations.
1578
+ *
1579
+ * @public
1580
+ * @param {Boolean} value
1581
+ */
1566
1582
  setExcluded(value) {
1567
1583
  assert.argumentIsRequired(value, 'value', Boolean);
1568
1584
 
@@ -1701,6 +1717,10 @@ module.exports = (() => {
1701
1717
  updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrent));
1702
1718
  updates.summaryTotalPrevious = updates.summaryTotalPrevious.add(translate(item, item.data.summaryTotalPrevious));
1703
1719
 
1720
+ if (item.position.type === InstrumentType.CASH) {
1721
+ updates.cashTotal = updates.cashTotal.add(translate(item, item.data.market));
1722
+ }
1723
+
1704
1724
  return updates;
1705
1725
  }, {
1706
1726
  basis: Decimal.ZERO,
@@ -1708,7 +1728,8 @@ module.exports = (() => {
1708
1728
  unrealized: Decimal.ZERO,
1709
1729
  income: Decimal.ZERO,
1710
1730
  summaryTotalCurrent: Decimal.ZERO,
1711
- summaryTotalPrevious: Decimal.ZERO
1731
+ summaryTotalPrevious: Decimal.ZERO,
1732
+ cashTotal: Decimal.ZERO
1712
1733
  });
1713
1734
 
1714
1735
  actual.basis = updates.basis;
@@ -1717,6 +1738,7 @@ module.exports = (() => {
1717
1738
  actual.income = updates.income;
1718
1739
  actual.summaryTotalCurrent = updates.summaryTotalCurrent;
1719
1740
  actual.summaryTotalPrevious = updates.summaryTotalPrevious;
1741
+ actual.cashTotal = updates.cashTotal;
1720
1742
 
1721
1743
  format.basis = formatCurrency(actual.basis, currency);
1722
1744
  format.realized = formatCurrency(actual.basis, currency);
@@ -1725,12 +1747,15 @@ module.exports = (() => {
1725
1747
  format.summaryTotalCurrent = formatCurrency(updates.summaryTotalCurrent, currency);
1726
1748
  format.summaryTotalPrevious = formatCurrency(updates.summaryTotalPrevious, currency);
1727
1749
  format.summaryTotalPreviousNegative = updates.summaryTotalPrevious.getIsNegative();
1750
+ format.cashTotal = formatCurrency(updates.cashTotal, currency);
1728
1751
 
1729
1752
  calculateUnrealizedPercent(group);
1730
1753
 
1731
1754
  if (group.single) {
1732
1755
  const item = group._items[0];
1733
1756
 
1757
+ format.type = item.data.type || null;
1758
+
1734
1759
  actual.quantity = item.position.snapshot.open;
1735
1760
  actual.basisPrice = item.data.basisPrice;
1736
1761
 
@@ -1886,7 +1911,7 @@ module.exports = (() => {
1886
1911
  return PositionGroup;
1887
1912
  })();
1888
1913
 
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){
1914
+ },{"./../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
1915
  const array = require('@barchart/common-js/lang/array'),
1891
1916
  assert = require('@barchart/common-js/lang/assert'),
1892
1917
  Currency = require('@barchart/common-js/lang/Currency'),
@@ -1924,9 +1949,7 @@ module.exports = (() => {
1924
1949
  this._data.basis = null;
1925
1950
 
1926
1951
  this._currentQuote = null;
1927
-
1928
1952
  this._currentPrice = null;
1929
- this._previousPrice = null;
1930
1953
 
1931
1954
  this._data.currentPrice = null;
1932
1955
  this._data.currentPricePrevious = null;
@@ -1952,6 +1975,8 @@ module.exports = (() => {
1952
1975
  this._data.newsExists = false;
1953
1976
  this._data.fundamental = { };
1954
1977
 
1978
+ this._data.type = null;
1979
+
1955
1980
  calculateStaticData(this);
1956
1981
  calculatePriceData(this, null);
1957
1982
 
@@ -2125,6 +2150,10 @@ module.exports = (() => {
2125
2150
 
2126
2151
  const data = item._data;
2127
2152
 
2153
+ if (position.miscellany && position.miscellany.type && position.miscellany.type.value) {
2154
+ data.type = position.miscellany.type.value;
2155
+ }
2156
+
2128
2157
  data.previousPrice = position.previous || null;
2129
2158
 
2130
2159
  let basis;
@@ -2273,10 +2302,12 @@ module.exports = (() => {
2273
2302
  * @param {PositionLevelDefinition~descriptionSelector} descriptionSelector
2274
2303
  * @param {PositionLevelDefinition~currencySelector} currencySelector
2275
2304
  * @param {Array.<PositionLevelDefinition~RequiredGroup>=} requiredGroups
2305
+ * @param {Array.<PositionLevelDefinition~RequiredGroup>=} requiredGroups
2276
2306
  * @param {Boolean=} single
2307
+ * @param {Boolean=} aggregateCash
2277
2308
  */
2278
2309
  class PositionLevelDefinition {
2279
- constructor(name, keySelector, descriptionSelector, currencySelector, requiredGroups, single) {
2310
+ constructor(name, keySelector, descriptionSelector, currencySelector, requiredGroups, single, aggregateCash) {
2280
2311
  assert.argumentIsRequired(name, 'name', String);
2281
2312
  assert.argumentIsRequired(keySelector, 'keySelector', Function);
2282
2313
  assert.argumentIsRequired(descriptionSelector, 'descriptionSelector', Function);
@@ -2287,6 +2318,7 @@ module.exports = (() => {
2287
2318
  }
2288
2319
 
2289
2320
  assert.argumentIsOptional(single, 'single', Boolean);
2321
+ assert.argumentIsOptional(aggregateCash, 'aggregateCash', Boolean);
2290
2322
 
2291
2323
  this._name = name;
2292
2324
 
@@ -2296,6 +2328,7 @@ module.exports = (() => {
2296
2328
 
2297
2329
  this._requiredGroups = requiredGroups || [ ];
2298
2330
  this._single = is.boolean(single) && single;
2331
+ this._aggregateCash = is.boolean(aggregateCash) && aggregateCash;
2299
2332
  }
2300
2333
 
2301
2334
  /**
@@ -2362,6 +2395,16 @@ module.exports = (() => {
2362
2395
  return this._single;
2363
2396
  }
2364
2397
 
2398
+ /**
2399
+ * Indicates if the grouping level should aggregate cash positions.
2400
+ *
2401
+ * @public
2402
+ * @returns {Boolean}
2403
+ */
2404
+ get aggregateCash() {
2405
+ return this._aggregateCash;
2406
+ }
2407
+
2365
2408
  toString() {
2366
2409
  return '[PositionLevelDefinition]';
2367
2410
  }