@barchart/portfolio-api-common 1.0.151 → 1.0.155

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;
@@ -102,6 +106,8 @@ module.exports = (() => {
102
106
  this._dataFormat.quoteChangePercent = null;
103
107
  this._dataFormat.quoteTime = null;
104
108
  this._dataFormat.quoteVolume = null;
109
+ this._dataFormat.quoteChangeDirection = unchanged;
110
+ this._dataFormat.quoteChangeNegative = false;
105
111
 
106
112
  this._dataActual.currentPrice = null;
107
113
  this._dataActual.previousPrice = null;
@@ -115,6 +121,7 @@ module.exports = (() => {
115
121
  this._dataActual.total = null;
116
122
  this._dataActual.summaryTotalCurrent = null;
117
123
  this._dataActual.summaryTotalPrevious = null;
124
+ this._dataActual.cashTotal = null;
118
125
 
119
126
  this._dataFormat.currentPrice = null;
120
127
  this._dataFormat.previousPrice = null;
@@ -135,6 +142,7 @@ module.exports = (() => {
135
142
  this._dataActual.summaryTotalCurrentNegative = false;
136
143
  this._dataFormat.summaryTotalPrevious = null;
137
144
  this._dataFormat.summaryTotalPreviousNegative = false;
145
+ this._dataFormat.cashTotal = null;
138
146
 
139
147
  this._items.forEach((item) => {
140
148
  this._disposeStack.push(item.registerQuoteChangeHandler((quote, sender) => {
@@ -161,6 +169,12 @@ module.exports = (() => {
161
169
  this._dataFormat.quoteChangePercent = formatPercent(new Decimal(this._dataActual.quoteChangePercent || 0), 2);
162
170
  this._dataFormat.quoteTime = this._dataActual.quoteTime;
163
171
  this._dataFormat.quoteVolume = formatNumber(this._dataActual.quoteVolume, 0);
172
+
173
+ const quoteChangePositive = is.number(this._dataActual.quoteChange) && this._dataActual.quoteChange.getIsPositive() > 0;
174
+ const quoteChangeNegative = is.number(this._dataActual.quoteChange) && this._dataActual.quoteChange.getIsPositive() < 0;
175
+
176
+ setTimeout(() => this._dataFormat.quoteChangeDirection = { up: quoteChangePositive, down: quoteChangeNegative }, 0);
177
+ this._dataFormat.quoteChangeNegative = quoteChangeNegative;
164
178
  } else {
165
179
  this._dataActual.currentPrice = null;
166
180
  this._dataFormat.currentPrice = null;
@@ -185,7 +199,7 @@ module.exports = (() => {
185
199
  }
186
200
 
187
201
  /**
188
- * A unique (and otherwise meaningless) idenfitifer for the group.
202
+ * A unique (and otherwise meaningless) identifier for the group.
189
203
  *
190
204
  * @public
191
205
  * @returns {Number}
@@ -312,6 +326,13 @@ module.exports = (() => {
312
326
  }
313
327
  }
314
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
+ */
315
336
  setExcluded(value) {
316
337
  assert.argumentIsRequired(value, 'value', Boolean);
317
338
 
@@ -450,6 +471,10 @@ module.exports = (() => {
450
471
  updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrent));
451
472
  updates.summaryTotalPrevious = updates.summaryTotalPrevious.add(translate(item, item.data.summaryTotalPrevious));
452
473
 
474
+ if (item.position.type === InstrumentType.CASH) {
475
+ updates.cashTotal = updates.cashTotal.add(translate(item, item.data.market));
476
+ }
477
+
453
478
  return updates;
454
479
  }, {
455
480
  basis: Decimal.ZERO,
@@ -457,7 +482,8 @@ module.exports = (() => {
457
482
  unrealized: Decimal.ZERO,
458
483
  income: Decimal.ZERO,
459
484
  summaryTotalCurrent: Decimal.ZERO,
460
- summaryTotalPrevious: Decimal.ZERO
485
+ summaryTotalPrevious: Decimal.ZERO,
486
+ cashTotal: Decimal.ZERO
461
487
  });
462
488
 
463
489
  actual.basis = updates.basis;
@@ -466,6 +492,7 @@ module.exports = (() => {
466
492
  actual.income = updates.income;
467
493
  actual.summaryTotalCurrent = updates.summaryTotalCurrent;
468
494
  actual.summaryTotalPrevious = updates.summaryTotalPrevious;
495
+ actual.cashTotal = updates.cashTotal;
469
496
 
470
497
  format.basis = formatCurrency(actual.basis, currency);
471
498
  format.realized = formatCurrency(actual.basis, currency);
@@ -474,6 +501,7 @@ module.exports = (() => {
474
501
  format.summaryTotalCurrent = formatCurrency(updates.summaryTotalCurrent, currency);
475
502
  format.summaryTotalPrevious = formatCurrency(updates.summaryTotalPrevious, currency);
476
503
  format.summaryTotalPreviousNegative = updates.summaryTotalPrevious.getIsNegative();
504
+ format.cashTotal = formatCurrency(updates.cashTotal, currency);
477
505
 
478
506
  calculateUnrealizedPercent(group);
479
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.151",
3
+ "version": "1.0.155",
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;
@@ -1348,6 +1351,8 @@ module.exports = (() => {
1348
1351
  this._dataFormat.quoteChangePercent = null;
1349
1352
  this._dataFormat.quoteTime = null;
1350
1353
  this._dataFormat.quoteVolume = null;
1354
+ this._dataFormat.quoteChangeDirection = unchanged;
1355
+ this._dataFormat.quoteChangeNegative = false;
1351
1356
 
1352
1357
  this._dataActual.currentPrice = null;
1353
1358
  this._dataActual.previousPrice = null;
@@ -1361,6 +1366,7 @@ module.exports = (() => {
1361
1366
  this._dataActual.total = null;
1362
1367
  this._dataActual.summaryTotalCurrent = null;
1363
1368
  this._dataActual.summaryTotalPrevious = null;
1369
+ this._dataActual.cashTotal = null;
1364
1370
 
1365
1371
  this._dataFormat.currentPrice = null;
1366
1372
  this._dataFormat.previousPrice = null;
@@ -1381,6 +1387,7 @@ module.exports = (() => {
1381
1387
  this._dataActual.summaryTotalCurrentNegative = false;
1382
1388
  this._dataFormat.summaryTotalPrevious = null;
1383
1389
  this._dataFormat.summaryTotalPreviousNegative = false;
1390
+ this._dataFormat.cashTotal = null;
1384
1391
 
1385
1392
  this._items.forEach((item) => {
1386
1393
  this._disposeStack.push(item.registerQuoteChangeHandler((quote, sender) => {
@@ -1407,6 +1414,12 @@ module.exports = (() => {
1407
1414
  this._dataFormat.quoteChangePercent = formatPercent(new Decimal(this._dataActual.quoteChangePercent || 0), 2);
1408
1415
  this._dataFormat.quoteTime = this._dataActual.quoteTime;
1409
1416
  this._dataFormat.quoteVolume = formatNumber(this._dataActual.quoteVolume, 0);
1417
+
1418
+ const quoteChangePositive = is.number(this._dataActual.quoteChange) && this._dataActual.quoteChange.getIsPositive() > 0;
1419
+ const quoteChangeNegative = is.number(this._dataActual.quoteChange) && this._dataActual.quoteChange.getIsPositive() < 0;
1420
+
1421
+ setTimeout(() => this._dataFormat.quoteChangeDirection = { up: quoteChangePositive, down: quoteChangeNegative }, 0);
1422
+ this._dataFormat.quoteChangeNegative = quoteChangeNegative;
1410
1423
  } else {
1411
1424
  this._dataActual.currentPrice = null;
1412
1425
  this._dataFormat.currentPrice = null;
@@ -1431,7 +1444,7 @@ module.exports = (() => {
1431
1444
  }
1432
1445
 
1433
1446
  /**
1434
- * A unique (and otherwise meaningless) idenfitifer for the group.
1447
+ * A unique (and otherwise meaningless) identifier for the group.
1435
1448
  *
1436
1449
  * @public
1437
1450
  * @returns {Number}
@@ -1558,6 +1571,13 @@ module.exports = (() => {
1558
1571
  }
1559
1572
  }
1560
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
+ */
1561
1581
  setExcluded(value) {
1562
1582
  assert.argumentIsRequired(value, 'value', Boolean);
1563
1583
 
@@ -1696,6 +1716,10 @@ module.exports = (() => {
1696
1716
  updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrent));
1697
1717
  updates.summaryTotalPrevious = updates.summaryTotalPrevious.add(translate(item, item.data.summaryTotalPrevious));
1698
1718
 
1719
+ if (item.position.type === InstrumentType.CASH) {
1720
+ updates.cashTotal = updates.cashTotal.add(translate(item, item.data.market));
1721
+ }
1722
+
1699
1723
  return updates;
1700
1724
  }, {
1701
1725
  basis: Decimal.ZERO,
@@ -1703,7 +1727,8 @@ module.exports = (() => {
1703
1727
  unrealized: Decimal.ZERO,
1704
1728
  income: Decimal.ZERO,
1705
1729
  summaryTotalCurrent: Decimal.ZERO,
1706
- summaryTotalPrevious: Decimal.ZERO
1730
+ summaryTotalPrevious: Decimal.ZERO,
1731
+ cashTotal: Decimal.ZERO
1707
1732
  });
1708
1733
 
1709
1734
  actual.basis = updates.basis;
@@ -1712,6 +1737,7 @@ module.exports = (() => {
1712
1737
  actual.income = updates.income;
1713
1738
  actual.summaryTotalCurrent = updates.summaryTotalCurrent;
1714
1739
  actual.summaryTotalPrevious = updates.summaryTotalPrevious;
1740
+ actual.cashTotal = updates.cashTotal;
1715
1741
 
1716
1742
  format.basis = formatCurrency(actual.basis, currency);
1717
1743
  format.realized = formatCurrency(actual.basis, currency);
@@ -1720,6 +1746,7 @@ module.exports = (() => {
1720
1746
  format.summaryTotalCurrent = formatCurrency(updates.summaryTotalCurrent, currency);
1721
1747
  format.summaryTotalPrevious = formatCurrency(updates.summaryTotalPrevious, currency);
1722
1748
  format.summaryTotalPreviousNegative = updates.summaryTotalPrevious.getIsNegative();
1749
+ format.cashTotal = formatCurrency(updates.cashTotal, currency);
1723
1750
 
1724
1751
  calculateUnrealizedPercent(group);
1725
1752
 
@@ -1881,7 +1908,7 @@ module.exports = (() => {
1881
1908
  return PositionGroup;
1882
1909
  })();
1883
1910
 
1884
- },{"@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){
1885
1912
  const array = require('@barchart/common-js/lang/array'),
1886
1913
  assert = require('@barchart/common-js/lang/assert'),
1887
1914
  Currency = require('@barchart/common-js/lang/Currency'),
@@ -1919,9 +1946,7 @@ module.exports = (() => {
1919
1946
  this._data.basis = null;
1920
1947
 
1921
1948
  this._currentQuote = null;
1922
-
1923
1949
  this._currentPrice = null;
1924
- this._previousPrice = null;
1925
1950
 
1926
1951
  this._data.currentPrice = null;
1927
1952
  this._data.currentPricePrevious = null;
@@ -2268,10 +2293,12 @@ module.exports = (() => {
2268
2293
  * @param {PositionLevelDefinition~descriptionSelector} descriptionSelector
2269
2294
  * @param {PositionLevelDefinition~currencySelector} currencySelector
2270
2295
  * @param {Array.<PositionLevelDefinition~RequiredGroup>=} requiredGroups
2296
+ * @param {Array.<PositionLevelDefinition~RequiredGroup>=} requiredGroups
2271
2297
  * @param {Boolean=} single
2298
+ * @param {Boolean=} aggregateCash
2272
2299
  */
2273
2300
  class PositionLevelDefinition {
2274
- constructor(name, keySelector, descriptionSelector, currencySelector, requiredGroups, single) {
2301
+ constructor(name, keySelector, descriptionSelector, currencySelector, requiredGroups, single, aggregateCash) {
2275
2302
  assert.argumentIsRequired(name, 'name', String);
2276
2303
  assert.argumentIsRequired(keySelector, 'keySelector', Function);
2277
2304
  assert.argumentIsRequired(descriptionSelector, 'descriptionSelector', Function);
@@ -2282,6 +2309,7 @@ module.exports = (() => {
2282
2309
  }
2283
2310
 
2284
2311
  assert.argumentIsOptional(single, 'single', Boolean);
2312
+ assert.argumentIsOptional(aggregateCash, 'aggregateCash', Boolean);
2285
2313
 
2286
2314
  this._name = name;
2287
2315
 
@@ -2291,6 +2319,7 @@ module.exports = (() => {
2291
2319
 
2292
2320
  this._requiredGroups = requiredGroups || [ ];
2293
2321
  this._single = is.boolean(single) && single;
2322
+ this._aggregateCash = is.boolean(aggregateCash) && aggregateCash;
2294
2323
  }
2295
2324
 
2296
2325
  /**
@@ -2357,6 +2386,16 @@ module.exports = (() => {
2357
2386
  return this._single;
2358
2387
  }
2359
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
+
2360
2399
  toString() {
2361
2400
  return '[PositionLevelDefinition]';
2362
2401
  }