@barchart/portfolio-api-common 1.0.64 → 1.0.68

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.
@@ -40,6 +40,8 @@ module.exports = (() => {
40
40
  this._dataFormat.marketPercent = null;
41
41
  this._dataFormat.unrealizedToday = null;
42
42
 
43
+ this._dataFormat.unrealizedTodayNegative = false;
44
+
43
45
  this._items.forEach((item) => {
44
46
  item.registerPriceChangeHandler((data, sender) => {
45
47
  if (this._single) {
@@ -87,15 +89,15 @@ module.exports = (() => {
87
89
  if (decimal !== null) {
88
90
  return formatter.numberToString(decimal.toFloat(), precision, ',', false);
89
91
  } else {
90
- return '--';
92
+ return '';
91
93
  }
92
94
  }
93
95
 
94
96
  function formatPercent(decimal, precision) {
95
97
  if (decimal !== null) {
96
- return formatNumber(decimal.multiply(100));
98
+ return formatNumber(decimal.multiply(100), precision);
97
99
  } else {
98
- return '--';
100
+ return '';
99
101
  }
100
102
  }
101
103
 
@@ -158,7 +160,11 @@ module.exports = (() => {
158
160
 
159
161
  if (parentData.market !== null && !parentData.market.getIsZero()) {
160
162
  updates.marketPercent = updates.market.divide(parentData.market);
163
+ } else {
164
+ updates.marketPercent = null;
161
165
  }
166
+ } else {
167
+ updates.marketPercent = null;
162
168
  }
163
169
 
164
170
  actual.market = updates.market;
@@ -166,8 +172,9 @@ module.exports = (() => {
166
172
  actual.unrealizedToday = updates.unrealizedToday;
167
173
 
168
174
  format.market = formatCurrency(updates.market, currency);
169
- format.marketPercent = formatPercent(updates.unrealizedToday, 2);
175
+ format.marketPercent = formatPercent(updates.marketPercent, 2);
170
176
  format.unrealizedToday = formatCurrency(updates.unrealizedToday, currency);
177
+ format.unrealizedTodayNegative = actual.unrealizedToday.getIsNegative();
171
178
  }
172
179
 
173
180
  return PositionGroup;
@@ -26,7 +26,7 @@ module.exports = (() => {
26
26
 
27
27
  this._data.market = null;
28
28
  this._data.marketChange = null;
29
-
29
+
30
30
  this._data.unrealizedToday = null;
31
31
  this._data.unrealizedTodayChange = null;
32
32
 
@@ -77,7 +77,7 @@ module.exports = (() => {
77
77
 
78
78
  const data = item._data;
79
79
 
80
- data.previousPrice = position.previousPrice || null;
80
+ data.previousPrice = position.previous || null;
81
81
 
82
82
  let basis;
83
83
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.0.64",
3
+ "version": "1.0.68",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -858,6 +858,8 @@ module.exports = (() => {
858
858
  this._dataFormat.marketPercent = null;
859
859
  this._dataFormat.unrealizedToday = null;
860
860
 
861
+ this._dataFormat.unrealizedTodayNegative = false;
862
+
861
863
  this._items.forEach((item) => {
862
864
  item.registerPriceChangeHandler((data, sender) => {
863
865
  if (this._single) {
@@ -905,15 +907,15 @@ module.exports = (() => {
905
907
  if (decimal !== null) {
906
908
  return formatter.numberToString(decimal.toFloat(), precision, ',', false);
907
909
  } else {
908
- return '--';
910
+ return '';
909
911
  }
910
912
  }
911
913
 
912
914
  function formatPercent(decimal, precision) {
913
915
  if (decimal !== null) {
914
- return formatNumber(decimal.multiply(100));
916
+ return formatNumber(decimal.multiply(100), precision);
915
917
  } else {
916
- return '--';
918
+ return '';
917
919
  }
918
920
  }
919
921
 
@@ -976,7 +978,11 @@ module.exports = (() => {
976
978
 
977
979
  if (parentData.market !== null && !parentData.market.getIsZero()) {
978
980
  updates.marketPercent = updates.market.divide(parentData.market);
981
+ } else {
982
+ updates.marketPercent = null;
979
983
  }
984
+ } else {
985
+ updates.marketPercent = null;
980
986
  }
981
987
 
982
988
  actual.market = updates.market;
@@ -984,8 +990,9 @@ module.exports = (() => {
984
990
  actual.unrealizedToday = updates.unrealizedToday;
985
991
 
986
992
  format.market = formatCurrency(updates.market, currency);
987
- format.marketPercent = formatPercent(updates.unrealizedToday, 2);
993
+ format.marketPercent = formatPercent(updates.marketPercent, 2);
988
994
  format.unrealizedToday = formatCurrency(updates.unrealizedToday, currency);
995
+ format.unrealizedTodayNegative = actual.unrealizedToday.getIsNegative();
989
996
  }
990
997
 
991
998
  return PositionGroup;
@@ -1070,7 +1077,7 @@ module.exports = (() => {
1070
1077
 
1071
1078
  this._data.market = null;
1072
1079
  this._data.marketChange = null;
1073
-
1080
+
1074
1081
  this._data.unrealizedToday = null;
1075
1082
  this._data.unrealizedTodayChange = null;
1076
1083
 
@@ -1121,7 +1128,7 @@ module.exports = (() => {
1121
1128
 
1122
1129
  const data = item._data;
1123
1130
 
1124
- data.previousPrice = position.previousPrice || null;
1131
+ data.previousPrice = position.previous || null;
1125
1132
 
1126
1133
  let basis;
1127
1134