@barchart/portfolio-api-common 1.0.168 → 1.0.172

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.
@@ -243,16 +243,12 @@ module.exports = (() => {
243
243
  assert.argumentIsRequired(portfolio.portfolio, 'portfolio.portfolio', String);
244
244
 
245
245
  this.startTransaction(() => {
246
- const itemsToRemove = getPositionItemsForPortfolio(this._items, portfolio.portfolio).forEach(i => removePositionItem.call(this, i));
247
-
248
- itemsToRemove.forEach(item => removePositionItem.call(this, item));
246
+ getPositionItemsForPortfolio(this._items, portfolio.portfolio).forEach(item => removePositionItem.call(this, item));
249
247
 
250
248
  delete this._portfolios[portfolio.portfolio];
251
249
 
252
250
  Object.keys(this._trees).forEach((key) => {
253
- const tree = this._tree[key];
254
-
255
- tree.walk((group, groupNode) => {
251
+ this._trees[key].walk((group, groupNode) => {
256
252
  if (group.definition.type === PositionLevelType.PORTFOLIO && group.key === PositionLevelDefinition.getKeyForPortfolioGroup(portfolio)) {
257
253
  groupNode.sever();
258
254
  }
@@ -627,6 +627,7 @@ module.exports = (() => {
627
627
 
628
628
  updates = items.reduce((updates, item) => {
629
629
  updates.market = updates.market.add(translate(item, item.data.market));
630
+ updates.marketAbsolute = updates.marketAbsolute.add(translate(item, item.data.market));
630
631
  updates.unrealized = updates.unrealized.add(translate(item, item.data.unrealized));
631
632
  updates.unrealizedToday = updates.unrealizedToday.add(translate(item, item.data.unrealizedToday));
632
633
  updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrent));
@@ -634,6 +635,7 @@ module.exports = (() => {
634
635
  return updates;
635
636
  }, {
636
637
  market: Decimal.ZERO,
638
+ marketAbsolute: Decimal.ZERO,
637
639
  marketDirection: unchanged,
638
640
  unrealized: Decimal.ZERO,
639
641
  unrealizedToday: Decimal.ZERO,
@@ -642,6 +644,7 @@ module.exports = (() => {
642
644
  } else {
643
645
  updates = {
644
646
  market: actual.market.add(translate(item, item.data.marketChange)),
647
+ marketAbsolute: actual.marketAbsolute.add(translate(item, item.data.marketAbsoluteChange)),
645
648
  marketDirection: { up: item.data.marketChange.getIsPositive(), down: item.data.marketChange.getIsNegative() },
646
649
  unrealized: actual.unrealized.add(translate(item, item.data.unrealizedChange)),
647
650
  unrealizedToday: actual.unrealizedToday.add(translate(item, item.data.unrealizedTodayChange)),
@@ -650,6 +653,7 @@ module.exports = (() => {
650
653
  }
651
654
 
652
655
  actual.market = updates.market;
656
+ actual.marketAbsolute = updates.marketAbsolute;
653
657
  actual.unrealized = updates.unrealized;
654
658
  actual.unrealizedToday = updates.unrealizedToday;
655
659
  actual.summaryTotalCurrent = updates.summaryTotalCurrent;
@@ -694,16 +698,16 @@ module.exports = (() => {
694
698
  if (parent !== null && !excluded) {
695
699
  const parentData = parent._dataActual;
696
700
 
697
- if (parentData.market !== null && !parentData.market.getIsZero()) {
701
+ if (parentData.marketAbsolute !== null && !parentData.marketAbsolute.getIsZero()) {
698
702
  let numerator;
699
703
 
700
704
  if (group.currency !== parent.currency) {
701
705
  numerator = Rate.convert(actual.market, group.currency, parent.currency, ...rates);
702
706
  } else {
703
- numerator = actual.market;
707
+ numerator = actual.marketAbsolute;
704
708
  }
705
709
 
706
- marketPercent = numerator.divide(parentData.market);
710
+ marketPercent = numerator.divide(parentData.marketAbsolute);
707
711
  } else {
708
712
  marketPercent = null;
709
713
  }
@@ -46,6 +46,9 @@ module.exports = (() => {
46
46
  this._data.market = null;
47
47
  this._data.marketChange = null;
48
48
 
49
+ this._data.marketAbsolute = null;
50
+ this._data.marketAbsoluteChange = null;
51
+
49
52
  this._data.unrealizedToday = null;
50
53
  this._data.unrealizedTodayChange = null;
51
54
 
@@ -329,6 +332,18 @@ module.exports = (() => {
329
332
  data.market = market;
330
333
  data.marketChange = marketChange;
331
334
 
335
+ let marketAbsolute = market.absolute();
336
+ let marketAbsoluteChange;
337
+
338
+ if (data.marketAbsolute === null) {
339
+ marketAbsoluteChange = marketAbsolute;
340
+ } else {
341
+ marketAbsoluteChange = marketAbsolute.subtract(data.marketAbsolute);
342
+ }
343
+
344
+ data.marketAbsolute = market;
345
+ data.marketAbsoluteChange = marketChange;
346
+
332
347
  let unrealizedToday;
333
348
  let unrealizedTodayChange;
334
349
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.0.168",
3
+ "version": "1.0.172",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -959,16 +959,12 @@ module.exports = (() => {
959
959
  assert.argumentIsRequired(portfolio.portfolio, 'portfolio.portfolio', String);
960
960
 
961
961
  this.startTransaction(() => {
962
- const itemsToRemove = getPositionItemsForPortfolio(this._items, portfolio.portfolio).forEach(i => removePositionItem.call(this, i));
963
-
964
- itemsToRemove.forEach(item => removePositionItem.call(this, item));
962
+ getPositionItemsForPortfolio(this._items, portfolio.portfolio).forEach(item => removePositionItem.call(this, item));
965
963
 
966
964
  delete this._portfolios[portfolio.portfolio];
967
965
 
968
966
  Object.keys(this._trees).forEach((key) => {
969
- const tree = this._tree[key];
970
-
971
- tree.walk((group, groupNode) => {
967
+ this._trees[key].walk((group, groupNode) => {
972
968
  if (group.definition.type === PositionLevelType.PORTFOLIO && group.key === PositionLevelDefinition.getKeyForPortfolioGroup(portfolio)) {
973
969
  groupNode.sever();
974
970
  }
@@ -2054,6 +2050,7 @@ module.exports = (() => {
2054
2050
 
2055
2051
  updates = items.reduce((updates, item) => {
2056
2052
  updates.market = updates.market.add(translate(item, item.data.market));
2053
+ updates.marketAbsolute = updates.marketAbsolute.add(translate(item, item.data.market));
2057
2054
  updates.unrealized = updates.unrealized.add(translate(item, item.data.unrealized));
2058
2055
  updates.unrealizedToday = updates.unrealizedToday.add(translate(item, item.data.unrealizedToday));
2059
2056
  updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrent));
@@ -2061,6 +2058,7 @@ module.exports = (() => {
2061
2058
  return updates;
2062
2059
  }, {
2063
2060
  market: Decimal.ZERO,
2061
+ marketAbsolute: Decimal.ZERO,
2064
2062
  marketDirection: unchanged,
2065
2063
  unrealized: Decimal.ZERO,
2066
2064
  unrealizedToday: Decimal.ZERO,
@@ -2069,6 +2067,7 @@ module.exports = (() => {
2069
2067
  } else {
2070
2068
  updates = {
2071
2069
  market: actual.market.add(translate(item, item.data.marketChange)),
2070
+ marketAbsolute: actual.marketAbsolute.add(translate(item, item.data.marketAbsoluteChange)),
2072
2071
  marketDirection: { up: item.data.marketChange.getIsPositive(), down: item.data.marketChange.getIsNegative() },
2073
2072
  unrealized: actual.unrealized.add(translate(item, item.data.unrealizedChange)),
2074
2073
  unrealizedToday: actual.unrealizedToday.add(translate(item, item.data.unrealizedTodayChange)),
@@ -2077,6 +2076,7 @@ module.exports = (() => {
2077
2076
  }
2078
2077
 
2079
2078
  actual.market = updates.market;
2079
+ actual.marketAbsolute = updates.marketAbsolute;
2080
2080
  actual.unrealized = updates.unrealized;
2081
2081
  actual.unrealizedToday = updates.unrealizedToday;
2082
2082
  actual.summaryTotalCurrent = updates.summaryTotalCurrent;
@@ -2121,16 +2121,16 @@ module.exports = (() => {
2121
2121
  if (parent !== null && !excluded) {
2122
2122
  const parentData = parent._dataActual;
2123
2123
 
2124
- if (parentData.market !== null && !parentData.market.getIsZero()) {
2124
+ if (parentData.marketAbsolute !== null && !parentData.marketAbsolute.getIsZero()) {
2125
2125
  let numerator;
2126
2126
 
2127
2127
  if (group.currency !== parent.currency) {
2128
2128
  numerator = Rate.convert(actual.market, group.currency, parent.currency, ...rates);
2129
2129
  } else {
2130
- numerator = actual.market;
2130
+ numerator = actual.marketAbsolute;
2131
2131
  }
2132
2132
 
2133
- marketPercent = numerator.divide(parentData.market);
2133
+ marketPercent = numerator.divide(parentData.marketAbsolute);
2134
2134
  } else {
2135
2135
  marketPercent = null;
2136
2136
  }
@@ -2214,6 +2214,9 @@ module.exports = (() => {
2214
2214
  this._data.market = null;
2215
2215
  this._data.marketChange = null;
2216
2216
 
2217
+ this._data.marketAbsolute = null;
2218
+ this._data.marketAbsoluteChange = null;
2219
+
2217
2220
  this._data.unrealizedToday = null;
2218
2221
  this._data.unrealizedTodayChange = null;
2219
2222
 
@@ -2497,6 +2500,18 @@ module.exports = (() => {
2497
2500
  data.market = market;
2498
2501
  data.marketChange = marketChange;
2499
2502
 
2503
+ let marketAbsolute = market.absolute();
2504
+ let marketAbsoluteChange;
2505
+
2506
+ if (data.marketAbsolute === null) {
2507
+ marketAbsoluteChange = marketAbsolute;
2508
+ } else {
2509
+ marketAbsoluteChange = marketAbsolute.subtract(data.marketAbsolute);
2510
+ }
2511
+
2512
+ data.marketAbsolute = market;
2513
+ data.marketAbsoluteChange = marketChange;
2514
+
2500
2515
  let unrealizedToday;
2501
2516
  let unrealizedTodayChange;
2502
2517