@barchart/portfolio-api-common 1.2.94 → 1.2.95
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.
|
@@ -75,12 +75,14 @@ module.exports = (() => {
|
|
|
75
75
|
this._dataFormat.locked = false;
|
|
76
76
|
this._dataFormat.newsExists = false;
|
|
77
77
|
this._dataFormat.quantity = null;
|
|
78
|
+
this._dataFormat.quantityPrevious = null;
|
|
78
79
|
this._dataFormat.basisPrice = null;
|
|
79
80
|
|
|
80
81
|
this._dataActual.key = this._key;
|
|
81
82
|
this._dataActual.description = this._description;
|
|
82
83
|
this._dataActual.newsExists = false;
|
|
83
84
|
this._dataActual.quantity = null;
|
|
85
|
+
this._dataActual.quantityPrevious = null;
|
|
84
86
|
this._dataActual.basisPrice = null;
|
|
85
87
|
|
|
86
88
|
if (this._single && items.length === 1) {
|
|
@@ -130,10 +132,10 @@ module.exports = (() => {
|
|
|
130
132
|
this._dataActual.summaryTotalCurrent = null;
|
|
131
133
|
this._dataActual.summaryTotalPrevious = null;
|
|
132
134
|
this._dataActual.summaryTotalPrevious2 = null;
|
|
133
|
-
this._dataActual.
|
|
134
|
-
this._dataActual.
|
|
135
|
-
this._dataActual.
|
|
136
|
-
this._dataActual.
|
|
135
|
+
this._dataActual.marketPrevious = null;
|
|
136
|
+
this._dataActual.marketPrevious2 = null;
|
|
137
|
+
this._dataActual.marketChange = null;
|
|
138
|
+
this._dataActual.marketChangePercent = null;
|
|
137
139
|
this._dataActual.cashTotal = null;
|
|
138
140
|
|
|
139
141
|
this._dataFormat.currentPrice = null;
|
|
@@ -157,10 +159,10 @@ module.exports = (() => {
|
|
|
157
159
|
this._dataFormat.summaryTotalPreviousNegative = false;
|
|
158
160
|
this._dataFormat.summaryTotalPrevious2 = null;
|
|
159
161
|
this._dataFormat.summaryTotalPrevious2Negative = false;
|
|
160
|
-
this._dataFormat.
|
|
161
|
-
this._dataFormat.
|
|
162
|
-
this._dataFormat.
|
|
163
|
-
this._dataFormat.
|
|
162
|
+
this._dataFormat.marketPrevious = null;
|
|
163
|
+
this._dataFormat.marketPrevious2 = null;
|
|
164
|
+
this._dataFormat.marketChange = null;
|
|
165
|
+
this._dataFormat.marketChangePercent = null;
|
|
164
166
|
this._dataFormat.cashTotal = null;
|
|
165
167
|
this._dataFormat.portfolioType = null;
|
|
166
168
|
|
|
@@ -657,8 +659,8 @@ module.exports = (() => {
|
|
|
657
659
|
updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrent));
|
|
658
660
|
updates.summaryTotalPrevious = updates.summaryTotalPrevious.add(translate(item, item.data.summaryTotalPrevious));
|
|
659
661
|
updates.summaryTotalPrevious2 = updates.summaryTotalPrevious2.add(translate(item, item.data.summaryTotalPrevious2));
|
|
660
|
-
updates.
|
|
661
|
-
updates.
|
|
662
|
+
updates.marketPrevious = updates.marketPrevious.add(translate(item, item.data.marketPrevious));
|
|
663
|
+
updates.marketPrevious2 = updates.marketPrevious2.add(translate(item, item.data.marketPrevious2));
|
|
662
664
|
|
|
663
665
|
if (item.position.instrument.type === InstrumentType.CASH) {
|
|
664
666
|
updates.cashTotal = updates.cashTotal.add(translate(item, item.data.market));
|
|
@@ -673,8 +675,8 @@ module.exports = (() => {
|
|
|
673
675
|
summaryTotalCurrent: Decimal.ZERO,
|
|
674
676
|
summaryTotalPrevious: Decimal.ZERO,
|
|
675
677
|
summaryTotalPrevious2: Decimal.ZERO,
|
|
676
|
-
|
|
677
|
-
|
|
678
|
+
marketPrevious: Decimal.ZERO,
|
|
679
|
+
marketPrevious2: Decimal.ZERO,
|
|
678
680
|
cashTotal: Decimal.ZERO
|
|
679
681
|
});
|
|
680
682
|
|
|
@@ -685,8 +687,8 @@ module.exports = (() => {
|
|
|
685
687
|
actual.summaryTotalCurrent = updates.summaryTotalCurrent;
|
|
686
688
|
actual.summaryTotalPrevious = updates.summaryTotalPrevious;
|
|
687
689
|
actual.summaryTotalPrevious2 = updates.summaryTotalPrevious2;
|
|
688
|
-
actual.
|
|
689
|
-
actual.
|
|
690
|
+
actual.marketPrevious = updates.marketPrevious;
|
|
691
|
+
actual.marketPrevious2 = updates.marketPrevious2;
|
|
690
692
|
actual.cashTotal = updates.cashTotal;
|
|
691
693
|
|
|
692
694
|
format.basis = formatCurrency(actual.basis, currency);
|
|
@@ -698,8 +700,8 @@ module.exports = (() => {
|
|
|
698
700
|
format.summaryTotalPreviousNegative = updates.summaryTotalPrevious.getIsNegative();
|
|
699
701
|
format.summaryTotalPrevious2 = formatCurrency(updates.summaryTotalPrevious2, currency);
|
|
700
702
|
format.summaryTotalPrevious2Negative = updates.summaryTotalPrevious2.getIsNegative();
|
|
701
|
-
format.
|
|
702
|
-
format.
|
|
703
|
+
format.marketPrevious = formatCurrency(updates.marketPrevious, currency);
|
|
704
|
+
format.marketPrevious2 = formatCurrency(updates.marketPrevious2, currency);
|
|
703
705
|
format.cashTotal = formatCurrency(updates.cashTotal, currency);
|
|
704
706
|
|
|
705
707
|
calculateUnrealizedPercent(group);
|
|
@@ -708,9 +710,13 @@ module.exports = (() => {
|
|
|
708
710
|
const item = group._items[0];
|
|
709
711
|
|
|
710
712
|
actual.quantity = item.position.snapshot.open;
|
|
713
|
+
actual.quantityPrevious = item.data.quantityPrevious;
|
|
714
|
+
|
|
711
715
|
actual.basisPrice = item.data.basisPrice;
|
|
712
716
|
|
|
713
717
|
format.quantity = formatDecimal(actual.quantity, 2);
|
|
718
|
+
format.quantityPrevious = formatDecimal(actual.quantityPrevious, 2);
|
|
719
|
+
|
|
714
720
|
format.basisPrice = formatCurrency(actual.basisPrice, currency);
|
|
715
721
|
|
|
716
722
|
format.invalid = definition.type === PositionLevelType.POSITION && item.invalid;
|
|
@@ -797,23 +803,23 @@ module.exports = (() => {
|
|
|
797
803
|
actual.summaryTotalCurrent = updates.summaryTotalCurrent;
|
|
798
804
|
actual.total = updates.unrealized.add(actual.realized).add(actual.income);
|
|
799
805
|
|
|
800
|
-
let
|
|
801
|
-
let
|
|
806
|
+
let marketChange = updates.market.subtract(actual.marketPrevious);
|
|
807
|
+
let marketChangePercent;
|
|
802
808
|
|
|
803
|
-
if (actual.
|
|
804
|
-
if (
|
|
805
|
-
|
|
806
|
-
} else if (
|
|
807
|
-
|
|
809
|
+
if (actual.marketPrevious.getIsZero()) {
|
|
810
|
+
if (marketChange.getIsPositive()) {
|
|
811
|
+
marketChangePercent = Decimal.ONE;
|
|
812
|
+
} else if (marketChange.getIsNegative()) {
|
|
813
|
+
marketChangePercent = Decimal.NEGATIVE_ONE;
|
|
808
814
|
} else {
|
|
809
|
-
|
|
815
|
+
marketChangePercent = Decimal.ZERO;
|
|
810
816
|
}
|
|
811
817
|
} else {
|
|
812
|
-
|
|
818
|
+
marketChangePercent = marketChange.divide(actual.marketPrevious);
|
|
813
819
|
}
|
|
814
820
|
|
|
815
|
-
actual.
|
|
816
|
-
actual.
|
|
821
|
+
actual.marketChange = marketChange;
|
|
822
|
+
actual.marketChangePercent = marketChangePercent;
|
|
817
823
|
|
|
818
824
|
format.market = formatCurrency(actual.market, currency);
|
|
819
825
|
|
|
@@ -834,8 +840,8 @@ module.exports = (() => {
|
|
|
834
840
|
format.total = formatCurrency(actual.total, currency);
|
|
835
841
|
format.totalNegative = actual.total.getIsNegative();
|
|
836
842
|
|
|
837
|
-
format.
|
|
838
|
-
format.
|
|
843
|
+
format.marketChange = formatCurrency(actual.marketChange, currency);
|
|
844
|
+
format.marketChangePercent = formatPercent(actual.marketChangePercent, 2);
|
|
839
845
|
|
|
840
846
|
calculateUnrealizedPercent(group);
|
|
841
847
|
}
|
|
@@ -65,9 +65,12 @@ module.exports = (() => {
|
|
|
65
65
|
this._data.summaryTotalPrevious = null;
|
|
66
66
|
this._data.summaryTotalPrevious2 = null;
|
|
67
67
|
|
|
68
|
-
this._data.
|
|
69
|
-
this._data.
|
|
68
|
+
this._data.marketPrevious = null;
|
|
69
|
+
this._data.marketPrevious2 = null;
|
|
70
70
|
|
|
71
|
+
this._data.quantityPrevious = null;
|
|
72
|
+
this._data.quantityPrevious2 = null;
|
|
73
|
+
|
|
71
74
|
this._data.realized = null;
|
|
72
75
|
this._data.income = null;
|
|
73
76
|
this._data.basisPrice = null;
|
|
@@ -391,8 +394,10 @@ module.exports = (() => {
|
|
|
391
394
|
data.summaryTotalPrevious = calculateSummaryTotal(previousSummary1, previousSummary2);
|
|
392
395
|
data.summaryTotalPrevious2 = calculateSummaryTotal(previousSummary2, previousSummary3);
|
|
393
396
|
|
|
394
|
-
data.
|
|
395
|
-
data.
|
|
397
|
+
data.marketPrevious = previousSummary1 === null ? Decimal.ZERO : previousSummary1.end.value;
|
|
398
|
+
data.marketPrevious2 = previousSummary2 === null ? Decimal.ZERO : previousSummary2.end.value;
|
|
399
|
+
|
|
400
|
+
data.quantityPrevious = previousSummary1 === null ? Decimal.ZERO : previousSummary1.end.open;
|
|
396
401
|
|
|
397
402
|
if (snapshot.open.getIsZero()) {
|
|
398
403
|
data.basisPrice = Decimal.ZERO;
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -399,7 +399,7 @@ module.exports = (() => {
|
|
|
399
399
|
'use strict';
|
|
400
400
|
|
|
401
401
|
/**
|
|
402
|
-
* An enumeration used to define
|
|
402
|
+
* An enumeration used to define time frames for position summaries.
|
|
403
403
|
*
|
|
404
404
|
* @public
|
|
405
405
|
* @extends {Enum}
|
|
@@ -2505,12 +2505,14 @@ module.exports = (() => {
|
|
|
2505
2505
|
this._dataFormat.locked = false;
|
|
2506
2506
|
this._dataFormat.newsExists = false;
|
|
2507
2507
|
this._dataFormat.quantity = null;
|
|
2508
|
+
this._dataFormat.quantityPrevious = null;
|
|
2508
2509
|
this._dataFormat.basisPrice = null;
|
|
2509
2510
|
|
|
2510
2511
|
this._dataActual.key = this._key;
|
|
2511
2512
|
this._dataActual.description = this._description;
|
|
2512
2513
|
this._dataActual.newsExists = false;
|
|
2513
2514
|
this._dataActual.quantity = null;
|
|
2515
|
+
this._dataActual.quantityPrevious = null;
|
|
2514
2516
|
this._dataActual.basisPrice = null;
|
|
2515
2517
|
|
|
2516
2518
|
if (this._single && items.length === 1) {
|
|
@@ -2560,10 +2562,10 @@ module.exports = (() => {
|
|
|
2560
2562
|
this._dataActual.summaryTotalCurrent = null;
|
|
2561
2563
|
this._dataActual.summaryTotalPrevious = null;
|
|
2562
2564
|
this._dataActual.summaryTotalPrevious2 = null;
|
|
2563
|
-
this._dataActual.
|
|
2564
|
-
this._dataActual.
|
|
2565
|
-
this._dataActual.
|
|
2566
|
-
this._dataActual.
|
|
2565
|
+
this._dataActual.marketPrevious = null;
|
|
2566
|
+
this._dataActual.marketPrevious2 = null;
|
|
2567
|
+
this._dataActual.marketChange = null;
|
|
2568
|
+
this._dataActual.marketChangePercent = null;
|
|
2567
2569
|
this._dataActual.cashTotal = null;
|
|
2568
2570
|
|
|
2569
2571
|
this._dataFormat.currentPrice = null;
|
|
@@ -2587,10 +2589,10 @@ module.exports = (() => {
|
|
|
2587
2589
|
this._dataFormat.summaryTotalPreviousNegative = false;
|
|
2588
2590
|
this._dataFormat.summaryTotalPrevious2 = null;
|
|
2589
2591
|
this._dataFormat.summaryTotalPrevious2Negative = false;
|
|
2590
|
-
this._dataFormat.
|
|
2591
|
-
this._dataFormat.
|
|
2592
|
-
this._dataFormat.
|
|
2593
|
-
this._dataFormat.
|
|
2592
|
+
this._dataFormat.marketPrevious = null;
|
|
2593
|
+
this._dataFormat.marketPrevious2 = null;
|
|
2594
|
+
this._dataFormat.marketChange = null;
|
|
2595
|
+
this._dataFormat.marketChangePercent = null;
|
|
2594
2596
|
this._dataFormat.cashTotal = null;
|
|
2595
2597
|
this._dataFormat.portfolioType = null;
|
|
2596
2598
|
|
|
@@ -3087,8 +3089,8 @@ module.exports = (() => {
|
|
|
3087
3089
|
updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrent));
|
|
3088
3090
|
updates.summaryTotalPrevious = updates.summaryTotalPrevious.add(translate(item, item.data.summaryTotalPrevious));
|
|
3089
3091
|
updates.summaryTotalPrevious2 = updates.summaryTotalPrevious2.add(translate(item, item.data.summaryTotalPrevious2));
|
|
3090
|
-
updates.
|
|
3091
|
-
updates.
|
|
3092
|
+
updates.marketPrevious = updates.marketPrevious.add(translate(item, item.data.marketPrevious));
|
|
3093
|
+
updates.marketPrevious2 = updates.marketPrevious2.add(translate(item, item.data.marketPrevious2));
|
|
3092
3094
|
|
|
3093
3095
|
if (item.position.instrument.type === InstrumentType.CASH) {
|
|
3094
3096
|
updates.cashTotal = updates.cashTotal.add(translate(item, item.data.market));
|
|
@@ -3103,8 +3105,8 @@ module.exports = (() => {
|
|
|
3103
3105
|
summaryTotalCurrent: Decimal.ZERO,
|
|
3104
3106
|
summaryTotalPrevious: Decimal.ZERO,
|
|
3105
3107
|
summaryTotalPrevious2: Decimal.ZERO,
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
+
marketPrevious: Decimal.ZERO,
|
|
3109
|
+
marketPrevious2: Decimal.ZERO,
|
|
3108
3110
|
cashTotal: Decimal.ZERO
|
|
3109
3111
|
});
|
|
3110
3112
|
|
|
@@ -3115,8 +3117,8 @@ module.exports = (() => {
|
|
|
3115
3117
|
actual.summaryTotalCurrent = updates.summaryTotalCurrent;
|
|
3116
3118
|
actual.summaryTotalPrevious = updates.summaryTotalPrevious;
|
|
3117
3119
|
actual.summaryTotalPrevious2 = updates.summaryTotalPrevious2;
|
|
3118
|
-
actual.
|
|
3119
|
-
actual.
|
|
3120
|
+
actual.marketPrevious = updates.marketPrevious;
|
|
3121
|
+
actual.marketPrevious2 = updates.marketPrevious2;
|
|
3120
3122
|
actual.cashTotal = updates.cashTotal;
|
|
3121
3123
|
|
|
3122
3124
|
format.basis = formatCurrency(actual.basis, currency);
|
|
@@ -3128,8 +3130,8 @@ module.exports = (() => {
|
|
|
3128
3130
|
format.summaryTotalPreviousNegative = updates.summaryTotalPrevious.getIsNegative();
|
|
3129
3131
|
format.summaryTotalPrevious2 = formatCurrency(updates.summaryTotalPrevious2, currency);
|
|
3130
3132
|
format.summaryTotalPrevious2Negative = updates.summaryTotalPrevious2.getIsNegative();
|
|
3131
|
-
format.
|
|
3132
|
-
format.
|
|
3133
|
+
format.marketPrevious = formatCurrency(updates.marketPrevious, currency);
|
|
3134
|
+
format.marketPrevious2 = formatCurrency(updates.marketPrevious2, currency);
|
|
3133
3135
|
format.cashTotal = formatCurrency(updates.cashTotal, currency);
|
|
3134
3136
|
|
|
3135
3137
|
calculateUnrealizedPercent(group);
|
|
@@ -3138,9 +3140,13 @@ module.exports = (() => {
|
|
|
3138
3140
|
const item = group._items[0];
|
|
3139
3141
|
|
|
3140
3142
|
actual.quantity = item.position.snapshot.open;
|
|
3143
|
+
actual.quantityPrevious = item.data.quantityPrevious;
|
|
3144
|
+
|
|
3141
3145
|
actual.basisPrice = item.data.basisPrice;
|
|
3142
3146
|
|
|
3143
3147
|
format.quantity = formatDecimal(actual.quantity, 2);
|
|
3148
|
+
format.quantityPrevious = formatDecimal(actual.quantityPrevious, 2);
|
|
3149
|
+
|
|
3144
3150
|
format.basisPrice = formatCurrency(actual.basisPrice, currency);
|
|
3145
3151
|
|
|
3146
3152
|
format.invalid = definition.type === PositionLevelType.POSITION && item.invalid;
|
|
@@ -3227,23 +3233,23 @@ module.exports = (() => {
|
|
|
3227
3233
|
actual.summaryTotalCurrent = updates.summaryTotalCurrent;
|
|
3228
3234
|
actual.total = updates.unrealized.add(actual.realized).add(actual.income);
|
|
3229
3235
|
|
|
3230
|
-
let
|
|
3231
|
-
let
|
|
3236
|
+
let marketChange = updates.market.subtract(actual.marketPrevious);
|
|
3237
|
+
let marketChangePercent;
|
|
3232
3238
|
|
|
3233
|
-
if (actual.
|
|
3234
|
-
if (
|
|
3235
|
-
|
|
3236
|
-
} else if (
|
|
3237
|
-
|
|
3239
|
+
if (actual.marketPrevious.getIsZero()) {
|
|
3240
|
+
if (marketChange.getIsPositive()) {
|
|
3241
|
+
marketChangePercent = Decimal.ONE;
|
|
3242
|
+
} else if (marketChange.getIsNegative()) {
|
|
3243
|
+
marketChangePercent = Decimal.NEGATIVE_ONE;
|
|
3238
3244
|
} else {
|
|
3239
|
-
|
|
3245
|
+
marketChangePercent = Decimal.ZERO;
|
|
3240
3246
|
}
|
|
3241
3247
|
} else {
|
|
3242
|
-
|
|
3248
|
+
marketChangePercent = marketChange.divide(actual.marketPrevious);
|
|
3243
3249
|
}
|
|
3244
3250
|
|
|
3245
|
-
actual.
|
|
3246
|
-
actual.
|
|
3251
|
+
actual.marketChange = marketChange;
|
|
3252
|
+
actual.marketChangePercent = marketChangePercent;
|
|
3247
3253
|
|
|
3248
3254
|
format.market = formatCurrency(actual.market, currency);
|
|
3249
3255
|
|
|
@@ -3264,8 +3270,8 @@ module.exports = (() => {
|
|
|
3264
3270
|
format.total = formatCurrency(actual.total, currency);
|
|
3265
3271
|
format.totalNegative = actual.total.getIsNegative();
|
|
3266
3272
|
|
|
3267
|
-
format.
|
|
3268
|
-
format.
|
|
3273
|
+
format.marketChange = formatCurrency(actual.marketChange, currency);
|
|
3274
|
+
format.marketChangePercent = formatPercent(actual.marketChangePercent, 2);
|
|
3269
3275
|
|
|
3270
3276
|
calculateUnrealizedPercent(group);
|
|
3271
3277
|
}
|
|
@@ -3399,9 +3405,12 @@ module.exports = (() => {
|
|
|
3399
3405
|
this._data.summaryTotalPrevious = null;
|
|
3400
3406
|
this._data.summaryTotalPrevious2 = null;
|
|
3401
3407
|
|
|
3402
|
-
this._data.
|
|
3403
|
-
this._data.
|
|
3408
|
+
this._data.marketPrevious = null;
|
|
3409
|
+
this._data.marketPrevious2 = null;
|
|
3404
3410
|
|
|
3411
|
+
this._data.quantityPrevious = null;
|
|
3412
|
+
this._data.quantityPrevious2 = null;
|
|
3413
|
+
|
|
3405
3414
|
this._data.realized = null;
|
|
3406
3415
|
this._data.income = null;
|
|
3407
3416
|
this._data.basisPrice = null;
|
|
@@ -3725,8 +3734,10 @@ module.exports = (() => {
|
|
|
3725
3734
|
data.summaryTotalPrevious = calculateSummaryTotal(previousSummary1, previousSummary2);
|
|
3726
3735
|
data.summaryTotalPrevious2 = calculateSummaryTotal(previousSummary2, previousSummary3);
|
|
3727
3736
|
|
|
3728
|
-
data.
|
|
3729
|
-
data.
|
|
3737
|
+
data.marketPrevious = previousSummary1 === null ? Decimal.ZERO : previousSummary1.end.value;
|
|
3738
|
+
data.marketPrevious2 = previousSummary2 === null ? Decimal.ZERO : previousSummary2.end.value;
|
|
3739
|
+
|
|
3740
|
+
data.quantityPrevious = previousSummary1 === null ? Decimal.ZERO : previousSummary1.end.open;
|
|
3730
3741
|
|
|
3731
3742
|
if (snapshot.open.getIsZero()) {
|
|
3732
3743
|
data.basisPrice = Decimal.ZERO;
|