@barchart/portfolio-api-common 1.29.3 → 1.30.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.
@@ -689,6 +689,28 @@ module.exports = (() => {
689
689
  }
690
690
  }
691
691
 
692
+ function formatFractionAndTranslate(value, currency, instrument) {
693
+ let translatedCurrency;
694
+ let translatedValue;
695
+
696
+ if (currency === Currency.GBX) {
697
+ translatedCurrency = Currency.GBP;
698
+
699
+ if (value instanceof Decimal) {
700
+ translatedValue = Rate.convert(value, Currency.GBX, Currency.GBP);
701
+ } else if (is.number(value)) {
702
+ translatedValue = Rate.convert(new Decimal(value), Currency.GBX, Currency.GBP).toFloat();
703
+ } else {
704
+ translatedValue = value;
705
+ }
706
+ } else {
707
+ translatedCurrency = currency;
708
+ translatedValue = value;
709
+ }
710
+
711
+ return formatFraction(translatedValue, translatedCurrency, instrument);
712
+ }
713
+
692
714
  function formatNumber(number, precision) {
693
715
  if (is.number(number)) {
694
716
  return formatter.numberToString(number, precision, ',', false);
@@ -722,7 +744,15 @@ module.exports = (() => {
722
744
  }
723
745
 
724
746
  function formatCurrency(decimal, currency) {
725
- return formatDecimal(decimal, currency.precision);
747
+ let formatted;
748
+
749
+ if (decimal === null || currency !== Currency.GBX) {
750
+ formatted = formatDecimal(decimal, currency.precision);
751
+ } else {
752
+ formatted = formatDecimal(Rate.convert(decimal, Currency.GBX, Currency.GBP), Currency.GBP.precision);
753
+ }
754
+
755
+ return formatted;
726
756
  }
727
757
 
728
758
  function calculateStaticData(group, rates, definition) {
@@ -863,7 +893,7 @@ module.exports = (() => {
863
893
  format.quantityPrevious = formatDecimal(actual.quantityPrevious, 2);
864
894
 
865
895
  actual.basisPrice = item.data.basisPrice;
866
- format.basisPrice = formatFraction(actual.basisPrice, currency, instrument);
896
+ format.basisPrice = formatFractionAndTranslate(actual.basisPrice, currency, instrument);
867
897
 
868
898
  actual.periodPrice = item.data.periodPrice;
869
899
  actual.periodPricePrevious = item.data.periodPricePrevious;
@@ -872,7 +902,7 @@ module.exports = (() => {
872
902
  format.periodPricePrevious = formatCurrency(actual.periodPricePrevious, currency);
873
903
 
874
904
  actual.unrealizedPrice = item.data.unrealizedPrice;
875
- format.unrealizedPrice = formatFraction(actual.unrealizedPrice, currency, instrument);
905
+ format.unrealizedPrice = formatFractionAndTranslate(actual.unrealizedPrice, currency, instrument);
876
906
 
877
907
  format.invalid = definition.type === PositionLevelType.POSITION && item.invalid;
878
908
  format.locked = definition.type === PositionLevelType.POSITION && item.data.locked;
@@ -1032,7 +1062,7 @@ module.exports = (() => {
1032
1062
 
1033
1063
  if (group.single && item) {
1034
1064
  actual.unrealizedPrice = item.data.unrealizedPrice;
1035
- format.unrealizedPrice = formatFraction(actual.unrealizedPrice, currency, item.position.instrument);
1065
+ format.unrealizedPrice = formatFractionAndTranslate(actual.unrealizedPrice, currency, item.position.instrument);
1036
1066
  }
1037
1067
  }
1038
1068
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.29.3",
3
+ "version": "1.30.0",
4
4
  "description": "Common JavaScript code used by Barchart's Portfolio Service",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",