@barchart/portfolio-api-common 1.0.91 → 1.0.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.
@@ -58,9 +58,9 @@ module.exports = (() => {
58
58
  this._dataFormat.total = null;
59
59
  this._dataFormat.totalNegative = false;
60
60
  this._dataFormat.summaryTotalCurrent = null;
61
+ this._dataActual.summaryTotalCurrentNegative = false;
61
62
  this._dataFormat.summaryTotalPrevious = null;
62
-
63
- this._dataFormat.unrealizedTodayNegative = false;
63
+ this._dataFormat.summaryTotalPreviousNegative = false;
64
64
 
65
65
  this._items.forEach((item) => {
66
66
  item.registerPriceChangeHandler((data, sender) => {
@@ -210,6 +210,7 @@ module.exports = (() => {
210
210
  format.income = formatCurrency(actual.income, currency);
211
211
  format.summaryTotalCurrent = formatCurrency(updates.summaryTotalCurrent, currency);
212
212
  format.summaryTotalPrevious = formatCurrency(updates.summaryTotalPrevious, currency);
213
+ format.summaryTotalPreviousNegative = updates.summaryTotalPrevious.getIsNegative();
213
214
  }
214
215
 
215
216
  function calculatePriceData(group, item, forceRefresh) {
@@ -234,19 +235,22 @@ module.exports = (() => {
234
235
  updates = items.reduce((updates, item) => {
235
236
  updates.market = updates.market.add(item.data.market);
236
237
  updates.unrealizedToday = updates.unrealizedToday.add(item.data.unrealizedToday);
238
+ updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(item.data.summaryTotalCurrent);
237
239
 
238
240
  return updates;
239
241
  }, {
240
242
  market: Decimal.ZERO,
241
243
  marketDirection: unchanged,
242
- unrealizedToday: Decimal.ZERO
244
+ unrealizedToday: Decimal.ZERO,
245
+ summaryTotalCurrent: Decimal.ZERO
243
246
 
244
247
  });
245
248
  } else {
246
249
  updates = {
247
250
  market: actual.market.add(item.data.marketChange),
248
251
  marketDirection: { up: item.data.marketChange.getIsPositive(), down: item.data.marketChange.getIsNegative() },
249
- unrealizedToday: actual.unrealizedToday.add(item.data.unrealizedTodayChange)
252
+ unrealizedToday: actual.unrealizedToday.add(item.data.unrealizedTodayChange),
253
+ summaryTotalCurrent: actual.summaryTotalCurrent.add(item.data.summaryTotalCurrentChange)
250
254
  };
251
255
  }
252
256
 
@@ -264,6 +268,7 @@ module.exports = (() => {
264
268
 
265
269
  actual.market = updates.market;
266
270
  actual.unrealizedToday = updates.unrealizedToday;
271
+ actual.summaryTotalCurrent = updates.summaryTotalCurrent;
267
272
  actual.total = updates.unrealizedToday.add(actual.realized).add(actual.income);
268
273
 
269
274
  format.market = formatCurrency(actual.market, currency);
@@ -275,6 +280,10 @@ module.exports = (() => {
275
280
 
276
281
  format.unrealizedToday = formatCurrency(actual.unrealizedToday, currency);
277
282
  format.unrealizedTodayNegative = actual.unrealizedToday.getIsNegative();
283
+
284
+ format.summaryTotalCurrent = formatCurrency(actual.summaryTotalCurrent, currency);
285
+ format.summaryTotalCurrentNegative = actual.summaryTotalCurrent.getIsNegative();
286
+
278
287
  format.total = formatCurrency(actual.total, currency);
279
288
  format.totalNegative = actual.total.getIsNegative();
280
289
 
@@ -37,6 +37,8 @@ module.exports = (() => {
37
37
  this._data.income = null;
38
38
 
39
39
  this._data.summaryTotalCurrent = null;
40
+ this._data.summaryTotalCurrentChange = null;
41
+
40
42
  this._data.summaryTotalPrevious = null;
41
43
 
42
44
  this._excluded = false;
@@ -178,6 +180,28 @@ module.exports = (() => {
178
180
 
179
181
  data.unrealizedToday = unrealizedToday;
180
182
  data.unrealizedTodayChange = unrealizedTodayChange;
183
+
184
+ const summary = item.currentSummary;
185
+
186
+ if (summary && price) {
187
+ const period = summary.period;
188
+
189
+ let unrealizedCurrent = summary.end.open.multiply(price).add(summary.end.basis);
190
+
191
+ let summaryTotalCurrent = period.realized.add(period.income).add(unrealizedCurrent);
192
+ let summaryTotalCurrentChange;
193
+
194
+ if (data.summaryTotalCurrent !== null) {
195
+ summaryTotalCurrentChange = summaryTotalCurrent.subtract(data.summaryTotalCurrent);
196
+ } else {
197
+ summaryTotalCurrentChange = Decimal.ZERO;
198
+ }
199
+
200
+ data.summaryTotalCurrent = summaryTotalCurrent;
201
+ data.summaryTotalCurrentChange = summaryTotalCurrentChange;
202
+ } else {
203
+ data.summaryTotalCurrentChange = Decimal.ZERO;
204
+ }
181
205
  }
182
206
 
183
207
  function calculateSummaryTotal(summary) {
@@ -186,7 +210,7 @@ module.exports = (() => {
186
210
  if (summary) {
187
211
  const period = summary.period;
188
212
 
189
- returnRef = period.realized.add(period.unrealized).add(period.income);
213
+ returnRef = period.realized.add(period.income).add(period.unrealized);
190
214
  } else {
191
215
  returnRef = Decimal.ZERO;
192
216
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.0.91",
3
+ "version": "1.0.95",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -1038,9 +1038,9 @@ module.exports = (() => {
1038
1038
  this._dataFormat.total = null;
1039
1039
  this._dataFormat.totalNegative = false;
1040
1040
  this._dataFormat.summaryTotalCurrent = null;
1041
+ this._dataActual.summaryTotalCurrentNegative = false;
1041
1042
  this._dataFormat.summaryTotalPrevious = null;
1042
-
1043
- this._dataFormat.unrealizedTodayNegative = false;
1043
+ this._dataFormat.summaryTotalPreviousNegative = false;
1044
1044
 
1045
1045
  this._items.forEach((item) => {
1046
1046
  item.registerPriceChangeHandler((data, sender) => {
@@ -1190,6 +1190,7 @@ module.exports = (() => {
1190
1190
  format.income = formatCurrency(actual.income, currency);
1191
1191
  format.summaryTotalCurrent = formatCurrency(updates.summaryTotalCurrent, currency);
1192
1192
  format.summaryTotalPrevious = formatCurrency(updates.summaryTotalPrevious, currency);
1193
+ format.summaryTotalPreviousNegative = updates.summaryTotalPrevious.getIsNegative();
1193
1194
  }
1194
1195
 
1195
1196
  function calculatePriceData(group, item, forceRefresh) {
@@ -1214,19 +1215,22 @@ module.exports = (() => {
1214
1215
  updates = items.reduce((updates, item) => {
1215
1216
  updates.market = updates.market.add(item.data.market);
1216
1217
  updates.unrealizedToday = updates.unrealizedToday.add(item.data.unrealizedToday);
1218
+ updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(item.data.summaryTotalCurrent);
1217
1219
 
1218
1220
  return updates;
1219
1221
  }, {
1220
1222
  market: Decimal.ZERO,
1221
1223
  marketDirection: unchanged,
1222
- unrealizedToday: Decimal.ZERO
1224
+ unrealizedToday: Decimal.ZERO,
1225
+ summaryTotalCurrent: Decimal.ZERO
1223
1226
 
1224
1227
  });
1225
1228
  } else {
1226
1229
  updates = {
1227
1230
  market: actual.market.add(item.data.marketChange),
1228
1231
  marketDirection: { up: item.data.marketChange.getIsPositive(), down: item.data.marketChange.getIsNegative() },
1229
- unrealizedToday: actual.unrealizedToday.add(item.data.unrealizedTodayChange)
1232
+ unrealizedToday: actual.unrealizedToday.add(item.data.unrealizedTodayChange),
1233
+ summaryTotalCurrent: actual.summaryTotalCurrent.add(item.data.summaryTotalCurrentChange)
1230
1234
  };
1231
1235
  }
1232
1236
 
@@ -1244,6 +1248,7 @@ module.exports = (() => {
1244
1248
 
1245
1249
  actual.market = updates.market;
1246
1250
  actual.unrealizedToday = updates.unrealizedToday;
1251
+ actual.summaryTotalCurrent = updates.summaryTotalCurrent;
1247
1252
  actual.total = updates.unrealizedToday.add(actual.realized).add(actual.income);
1248
1253
 
1249
1254
  format.market = formatCurrency(actual.market, currency);
@@ -1255,6 +1260,10 @@ module.exports = (() => {
1255
1260
 
1256
1261
  format.unrealizedToday = formatCurrency(actual.unrealizedToday, currency);
1257
1262
  format.unrealizedTodayNegative = actual.unrealizedToday.getIsNegative();
1263
+
1264
+ format.summaryTotalCurrent = formatCurrency(actual.summaryTotalCurrent, currency);
1265
+ format.summaryTotalCurrentNegative = actual.summaryTotalCurrent.getIsNegative();
1266
+
1258
1267
  format.total = formatCurrency(actual.total, currency);
1259
1268
  format.totalNegative = actual.total.getIsNegative();
1260
1269
 
@@ -1389,6 +1398,8 @@ module.exports = (() => {
1389
1398
  this._data.income = null;
1390
1399
 
1391
1400
  this._data.summaryTotalCurrent = null;
1401
+ this._data.summaryTotalCurrentChange = null;
1402
+
1392
1403
  this._data.summaryTotalPrevious = null;
1393
1404
 
1394
1405
  this._excluded = false;
@@ -1530,6 +1541,28 @@ module.exports = (() => {
1530
1541
 
1531
1542
  data.unrealizedToday = unrealizedToday;
1532
1543
  data.unrealizedTodayChange = unrealizedTodayChange;
1544
+
1545
+ const summary = item.currentSummary;
1546
+
1547
+ if (summary && price) {
1548
+ const period = summary.period;
1549
+
1550
+ let unrealizedCurrent = summary.end.open.multiply(price).add(summary.end.basis);
1551
+
1552
+ let summaryTotalCurrent = period.realized.add(period.income).add(unrealizedCurrent);
1553
+ let summaryTotalCurrentChange;
1554
+
1555
+ if (data.summaryTotalCurrent !== null) {
1556
+ summaryTotalCurrentChange = summaryTotalCurrent.subtract(data.summaryTotalCurrent);
1557
+ } else {
1558
+ summaryTotalCurrentChange = Decimal.ZERO;
1559
+ }
1560
+
1561
+ data.summaryTotalCurrent = summaryTotalCurrent;
1562
+ data.summaryTotalCurrentChange = summaryTotalCurrentChange;
1563
+ } else {
1564
+ data.summaryTotalCurrentChange = Decimal.ZERO;
1565
+ }
1533
1566
  }
1534
1567
 
1535
1568
  function calculateSummaryTotal(summary) {
@@ -1538,7 +1571,7 @@ module.exports = (() => {
1538
1571
  if (summary) {
1539
1572
  const period = summary.period;
1540
1573
 
1541
- returnRef = period.realized.add(period.unrealized).add(period.income);
1574
+ returnRef = period.realized.add(period.income).add(period.unrealized);
1542
1575
  } else {
1543
1576
  returnRef = Decimal.ZERO;
1544
1577
  }
@@ -3189,9 +3222,9 @@ module.exports = function () {
3189
3222
  assert.argumentIsRequired(a, 'a', Decimal, 'Decimal');
3190
3223
  assert.argumentIsRequired(b, 'b', Decimal, 'Decimal');
3191
3224
 
3192
- if (a._big.gt(b)) {
3225
+ if (a._big.gt(b._big)) {
3193
3226
  return 1;
3194
- } else if (a._big.lt(b)) {
3227
+ } else if (a._big.lt(b._big)) {
3195
3228
  return -1;
3196
3229
  } else {
3197
3230
  return 0;