@barchart/portfolio-api-common 1.0.169 → 1.0.173
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.
|
@@ -248,9 +248,7 @@ module.exports = (() => {
|
|
|
248
248
|
delete this._portfolios[portfolio.portfolio];
|
|
249
249
|
|
|
250
250
|
Object.keys(this._trees).forEach((key) => {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
tree.walk((group, groupNode) => {
|
|
251
|
+
this._trees[key].walk((group, groupNode) => {
|
|
254
252
|
if (group.definition.type === PositionLevelType.PORTFOLIO && group.key === PositionLevelDefinition.getKeyForPortfolioGroup(portfolio)) {
|
|
255
253
|
groupNode.sever();
|
|
256
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.
|
|
701
|
+
if (parentData.marketAbsolute !== null && !parentData.marketAbsolute.getIsZero()) {
|
|
698
702
|
let numerator;
|
|
699
703
|
|
|
700
704
|
if (group.currency !== parent.currency) {
|
|
701
|
-
numerator = Rate.convert(actual.
|
|
705
|
+
numerator = Rate.convert(actual.marketAbsolute, group.currency, parent.currency, ...rates);
|
|
702
706
|
} else {
|
|
703
|
-
numerator = actual.
|
|
707
|
+
numerator = actual.marketAbsolute;
|
|
704
708
|
}
|
|
705
709
|
|
|
706
|
-
marketPercent = numerator.divide(parentData.
|
|
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
package/test/SpecRunner.js
CHANGED
|
@@ -964,9 +964,7 @@ module.exports = (() => {
|
|
|
964
964
|
delete this._portfolios[portfolio.portfolio];
|
|
965
965
|
|
|
966
966
|
Object.keys(this._trees).forEach((key) => {
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
tree.walk((group, groupNode) => {
|
|
967
|
+
this._trees[key].walk((group, groupNode) => {
|
|
970
968
|
if (group.definition.type === PositionLevelType.PORTFOLIO && group.key === PositionLevelDefinition.getKeyForPortfolioGroup(portfolio)) {
|
|
971
969
|
groupNode.sever();
|
|
972
970
|
}
|
|
@@ -2052,6 +2050,7 @@ module.exports = (() => {
|
|
|
2052
2050
|
|
|
2053
2051
|
updates = items.reduce((updates, item) => {
|
|
2054
2052
|
updates.market = updates.market.add(translate(item, item.data.market));
|
|
2053
|
+
updates.marketAbsolute = updates.marketAbsolute.add(translate(item, item.data.market));
|
|
2055
2054
|
updates.unrealized = updates.unrealized.add(translate(item, item.data.unrealized));
|
|
2056
2055
|
updates.unrealizedToday = updates.unrealizedToday.add(translate(item, item.data.unrealizedToday));
|
|
2057
2056
|
updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrent));
|
|
@@ -2059,6 +2058,7 @@ module.exports = (() => {
|
|
|
2059
2058
|
return updates;
|
|
2060
2059
|
}, {
|
|
2061
2060
|
market: Decimal.ZERO,
|
|
2061
|
+
marketAbsolute: Decimal.ZERO,
|
|
2062
2062
|
marketDirection: unchanged,
|
|
2063
2063
|
unrealized: Decimal.ZERO,
|
|
2064
2064
|
unrealizedToday: Decimal.ZERO,
|
|
@@ -2067,6 +2067,7 @@ module.exports = (() => {
|
|
|
2067
2067
|
} else {
|
|
2068
2068
|
updates = {
|
|
2069
2069
|
market: actual.market.add(translate(item, item.data.marketChange)),
|
|
2070
|
+
marketAbsolute: actual.marketAbsolute.add(translate(item, item.data.marketAbsoluteChange)),
|
|
2070
2071
|
marketDirection: { up: item.data.marketChange.getIsPositive(), down: item.data.marketChange.getIsNegative() },
|
|
2071
2072
|
unrealized: actual.unrealized.add(translate(item, item.data.unrealizedChange)),
|
|
2072
2073
|
unrealizedToday: actual.unrealizedToday.add(translate(item, item.data.unrealizedTodayChange)),
|
|
@@ -2075,6 +2076,7 @@ module.exports = (() => {
|
|
|
2075
2076
|
}
|
|
2076
2077
|
|
|
2077
2078
|
actual.market = updates.market;
|
|
2079
|
+
actual.marketAbsolute = updates.marketAbsolute;
|
|
2078
2080
|
actual.unrealized = updates.unrealized;
|
|
2079
2081
|
actual.unrealizedToday = updates.unrealizedToday;
|
|
2080
2082
|
actual.summaryTotalCurrent = updates.summaryTotalCurrent;
|
|
@@ -2119,16 +2121,16 @@ module.exports = (() => {
|
|
|
2119
2121
|
if (parent !== null && !excluded) {
|
|
2120
2122
|
const parentData = parent._dataActual;
|
|
2121
2123
|
|
|
2122
|
-
if (parentData.
|
|
2124
|
+
if (parentData.marketAbsolute !== null && !parentData.marketAbsolute.getIsZero()) {
|
|
2123
2125
|
let numerator;
|
|
2124
2126
|
|
|
2125
2127
|
if (group.currency !== parent.currency) {
|
|
2126
|
-
numerator = Rate.convert(actual.
|
|
2128
|
+
numerator = Rate.convert(actual.marketAbsolute, group.currency, parent.currency, ...rates);
|
|
2127
2129
|
} else {
|
|
2128
|
-
numerator = actual.
|
|
2130
|
+
numerator = actual.marketAbsolute;
|
|
2129
2131
|
}
|
|
2130
2132
|
|
|
2131
|
-
marketPercent = numerator.divide(parentData.
|
|
2133
|
+
marketPercent = numerator.divide(parentData.marketAbsolute);
|
|
2132
2134
|
} else {
|
|
2133
2135
|
marketPercent = null;
|
|
2134
2136
|
}
|
|
@@ -2212,6 +2214,9 @@ module.exports = (() => {
|
|
|
2212
2214
|
this._data.market = null;
|
|
2213
2215
|
this._data.marketChange = null;
|
|
2214
2216
|
|
|
2217
|
+
this._data.marketAbsolute = null;
|
|
2218
|
+
this._data.marketAbsoluteChange = null;
|
|
2219
|
+
|
|
2215
2220
|
this._data.unrealizedToday = null;
|
|
2216
2221
|
this._data.unrealizedTodayChange = null;
|
|
2217
2222
|
|
|
@@ -2495,6 +2500,18 @@ module.exports = (() => {
|
|
|
2495
2500
|
data.market = market;
|
|
2496
2501
|
data.marketChange = marketChange;
|
|
2497
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
|
+
|
|
2498
2515
|
let unrealizedToday;
|
|
2499
2516
|
let unrealizedTodayChange;
|
|
2500
2517
|
|