@barchart/portfolio-api-common 1.0.45 → 1.0.49

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.
@@ -1,6 +1,6 @@
1
1
  const assert = require('@barchart/common-js/lang/assert'),
2
2
  is = require('@barchart/common-js/lang/is'),
3
- numberFormatter = require('@barchart/common-js/lang/formatter');
3
+ formatter = require('@barchart/common-js/lang/formatter');
4
4
 
5
5
  const TransactionType = require('./../data/TransactionType');
6
6
 
@@ -51,7 +51,7 @@ module.exports = (() => {
51
51
  if (!is.undefined(formattedTransaction[key]) && is.fn(formattedTransaction[key].toFloat)) {
52
52
  const precision = transaction.instrument.currency.precision;
53
53
 
54
- formattedTransaction[key] = numberFormatter.numberToString(formattedTransaction[key].toFloat(), precision, ',');
54
+ formattedTransaction[key] = formatter.numberToString(formattedTransaction[key].toFloat(), precision, ',');
55
55
  }
56
56
  });
57
57
 
@@ -1,4 +1,6 @@
1
1
  const array = require('@barchart/common-js/lang/array'),
2
+ ComparatorBuilder = require('@barchart/common-js/collections/sorting/ComparatorBuilder'),
3
+ comparators = require('@barchart/common-js/collections/sorting/comparators'),
2
4
  assert = require('@barchart/common-js/lang/assert'),
3
5
  is = require('@barchart/common-js/lang/is'),
4
6
  Tree = require('@barchart/common-js/collections/Tree');
