@barchart/portfolio-api-common 9.0.1 → 9.1.1
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.
|
@@ -31,6 +31,7 @@ module.exports = (() => {
|
|
|
31
31
|
Currency.AUD,
|
|
32
32
|
Currency.CAD,
|
|
33
33
|
Currency.CHF,
|
|
34
|
+
Currency.CZK,
|
|
34
35
|
Currency.DKK,
|
|
35
36
|
Currency.GBP,
|
|
36
37
|
Currency.GBX,
|
|
@@ -225,11 +226,11 @@ module.exports = (() => {
|
|
|
225
226
|
this._suspendedPositionQuotes = new Map();
|
|
226
227
|
this._suspendedForexQuotes = new Map();
|
|
227
228
|
|
|
228
|
-
this.setQuotes(positionQuotes, forexQuotes);
|
|
229
|
-
|
|
230
229
|
Object.keys(this._trees).forEach((key) => {
|
|
231
230
|
this._trees[key].walk(group => group.resumeCalculations(), false, false);
|
|
232
231
|
});
|
|
232
|
+
|
|
233
|
+
this.setQuotes(positionQuotes, forexQuotes);
|
|
233
234
|
}
|
|
234
235
|
});
|
|
235
236
|
|
|
@@ -223,6 +223,18 @@ module.exports = (() => {
|
|
|
223
223
|
this._dataFormat.periodPercentPrevious = null;
|
|
224
224
|
this._dataFormat.periodPercentPrevious2 = null;
|
|
225
225
|
|
|
226
|
+
this._dataActual.todayQuote = null;
|
|
227
|
+
this._dataActual.todayExchange = null;
|
|
228
|
+
|
|
229
|
+
this._dataFormat.todayQuote = null;
|
|
230
|
+
this._dataFormat.todayExchange = null;
|
|
231
|
+
|
|
232
|
+
this._dataActual.todayPrice = null;
|
|
233
|
+
this._dataActual.todayPricePrevious = null;
|
|
234
|
+
|
|
235
|
+
this._dataFormat.todayPrice = null;
|
|
236
|
+
this._dataFormat.todayPricePrevious = null;
|
|
237
|
+
|
|
226
238
|
this._items.forEach((item) => {
|
|
227
239
|
bindItem.call(this, item);
|
|
228
240
|
});
|
|
@@ -695,7 +707,7 @@ module.exports = (() => {
|
|
|
695
707
|
summary.count = sums[fieldName].count + 1;
|
|
696
708
|
}
|
|
697
709
|
|
|
698
|
-
if ((i + 1)
|
|
710
|
+
if ((i + 1) === this.items.length) {
|
|
699
711
|
let averageFormat;
|
|
700
712
|
|
|
701
713
|
if (summary.count > 0) {
|
|
@@ -866,6 +878,10 @@ module.exports = (() => {
|
|
|
866
878
|
if (desired === Currency.GBX) {
|
|
867
879
|
desired = Currency.GBP;
|
|
868
880
|
|
|
881
|
+
if (is.number(value)) {
|
|
882
|
+
translated = new Decimal(value);
|
|
883
|
+
}
|
|
884
|
+
|
|
869
885
|
if (translated !== null) {
|
|
870
886
|
translated = translated.multiply(0.01);
|
|
871
887
|
}
|
|
@@ -893,7 +909,7 @@ module.exports = (() => {
|
|
|
893
909
|
return currencyTranslator.translate(value, item.currency, currency);
|
|
894
910
|
};
|
|
895
911
|
|
|
896
|
-
|
|
912
|
+
const updates = items.reduce((updates, item) => {
|
|
897
913
|
updates.basis = updates.basis.add(translate(item, item.data.basis));
|
|
898
914
|
|
|
899
915
|
if (item.position.instrument.type === InstrumentType.FUTURE) {
|
|
@@ -1061,6 +1077,15 @@ module.exports = (() => {
|
|
|
1061
1077
|
}
|
|
1062
1078
|
}
|
|
1063
1079
|
|
|
1080
|
+
format.todayQuote = '—';
|
|
1081
|
+
format.todayExchange = '—';
|
|
1082
|
+
|
|
1083
|
+
format.todayPrice = '—';
|
|
1084
|
+
format.todayPricePrevious = '—';
|
|
1085
|
+
|
|
1086
|
+
format.unrealizedToday = '—';
|
|
1087
|
+
format.gainToday = '—';
|
|
1088
|
+
|
|
1064
1089
|
format.portfolioType = portfolioType;
|
|
1065
1090
|
}
|
|
1066
1091
|
|
|
@@ -1214,6 +1239,26 @@ module.exports = (() => {
|
|
|
1214
1239
|
if (group.single && item) {
|
|
1215
1240
|
actual.unrealizedPrice = item.data.unrealizedPrice;
|
|
1216
1241
|
format.unrealizedPrice = formatFractionSpecial(actual.unrealizedPrice, currency, item.position.instrument);
|
|
1242
|
+
|
|
1243
|
+
actual.todayQuote = item.data.todayQuote;
|
|
1244
|
+
actual.todayExchange = item.data.todayExchange;
|
|
1245
|
+
|
|
1246
|
+
format.todayQuote = actual.todayQuote === null ? '—' : actual.todayQuote.format();
|
|
1247
|
+
format.todayExchange = actual.todayExchange === null ? '—' : actual.todayExchange.format();
|
|
1248
|
+
|
|
1249
|
+
actual.todayPrice = item.data.todayPrice;
|
|
1250
|
+
actual.todayPricePrevious = item.data.todayPricePrevious;
|
|
1251
|
+
|
|
1252
|
+
format.todayPrice = actual.todayPrice === null ? '—' : formatFractionSpecial(actual.todayPrice, currency, item.position.instrument);
|
|
1253
|
+
format.todayPricePrevious = actual.todayPricePrevious === null ? '—' : formatFractionSpecial(actual.todayPricePrevious, currency, item.position.instrument);
|
|
1254
|
+
|
|
1255
|
+
if (actual.todayPrice === null) {
|
|
1256
|
+
format.unrealizedToday = '—';
|
|
1257
|
+
|
|
1258
|
+
if (actual.realizedToday !== null && actual.realizedToday.getIsEqual(Decimal.ZERO)) {
|
|
1259
|
+
format.gainToday = '—';
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1217
1262
|
}
|
|
1218
1263
|
}
|
|
1219
1264
|
|
|
@@ -67,6 +67,12 @@ module.exports = (() => {
|
|
|
67
67
|
this._data.marketAbsolute = null;
|
|
68
68
|
this._data.marketAbsoluteChange = null;
|
|
69
69
|
|
|
70
|
+
this._data.todayQuote = null;
|
|
71
|
+
this._data.todayExchange = null;
|
|
72
|
+
|
|
73
|
+
this._data.todayPrice = null;
|
|
74
|
+
this._data.todayPricePrevious = null;
|
|
75
|
+
|
|
70
76
|
this._data.realizedToday = null;
|
|
71
77
|
this._data.realizedTodayChange = null;
|
|
72
78
|
|
|
@@ -612,6 +618,9 @@ module.exports = (() => {
|
|
|
612
618
|
data.marketAbsolute = marketAbsolute;
|
|
613
619
|
data.marketAbsoluteChange = marketAbsoluteChange;
|
|
614
620
|
|
|
621
|
+
data.todayQuote = day || null;
|
|
622
|
+
data.todayExchange = today || null;
|
|
623
|
+
|
|
615
624
|
let unrealizedToday;
|
|
616
625
|
let unrealizedTodayChange;
|
|
617
626
|
|
|
@@ -640,10 +649,21 @@ module.exports = (() => {
|
|
|
640
649
|
data.unrealizedToday = unrealizedToday;
|
|
641
650
|
data.unrealizedTodayChange = unrealizedTodayChange;
|
|
642
651
|
|
|
652
|
+
if (priceIsToday && price) {
|
|
653
|
+
data.todayPrice = price;
|
|
654
|
+
|
|
655
|
+
if (data.previousPrice) {
|
|
656
|
+
data.todayPricePrevious = data.previousPrice;
|
|
657
|
+
}
|
|
658
|
+
} else {
|
|
659
|
+
data.todayPrice = null;
|
|
660
|
+
data.todayPricePrevious = null;
|
|
661
|
+
}
|
|
662
|
+
|
|
643
663
|
let realizedToday;
|
|
644
664
|
let realizedTodayChange;
|
|
645
665
|
|
|
646
|
-
if (position.latest && position.latest.gain && position.latest.date &&
|
|
666
|
+
if (position.latest && position.latest.gain && position.latest.date && today && position.latest.date.getIsEqual(today)) {
|
|
647
667
|
realizedToday = position.latest.gain;
|
|
648
668
|
} else {
|
|
649
669
|
realizedToday = Decimal.ZERO;
|
|
@@ -32,7 +32,7 @@ module.exports = (() => {
|
|
|
32
32
|
assert.argumentIsRequired(currencySelector, 'currencySelector', Function);
|
|
33
33
|
|
|
34
34
|
if (requiredGroups) {
|
|
35
|
-
assert.argumentIsArray(requiredGroups, 'requiredGroups',
|
|
35
|
+
assert.argumentIsArray(requiredGroups, 'requiredGroups', validateRequiredGroup, 'RequiredGroup');
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
assert.argumentIsOptional(requiredGroupGenerator, 'requiredGroupGenerator', Function);
|
|
@@ -106,11 +106,11 @@ module.exports = (() => {
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
/**
|
|
109
|
-
* Indicates the required groups
|
|
109
|
+
* Indicates the required groups. This allows for the creation of empty
|
|
110
110
|
* groups.
|
|
111
111
|
*
|
|
112
112
|
* @public
|
|
113
|
-
* @returns {
|
|
113
|
+
* @returns {PositionLevelDefinition~RequiredGroup[]}
|
|
114
114
|
*/
|
|
115
115
|
get requiredGroups() {
|
|
116
116
|
return this._requiredGroups;
|
|
@@ -147,6 +147,8 @@ module.exports = (() => {
|
|
|
147
147
|
const requiredGroup = this._requiredGroupGenerator(input);
|
|
148
148
|
|
|
149
149
|
if (requiredGroup !== null) {
|
|
150
|
+
validateRequiredGroup(requiredGroup, 'requiredGroup');
|
|
151
|
+
|
|
150
152
|
this._requiredGroups.push(requiredGroup);
|
|
151
153
|
}
|
|
152
154
|
|
|
@@ -255,6 +257,13 @@ module.exports = (() => {
|
|
|
255
257
|
}
|
|
256
258
|
}
|
|
257
259
|
|
|
260
|
+
function validateRequiredGroup(requiredGroup, variableName) {
|
|
261
|
+
assert.argumentIsRequired(requiredGroup, variableName, Object);
|
|
262
|
+
assert.argumentIsRequired(requiredGroup.key, `${variableName}.key`, String);
|
|
263
|
+
assert.argumentIsRequired(requiredGroup.description, `${variableName}.description`, String);
|
|
264
|
+
assert.argumentIsRequired(requiredGroup.currency, `${variableName}.currency`, Currency, 'Currency');
|
|
265
|
+
}
|
|
266
|
+
|
|
258
267
|
/**
|
|
259
268
|
* A callback used to determine the eligibility for membership of a {@link PositionItem}
|
|
260
269
|
* within a group.
|