@barchart/portfolio-api-common 1.0.46 → 1.0.50

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,41 @@ 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
+ if (ordering.hasOwnProperty(description)) {
104
+ return ordering[description];
105
+ } else {
106
+ return Number.MAX_VALUE;
107
+ }
108
+ };
109
+
110
+ builder = ComparatorBuilder.startWith((a, b) => {
111
+ return comparators.compareNumbers(getIndex(a.description), getIndex(b.description));
112
+ }).thenBy((a, b) => {
113
+ return comparators.compareStrings(a.description, b.description);
114
+ });
115
+ } else {
116
+ builder = ComparatorBuilder.startWith((a, b) => {
117
+ return comparators.compareStrings(a.description, b.description);
118
+ });
119
+ }
120
+
121
+ compositeGroups.sort(builder.toComparator());
122
+
91
123
  compositeGroups.forEach((group) => {
92
124
  const child = tree.addChild(group);
93
125
 
@@ -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'))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.0.46",
3
+ "version": "1.0.50",
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,41 @@ 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
+ if (ordering.hasOwnProperty(description)) {
619
+ return ordering[description];
620
+ } else {
621
+ return Number.MAX_VALUE;
622
+ }
623
+ };
624
+
625
+ builder = ComparatorBuilder.startWith((a, b) => {
626
+ return comparators.compareNumbers(getIndex(a.description), getIndex(b.description));
627
+ }).thenBy((a, b) => {
628
+ return comparators.compareStrings(a.description, b.description);
629
+ });
630
+ } else {
631
+ builder = ComparatorBuilder.startWith((a, b) => {
632
+ return comparators.compareStrings(a.description, b.description);
633
+ });
634
+ }
635
+
636
+ compositeGroups.sort(builder.toComparator());
637
+
606
638
  compositeGroups.forEach((group) => {
607
639
  const child = tree.addChild(group);
608
640
 
@@ -651,9 +683,11 @@ module.exports = (() => {
651
683
  return PositionContainer;
652
684
  })();
653
685
 
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){
686
+ },{"./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
687
  const assert = require('@barchart/common-js/lang/assert'),
688
+ Currency = require('@barchart/common-js/lang/Currency'),
656
689
  Decimal = require('@barchart/common-js/lang/Decimal'),
690
+ formatter = require('@barchart/common-js/lang/formatter'),
657
691
  is = require('@barchart/common-js/lang/is');
658
692
 
659
693
  module.exports = (() => {
@@ -669,22 +703,31 @@ module.exports = (() => {
669
703
 
670
704
  this._single = is.boolean(single) && single;
671
705
 
672
- this._data = { };
706
+ this._dataFormat = { };
707
+ this._dataRaw = { };
708
+
709
+ this._dataFormat.description = this._description;
673
710
 
674
- this._data.description = this._description;
711
+ this._dataRaw.current = null;
712
+ this._dataRaw.previous = null;
675
713
 
676
- this._data.current = null;
677
- this._data.previous = null;
714
+ this._dataFormat.current = null;
715
+ this._dataFormat.previous = null;
678
716
 
679
- this._data.basis = null;
680
- this._data.market = null;
717
+ this._dataRaw.basis = null;
718
+ this._dataRaw.market = null;
719
+
720
+ this._dataFormat.basis = null;
721
+ this._dataFormat.market = null;
681
722
 
682
723
  this._items.forEach((item) => {
683
724
  item.registerPriceChangeHandler((data, sender) => {
684
725
  if (this._single) {
685
- data.current = data.current;
726
+ this._dataRaw.current = data.current;
727
+ this._dataFormat.current = format(data.current, sender.position.instrument.currency);
686
728
  } else {
687
- data.current = null;
729
+ this._dataRaw.current = null;
730
+ this._dataFormat.current = null;
688
731
  }
689
732
 
690
733
  calculateVariablePriceData(this, item, price);
@@ -699,7 +742,7 @@ module.exports = (() => {
699
742
  }
700
743
 
701
744
  get data() {
702
- return this._data;
745
+ return this._dataFormat;
703
746
  }
704
747
 
705
748
  get items() {
@@ -715,9 +758,15 @@ module.exports = (() => {
715
758
  }
716
759
  }
717
760
 
761
+ function format(decimal, currency) {
762
+ return formatter.numberToString(decimal.toFloat(), currency.precision, ',', false);
763
+ }
764
+
718
765
  function calculateStaticData(group) {
719
766
  const items = group._items;
720
- const data = group._data;
767
+
768
+ const raw = group._dataRaw;
769
+ const formatted = group._dataFormat;
721
770
 
722
771
  let updates;
723
772
 
@@ -738,7 +787,8 @@ module.exports = (() => {
738
787
  });
739
788
  }
740
789
 
741
- data.basis = updates.basis;
790
+ raw.basis = updates.basis;
791
+ formatted.basis = format(updates.basis, Currency.USD);
742
792
  }
743
793
 
744
794
  function calculateVariablePriceData(group, item, price) {
@@ -748,7 +798,7 @@ module.exports = (() => {
748
798
  return PositionGroup;
749
799
  })();
750
800
 
751
- },{"@barchart/common-js/lang/Decimal":11,"@barchart/common-js/lang/assert":15,"@barchart/common-js/lang/is":16}],5:[function(require,module,exports){
801
+ },{"@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
802
  const assert = require('@barchart/common-js/lang/assert'),
753
803
  is = require('@barchart/common-js/lang/is');
754
804
 
@@ -759,11 +809,12 @@ module.exports = (() => {
759
809
  * @public
760
810
  */
761
811
  class PositionGroupDefinition {
762
- constructor(name, keySelector, descriptionSelector, requiredGroups, single) {
812
+ constructor(name, keySelector, descriptionSelector, currencySelector, requiredGroups, single) {
763
813
  this._name = name;
764
814
 
765
815
  this._keySelector = keySelector;
766
816
  this._descriptionSelector = descriptionSelector;
817
+ this._currencySelector = currencySelector;
767
818
 
768
819
  this._requiredGroups = requiredGroups || [ ];
769
820
  this._single = is.boolean(single) && single;
@@ -781,6 +832,10 @@ module.exports = (() => {
781
832
  return this._descriptionSelector;
782
833
  }
783
834
 
835
+ get currencySelector() {
836
+ return this._currencySelector;
837
+ }
838
+
784
839
  get requiredGroups() {
785
840
  return this._requiredGroups;
786
841
  }
@@ -793,7 +848,7 @@ module.exports = (() => {
793
848
  return PositionGroupDefinition;
794
849
  })();
795
850
 
796
- },{"@barchart/common-js/lang/assert":15,"@barchart/common-js/lang/is":16}],6:[function(require,module,exports){
851
+ },{"@barchart/common-js/lang/assert":16,"@barchart/common-js/lang/is":18}],6:[function(require,module,exports){
797
852
  const assert = require('@barchart/common-js/lang/assert'),
798
853
  Event = require('@barchart/common-js/messaging/Event'),
799
854
  is = require('@barchart/common-js/lang/is');
@@ -854,7 +909,7 @@ module.exports = (() => {
854
909
  return PositionItem;
855
910
  })();
856
911
 
857
- },{"@barchart/common-js/lang/assert":15,"@barchart/common-js/lang/is":16,"@barchart/common-js/messaging/Event":17}],7:[function(require,module,exports){
912
+ },{"@barchart/common-js/lang/assert":16,"@barchart/common-js/lang/is":18,"@barchart/common-js/messaging/Event":19}],7:[function(require,module,exports){
858
913
  'use strict';
859
914
 
860
915
  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 +1218,7 @@ module.exports = function () {
1163
1218
  return Tree;
1164
1219
  }();
1165
1220
 
1166
- },{"./../lang/is":16}],8:[function(require,module,exports){
1221
+ },{"./../lang/is":18}],8:[function(require,module,exports){
1167
1222
  'use strict';
1168
1223
 
1169
1224
  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 +1362,7 @@ module.exports = function () {
1307
1362
  return ComparatorBuilder;
1308
1363
  }();
1309
1364
 
1310
- },{"./../../lang/assert":15,"./comparators":9}],9:[function(require,module,exports){
1365
+ },{"./../../lang/assert":16,"./comparators":9}],9:[function(require,module,exports){
1311
1366
  'use strict';
1312
1367
 
1313
1368
  var assert = require('./../../lang/assert');
@@ -1382,7 +1437,150 @@ module.exports = function () {
1382
1437
  };
1383
1438
  }();
1384
1439
 
1385
- },{"./../../lang/assert":15}],10:[function(require,module,exports){
1440
+ },{"./../../lang/assert":16}],10:[function(require,module,exports){
1441
+ 'use strict';
1442
+
1443
+ 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; }; }();
1444
+
1445
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1446
+
1447
+ 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; }
1448
+
1449
+ 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; }
1450
+
1451
+ var assert = require('./assert'),
1452
+ Enum = require('./Enum'),
1453
+ is = require('./is');
1454
+
1455
+ module.exports = function () {
1456
+ 'use strict';
1457
+
1458
+ /**
1459
+ * An enumeration for currency types.
1460
+ *
1461
+ * @public
1462
+ * @param {String} code - Currency code (e.g. "USD")
1463
+ * @param {String} description - The description (e.g. "US Dollar")
1464
+ * @param {Number} precision - The number of decimal places possible for by a real world transaction.
1465
+ * @extends {Enum}
1466
+ */
1467
+
1468
+ var Currency = function (_Enum) {
1469
+ _inherits(Currency, _Enum);
1470
+
1471
+ function Currency(code, description, precision, alternateDescription) {
1472
+ _classCallCheck(this, Currency);
1473
+
1474
+ var _this = _possibleConstructorReturn(this, (Currency.__proto__ || Object.getPrototypeOf(Currency)).call(this, code, description));
1475
+
1476
+ assert.argumentIsRequired(precision, 'precision', Number);
1477
+ assert.argumentIsValid(precision, 'precision', is.integer, 'is an integer');
1478
+
1479
+ assert.argumentIsOptional(alternateDescription, 'alternateDescription', String);
1480
+
1481
+ _this._precision = precision;
1482
+
1483
+ _this._alternateDescription = alternateDescription || description;
1484
+ return _this;
1485
+ }
1486
+
1487
+ /**
1488
+ * The maximum number of decimal places supported by a real world transaction.
1489
+ *
1490
+ * @public
1491
+ * @returns {Number}
1492
+ */
1493
+
1494
+
1495
+ _createClass(Currency, [{
1496
+ key: 'toString',
1497
+ value: function toString() {
1498
+ return '[Currency (code=' + this.code + ')]';
1499
+ }
1500
+ }, {
1501
+ key: 'precision',
1502
+ get: function get() {
1503
+ return this._precision;
1504
+ }
1505
+
1506
+ /**
1507
+ * An alternate human-readable description.
1508
+ *
1509
+ * @public
1510
+ * @returns {String}
1511
+ */
1512
+
1513
+ }, {
1514
+ key: 'alternateDescription',
1515
+ get: function get() {
1516
+ return this._alternateDescription;
1517
+ }
1518
+
1519
+ /**
1520
+ * Given a code, returns the enumeration item.
1521
+ *
1522
+ * @public
1523
+ * @param {String} code
1524
+ * @returns {Currency|null}
1525
+ */
1526
+
1527
+ }], [{
1528
+ key: 'parse',
1529
+ value: function parse(code) {
1530
+ return Enum.fromCode(Currency, code);
1531
+ }
1532
+
1533
+ /**
1534
+ * The Canadian Dollar.
1535
+ *
1536
+ * @public
1537
+ * @returns {Currency}
1538
+ */
1539
+
1540
+ }, {
1541
+ key: 'CAD',
1542
+ get: function get() {
1543
+ return cad;
1544
+ }
1545
+
1546
+ /**
1547
+ * The Euro.
1548
+ *
1549
+ * @public
1550
+ * @returns {Currency}
1551
+ */
1552
+
1553
+ }, {
1554
+ key: 'EUR',
1555
+ get: function get() {
1556
+ return eur;
1557
+ }
1558
+
1559
+ /**
1560
+ * The US Dollar.
1561
+ *
1562
+ * @public
1563
+ * @returns {Currency}
1564
+ */
1565
+
1566
+ }, {
1567
+ key: 'USD',
1568
+ get: function get() {
1569
+ return usd;
1570
+ }
1571
+ }]);
1572
+
1573
+ return Currency;
1574
+ }(Enum);
1575
+
1576
+ var cad = new Currency('CAD', 'Canadian Dollar', 2, 'CAD$');
1577
+ var eur = new Currency('EUR', 'Euro', 2, 'EUR');
1578
+ var usd = new Currency('USD', 'US Dollar', 2, 'US$');
1579
+
1580
+ return Currency;
1581
+ }();
1582
+
1583
+ },{"./Enum":14,"./assert":16,"./is":18}],11:[function(require,module,exports){
1386
1584
  'use strict';
1387
1585
 
1388
1586
  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 +2133,7 @@ module.exports = function () {
1935
2133
  return Day;
1936
2134
  }();
1937
2135
 
1938
- },{"./../collections/sorting/ComparatorBuilder":8,"./../collections/sorting/comparators":9,"./assert":15,"./is":16}],11:[function(require,module,exports){
2136
+ },{"./../collections/sorting/ComparatorBuilder":8,"./../collections/sorting/comparators":9,"./assert":16,"./is":18}],12:[function(require,module,exports){
1939
2137
  'use strict';
1940
2138
 
1941
2139
  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 +2713,7 @@ module.exports = function () {
2515
2713
  return Decimal;
2516
2714
  }();
2517
2715
 
2518
- },{"./Enum":13,"./assert":15,"./is":16,"big.js":18}],12:[function(require,module,exports){
2716
+ },{"./Enum":14,"./assert":16,"./is":18,"big.js":20}],13:[function(require,module,exports){
2519
2717
  'use strict';
2520
2718
 
2521
2719
  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 +2862,7 @@ module.exports = function () {
2664
2862
  return Disposable;
2665
2863
  }();
2666
2864
 
2667
- },{"./assert":15}],13:[function(require,module,exports){
2865
+ },{"./assert":16}],14:[function(require,module,exports){
2668
2866
  'use strict';
2669
2867
 
2670
2868
  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 +3004,7 @@ module.exports = function () {
2806
3004
  return Enum;
2807
3005
  }();
2808
3006
 
2809
- },{"./assert":15}],14:[function(require,module,exports){
3007
+ },{"./assert":16}],15:[function(require,module,exports){
2810
3008
  'use strict';
2811
3009
 
2812
3010
  var assert = require('./assert'),
@@ -3187,7 +3385,7 @@ module.exports = function () {
3187
3385
  };
3188
3386
  }();
3189
3387
 
3190
- },{"./assert":15,"./is":16}],15:[function(require,module,exports){
3388
+ },{"./assert":16,"./is":18}],16:[function(require,module,exports){
3191
3389
  'use strict';
3192
3390
 
3193
3391
  var is = require('./is');
@@ -3335,7 +3533,72 @@ module.exports = function () {
3335
3533
  };
3336
3534
  }();
3337
3535
 
3338
- },{"./is":16}],16:[function(require,module,exports){
3536
+ },{"./is":18}],17:[function(require,module,exports){
3537
+ 'use strict';
3538
+
3539
+ module.exports = function () {
3540
+ 'use strict';
3541
+
3542
+ return {
3543
+ /**
3544
+ * Formats a number into a string for display purposes.
3545
+ */
3546
+ numberToString: function numberToString(value, digits, thousandsSeparator, useParenthesis) {
3547
+ if (value === '' || value === undefined || value === null || isNaN(value)) {
3548
+ return '';
3549
+ }
3550
+
3551
+ var applyParenthesis = value < 0 && useParenthesis === true;
3552
+
3553
+ if (applyParenthesis) {
3554
+ value = 0 - value;
3555
+ }
3556
+
3557
+ var returnRef = value.toFixed(digits);
3558
+
3559
+ if (thousandsSeparator && !(value > -1000 && value < 1000)) {
3560
+ var length = returnRef.length;
3561
+ var negative = value < 0;
3562
+
3563
+ var found = digits === 0;
3564
+ var counter = 0;
3565
+
3566
+ var buffer = [];
3567
+
3568
+ for (var i = length - 1; !(i < 0); i--) {
3569
+ if (counter === 3 && !(negative && i === 0)) {
3570
+ buffer.unshift(thousandsSeparator);
3571
+
3572
+ counter = 0;
3573
+ }
3574
+
3575
+ var character = returnRef.charAt(i);
3576
+
3577
+ buffer.unshift(character);
3578
+
3579
+ if (found) {
3580
+ counter = counter + 1;
3581
+ } else if (character === '.') {
3582
+ found = true;
3583
+ }
3584
+ }
3585
+
3586
+ if (applyParenthesis) {
3587
+ buffer.unshift('(');
3588
+ buffer.push(')');
3589
+ }
3590
+
3591
+ returnRef = buffer.join('');
3592
+ } else if (applyParenthesis) {
3593
+ returnRef = '(' + returnRef + ')';
3594
+ }
3595
+
3596
+ return returnRef;
3597
+ }
3598
+ };
3599
+ }();
3600
+
3601
+ },{}],18:[function(require,module,exports){
3339
3602
  'use strict';
3340
3603
 
3341
3604
  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 +3821,7 @@ module.exports = function () {
3558
3821
  };
3559
3822
  }();
3560
3823
 
3561
- },{}],17:[function(require,module,exports){
3824
+ },{}],19:[function(require,module,exports){
3562
3825
  'use strict';
3563
3826
 
3564
3827
  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 +3993,7 @@ module.exports = function () {
3730
3993
  return Event;
3731
3994
  }();
3732
3995
 
3733
- },{"./../lang/Disposable":12,"./../lang/assert":15}],18:[function(require,module,exports){
3996
+ },{"./../lang/Disposable":13,"./../lang/assert":16}],20:[function(require,module,exports){
3734
3997
  /*
3735
3998
  * big.js v5.0.3
3736
3999
  * A small, fast, easy-to-use library for arbitrary-precision decimal arithmetic.
@@ -4671,7 +4934,7 @@ module.exports = function () {
4671
4934
  }
4672
4935
  })(this);
4673
4936
 
4674
- },{}],19:[function(require,module,exports){
4937
+ },{}],21:[function(require,module,exports){
4675
4938
  const Day = require('@barchart/common-js/lang/Day'),
4676
4939
  Decimal = require('@barchart/common-js/lang/Decimal');
4677
4940
 
@@ -5028,8 +5291,9 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
5028
5291
  });
5029
5292
  });
5030
5293
 
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');
5294
+ },{"./../../../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){
5295
+ const Currency = require('@barchart/common-js/lang/Currency'),
5296
+ Decimal = require('@barchart/common-js/lang/Decimal');
5033
5297
 
5034
5298
  const PositionContainer = require('./../../../lib/processing/PositionContainer'),
5035
5299
  PositionGroupDefinition = require('./../../../lib/processing/PositionGroupDefinition');
@@ -5039,13 +5303,14 @@ describe('When a position container data is gathered', () => {
5039
5303
 
5040
5304
  let positionCounter = 0;
5041
5305
 
5042
- function getPosition(portfolio, symbol) {
5306
+ function getPosition(portfolio, symbol, currency) {
5043
5307
  return {
5044
5308
  portfolio: portfolio,
5045
5309
  position: (positionCounter++).toString(),
5046
5310
  instrument: {
5047
5311
  symbol: {
5048
- barchart: symbol
5312
+ barchart: symbol,
5313
+ currency: currency || Currency.USD
5049
5314
  }
5050
5315
  },
5051
5316
  snapshot: {
@@ -5085,9 +5350,9 @@ describe('When a position container data is gathered', () => {
5085
5350
 
5086
5351
  beforeEach(() => {
5087
5352
  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)
5353
+ new PositionGroupDefinition('Total', x => true, x => 'Total', x => Currency.CAD),
5354
+ new PositionGroupDefinition('Portfolio', x => x.portfolio.portfolio, x => x.portfolio.name, x => Currency.CAD),
5355
+ new PositionGroupDefinition('Position', x => x.position.position, x => x.position.instrument.symbol.barchart, x => x.position.instrument.currency)
5091
5356
  ];
5092
5357
 
5093
5358
  try {
@@ -5124,4 +5389,4 @@ describe('When a position container data is gathered', () => {
5124
5389
  });
5125
5390
  });
5126
5391
 
5127
- },{"./../../../lib/processing/PositionContainer":3,"./../../../lib/processing/PositionGroupDefinition":5,"@barchart/common-js/lang/Decimal":11}]},{},[19,20]);
5392
+ },{"./../../../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 {