@@ -83,11 +85,37 @@ module.exports = (() => {
83
85
  const missingGroups = array.difference(currentDefinition.requiredGroups, populatedGroups.map(group => group.description));
84
86
 
85
87
  const empty = missingGroups.map((description) => {
86
- return new PositionGroup(description, [ ]);
88
+ return new PositionGroup([ ], description);
87
89
  });
88
90
 
89
91
  const compositeGroups = populatedGroups.concat(empty);
90
92
 
93
+ let builder;
94
+
95
+ if (currentDefinition.requiredGroups.length !== 0) {
96
+ const ordering = currentDefinition.requiredGroups.reduce((map, group, index) => {
97
+ map[group] = index;
98
+
99
+ return map;
100
+ }, { });
101
+
102
+ const getIndex = (description) => {
103
+ return ordering[description] || Math.MAX_VALUE;
104
+ };
105
+
106
+ builder = ComparatorBuilder.startWith((a, b) => {
107
+ return comparators.compareNumbers(getIndex(a.description), getIndex(b.description));
108
+ }).thenBy((a, b) => {
109
+ return comparators.compareStrings(a.description, b.description);
110
+ });
111
+ } else {
112
+ builder = ComparatorBuilder.startWith((a, b) => {
113
+ return comparators.compareStrings(a.description, b.description);
114
+ });
115
+ }
116
+
117
+ compositeGroups.sort(builder.toComparator());
118
+
91
119
  compositeGroups.forEach((group) => {
92
120
  const child = tree.addChild(group);
93
121
 
@@ -1,5 +1,7 @@
1
1
  const assert = require('@barchart/common-js/lang/assert'),
2
+ Currency = require('@barchart/common-js/lang/Currency'),
2
3
  Decimal = require('@barchart/common-js/lang/Decimal'),
4
+ formatter = require('@barchart/common-js/lang/formatter'),
3
5
  is = require('@barchart/common-js/lang/is');
4
6
 
5
7
  module.exports = (() => {
@@ -15,22 +17,31 @@ module.exports = (() => {
15
17
 
16
18
  this._single = is.boolean(single) && single;
17
19
 
18
- this._data = { };
20
+ this._dataFormat = { };
21
+ this._dataRaw = { };
22
+
23
+ this._dataFormat.description = this._description;
19
24
 
20
- this._data.description = this._description;
25
+ this._dataRaw.current = null;
26
+ this._dataRaw.previous = null;
21
27
 
22
- this._data.current = null;
23
- this._data.previous = null;
28
+ this._dataFormat.current = null;
29
+ this._dataFormat.previous = null;
24
30
 
25
- this._data.basis = null;
26
- this._data.market = null;
31
+ this._dataRaw.basis = null;
32
+ this._dataRaw.market = null;
33
+
34
+ this._dataFormat.basis = null;
35
+ this._dataFormat.market = null;
27
36
 
28
37
  this._items.forEach((item) => {
29
38
  item.registerPriceChangeHandler((data, sender) => {
30
39
  if (this._single) {
31
- data.current = data.current;
40
+ this._dataRaw.current = data.current;
41
+ this._dataFormat.current = format(data.current, sender.position.instrument.currency);
32
42
  } else {
33
- data.current = null;
43
+ this._dataRaw.current = null;
44
+ this._dataFormat.current = null;
34
45
  }
35
46
 
36
47
  calculateVariablePriceData(this, item, price);
@@ -45,7 +56,7 @@ module.exports = (() => {
45
56
  }
46
57
 
47
58
  get data() {
48
- return this._data;
59
+ return this._dataFormat;
49
60
  }
50
61
 
51
62
  get items() {
@@ -61,9 +72,15 @@ module.exports = (() => {
61
72
  }
62
73
  }
63
74
 
75
+ function format(decimal, currency) {
76
+ return formatter.numberToString(decimal.toFloat(), currency.precision, ',', false);
77
+ }
78
+
64
79
  function calculateStaticData(group) {
65
80
  const items = group._items;
66
- const data = group._data;
81
+
82
+ const raw = group._dataRaw;
83
+ const formatted = group._dataFormat;
67
84
 
68
85
  let updates;
69
86
 
@@ -84,7 +101,8 @@ module.exports = (() => {
84
101
  });
85
102
  }
86
103
 
87
- data.basis = updates.basis;
104
+ raw.basis = updates.basis;
105
+ formatted.basis = format(updates.basis, Currency.USD);
88
106
  }
89
107
 
90
108
  function calculateVariablePriceData(group, item, price) {
@@ -8,11 +8,12 @@ module.exports = (() => {
8
8
  * @public
9
9
  */
10
10
  class PositionGroupDefinition {
11
- constructor(name, keySelector, descriptionSelector, requiredGroups, single) {
11
+ constructor(name, keySelector, descriptionSelector, currencySelector, requiredGroups, single) {
12
12
  this._name = name;
13
13
 
14
14
  this._keySelector = keySelector;
15
15
  this._descriptionSelector = descriptionSelector;
16
+ this._currencySelector = currencySelector;
16
17
 
17
18
  this._requiredGroups = requiredGroups || [ ];
18
19
  this._single = is.boolean(single) && single;
@@ -30,6 +31,10 @@ module.exports = (() => {
30
31
  return this._descriptionSelector;
31
32
  }
32
33
 
34
+ get currencySelector() {
35
+ return this._currencySelector;
36
+ }
37
+
33
38
  get requiredGroups() {
34
39
  return this._requiredGroups;
35
40
  }
@@ -65,7 +65,6 @@ module.exports = (() => {
65
65
  const complete = new PositionSchema(SchemaBuilder.withName('complete')
66
66
  .withField('user', DataType.STRING)
67
67
  .withField('portfolio', DataType.STRING)
68
- .withField('sequence', DataType.NUMBER)
69
68
  .withField('instrument.id', DataType.STRING)
70
69
  .withField('instrument.name', DataType.STRING)
71
70
  .withField('instrument.type', DataType.forEnum(InstrumentType, 'InstrumentType'))
@@ -97,7 +96,6 @@ module.exports = (() => {
97
96
  const client = new PositionSchema(SchemaBuilder.withName('client')
98
97
  .withField('user', DataType.STRING)
99
98
  .withField('portfolio', DataType.STRING)
100
- .withField('sequence', DataType.NUMBER)
101
99
  .withField('instrument.id', DataType.STRING)
102
100
  .withField('instrument.name', DataType.STRING)
103
101
  .withField('instrument.type', DataType.forEnum(InstrumentType, 'InstrumentType'))
@@ -118,7 +116,7 @@ module.exports = (() => {
118
116
  .withField('snapshot.basis', DataType.DECIMAL)
119
117
  .withField('snapshot.income', DataType.DECIMAL)
120
118
  .withField('snapshot.value', DataType.DECIMAL)
121
- .withField('previous', DataType.DECIMAL, true)
119
+ .withField('previous', DataType.NUMBER, true)
122
120
  .schema
123
121
  );
124
122
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.0.45",
3
+ "version": "1.0.49",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -185,7 +185,7 @@ module.exports = (() => {
185
185
  return PositionSummaryFrame;
186
186
  })();
187
187
 
188
- },{"@barchart/common-js/lang/Day":10,"@barchart/common-js/lang/Enum":13,"@barchart/common-js/lang/array":14,"@barchart/common-js/lang/assert":15,"@barchart/common-js/lang/is":16}],2:[function(require,module,exports){
188
+ },{"@barchart/common-js/lang/Day":11,"@barchart/common-js/lang/Enum":14,"@barchart/common-js/lang/array":15,"@barchart/common-js/lang/assert":16,"@barchart/common-js/lang/is":18}],2:[function(require,module,exports){
189
189
  const assert = require('@barchart/common-js/lang/assert'),
190
190
  Enum = require('@barchart/common-js/lang/Enum');
191
191
 
@@ -512,8 +512,10 @@ module.exports = (() => {
512
512
  return TransactionType;
513
513
  })();
514
514
 
515
- },{"@barchart/common-js/lang/Enum":13,"@barchart/common-js/lang/assert":15}],3:[function(require,module,exports){
515
+ },{"@barchart/common-js/lang/Enum":14,"@barchart/common-js/lang/assert":16}],3:[function(require,module,exports){
516
516
  const array = require('@barchart/common-js/lang/array'),
517
+ ComparatorBuilder = require('@barchart/common-js/collections/sorting/ComparatorBuilder'),
518
+ comparators = require('@barchart/common-js/collections/sorting/comparators'),
517
519
  assert = require('@barchart/common-js/lang/assert'),
518
520
  is = require('@barchart/common-js/lang/is'),
519
521
  Tree = require('@barchart/common-js/collections/Tree');
@@ -598,11 +600,37 @@ module.exports = (() => {
598
600
  const missingGroups = array.difference(currentDefinition.requiredGroups, populatedGroups.map(group => group.description));
599
601
 
600
602
  const empty = missingGroups.map((description) => {
601
- return new PositionGroup(description, [ ]);
603
+ return new PositionGroup([ ], description);
602
604
  });
603
605
 
604
606
  const compositeGroups = populatedGroups.concat(empty);
605
607
 
608
+ let builder;
609
+
610
+ if (currentDefinition.requiredGroups.length !== 0) {
611
+ const ordering = currentDefinition.requiredGroups.reduce((map, group, index) => {
612
+ map[group] = index;
613
+
614
+ return map;
615
+ }, { });
616
+
617
+ const getIndex = (description) => {
618
+ return ordering[description] || Math.MAX_VALUE;
619
+ };
620
+
621
+ builder = ComparatorBuilder.startWith((a, b) => {
622
+ return comparators.compareNumbers(getIndex(a.description), getIndex(b.description));
623
+ }).thenBy((a, b) => {
624
+ return comparators.compareStrings(a.description, b.description);
625
+ });
626
+ } else {
627
+ builder = ComparatorBuilder.startWith((a, b) => {
628
+ return comparators.compareStrings(a.description, b.description);
629
+ });
630
+ }
631
+
632
+ compositeGroups.sort(builder.toComparator());
633
+
606
634
  compositeGroups.forEach((group) => {
607
635
  const child = tree.addChild(group);
608
636
 
@@ -651,9 +679,11 @@ module.exports = (() => {
651
679
  return PositionContainer;
652
680
  })();
653
681
 
654
- },{"./PositionGroup":4,"./PositionGroupDefinition":5,"./PositionItem":6,"@barchart/common-js/collections/Tree":7,"@barchart/common-js/lang/array":14,"@barchart/common-js/lang/assert":15,"@barchart/common-js/lang/is":16}],4:[function(require,module,exports){
682
+ },{"./PositionGroup":4,"./PositionGroupDefinition":5,"./PositionItem":6,"@barchart/common-js/collections/Tree":7,"@barchart/common-js/collections/sorting/ComparatorBuilder":8,"@barchart/common-js/collections/sorting/comparators":9,"@barchart/common-js/lang/array":15,"@barchart/common-js/lang/assert":16,"@barchart/common-js/lang/is":18}],4:[function(require,module,exports){
655
683
  const assert = require('@barchart/common-js/lang/assert'),
684
+ Currency = require('@barchart/common-js/lang/Currency'),
656
685
  Decimal = require('@barchart/common-js/lang/Decimal'),
686
+ formatter = require('@barchart/common-js/lang/formatter'),
657
687
  is = require('@barchart/common-js/lang/is');
658
688
 
659
689
  module.exports = (() => {
@@ -669,22 +699,31 @@ module.exports = (() => {
669
699
 
670
700
  this._single = is.boolean(single) && single;
671
701
 
672
- this._data = { };
702
+ this._dataFormat = { };
703
+ this._dataRaw = { };
704
+
705
+ this._dataFormat.description = this._description;
673
706
 
674
- this._data.description = this._description;
707
+ this._dataRaw.current = null;
708
+ this._dataRaw.previous = null;
675
709
 
676
- this._data.current = null;
677
- this._data.previous = null;
710
+ this._dataFormat.current = null;
711
+ this._dataFormat.previous = null;
678
712
 
679
- this._data.basis = null;
680
- this._data.market = null;
713
+ this._dataRaw.basis = null;
714
+ this._dataRaw.market = null;
715
+
716
+ this._dataFormat.basis = null;
717
+ this._dataFormat.market = null;
681
718
 
682
719
  this._items.forEach((item) => {
683
720
  item.registerPriceChangeHandler((data, sender) => {
684
721
  if (this._single) {
685
- data.current = data.current;
722
+ this._dataRaw.current = data.current;
723
+ this._dataFormat.current = format(data.current, sender.position.instrument.currency);
686
724
  } else {
687
- data.current = null;
725
+ this._dataRaw.current = null;
726
+ this._dataFormat.current = null;
688
727
  }
689
728
 
690
729
  calculateVariablePriceData(this, item, price);
@@ -699,7 +738,7 @@ module.exports = (() => {
699
738
  }
700
739
 
701
740
  get data() {
702
- return this._data;
741
+ return this._dataFormat;
703
742
  }
704
743
 
705
744
  get items() {
@@ -715,9 +754,15 @@ module.exports = (() => {
715
754
  }
716
755
  }
717
756
 
757
+ function format(decimal, currency) {
758
+ return formatter.numberToString(decimal.toFloat(), currency.precision, ',', false);
759
+ }
760
+
718
761
  function calculateStaticData(group) {
719
762
  const items = group._items;
720
- const data = group._data;
763
+
764
+ const raw = group._dataRaw;
765
+ const formatted = group._dataFormat;
721
766
 
722
767
  let updates;
723
768
 
@@ -738,7 +783,8 @@ module.exports = (() => {
738
783
  });
739
784
  }
740
785
 
741
- data.basis = updates.basis;
786
+ raw.basis = updates.basis;
787
+ formatted.basis = format(updates.basis, Currency.USD);
742
788
  }
743
789
 
744
790
  function calculateVariablePriceData(group, item, price) {
@@ -748,7 +794,7 @@ module.exports = (() => {
748
794
  return PositionGroup;
749
795
  })();
750
796
 
751
- },{"@barchart/common-js/lang/Decimal":11,"@barchart/common-js/lang/assert":15,"@barchart/common-js/lang/is":16}],5:[function(require,module,exports){
797
+ },{"@barchart/common-js/lang/Currency":10,"@barchart/common-js/lang/Decimal":12,"@barchart/common-js/lang/assert":16,"@barchart/common-js/lang/formatter":17,"@barchart/common-js/lang/is":18}],5:[function(require,module,exports){
752
798
  const assert = require('@barchart/common-js/lang/assert'),
753
799
  is = require('@barchart/common-js/lang/is');
754
800
 
@@ -759,11 +805,12 @@ module.exports = (() => {
759
805
  * @public
760
806
  */
761
807
  class PositionGroupDefinition {
762
- constructor(name, keySelector, descriptionSelector, requiredGroups, single) {
808
+ constructor(name, keySelector, descriptionSelector, currencySelector, requiredGroups, single) {
763
809
  this._name = name;
764
810
 
765
811
  this._keySelector = keySelector;
766
812
  this._descriptionSelector = descriptionSelector;
813
+ this._currencySelector = currencySelector;
767
814
 
768
815
  this._requiredGroups = requiredGroups || [ ];
769
816
  this._single = is.boolean(single) && single;
@@ -781,6 +828,10 @@ module.exports = (() => {
781
828
  return this._descriptionSelector;
782
829
  }
783
830
 
831
+ get currencySelector() {
832
+ return this._currencySelector;
833
+ }
834
+
784
835
  get requiredGroups() {
785
836
  return this._requiredGroups;
786
837
  }
@@ -793,7 +844,7 @@ module.exports = (() => {
793
844
  return PositionGroupDefinition;
794
845
  })();
795
846
 
796
- },{"@barchart/common-js/lang/assert":15,"@barchart/common-js/lang/is":16}],6:[function(require,module,exports){
847
+ },{"@barchart/common-js/lang/assert":16,"@barchart/common-js/lang/is":18}],6:[function(require,module,exports){
797
848
  const assert = require('@barchart/common-js/lang/assert'),
798
849
  Event = require('@barchart/common-js/messaging/Event'),
799
850
  is = require('@barchart/common-js/lang/is');
@@ -854,7 +905,7 @@ module.exports = (() => {
854
905
  return PositionItem;
855
906
  })();
856
907
 
857
- },{"@barchart/common-js/lang/assert":15,"@barchart/common-js/lang/is":16,"@barchart/common-js/messaging/Event":17}],7:[function(require,module,exports){
908
+ },{"@barchart/common-js/lang/assert":16,"@barchart/common-js/lang/is":18,"@barchart/common-js/messaging/Event":19}],7:[function(require,module,exports){
858
909
  'use strict';
859
910
 
860
911
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
@@ -1163,7 +1214,7 @@ module.exports = function () {
1163
1214
  return Tree;
1164
1215
  }();
1165
1216
 
1166
- },{"./../lang/is":16}],8:[function(require,module,exports){
1217
+ },{"./../lang/is":18}],8:[function(require,module,exports){
1167
1218
  'use strict';
1168
1219
 
1169
1220
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
@@ -1307,7 +1358,7 @@ module.exports = function () {
1307
1358
  return ComparatorBuilder;
1308
1359
  }();
1309
1360
 
1310
- },{"./../../lang/assert":15,"./comparators":9}],9:[function(require,module,exports){
1361
+ },{"./../../lang/assert":16,"./comparators":9}],9:[function(require,module,exports){
1311
1362
  'use strict';
1312
1363
 
1313
1364
  var assert = require('./../../lang/assert');
@@ -1382,7 +1433,150 @@ module.exports = function () {
1382
1433
  };
1383
1434
  }();
1384
1435
 
1385
- },{"./../../lang/assert":15}],10:[function(require,module,exports){
1436
+ },{"./../../lang/assert":16}],10:[function(require,module,exports){
1437
+ 'use strict';
1438
+
1439
+ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
1440
+
1441
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1442
+
1443
+ function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
1444
+
1445
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
1446
+
1447
+ var assert = require('./assert'),
1448
+ Enum = require('./Enum'),
1449
+ is = require('./is');
1450
+
1451
+ module.exports = function () {
1452
+ 'use strict';
1453
+
1454
+ /**
1455
+ * An enumeration for currency types.
1456
+ *
1457
+ * @public
1458
+ * @param {String} code - Currency code (e.g. "USD")
1459
+ * @param {String} description - The description (e.g. "US Dollar")
1460
+ * @param {Number} precision - The number of decimal places possible for by a real world transaction.
1461
+ * @extends {Enum}
1462
+ */
1463
+
1464
+ var Currency = function (_Enum) {
1465
+ _inherits(Currency, _Enum);
1466
+
1467
+ function Currency(code, description, precision, alternateDescription) {
1468
+ _classCallCheck(this, Currency);
1469
+
1470
+ var _this = _possibleConstructorReturn(this, (Currency.__proto__ || Object.getPrototypeOf(Currency)).call(this, code, description));
1471
+
1472
+ assert.argumentIsRequired(precision, 'precision', Number);
1473
+ assert.argumentIsValid(precision, 'precision', is.integer, 'is an integer');
1474
+
1475
+ assert.argumentIsOptional(alternateDescription, 'alternateDescription', String);
1476
+
1477
+ _this._precision = precision;
1478
+
1479
+ _this._alternateDescription = alternateDescription || description;
1480
+ return _this;
1481
+ }
1482
+
1483
+ /**
1484
+ * The maximum number of decimal places supported by a real world transaction.
1485
+ *
1486
+ * @public
1487
+ * @returns {Number}
1488
+ */
1489
+
1490
+
1491
+ _createClass(Currency, [{
1492
+ key: 'toString',
1493
+ value: function toString() {
1494
+ return '[Currency (code=' + this.code + ')]';
1495
+ }
1496
+ }, {
1497
+ key: 'precision',
1498
+ get: function get() {
1499
+ return this._precision;
1500
+ }
1501
+
1502
+ /**
1503
+ * An alternate human-readable description.
1504
+ *
1505
+ * @public
1506
+ * @returns {String}
1507
+ */
1508
+
1509
+ }, {
1510
+ key: 'alternateDescription',
1511
+ get: function get() {
1512
+ return this._alternateDescription;
1513
+ }
1514
+
1515
+ /**
1516
+ * Given a code, returns the enumeration item.
1517
+ *
1518
+ * @public
1519
+ * @param {String} code
1520
+ * @returns {Currency|null}
1521
+ */
1522
+
1523
+ }], [{
1524
+ key: 'parse',
1525
+ value: function parse(code) {
1526
+ return Enum.fromCode(Currency, code);
1527
+ }
1528
+
1529
+ /**
1530
+ * The Canadian Dollar.
1531
+ *
1532
+ * @public
1533
+ * @returns {Currency}
1534
+ */
1535
+
1536
+ }, {
1537
+ key: 'CAD',
1538
+ get: function get() {
1539
+ return cad;
1540
+ }
1541
+
1542
+ /**
1543
+ * The Euro.
1544
+ *
1545
+ * @public
1546
+ * @returns {Currency}
1547
+ */
1548
+
1549
+ }, {
1550
+ key: 'EUR',
1551
+ get: function get() {
1552
+ return eur;
1553
+ }
1554
+
1555
+ /**
1556
+ * The US Dollar.
1557
+ *
1558
+ * @public
1559
+ * @returns {Currency}
1560
+ */
1561
+
1562
+ }, {
1563
+ key: 'USD',
1564
+ get: function get() {
1565
+ return usd;
1566
+ }
1567
+ }]);
1568
+
1569
+ return Currency;
1570
+ }(Enum);
1571
+
1572
+ var cad = new Currency('CAD', 'Canadian Dollar', 2, 'CAD$');
1573
+ var eur = new Currency('EUR', 'Euro', 2, 'EUR');
1574
+ var usd = new Currency('USD', 'US Dollar', 2, 'US$');
1575
+
1576
+ return Currency;
1577
+ }();
1578
+
1579
+ },{"./Enum":14,"./assert":16,"./is":18}],11:[function(require,module,exports){
1386
1580
  'use strict';
1387
1581
 
1388
1582
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
@@ -1935,7 +2129,7 @@ module.exports = function () {
1935
2129
  return Day;
1936
2130
  }();
1937
2131
 
1938
- },{"./../collections/sorting/ComparatorBuilder":8,"./../collections/sorting/comparators":9,"./assert":15,"./is":16}],11:[function(require,module,exports){
2132
+ },{"./../collections/sorting/ComparatorBuilder":8,"./../collections/sorting/comparators":9,"./assert":16,"./is":18}],12:[function(require,module,exports){
1939
2133
  'use strict';
1940
2134
 
1941
2135
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
@@ -2515,7 +2709,7 @@ module.exports = function () {
2515
2709
  return Decimal;
2516
2710
  }();
2517
2711
 
2518
- },{"./Enum":13,"./assert":15,"./is":16,"big.js":18}],12:[function(require,module,exports){
2712
+ },{"./Enum":14,"./assert":16,"./is":18,"big.js":20}],13:[function(require,module,exports){
2519
2713
  'use strict';
2520
2714
 
2521
2715
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
@@ -2664,7 +2858,7 @@ module.exports = function () {
2664
2858
  return Disposable;
2665
2859
  }();
2666
2860
 
2667
- },{"./assert":15}],13:[function(require,module,exports){
2861
+ },{"./assert":16}],14:[function(require,module,exports){
2668
2862
  'use strict';
2669
2863
 
2670
2864
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
@@ -2806,7 +3000,7 @@ module.exports = function () {
2806
3000
  return Enum;
2807
3001
  }();
2808
3002
 
2809
- },{"./assert":15}],14:[function(require,module,exports){
3003
+ },{"./assert":16}],15:[function(require,module,exports){
2810
3004
  'use strict';
2811
3005
 
2812
3006
  var assert = require('./assert'),
@@ -3187,7 +3381,7 @@ module.exports = function () {
3187
3381
  };
3188
3382
  }();
3189
3383
 
3190
- },{"./assert":15,"./is":16}],15:[function(require,module,exports){
3384
+ },{"./assert":16,"./is":18}],16:[function(require,module,exports){
3191
3385
  'use strict';
3192
3386
 
3193
3387
  var is = require('./is');
@@ -3335,7 +3529,72 @@ module.exports = function () {
3335
3529
  };
3336
3530
  }();
3337
3531
 
3338
- },{"./is":16}],16:[function(require,module,exports){
3532
+ },{"./is":18}],17:[function(require,module,exports){
3533
+ 'use strict';
3534
+
3535
+ module.exports = function () {
3536
+ 'use strict';
3537
+
3538
+ return {
3539
+ /**
3540
+ * Formats a number into a string for display purposes.
3541
+ */
3542
+ numberToString: function numberToString(value, digits, thousandsSeparator, useParenthesis) {
3543
+ if (value === '' || value === undefined || value === null || isNaN(value)) {
3544
+ return '';
3545
+ }
3546
+
3547
+ var applyParenthesis = value < 0 && useParenthesis === true;
3548
+
3549
+ if (applyParenthesis) {
3550
+ value = 0 - value;
3551
+ }
3552
+
3553
+ var returnRef = value.toFixed(digits);
3554
+
3555
+ if (thousandsSeparator && !(value > -1000 && value < 1000)) {
3556
+ var length = returnRef.length;
3557
+ var negative = value < 0;
3558
+
3559
+ var found = digits === 0;
3560
+ var counter = 0;
3561
+
3562
+ var buffer = [];
3563
+
3564
+ for (var i = length - 1; !(i < 0); i--) {
3565
+ if (counter === 3 && !(negative && i === 0)) {
3566
+ buffer.unshift(thousandsSeparator);
3567
+
3568
+ counter = 0;
3569
+ }
3570
+
3571
+ var character = returnRef.charAt(i);
3572
+
3573
+ buffer.unshift(character);
3574
+
3575
+ if (found) {
3576
+ counter = counter + 1;
3577
+ } else if (character === '.') {
3578
+ found = true;
3579
+ }
3580
+ }
3581
+
3582
+ if (applyParenthesis) {
3583
+ buffer.unshift('(');
3584
+ buffer.push(')');
3585
+ }
3586
+
3587
+ returnRef = buffer.join('');
3588
+ } else if (applyParenthesis) {
3589
+ returnRef = '(' + returnRef + ')';
3590
+ }
3591
+
3592
+ return returnRef;
3593
+ }
3594
+ };
3595
+ }();
3596
+
3597
+ },{}],18:[function(require,module,exports){
3339
3598
  'use strict';
3340
3599
 
3341
3600
  var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
@@ -3558,7 +3817,7 @@ module.exports = function () {
3558
3817
  };
3559
3818
  }();
3560
3819
 
3561
- },{}],17:[function(require,module,exports){
3820
+ },{}],19:[function(require,module,exports){
3562
3821
  'use strict';
3563
3822
 
3564
3823
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
@@ -3730,7 +3989,7 @@ module.exports = function () {
3730
3989
  return Event;
3731
3990
  }();
3732
3991
 
3733
- },{"./../lang/Disposable":12,"./../lang/assert":15}],18:[function(require,module,exports){
3992
+ },{"./../lang/Disposable":13,"./../lang/assert":16}],20:[function(require,module,exports){
3734
3993
  /*
3735
3994
  * big.js v5.0.3
3736
3995
  * A small, fast, easy-to-use library for arbitrary-precision decimal arithmetic.
@@ -4671,7 +4930,7 @@ module.exports = function () {
4671
4930
  }
4672
4931
  })(this);
4673
4932
 
4674
- },{}],19:[function(require,module,exports){
4933
+ },{}],21:[function(require,module,exports){
4675
4934
  const Day = require('@barchart/common-js/lang/Day'),
4676
4935
  Decimal = require('@barchart/common-js/lang/Decimal');
4677
4936
 
@@ -5028,8 +5287,9 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
5028
5287
  });
5029
5288
  });
5030
5289
 
5031
- },{"./../../../lib/data/PositionSummaryFrame":1,"./../../../lib/data/TransactionType":2,"@barchart/common-js/lang/Day":10,"@barchart/common-js/lang/Decimal":11}],20:[function(require,module,exports){
5032
- const Decimal = require('@barchart/common-js/lang/Decimal');
5290
+ },{"./../../../lib/data/PositionSummaryFrame":1,"./../../../lib/data/TransactionType":2,"@barchart/common-js/lang/Day":11,"@barchart/common-js/lang/Decimal":12}],22:[function(require,module,exports){
5291
+ const Currency = require('@barchart/common-js/lang/Currency'),
5292
+ Decimal = require('@barchart/common-js/lang/Decimal');
5033
5293
 
5034
5294
  const PositionContainer = require('./../../../lib/processing/PositionContainer'),
5035
5295
  PositionGroupDefinition = require('./../../../lib/processing/PositionGroupDefinition');
@@ -5039,13 +5299,14 @@ describe('When a position container data is gathered', () => {
5039
5299
 
5040
5300
  let positionCounter = 0;
5041
5301
 
5042
- function getPosition(portfolio, symbol) {
5302
+ function getPosition(portfolio, symbol, currency) {
5043
5303
  return {
5044
5304
  portfolio: portfolio,
5045
5305
  position: (positionCounter++).toString(),
5046
5306
  instrument: {
5047
5307
  symbol: {
5048
- barchart: symbol
5308
+ barchart: symbol,
5309
+ currency: currency || Currency.USD
5049
5310
  }
5050
5311
  },
5051
5312
  snapshot: {
@@ -5085,9 +5346,9 @@ describe('When a position container data is gathered', () => {
5085
5346
 
5086
5347
  beforeEach(() => {
5087
5348
  definitions = [
5088
- new PositionGroupDefinition('Total', x => true, x => 'Total'),
5089
- new PositionGroupDefinition('Portfolio', x => x.portfolio.portfolio, x => x.portfolio.name),
5090
- new PositionGroupDefinition('Position', x => x.position.position, x => x.position.instrument.symbol.barchart)
5349
+ new PositionGroupDefinition('Total', x => true, x => 'Total', x => Currency.CAD),
5350
+ new PositionGroupDefinition('Portfolio', x => x.portfolio.portfolio, x => x.portfolio.name, x => Currency.CAD),
5351
+ new PositionGroupDefinition('Position', x => x.position.position, x => x.position.instrument.symbol.barchart, x => x.position.instrument.currency)
5091
5352
  ];
5092
5353
 
5093
5354
  try {
@@ -5124,4 +5385,4 @@ describe('When a position container data is gathered', () => {
5124
5385
  });
5125
5386
  });
5126
5387
 
5127
- },{"./../../../lib/processing/PositionContainer":3,"./../../../lib/processing/PositionGroupDefinition":5,"@barchart/common-js/lang/Decimal":11}]},{},[19,20]);
5388
+ },{"./../../../lib/processing/PositionContainer":3,"./../../../lib/processing/PositionGroupDefinition":5,"@barchart/common-js/lang/Currency":10,"@barchart/common-js/lang/Decimal":12}]},{},[21,22]);
@@ -1,4 +1,5 @@
1
- const Decimal = require('@barchart/common-js/lang/Decimal');
1
+ const Currency = require('@barchart/common-js/lang/Currency'),
2
+ Decimal = require('@barchart/common-js/lang/Decimal');
2
3
 
3
4
  const PositionContainer = require('./../../../lib/processing/PositionContainer'),
4
5
  PositionGroupDefinition = require('./../../../lib/processing/PositionGroupDefinition');
@@ -8,13 +9,14 @@ describe('When a position container data is gathered', () => {
8
9
 
9
10
  let positionCounter = 0;
10
11
 
11
- function getPosition(portfolio, symbol) {
12
+ function getPosition(portfolio, symbol, currency) {
12
13
  return {
13
14
  portfolio: portfolio,
14
15
  position: (positionCounter++).toString(),
15
16
  instrument: {
16
17
  symbol: {
17
- barchart: symbol
18
+ barchart: symbol,
19
+ currency: currency || Currency.USD
18
20
  }
19
21
  },
20
22
  snapshot: {
@@ -54,9 +56,9 @@ describe('When a position container data is gathered', () => {
54
56
 
55
57
  beforeEach(() => {
56
58
  definitions = [
57
- new PositionGroupDefinition('Total', x => true, x => 'Total'),
58
- new PositionGroupDefinition('Portfolio', x => x.portfolio.portfolio, x => x.portfolio.name),
59
- new PositionGroupDefinition('Position', x => x.position.position, x => x.position.instrument.symbol.barchart)
59
+ new PositionGroupDefinition('Total', x => true, x => 'Total', x => Currency.CAD),
60
+ new PositionGroupDefinition('Portfolio', x => x.portfolio.portfolio, x => x.portfolio.name, x => Currency.CAD),
61
+ new PositionGroupDefinition('Position', x => x.position.position, x => x.position.instrument.symbol.barchart, x => x.position.instrument.currency)
60
62
  ];
61
63
 
62
64
  try {