@barchart/portfolio-api-common 1.2.145 → 1.3.2

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.
@@ -691,9 +691,9 @@ module.exports = (() => {
691
691
  updates.marketPrevious = updates.marketPrevious.add(translate(item, item.data.marketPrevious));
692
692
  updates.marketPrevious2 = updates.marketPrevious2.add(translate(item, item.data.marketPrevious2));
693
693
 
694
+ updates.periodIncome = updates.periodIncome.add(translate(item, item.data.periodIncome));
694
695
  updates.periodRealized = updates.periodRealized.add(translate(item, item.data.periodRealized));
695
696
  updates.periodUnrealized = updates.periodUnrealized.add(translate(item, item.data.periodUnrealized));
696
- updates.periodIncome = updates.periodIncome.add(translate(item, item.data.periodIncome));
697
697
 
698
698
  if (item.position.instrument.type === InstrumentType.CASH) {
699
699
  updates.cashTotal = updates.cashTotal.add(translate(item, item.data.market));
@@ -715,9 +715,9 @@ module.exports = (() => {
715
715
  summaryTotalPrevious2: Decimal.ZERO,
716
716
  marketPrevious: Decimal.ZERO,
717
717
  marketPrevious2: Decimal.ZERO,
718
+ periodIncome: Decimal.ZERO,
718
719
  periodRealized: Decimal.ZERO,
719
720
  periodUnrealized: Decimal.ZERO,
720
- periodIncome: Decimal.ZERO,
721
721
  cashTotal: Decimal.ZERO,
722
722
  totalDivisor: Decimal.ZERO,
723
723
  periodDivisorCurrent: Decimal.ZERO,
@@ -734,9 +734,9 @@ module.exports = (() => {
734
734
  actual.summaryTotalPrevious2 = updates.summaryTotalPrevious2;
735
735
  actual.marketPrevious = updates.marketPrevious;
736
736
  actual.marketPrevious2 = updates.marketPrevious2;
737
+ actual.periodIncome = updates.periodIncome;
737
738
  actual.periodRealized = updates.periodRealized;
738
739
  actual.periodUnrealized = updates.periodUnrealized;
739
- actual.periodIncome = updates.periodIncome;
740
740
  actual.cashTotal = updates.cashTotal;
741
741
  actual.totalDivisor = updates.totalDivisor;
742
742
  actual.periodDivisorCurrent = updates.periodDivisorCurrent;
@@ -755,9 +755,9 @@ module.exports = (() => {
755
755
  format.summaryTotalPrevious2Negative = updates.summaryTotalPrevious2.getIsNegative();
756
756
  format.marketPrevious = formatCurrency(updates.marketPrevious, currency);
757
757
  format.marketPrevious2 = formatCurrency(updates.marketPrevious2, currency);
758
+ format.periodIncome = formatCurrency(updates.periodIncome, currency);
758
759
  format.periodRealized = formatCurrency(updates.periodRealized, currency);
759
760
  format.periodUnrealized = formatCurrency(updates.periodUnrealized, currency);
760
- format.periodIncome = formatCurrency(updates.periodIncome, currency);
761
761
  format.cashTotal = formatCurrency(updates.cashTotal, currency);
762
762
 
763
763
  calculateRealizedPercent(group);
@@ -846,6 +846,7 @@ module.exports = (() => {
846
846
  updates.unrealized = updates.unrealized.add(translate(item, item.data.unrealized));
847
847
  updates.unrealizedToday = updates.unrealizedToday.add(translate(item, item.data.unrealizedToday));
848
848
  updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.periodGain));
849
+ updates.periodUnrealized = updates.periodUnrealized.add(translate(item, item.data.periodUnrealized));
849
850
 
850
851
  return updates;
851
852
  }, {
@@ -854,7 +855,8 @@ module.exports = (() => {
854
855
  marketDirection: unchanged,
855
856
  unrealized: Decimal.ZERO,
856
857
  unrealizedToday: Decimal.ZERO,
857
- summaryTotalCurrent: Decimal.ZERO
858
+ summaryTotalCurrent: Decimal.ZERO,
859
+ periodUnrealized: Decimal.ZERO
858
860
  });
859
861
  } else {
860
862
  updates = {
@@ -863,7 +865,8 @@ module.exports = (() => {
863
865
  marketDirection: { up: item.data.marketChange.getIsPositive(), down: item.data.marketChange.getIsNegative() },
864
866
  unrealized: actual.unrealized.add(translate(item, item.data.unrealizedChange)),
865
867
  unrealizedToday: actual.unrealizedToday.add(translate(item, item.data.unrealizedTodayChange)),
866
- summaryTotalCurrent: actual.summaryTotalCurrent.add(translate(item, item.data.periodGainChange))
868
+ summaryTotalCurrent: actual.summaryTotalCurrent.add(translate(item, item.data.periodGainChange)),
869
+ periodUnrealized: actual.periodUnrealized.add(translate(item, item.data.periodUnrealizedChange))
867
870
  };
868
871
  }
869
872
 
@@ -872,6 +875,7 @@ module.exports = (() => {
872
875
  actual.unrealized = updates.unrealized;
873
876
  actual.unrealizedToday = updates.unrealizedToday;
874
877
  actual.summaryTotalCurrent = updates.summaryTotalCurrent;
878
+ actual.periodUnrealized = updates.periodUnrealized;
875
879
 
876
880
  actual.total = updates.unrealized.add(actual.realized).add(actual.income);
877
881
  actual.totalPercent = calculateGainPercent(actual.total, actual.totalDivisor);
@@ -910,6 +914,8 @@ module.exports = (() => {
910
914
  format.summaryTotalCurrent = formatCurrency(actual.summaryTotalCurrent, currency);
911
915
  format.summaryTotalCurrentNegative = actual.summaryTotalCurrent.getIsNegative();
912
916
 
917
+ format.periodUnrealized = formatCurrency(actual.periodUnrealized, currency);
918
+
913
919
  format.total = formatCurrency(actual.total, currency);
914
920
  format.totalNegative = actual.total.getIsNegative();
915
921
  format.totalPercent = formatPercent(actual.totalPercent, 2);
@@ -922,10 +928,6 @@ module.exports = (() => {
922
928
 
923
929
  actual.periodPercent = calculateGainPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
924
930
  format.periodPercent = formatPercent(actual.periodPercent, 2);
925
-
926
- if (group.single && item) {
927
- actual.periodUnrealized = item.data.periodUnrealized;
928
- }
929
931
  }
930
932
 
931
933
  function calculateMarketPercent(group, rates, parentGroup, portfolioGroup) {
@@ -75,7 +75,9 @@ module.exports = (() => {
75
75
 
76
76
  this._data.periodIncome = null;
77
77
  this._data.periodRealized = null;
78
+
78
79
  this._data.periodUnrealized = null;
80
+ this._data.periodUnrealizedChange = null;
79
81
 
80
82
  this._data.periodPrice = null;
81
83
  this._data.periodPricePrevious = null;
@@ -420,14 +422,14 @@ module.exports = (() => {
420
422
  data.marketPrevious2 = previousSummary2 === null ? Decimal.ZERO : previousSummary2.end.value;
421
423
  data.quantityPrevious = previousSummary1 === null ? Decimal.ZERO : previousSummary1.end.open;
422
424
 
423
- data.periodIncome = currentSummary !== null ? currentSummary.period.income : Decimal.ZERO;
424
- data.periodRealized = currentSummary !== null ? currentSummary.period.realized : Decimal.ZERO;
425
- data.periodUnrealized = currentSummary !== null ? currentSummary.period.unrealized : Decimal.ZERO;
426
-
427
425
  data.periodGain = calculatePeriodGain(position.instrument.type, data.initiate, currentSummary, previousSummary1);
428
426
  data.periodGainPrevious = calculatePeriodGain(position.instrument.type, data.initiate, previousSummary1, previousSummary2);
429
427
  data.periodGainPrevious2 = calculatePeriodGain(position.instrument.type, data.initiate, previousSummary2, previousSummary3);
430
428
 
429
+ data.periodIncome = currentSummary !== null ? currentSummary.period.income : Decimal.ZERO;
430
+ data.periodRealized = currentSummary !== null ? currentSummary.period.realized : Decimal.ZERO;
431
+ data.periodUnrealized = calculatePeriodUnrealized(position.instrument.type, data.periodGain, data.periodRealized, data.periodIncome);
432
+
431
433
  data.periodDivisor = calculatePeriodDivisor(position.instrument.type, data.initiate, currentSummary, previousSummary1);
432
434
  data.periodDivisorPrevious = calculatePeriodDivisor(position.instrument.type, data.initiate, previousSummary1, previousSummary2);
433
435
  data.periodDivisorPrevious2 = calculatePeriodDivisor(position.instrument.type, data.initiate, previousSummary2, previousSummary3);
@@ -450,7 +452,7 @@ module.exports = (() => {
450
452
  data.periodPricePrevious = null;
451
453
  }
452
454
 
453
- data.totalDivisor = calculateTotalDivisor(position.instrument.type, data.initiate, currentSummary);
455
+ data.totalDivisor = calculateTotalDivisor(position.instrument.type, data.initiate, currentSummary, position);
454
456
  }
455
457
 
456
458
  function calculatePriceData(item, price) {
@@ -555,16 +557,26 @@ module.exports = (() => {
555
557
 
556
558
  data.periodGain = periodGain;
557
559
  data.periodGainChange = periodGainChange;
560
+
561
+ let periodUnrealized = calculatePeriodUnrealized(position.instrument.type, data.periodGain, data.periodRealized, data.periodIncome);
562
+ let periodUnrealizedChange;
563
+
564
+ if (data.periodUnrealized !== null) {
565
+ periodUnrealizedChange = periodUnrealized.subtract(data.periodUnrealized);
566
+ } else {
567
+ periodUnrealizedChange = Decimal.ZERO;
568
+ }
569
+
570
+ data.periodUnrealized = periodUnrealized;
571
+ data.periodUnrealizedChange = periodUnrealizedChange;
558
572
  } else {
559
- data.unrealized = Decimal.ZERO;
560
573
  data.unrealizedChange = Decimal.ZERO;
561
-
574
+ data.periodUnrealized = Decimal.ZERO;
562
575
  data.periodGainChange = Decimal.ZERO;
563
576
  }
564
577
  } else {
565
- data.unrealized = Decimal.ZERO;
566
578
  data.unrealizedChange = Decimal.ZERO;
567
-
579
+ data.periodUnrealized = Decimal.ZERO;
568
580
  data.periodGainChange = Decimal.ZERO;
569
581
  }
570
582
  }
@@ -645,14 +657,30 @@ module.exports = (() => {
645
657
  return returnRef;
646
658
  }
647
659
 
648
- function calculateTotalDivisor(type, direction, finalSummary) {
660
+ function calculatePeriodUnrealized(type, periodGain, periodRealized, periodIncome) {
661
+ let returnRef;
662
+
663
+ if (type !== InstrumentType.CASH) {
664
+ returnRef = periodRealized.add(periodIncome).subtract(periodGain).opposite();
665
+ } else {
666
+ returnRef = Decimal.ZERO;
667
+ }
668
+
669
+ return returnRef;
670
+ }
671
+
672
+ function calculateTotalDivisor(type, direction, finalSummary, position) {
649
673
  let returnRef;
650
674
 
675
+ // 2019-06-05, BRI. We should be reading from the summary -- in case we are
676
+ // running for a previous period. However, the summary does not have buy and
677
+ // sell totals for the entire history. Could be added.
678
+
651
679
  if (finalSummary && type !== InstrumentType.CASH) {
652
680
  if (direction === PositionDirection.SHORT) {
653
- returnRef = finalSummary.period.sells;
681
+ returnRef = position.snapshot.sells;
654
682
  } else {
655
- returnRef = finalSummary.period.buys.opposite();
683
+ returnRef = position.snapshot.buys.opposite();
656
684
  }
657
685
  } else {
658
686
  returnRef = Decimal.ZERO;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.2.145",
3
+ "version": "1.3.2",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "scripts": {},
11
11
  "dependencies": {
12
- "@barchart/common-js": "~3.2.0",
12
+ "@barchart/common-js": "~3.3.0",
13
13
  "uuid": "3.1.0"
14
14
  },
15
15
  "devDependencies": {
@@ -3213,9 +3213,9 @@ module.exports = (() => {
3213
3213
  updates.marketPrevious = updates.marketPrevious.add(translate(item, item.data.marketPrevious));
3214
3214
  updates.marketPrevious2 = updates.marketPrevious2.add(translate(item, item.data.marketPrevious2));
3215
3215
 
3216
+ updates.periodIncome = updates.periodIncome.add(translate(item, item.data.periodIncome));
3216
3217
  updates.periodRealized = updates.periodRealized.add(translate(item, item.data.periodRealized));
3217
3218
  updates.periodUnrealized = updates.periodUnrealized.add(translate(item, item.data.periodUnrealized));
3218
- updates.periodIncome = updates.periodIncome.add(translate(item, item.data.periodIncome));
3219
3219
 
3220
3220
  if (item.position.instrument.type === InstrumentType.CASH) {
3221
3221
  updates.cashTotal = updates.cashTotal.add(translate(item, item.data.market));
@@ -3237,9 +3237,9 @@ module.exports = (() => {
3237
3237
  summaryTotalPrevious2: Decimal.ZERO,
3238
3238
  marketPrevious: Decimal.ZERO,
3239
3239
  marketPrevious2: Decimal.ZERO,
3240
+ periodIncome: Decimal.ZERO,
3240
3241
  periodRealized: Decimal.ZERO,
3241
3242
  periodUnrealized: Decimal.ZERO,
3242
- periodIncome: Decimal.ZERO,
3243
3243
  cashTotal: Decimal.ZERO,
3244
3244
  totalDivisor: Decimal.ZERO,
3245
3245
  periodDivisorCurrent: Decimal.ZERO,
@@ -3256,9 +3256,9 @@ module.exports = (() => {
3256
3256
  actual.summaryTotalPrevious2 = updates.summaryTotalPrevious2;
3257
3257
  actual.marketPrevious = updates.marketPrevious;
3258
3258
  actual.marketPrevious2 = updates.marketPrevious2;
3259
+ actual.periodIncome = updates.periodIncome;
3259
3260
  actual.periodRealized = updates.periodRealized;
3260
3261
  actual.periodUnrealized = updates.periodUnrealized;
3261
- actual.periodIncome = updates.periodIncome;
3262
3262
  actual.cashTotal = updates.cashTotal;
3263
3263
  actual.totalDivisor = updates.totalDivisor;
3264
3264
  actual.periodDivisorCurrent = updates.periodDivisorCurrent;
@@ -3277,9 +3277,9 @@ module.exports = (() => {
3277
3277
  format.summaryTotalPrevious2Negative = updates.summaryTotalPrevious2.getIsNegative();
3278
3278
  format.marketPrevious = formatCurrency(updates.marketPrevious, currency);
3279
3279
  format.marketPrevious2 = formatCurrency(updates.marketPrevious2, currency);
3280
+ format.periodIncome = formatCurrency(updates.periodIncome, currency);
3280
3281
  format.periodRealized = formatCurrency(updates.periodRealized, currency);
3281
3282
  format.periodUnrealized = formatCurrency(updates.periodUnrealized, currency);
3282
- format.periodIncome = formatCurrency(updates.periodIncome, currency);
3283
3283
  format.cashTotal = formatCurrency(updates.cashTotal, currency);
3284
3284
 
3285
3285
  calculateRealizedPercent(group);
@@ -3368,6 +3368,7 @@ module.exports = (() => {
3368
3368
  updates.unrealized = updates.unrealized.add(translate(item, item.data.unrealized));
3369
3369
  updates.unrealizedToday = updates.unrealizedToday.add(translate(item, item.data.unrealizedToday));
3370
3370
  updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.periodGain));
3371
+ updates.periodUnrealized = updates.periodUnrealized.add(translate(item, item.data.periodUnrealized));
3371
3372
 
3372
3373
  return updates;
3373
3374
  }, {
@@ -3376,7 +3377,8 @@ module.exports = (() => {
3376
3377
  marketDirection: unchanged,
3377
3378
  unrealized: Decimal.ZERO,
3378
3379
  unrealizedToday: Decimal.ZERO,
3379
- summaryTotalCurrent: Decimal.ZERO
3380
+ summaryTotalCurrent: Decimal.ZERO,
3381
+ periodUnrealized: Decimal.ZERO
3380
3382
  });
3381
3383
  } else {
3382
3384
  updates = {
@@ -3385,7 +3387,8 @@ module.exports = (() => {
3385
3387
  marketDirection: { up: item.data.marketChange.getIsPositive(), down: item.data.marketChange.getIsNegative() },
3386
3388
  unrealized: actual.unrealized.add(translate(item, item.data.unrealizedChange)),
3387
3389
  unrealizedToday: actual.unrealizedToday.add(translate(item, item.data.unrealizedTodayChange)),
3388
- summaryTotalCurrent: actual.summaryTotalCurrent.add(translate(item, item.data.periodGainChange))
3390
+ summaryTotalCurrent: actual.summaryTotalCurrent.add(translate(item, item.data.periodGainChange)),
3391
+ periodUnrealized: actual.periodUnrealized.add(translate(item, item.data.periodUnrealizedChange))
3389
3392
  };
3390
3393
  }
3391
3394
 
@@ -3394,6 +3397,7 @@ module.exports = (() => {
3394
3397
  actual.unrealized = updates.unrealized;
3395
3398
  actual.unrealizedToday = updates.unrealizedToday;
3396
3399
  actual.summaryTotalCurrent = updates.summaryTotalCurrent;
3400
+ actual.periodUnrealized = updates.periodUnrealized;
3397
3401
 
3398
3402
  actual.total = updates.unrealized.add(actual.realized).add(actual.income);
3399
3403
  actual.totalPercent = calculateGainPercent(actual.total, actual.totalDivisor);
@@ -3432,6 +3436,8 @@ module.exports = (() => {
3432
3436
  format.summaryTotalCurrent = formatCurrency(actual.summaryTotalCurrent, currency);
3433
3437
  format.summaryTotalCurrentNegative = actual.summaryTotalCurrent.getIsNegative();
3434
3438
 
3439
+ format.periodUnrealized = formatCurrency(actual.periodUnrealized, currency);
3440
+
3435
3441
  format.total = formatCurrency(actual.total, currency);
3436
3442
  format.totalNegative = actual.total.getIsNegative();
3437
3443
  format.totalPercent = formatPercent(actual.totalPercent, 2);
@@ -3444,10 +3450,6 @@ module.exports = (() => {
3444
3450
 
3445
3451
  actual.periodPercent = calculateGainPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
3446
3452
  format.periodPercent = formatPercent(actual.periodPercent, 2);
3447
-
3448
- if (group.single && item) {
3449
- actual.periodUnrealized = item.data.periodUnrealized;
3450
- }
3451
3453
  }
3452
3454
 
3453
3455
  function calculateMarketPercent(group, rates, parentGroup, portfolioGroup) {
@@ -3615,7 +3617,9 @@ module.exports = (() => {
3615
3617
 
3616
3618
  this._data.periodIncome = null;
3617
3619
  this._data.periodRealized = null;
3620
+
3618
3621
  this._data.periodUnrealized = null;
3622
+ this._data.periodUnrealizedChange = null;
3619
3623
 
3620
3624
  this._data.periodPrice = null;
3621
3625
  this._data.periodPricePrevious = null;
@@ -3960,14 +3964,14 @@ module.exports = (() => {
3960
3964
  data.marketPrevious2 = previousSummary2 === null ? Decimal.ZERO : previousSummary2.end.value;
3961
3965
  data.quantityPrevious = previousSummary1 === null ? Decimal.ZERO : previousSummary1.end.open;
3962
3966
 
3963
- data.periodIncome = currentSummary !== null ? currentSummary.period.income : Decimal.ZERO;
3964
- data.periodRealized = currentSummary !== null ? currentSummary.period.realized : Decimal.ZERO;
3965
- data.periodUnrealized = currentSummary !== null ? currentSummary.period.unrealized : Decimal.ZERO;
3966
-
3967
3967
  data.periodGain = calculatePeriodGain(position.instrument.type, data.initiate, currentSummary, previousSummary1);
3968
3968
  data.periodGainPrevious = calculatePeriodGain(position.instrument.type, data.initiate, previousSummary1, previousSummary2);
3969
3969
  data.periodGainPrevious2 = calculatePeriodGain(position.instrument.type, data.initiate, previousSummary2, previousSummary3);
3970
3970
 
3971
+ data.periodIncome = currentSummary !== null ? currentSummary.period.income : Decimal.ZERO;
3972
+ data.periodRealized = currentSummary !== null ? currentSummary.period.realized : Decimal.ZERO;
3973
+ data.periodUnrealized = calculatePeriodUnrealized(position.instrument.type, data.periodGain, data.periodRealized, data.periodIncome);
3974
+
3971
3975
  data.periodDivisor = calculatePeriodDivisor(position.instrument.type, data.initiate, currentSummary, previousSummary1);
3972
3976
  data.periodDivisorPrevious = calculatePeriodDivisor(position.instrument.type, data.initiate, previousSummary1, previousSummary2);
3973
3977
  data.periodDivisorPrevious2 = calculatePeriodDivisor(position.instrument.type, data.initiate, previousSummary2, previousSummary3);
@@ -3990,7 +3994,7 @@ module.exports = (() => {
3990
3994
  data.periodPricePrevious = null;
3991
3995
  }
3992
3996
 
3993
- data.totalDivisor = calculateTotalDivisor(position.instrument.type, data.initiate, currentSummary);
3997
+ data.totalDivisor = calculateTotalDivisor(position.instrument.type, data.initiate, currentSummary, position);
3994
3998
  }
3995
3999
 
3996
4000
  function calculatePriceData(item, price) {
@@ -4095,16 +4099,26 @@ module.exports = (() => {
4095
4099
 
4096
4100
  data.periodGain = periodGain;
4097
4101
  data.periodGainChange = periodGainChange;
4102
+
4103
+ let periodUnrealized = calculatePeriodUnrealized(position.instrument.type, data.periodGain, data.periodRealized, data.periodIncome);
4104
+ let periodUnrealizedChange;
4105
+
4106
+ if (data.periodUnrealized !== null) {
4107
+ periodUnrealizedChange = periodUnrealized.subtract(data.periodUnrealized);
4108
+ } else {
4109
+ periodUnrealizedChange = Decimal.ZERO;
4110
+ }
4111
+
4112
+ data.periodUnrealized = periodUnrealized;
4113
+ data.periodUnrealizedChange = periodUnrealizedChange;
4098
4114
  } else {
4099
- data.unrealized = Decimal.ZERO;
4100
4115
  data.unrealizedChange = Decimal.ZERO;
4101
-
4116
+ data.periodUnrealized = Decimal.ZERO;
4102
4117
  data.periodGainChange = Decimal.ZERO;
4103
4118
  }
4104
4119
  } else {
4105
- data.unrealized = Decimal.ZERO;
4106
4120
  data.unrealizedChange = Decimal.ZERO;
4107
-
4121
+ data.periodUnrealized = Decimal.ZERO;
4108
4122
  data.periodGainChange = Decimal.ZERO;
4109
4123
  }
4110
4124
  }
@@ -4185,14 +4199,30 @@ module.exports = (() => {
4185
4199
  return returnRef;
4186
4200
  }
4187
4201
 
4188
- function calculateTotalDivisor(type, direction, finalSummary) {
4202
+ function calculatePeriodUnrealized(type, periodGain, periodRealized, periodIncome) {
4203
+ let returnRef;
4204
+
4205
+ if (type !== InstrumentType.CASH) {
4206
+ returnRef = periodRealized.add(periodIncome).subtract(periodGain).opposite();
4207
+ } else {
4208
+ returnRef = Decimal.ZERO;
4209
+ }
4210
+
4211
+ return returnRef;
4212
+ }
4213
+
4214
+ function calculateTotalDivisor(type, direction, finalSummary, position) {
4189
4215
  let returnRef;
4190
4216
 
4217
+ // 2019-06-05, BRI. We should be reading from the summary -- in case we are
4218
+ // running for a previous period. However, the summary does not have buy and
4219
+ // sell totals for the entire history. Could be added.
4220
+
4191
4221
  if (finalSummary && type !== InstrumentType.CASH) {
4192
4222
  if (direction === PositionDirection.SHORT) {
4193
- returnRef = finalSummary.period.sells;
4223
+ returnRef = position.snapshot.sells;
4194
4224
  } else {
4195
- returnRef = finalSummary.period.buys.opposite();
4225
+ returnRef = position.snapshot.buys.opposite();
4196
4226
  }
4197
4227
  } else {
4198
4228
  returnRef = Decimal.ZERO;
@@ -18469,7 +18499,9 @@ describe('When a position container data is gathered', () => {
18469
18499
  value: new Decimal(456),
18470
18500
  open: new Decimal(1),
18471
18501
  income: new Decimal(0),
18472
- gain: new Decimal(0)
18502
+ gain: new Decimal(0),
18503
+ buys: new Decimal(50),
18504
+ sells: new Decimal(0)
18473
18505
  }
18474
18506
  };
18475
18507
  }
@@ -30,7 +30,9 @@ describe('When a position container data is gathered', () => {
30
30
  value: new Decimal(456),
31
31
  open: new Decimal(1),
32
32
  income: new Decimal(0),
33
- gain: new Decimal(0)
33
+ gain: new Decimal(0),
34
+ buys: new Decimal(50),
35
+ sells: new Decimal(0)
34
36
  }
35
37
  };
36
38
  }