@barchart/portfolio-api-common 1.0.148 → 1.0.152

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.
@@ -34,10 +34,9 @@ module.exports = (() => {
34
34
  * @param {Array.<Object>} portfolios
35
35
  * @param {Array.<Object>} positions
36
36
  * @param {Array.<Object>} summaries
37
- * @param {Object=} exclusionDependencies
38
37
  */
39
38
  class PositionContainer {
40
- constructor(definitions, portfolios, positions, summaries, exclusionDependencies) {
39
+ constructor(definitions, portfolios, positions, summaries) {
41
40
  assert.argumentIsArray(definitions, 'definitions', PositionTreeDefinition, 'PositionTreeDefinition');
42
41
  assert.argumentIsArray(portfolios, 'portfolios');
43
42
  assert.argumentIsArray(positions, 'positions');
@@ -244,19 +243,9 @@ module.exports = (() => {
244
243
  }
245
244
  }, false);
246
245
 
247
- const treeName = treeDefinition.name;
248
-
249
- if (exclusionDependencies && exclusionDependencies.hasOwnProperty(treeName)) {
250
- let dependantNames = exclusionDependencies[treeName];
251
-
252
- if (is.string(dependantNames)) {
253
- dependantNames = [ dependantNames ];
254
- } else if (!is.array(dependantNames)) {
255
- dependantNames = [ ];
256
- }
257
-
258
- const dependantTrees = dependantNames.reduce((trees, name) => {
259
- if ( this._trees.hasOwnProperty(name)) {
246
+ if (treeDefinition.exclusionDependencies.length > 0) {
247
+ const dependantTrees = treeDefinition.exclusionDependencies.reduce((trees, name) => {
248
+ if (this._trees.hasOwnProperty(name)) {
260
249
  trees.push(this._trees[name]);
261
250
  }
262
251
 
@@ -266,7 +255,7 @@ module.exports = (() => {
266
255
  if (dependantTrees.length > 0) {
267
256
  let excludedItems = [ ];
268
257
 
269
- groupTree.walk((childGroup) => {
258
+ tree.walk((childGroup) => {
270
259
  if (childGroup.excluded) {
271
260
  excludedItems = excludedItems.concat(childGroup.items);
272
261
  }
@@ -102,6 +102,8 @@ module.exports = (() => {
102
102
  this._dataFormat.quoteChangePercent = null;
103
103
  this._dataFormat.quoteTime = null;
104
104
  this._dataFormat.quoteVolume = null;
105
+ this._dataFormat.quoteChangeDirection = unchanged;
106
+ this._dataFormat.quoteChangeNegative = false;
105
107
 
106
108
  this._dataActual.currentPrice = null;
107
109
  this._dataActual.previousPrice = null;
@@ -161,6 +163,9 @@ module.exports = (() => {
161
163
  this._dataFormat.quoteChangePercent = formatPercent(new Decimal(this._dataActual.quoteChangePercent || 0), 2);
162
164
  this._dataFormat.quoteTime = this._dataActual.quoteTime;
163
165
  this._dataFormat.quoteVolume = formatNumber(this._dataActual.quoteVolume, 0);
166
+
167
+ setTimeout(() => this._dataFormat.quoteChangeDirection = { up: this._dataActual.quoteChange.getIsPositive(), down: this._dataActual.quoteChange.getIsNegative() });
168
+ this._dataFormat.quoteChangeNegative = this._dataActual.quoteChange.getIsNegative();
164
169
  } else {
165
170
  this._dataActual.currentPrice = null;
166
171
  this._dataFormat.currentPrice = null;
@@ -185,7 +190,7 @@ module.exports = (() => {
185
190
  }
186
191
 
187
192
  /**
188
- * A unique (and otherwise meaningless) idenfitifer for the group.
193
+ * A unique (and otherwise meaningless) identifier for the group.
189
194
  *
190
195
  * @public
191
196
  * @returns {Number}
@@ -545,18 +550,6 @@ module.exports = (() => {
545
550
  summaryTotalCurrent: actual.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrentChange))
546
551
  };
547
552
  }
548
-
549
- if (parent !== null) {
550
- const parentData = parent._dataActual;
551
-
552
- if (parentData.market !== null && !parentData.market.getIsZero()) {
553
- updates.marketPercent = updates.market.divide(parentData.market);
554
- } else {
555
- updates.marketPercent = null;
556
- }
557
- } else {
558
- updates.marketPercent = null;
559
- }
560
553
 
561
554
  actual.market = updates.market;
562
555
  actual.unrealized = updates.unrealized;
@@ -593,13 +586,14 @@ module.exports = (() => {
593
586
  }
594
587
 
595
588
  const parent = group._parent;
589
+ const excluded = group._excluded;
596
590
 
597
591
  const actual = group._dataActual;
598
592
  const format = group._dataFormat;
599
593
 
600
594
  let marketPercent;
601
595
 
602
- if (parent !== null) {
596
+ if (parent !== null && !excluded) {
603
597
  const parentData = parent._dataActual;
604
598
 
605
599
  if (parentData.market !== null && !parentData.market.getIsZero()) {
@@ -13,12 +13,17 @@ module.exports = (() => {
13
13
  * @param {Array.<PositionLevelDefinition>} definitions
14
14
  */
15
15
  class PositionTreeDefinitions {
16
- constructor(name, definitions) {
16
+ constructor(name, definitions, exclusionDependencies) {
17
17
  assert.argumentIsRequired(name, 'name', String);
18
18
  assert.argumentIsArray(definitions, 'definitions', PositionLevelDefinition, 'PositionLevelDefinition');
19
19
 
20
+ if (exclusionDependencies) {
21
+ assert.argumentIsArray(exclusionDependencies, 'exclusionDependencies', String);
22
+ }
23
+
20
24
  this._name = name;
21
25
  this._definitions = definitions;
26
+ this._exclusionDependencies = exclusionDependencies || [ ];
22
27
  }
23
28
 
24
29
  /**
@@ -44,6 +49,17 @@ module.exports = (() => {
44
49
  return this._definitions;
45
50
  }
46
51
 
52
+ /**
53
+ * Returns the names of other trees which should be impacted when a
54
+ * group (from the current tree) is excluded.
55
+ *
56
+ * @public
57
+ * @return {Array.<String>}
58
+ */
59
+ get exclusionDependencies() {
60
+ return this._exclusionDependencies;
61
+ }
62
+
47
63
  toString() {
48
64
  return '[PositionTreeDefinitions]';
49
65
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.0.148",
3
+ "version": "1.0.152",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -750,10 +750,9 @@ module.exports = (() => {
750
750
  * @param {Array.<Object>} portfolios
751
751
  * @param {Array.<Object>} positions
752
752
  * @param {Array.<Object>} summaries
753
- * @param {Object=} exclusionDependencies
754
753
  */
755
754
  class PositionContainer {
756
- constructor(definitions, portfolios, positions, summaries, exclusionDependencies) {
755
+ constructor(definitions, portfolios, positions, summaries) {
757
756
  assert.argumentIsArray(definitions, 'definitions', PositionTreeDefinition, 'PositionTreeDefinition');
758
757
  assert.argumentIsArray(portfolios, 'portfolios');
759
758
  assert.argumentIsArray(positions, 'positions');
@@ -960,19 +959,9 @@ module.exports = (() => {
960
959
  }
961
960
  }, false);
962
961
 
963
- const treeName = treeDefinition.name;
964
-
965
- if (exclusionDependencies && exclusionDependencies.hasOwnProperty(treeName)) {
966
- let dependantNames = exclusionDependencies[treeName];
967
-
968
- if (is.string(dependantNames)) {
969
- dependantNames = [ dependantNames ];
970
- } else if (!is.array(dependantNames)) {
971
- dependantNames = [ ];
972
- }
973
-
974
- const dependantTrees = dependantNames.reduce((trees, name) => {
975
- if ( this._trees.hasOwnProperty(name)) {
962
+ if (treeDefinition.exclusionDependencies.length > 0) {
963
+ const dependantTrees = treeDefinition.exclusionDependencies.reduce((trees, name) => {
964
+ if (this._trees.hasOwnProperty(name)) {
976
965
  trees.push(this._trees[name]);
977
966
  }
978
967
 
@@ -982,7 +971,7 @@ module.exports = (() => {
982
971
  if (dependantTrees.length > 0) {
983
972
  let excludedItems = [ ];
984
973
 
985
- groupTree.walk((childGroup) => {
974
+ tree.walk((childGroup) => {
986
975
  if (childGroup.excluded) {
987
976
  excludedItems = excludedItems.concat(childGroup.items);
988
977
  }
@@ -1359,6 +1348,8 @@ module.exports = (() => {
1359
1348
  this._dataFormat.quoteChangePercent = null;
1360
1349
  this._dataFormat.quoteTime = null;
1361
1350
  this._dataFormat.quoteVolume = null;
1351
+ this._dataFormat.quoteChangeDirection = unchanged;
1352
+ this._dataFormat.quoteChangeNegative = false;
1362
1353
 
1363
1354
  this._dataActual.currentPrice = null;
1364
1355
  this._dataActual.previousPrice = null;
@@ -1418,6 +1409,9 @@ module.exports = (() => {
1418
1409
  this._dataFormat.quoteChangePercent = formatPercent(new Decimal(this._dataActual.quoteChangePercent || 0), 2);
1419
1410
  this._dataFormat.quoteTime = this._dataActual.quoteTime;
1420
1411
  this._dataFormat.quoteVolume = formatNumber(this._dataActual.quoteVolume, 0);
1412
+
1413
+ setTimeout(() => this._dataFormat.quoteChangeDirection = { up: this._dataActual.quoteChange.getIsPositive(), down: this._dataActual.quoteChange.getIsNegative() });
1414
+ this._dataFormat.quoteChangeNegative = this._dataActual.quoteChange.getIsNegative();
1421
1415
  } else {
1422
1416
  this._dataActual.currentPrice = null;
1423
1417
  this._dataFormat.currentPrice = null;
@@ -1442,7 +1436,7 @@ module.exports = (() => {
1442
1436
  }
1443
1437
 
1444
1438
  /**
1445
- * A unique (and otherwise meaningless) idenfitifer for the group.
1439
+ * A unique (and otherwise meaningless) identifier for the group.
1446
1440
  *
1447
1441
  * @public
1448
1442
  * @returns {Number}
@@ -1802,18 +1796,6 @@ module.exports = (() => {
1802
1796
  summaryTotalCurrent: actual.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrentChange))
1803
1797
  };
1804
1798
  }
1805
-
1806
- if (parent !== null) {
1807
- const parentData = parent._dataActual;
1808
-
1809
- if (parentData.market !== null && !parentData.market.getIsZero()) {
1810
- updates.marketPercent = updates.market.divide(parentData.market);
1811
- } else {
1812
- updates.marketPercent = null;
1813
- }
1814
- } else {
1815
- updates.marketPercent = null;
1816
- }
1817
1799
 
1818
1800
  actual.market = updates.market;
1819
1801
  actual.unrealized = updates.unrealized;
@@ -1850,13 +1832,14 @@ module.exports = (() => {
1850
1832
  }
1851
1833
 
1852
1834
  const parent = group._parent;
1835
+ const excluded = group._excluded;
1853
1836
 
1854
1837
  const actual = group._dataActual;
1855
1838
  const format = group._dataFormat;
1856
1839
 
1857
1840
  let marketPercent;
1858
1841
 
1859
- if (parent !== null) {
1842
+ if (parent !== null && !excluded) {
1860
1843
  const parentData = parent._dataActual;
1861
1844
 
1862
1845
  if (parentData.market !== null && !parentData.market.getIsZero()) {
@@ -2444,12 +2427,17 @@ module.exports = (() => {
2444
2427
  * @param {Array.<PositionLevelDefinition>} definitions
2445
2428
  */
2446
2429
  class PositionTreeDefinitions {
2447
- constructor(name, definitions) {
2430
+ constructor(name, definitions, exclusionDependencies) {
2448
2431
  assert.argumentIsRequired(name, 'name', String);
2449
2432
  assert.argumentIsArray(definitions, 'definitions', PositionLevelDefinition, 'PositionLevelDefinition');
2450
2433
 
2434
+ if (exclusionDependencies) {
2435
+ assert.argumentIsArray(exclusionDependencies, 'exclusionDependencies', String);
2436
+ }
2437
+
2451
2438
  this._name = name;
2452
2439
  this._definitions = definitions;
2440
+ this._exclusionDependencies = exclusionDependencies || [ ];
2453
2441
  }
2454
2442
 
2455
2443
  /**
@@ -2475,6 +2463,17 @@ module.exports = (() => {
2475
2463
  return this._definitions;
2476
2464
  }
2477
2465
 
2466
+ /**
2467
+ * Returns the names of other trees which should be impacted when a
2468
+ * group (from the current tree) is excluded.
2469
+ *
2470
+ * @public
2471
+ * @return {Array.<String>}
2472
+ */
2473
+ get exclusionDependencies() {
2474
+ return this._exclusionDependencies;
2475
+ }
2476
+
2478
2477
  toString() {
2479
2478
  return '[PositionTreeDefinitions]';
2480
2479
  }