@barchart/portfolio-api-common 9.0.1 → 9.1.0

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) == this.items.length) {
710
+ if ((i + 1) === this.items.length) {
699
711
  let averageFormat;
700
712
 
701
713
  if (summary.count > 0) {
@@ -893,7 +905,7 @@ module.exports = (() => {
893
905
  return currencyTranslator.translate(value, item.currency, currency);
894
906
  };
895
907
 
896
- let updates = items.reduce((updates, item) => {
908
+ const updates = items.reduce((updates, item) => {
897
909
  updates.basis = updates.basis.add(translate(item, item.data.basis));
898
910
 
899
911
  if (item.position.instrument.type === InstrumentType.FUTURE) {
@@ -1061,6 +1073,15 @@ module.exports = (() => {
1061
1073
  }
1062
1074
  }
1063
1075
 
1076
+ format.todayQuote = '—';
1077
+ format.todayExchange = '—';
1078
+
1079
+ format.todayPrice = '—';
1080
+ format.todayPricePrevious = '—';
1081
+
1082
+ format.unrealizedToday = '—';
1083
+ format.gainToday = '—';
1084
+
1064
1085
  format.portfolioType = portfolioType;
1065
1086
  }
1066
1087
 
@@ -1214,6 +1235,26 @@ module.exports = (() => {
1214
1235
  if (group.single && item) {
1215
1236
  actual.unrealizedPrice = item.data.unrealizedPrice;
1216
1237
  format.unrealizedPrice = formatFractionSpecial(actual.unrealizedPrice, currency, item.position.instrument);
1238
+
1239
+ actual.todayQuote = item.data.todayQuote;
1240
+ actual.todayExchange = item.data.todayExchange;
1241
+
1242
+ format.todayQuote = actual.todayQuote === null ? '—' : actual.todayQuote.format();
1243
+ format.todayExchange = actual.todayExchange === null ? '—' : actual.todayExchange.format();
1244
+
1245
+ actual.todayPrice = item.data.todayPrice;
1246
+ actual.todayPricePrevious = item.data.todayPricePrevious;
1247
+
1248
+ format.todayPrice = actual.todayPrice === null ? '—' : formatFractionSpecial(actual.todayPrice, currency, item.position.instrument);
1249
+ format.todayPricePrevious = actual.todayPricePrevious === null ? '—' : formatFractionSpecial(actual.todayPricePrevious, currency, item.position.instrument);
1250
+
1251
+ if (actual.todayPrice === null) {
1252
+ format.unrealizedToday = '—';
1253
+
1254
+ if (actual.realizedToday !== null && actual.realizedToday.getIsEqual(Decimal.ZERO)) {
1255
+ format.gainToday = '—';
1256
+ }
1257
+ }
1217
1258
  }
1218
1259
  }
1219
1260
 
@@ -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 && day && position.latest.date.getIsEqual(day)) {
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', String);
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 (i.e. descriptions). The allows for the creation of empty
109
+ * Indicates the required groups. This allows for the creation of empty
110
110
  * groups.
111
111
  *
112
112
  * @public
113
- * @returns {String[]}
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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "9.0.1",
3
+ "version": "9.1.0",
4
4
  "description": "Common JavaScript code used by Barchart's Portfolio Service",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",