@barchart/portfolio-api-common 1.2.15 → 1.2.16

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.
@@ -406,32 +406,57 @@ module.exports = (() => {
406
406
 
407
407
  const summary = item.currentSummary;
408
408
 
409
- if (summary && price) {
410
- const period = summary.period;
409
+ let priceToUse;
411
410
 
412
- let unrealized = summary.end.open.multiply(price).add(summary.end.basis);
413
- let unrealizedChange;
411
+ if (price) {
412
+ priceToUse = price;
413
+ } else {
414
414
 
415
- if (data.unrealizedToday !== null) {
416
- unrealizedChange = unrealized.subtract(data.unrealized);
415
+ }
416
+
417
+ if (summary) {
418
+ let priceToUse;
419
+
420
+ if (price) {
421
+ priceToUse = price;
422
+ } else if (!summary.end.open.getIsZero()) {
423
+ priceToUse = summary.end.value.divide(summary.end.open);
417
424
  } else {
418
- unrealizedChange = Decimal.ZERO;
425
+ priceToUse = null;
419
426
  }
420
427
 
421
- let summaryTotalCurrent = period.realized.add(period.income).add(unrealized);
422
- let summaryTotalCurrentChange;
428
+ if (priceToUse !== null) {
429
+ const period = summary.period;
423
430
 
424
- if (data.summaryTotalCurrent !== null) {
425
- summaryTotalCurrentChange = summaryTotalCurrent.subtract(data.summaryTotalCurrent);
426
- } else {
427
- summaryTotalCurrentChange = Decimal.ZERO;
428
- }
431
+ let unrealized = summary.end.open.multiply(priceToUse).add(summary.end.basis);
432
+ let unrealizedChange;
433
+
434
+ if (data.unrealizedToday !== null) {
435
+ unrealizedChange = unrealized.subtract(data.unrealized);
436
+ } else {
437
+ unrealizedChange = Decimal.ZERO;
438
+ }
439
+
440
+ let summaryTotalCurrent = period.realized.add(period.income).add(unrealized);
441
+ let summaryTotalCurrentChange;
442
+
443
+ if (data.summaryTotalCurrent !== null) {
444
+ summaryTotalCurrentChange = summaryTotalCurrent.subtract(data.summaryTotalCurrent);
445
+ } else {
446
+ summaryTotalCurrentChange = Decimal.ZERO;
447
+ }
429
448
 
430
- data.summaryTotalCurrent = summaryTotalCurrent;
431
- data.summaryTotalCurrentChange = summaryTotalCurrentChange;
449
+ data.summaryTotalCurrent = summaryTotalCurrent;
450
+ data.summaryTotalCurrentChange = summaryTotalCurrentChange;
432
451
 
433
- data.unrealized = unrealized;
434
- data.unrealizedChange = unrealizedChange;
452
+ data.unrealized = unrealized;
453
+ data.unrealizedChange = unrealizedChange;
454
+ } else {
455
+ data.summaryTotalCurrentChange = Decimal.ZERO;
456
+
457
+ data.unrealized = Decimal.ZERO;
458
+ data.unrealizedChange = Decimal.ZERO;
459
+ }
435
460
  } else {
436
461
  data.summaryTotalCurrentChange = Decimal.ZERO;
437
462
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.2.15",
3
+ "version": "1.2.16",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -3424,32 +3424,57 @@ module.exports = (() => {
3424
3424
 
3425
3425
  const summary = item.currentSummary;
3426
3426
 
3427
- if (summary && price) {
3428
- const period = summary.period;
3427
+ let priceToUse;
3429
3428
 
3430
- let unrealized = summary.end.open.multiply(price).add(summary.end.basis);
3431
- let unrealizedChange;
3429
+ if (price) {
3430
+ priceToUse = price;
3431
+ } else {
3432
3432
 
3433
- if (data.unrealizedToday !== null) {
3434
- unrealizedChange = unrealized.subtract(data.unrealized);
3433
+ }
3434
+
3435
+ if (summary) {
3436
+ let priceToUse;
3437
+
3438
+ if (price) {
3439
+ priceToUse = price;
3440
+ } else if (!summary.end.open.getIsZero()) {
3441
+ priceToUse = summary.end.value.divide(summary.end.open);
3435
3442
  } else {
3436
- unrealizedChange = Decimal.ZERO;
3443
+ priceToUse = null;
3437
3444
  }
3438
3445
 
3439
- let summaryTotalCurrent = period.realized.add(period.income).add(unrealized);
3440
- let summaryTotalCurrentChange;
3446
+ if (priceToUse !== null) {
3447
+ const period = summary.period;
3441
3448
 
3442
- if (data.summaryTotalCurrent !== null) {
3443
- summaryTotalCurrentChange = summaryTotalCurrent.subtract(data.summaryTotalCurrent);
3444
- } else {
3445
- summaryTotalCurrentChange = Decimal.ZERO;
3446
- }
3449
+ let unrealized = summary.end.open.multiply(priceToUse).add(summary.end.basis);
3450
+ let unrealizedChange;
3447
3451
 
3448
- data.summaryTotalCurrent = summaryTotalCurrent;
3449
- data.summaryTotalCurrentChange = summaryTotalCurrentChange;
3452
+ if (data.unrealizedToday !== null) {
3453
+ unrealizedChange = unrealized.subtract(data.unrealized);
3454
+ } else {
3455
+ unrealizedChange = Decimal.ZERO;
3456
+ }
3457
+
3458
+ let summaryTotalCurrent = period.realized.add(period.income).add(unrealized);
3459
+ let summaryTotalCurrentChange;
3460
+
3461
+ if (data.summaryTotalCurrent !== null) {
3462
+ summaryTotalCurrentChange = summaryTotalCurrent.subtract(data.summaryTotalCurrent);
3463
+ } else {
3464
+ summaryTotalCurrentChange = Decimal.ZERO;
3465
+ }
3450
3466
 
3451
- data.unrealized = unrealized;
3452
- data.unrealizedChange = unrealizedChange;
3467
+ data.summaryTotalCurrent = summaryTotalCurrent;
3468
+ data.summaryTotalCurrentChange = summaryTotalCurrentChange;
3469
+
3470
+ data.unrealized = unrealized;
3471
+ data.unrealizedChange = unrealizedChange;
3472
+ } else {
3473
+ data.summaryTotalCurrentChange = Decimal.ZERO;
3474
+
3475
+ data.unrealized = Decimal.ZERO;
3476
+ data.unrealizedChange = Decimal.ZERO;
3477
+ }
3453
3478
  } else {
3454
3479
  data.summaryTotalCurrentChange = Decimal.ZERO;
3455
3480