@barchart/portfolio-api-common 1.0.44 → 1.0.48
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.
- package/lib/formatters/TransactionFormatter.js +2 -2
- package/lib/processing/PositionContainer.js +1 -1
- package/lib/processing/PositionGroup.js +29 -11
- package/lib/processing/PositionItem.js +2 -0
- package/lib/serialization/PositionSchema.js +1 -3
- package/package.json +1 -1
- package/test/SpecRunner.js +265 -35
- package/test/specs/processing/PositionContainerSpec.js +5 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
2
2
|
is = require('@barchart/common-js/lang/is'),
|
|
3
|
-
|
|
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] =
|
|
54
|
+
formattedTransaction[key] = formatter.numberToString(formattedTransaction[key].toFloat(), precision, ',');
|
|
55
55
|
}
|
|
56
56
|
});
|
|
57
57
|
|
|
@@ -83,7 +83,7 @@ module.exports = (() => {
|
|
|
83
83
|
const missingGroups = array.difference(currentDefinition.requiredGroups, populatedGroups.map(group => group.description));
|
|
84
84
|
|
|
85
85
|
const empty = missingGroups.map((description) => {
|
|
86
|
-
return new PositionGroup(
|
|
86
|
+
return new PositionGroup([ ], description);
|
|
87
87
|
});
|
|
88
88
|
|
|
89
89
|
const compositeGroups = populatedGroups.concat(empty);
|
|
@@ -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.
|
|
20
|
+
this._dataFormat = { };
|
|
21
|
+
this._dataRaw = { };
|
|
22
|
+
|
|
23
|
+
this._dataFormat.description = this._description;
|
|
19
24
|
|
|
20
|
-
this.
|
|
25
|
+
this._dataRaw.current = null;
|
|
26
|
+
this._dataRaw.previous = null;
|
|
21
27
|
|
|
22
|
-
this.
|
|
23
|
-
this.
|
|
28
|
+
this._dataFormat.current = null;
|
|
29
|
+
this._dataFormat.previous = null;
|
|
24
30
|
|
|
25
|
-
this.
|
|
26
|
-
this.
|
|
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
|
-
|
|
40
|
+
this._dataRaw.current = data.current;
|
|
41
|
+
this._dataFormat.current = format(data.current, sender.position.instrument.currency);
|
|
32
42
|
} else {
|
|
33
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
104
|
+
raw.basis = updates.basis;
|
|
105
|
+
formatted.basis = format(updates.basis, Currency.USD);
|
|
88
106
|
}
|
|
89
107
|
|
|
90
108
|
function calculateVariablePriceData(group, item, price) {
|
|
@@ -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.
|
|
119
|
+
.withField('previous', DataType.NUMBER, true)
|
|
122
120
|
.schema
|
|
123
121
|
);
|
|
124
122
|
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -185,7 +185,7 @@ module.exports = (() => {
|
|
|
185
185
|
return PositionSummaryFrame;
|
|
186
186
|
})();
|
|
187
187
|
|
|
188
|
-
},{"@barchart/common-js/lang/Day":
|
|
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,7 +512,7 @@ module.exports = (() => {
|
|
|
512
512
|
return TransactionType;
|
|
513
513
|
})();
|
|
514
514
|
|
|
515
|
-
},{"@barchart/common-js/lang/Enum":
|
|
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
517
|
assert = require('@barchart/common-js/lang/assert'),
|
|
518
518
|
is = require('@barchart/common-js/lang/is'),
|
|
@@ -598,7 +598,7 @@ module.exports = (() => {
|
|
|
598
598
|
const missingGroups = array.difference(currentDefinition.requiredGroups, populatedGroups.map(group => group.description));
|
|
599
599
|
|
|
600
600
|
const empty = missingGroups.map((description) => {
|
|
601
|
-
return new PositionGroup(
|
|
601
|
+
return new PositionGroup([ ], description);
|
|
602
602
|
});
|
|
603
603
|
|
|
604
604
|
const compositeGroups = populatedGroups.concat(empty);
|
|
@@ -651,9 +651,11 @@ module.exports = (() => {
|
|
|
651
651
|
return PositionContainer;
|
|
652
652
|
})();
|
|
653
653
|
|
|
654
|
-
},{"./PositionGroup":4,"./PositionGroupDefinition":5,"./PositionItem":6,"@barchart/common-js/collections/Tree":7,"@barchart/common-js/lang/array":
|
|
654
|
+
},{"./PositionGroup":4,"./PositionGroupDefinition":5,"./PositionItem":6,"@barchart/common-js/collections/Tree":7,"@barchart/common-js/lang/array":15,"@barchart/common-js/lang/assert":16,"@barchart/common-js/lang/is":18}],4:[function(require,module,exports){
|
|
655
655
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
656
|
+
Currency = require('@barchart/common-js/lang/Currency'),
|
|
656
657
|
Decimal = require('@barchart/common-js/lang/Decimal'),
|
|
658
|
+
formatter = require('@barchart/common-js/lang/formatter'),
|
|
657
659
|
is = require('@barchart/common-js/lang/is');
|
|
658
660
|
|
|
659
661
|
module.exports = (() => {
|
|
@@ -669,22 +671,31 @@ module.exports = (() => {
|
|
|
669
671
|
|
|
670
672
|
this._single = is.boolean(single) && single;
|
|
671
673
|
|
|
672
|
-
this.
|
|
674
|
+
this._dataFormat = { };
|
|
675
|
+
this._dataRaw = { };
|
|
676
|
+
|
|
677
|
+
this._dataFormat.description = this._description;
|
|
673
678
|
|
|
674
|
-
this.
|
|
679
|
+
this._dataRaw.current = null;
|
|
680
|
+
this._dataRaw.previous = null;
|
|
675
681
|
|
|
676
|
-
this.
|
|
677
|
-
this.
|
|
682
|
+
this._dataFormat.current = null;
|
|
683
|
+
this._dataFormat.previous = null;
|
|
684
|
+
|
|
685
|
+
this._dataRaw.basis = null;
|
|
686
|
+
this._dataRaw.market = null;
|
|
678
687
|
|
|
679
|
-
this.
|
|
680
|
-
this.
|
|
688
|
+
this._dataFormat.basis = null;
|
|
689
|
+
this._dataFormat.market = null;
|
|
681
690
|
|
|
682
691
|
this._items.forEach((item) => {
|
|
683
692
|
item.registerPriceChangeHandler((data, sender) => {
|
|
684
693
|
if (this._single) {
|
|
685
|
-
|
|
694
|
+
this._dataRaw.current = data.current;
|
|
695
|
+
this._dataFormat.current = format(data.current, sender.position.instrument.currency);
|
|
686
696
|
} else {
|
|
687
|
-
|
|
697
|
+
this._dataRaw.current = null;
|
|
698
|
+
this._dataFormat.current = null;
|
|
688
699
|
}
|
|
689
700
|
|
|
690
701
|
calculateVariablePriceData(this, item, price);
|
|
@@ -699,7 +710,7 @@ module.exports = (() => {
|
|
|
699
710
|
}
|
|
700
711
|
|
|
701
712
|
get data() {
|
|
702
|
-
return this.
|
|
713
|
+
return this._dataFormat;
|
|
703
714
|
}
|
|
704
715
|
|
|
705
716
|
get items() {
|
|
@@ -715,9 +726,15 @@ module.exports = (() => {
|
|
|
715
726
|
}
|
|
716
727
|
}
|
|
717
728
|
|
|
729
|
+
function format(decimal, currency) {
|
|
730
|
+
return formatter.numberToString(decimal.toFloat(), currency.precision, ',', false);
|
|
731
|
+
}
|
|
732
|
+
|
|
718
733
|
function calculateStaticData(group) {
|
|
719
734
|
const items = group._items;
|
|
720
|
-
|
|
735
|
+
|
|
736
|
+
const raw = group._dataRaw;
|
|
737
|
+
const formatted = group._dataFormat;
|
|
721
738
|
|
|
722
739
|
let updates;
|
|
723
740
|
|
|
@@ -738,7 +755,8 @@ module.exports = (() => {
|
|
|
738
755
|
});
|
|
739
756
|
}
|
|
740
757
|
|
|
741
|
-
|
|
758
|
+
raw.basis = updates.basis;
|
|
759
|
+
formatted.basis = format(updates.basis, Currency.USD);
|
|
742
760
|
}
|
|
743
761
|
|
|
744
762
|
function calculateVariablePriceData(group, item, price) {
|
|
@@ -748,7 +766,7 @@ module.exports = (() => {
|
|
|
748
766
|
return PositionGroup;
|
|
749
767
|
})();
|
|
750
768
|
|
|
751
|
-
},{"@barchart/common-js/lang/Decimal":
|
|
769
|
+
},{"@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
770
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
753
771
|
is = require('@barchart/common-js/lang/is');
|
|
754
772
|
|
|
@@ -793,7 +811,7 @@ module.exports = (() => {
|
|
|
793
811
|
return PositionGroupDefinition;
|
|
794
812
|
})();
|
|
795
813
|
|
|
796
|
-
},{"@barchart/common-js/lang/assert":
|
|
814
|
+
},{"@barchart/common-js/lang/assert":16,"@barchart/common-js/lang/is":18}],6:[function(require,module,exports){
|
|
797
815
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
798
816
|
Event = require('@barchart/common-js/messaging/Event'),
|
|
799
817
|
is = require('@barchart/common-js/lang/is');
|
|
@@ -815,6 +833,8 @@ module.exports = (() => {
|
|
|
815
833
|
this._data.current = null;
|
|
816
834
|
this._data.previous = position.previous || null;
|
|
817
835
|
|
|
836
|
+
const snapshot = this._position.snapshot;
|
|
837
|
+
|
|
818
838
|
this._priceChangeEvent = new Event(this);
|
|
819
839
|
}
|
|
820
840
|
|
|
@@ -852,7 +872,7 @@ module.exports = (() => {
|
|
|
852
872
|
return PositionItem;
|
|
853
873
|
})();
|
|
854
874
|
|
|
855
|
-
},{"@barchart/common-js/lang/assert":
|
|
875
|
+
},{"@barchart/common-js/lang/assert":16,"@barchart/common-js/lang/is":18,"@barchart/common-js/messaging/Event":19}],7:[function(require,module,exports){
|
|
856
876
|
'use strict';
|
|
857
877
|
|
|
858
878
|
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; }; }();
|
|
@@ -1161,7 +1181,7 @@ module.exports = function () {
|
|
|
1161
1181
|
return Tree;
|
|
1162
1182
|
}();
|
|
1163
1183
|
|
|
1164
|
-
},{"./../lang/is":
|
|
1184
|
+
},{"./../lang/is":18}],8:[function(require,module,exports){
|
|
1165
1185
|
'use strict';
|
|
1166
1186
|
|
|
1167
1187
|
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; }; }();
|
|
@@ -1305,7 +1325,7 @@ module.exports = function () {
|
|
|
1305
1325
|
return ComparatorBuilder;
|
|
1306
1326
|
}();
|
|
1307
1327
|
|
|
1308
|
-
},{"./../../lang/assert":
|
|
1328
|
+
},{"./../../lang/assert":16,"./comparators":9}],9:[function(require,module,exports){
|
|
1309
1329
|
'use strict';
|
|
1310
1330
|
|
|
1311
1331
|
var assert = require('./../../lang/assert');
|
|
@@ -1380,7 +1400,150 @@ module.exports = function () {
|
|
|
1380
1400
|
};
|
|
1381
1401
|
}();
|
|
1382
1402
|
|
|
1383
|
-
},{"./../../lang/assert":
|
|
1403
|
+
},{"./../../lang/assert":16}],10:[function(require,module,exports){
|
|
1404
|
+
'use strict';
|
|
1405
|
+
|
|
1406
|
+
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; }; }();
|
|
1407
|
+
|
|
1408
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
1409
|
+
|
|
1410
|
+
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; }
|
|
1411
|
+
|
|
1412
|
+
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; }
|
|
1413
|
+
|
|
1414
|
+
var assert = require('./assert'),
|
|
1415
|
+
Enum = require('./Enum'),
|
|
1416
|
+
is = require('./is');
|
|
1417
|
+
|
|
1418
|
+
module.exports = function () {
|
|
1419
|
+
'use strict';
|
|
1420
|
+
|
|
1421
|
+
/**
|
|
1422
|
+
* An enumeration for currency types.
|
|
1423
|
+
*
|
|
1424
|
+
* @public
|
|
1425
|
+
* @param {String} code - Currency code (e.g. "USD")
|
|
1426
|
+
* @param {String} description - The description (e.g. "US Dollar")
|
|
1427
|
+
* @param {Number} precision - The number of decimal places possible for by a real world transaction.
|
|
1428
|
+
* @extends {Enum}
|
|
1429
|
+
*/
|
|
1430
|
+
|
|
1431
|
+
var Currency = function (_Enum) {
|
|
1432
|
+
_inherits(Currency, _Enum);
|
|
1433
|
+
|
|
1434
|
+
function Currency(code, description, precision, alternateDescription) {
|
|
1435
|
+
_classCallCheck(this, Currency);
|
|
1436
|
+
|
|
1437
|
+
var _this = _possibleConstructorReturn(this, (Currency.__proto__ || Object.getPrototypeOf(Currency)).call(this, code, description));
|
|
1438
|
+
|
|
1439
|
+
assert.argumentIsRequired(precision, 'precision', Number);
|
|
1440
|
+
assert.argumentIsValid(precision, 'precision', is.integer, 'is an integer');
|
|
1441
|
+
|
|
1442
|
+
assert.argumentIsOptional(alternateDescription, 'alternateDescription', String);
|
|
1443
|
+
|
|
1444
|
+
_this._precision = precision;
|
|
1445
|
+
|
|
1446
|
+
_this._alternateDescription = alternateDescription || description;
|
|
1447
|
+
return _this;
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1450
|
+
/**
|
|
1451
|
+
* The maximum number of decimal places supported by a real world transaction.
|
|
1452
|
+
*
|
|
1453
|
+
* @public
|
|
1454
|
+
* @returns {Number}
|
|
1455
|
+
*/
|
|
1456
|
+
|
|
1457
|
+
|
|
1458
|
+
_createClass(Currency, [{
|
|
1459
|
+
key: 'toString',
|
|
1460
|
+
value: function toString() {
|
|
1461
|
+
return '[Currency (code=' + this.code + ')]';
|
|
1462
|
+
}
|
|
1463
|
+
}, {
|
|
1464
|
+
key: 'precision',
|
|
1465
|
+
get: function get() {
|
|
1466
|
+
return this._precision;
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1469
|
+
/**
|
|
1470
|
+
* An alternate human-readable description.
|
|
1471
|
+
*
|
|
1472
|
+
* @public
|
|
1473
|
+
* @returns {String}
|
|
1474
|
+
*/
|
|
1475
|
+
|
|
1476
|
+
}, {
|
|
1477
|
+
key: 'alternateDescription',
|
|
1478
|
+
get: function get() {
|
|
1479
|
+
return this._alternateDescription;
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
/**
|
|
1483
|
+
* Given a code, returns the enumeration item.
|
|
1484
|
+
*
|
|
1485
|
+
* @public
|
|
1486
|
+
* @param {String} code
|
|
1487
|
+
* @returns {Currency|null}
|
|
1488
|
+
*/
|
|
1489
|
+
|
|
1490
|
+
}], [{
|
|
1491
|
+
key: 'parse',
|
|
1492
|
+
value: function parse(code) {
|
|
1493
|
+
return Enum.fromCode(Currency, code);
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
/**
|
|
1497
|
+
* The Canadian Dollar.
|
|
1498
|
+
*
|
|
1499
|
+
* @public
|
|
1500
|
+
* @returns {Currency}
|
|
1501
|
+
*/
|
|
1502
|
+
|
|
1503
|
+
}, {
|
|
1504
|
+
key: 'CAD',
|
|
1505
|
+
get: function get() {
|
|
1506
|
+
return cad;
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
/**
|
|
1510
|
+
* The Euro.
|
|
1511
|
+
*
|
|
1512
|
+
* @public
|
|
1513
|
+
* @returns {Currency}
|
|
1514
|
+
*/
|
|
1515
|
+
|
|
1516
|
+
}, {
|
|
1517
|
+
key: 'EUR',
|
|
1518
|
+
get: function get() {
|
|
1519
|
+
return eur;
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
/**
|
|
1523
|
+
* The US Dollar.
|
|
1524
|
+
*
|
|
1525
|
+
* @public
|
|
1526
|
+
* @returns {Currency}
|
|
1527
|
+
*/
|
|
1528
|
+
|
|
1529
|
+
}, {
|
|
1530
|
+
key: 'USD',
|
|
1531
|
+
get: function get() {
|
|
1532
|
+
return usd;
|
|
1533
|
+
}
|
|
1534
|
+
}]);
|
|
1535
|
+
|
|
1536
|
+
return Currency;
|
|
1537
|
+
}(Enum);
|
|
1538
|
+
|
|
1539
|
+
var cad = new Currency('CAD', 'Canadian Dollar', 2, 'CAD$');
|
|
1540
|
+
var eur = new Currency('EUR', 'Euro', 2, 'EUR');
|
|
1541
|
+
var usd = new Currency('USD', 'US Dollar', 2, 'US$');
|
|
1542
|
+
|
|
1543
|
+
return Currency;
|
|
1544
|
+
}();
|
|
1545
|
+
|
|
1546
|
+
},{"./Enum":14,"./assert":16,"./is":18}],11:[function(require,module,exports){
|
|
1384
1547
|
'use strict';
|
|
1385
1548
|
|
|
1386
1549
|
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; }; }();
|
|
@@ -1933,7 +2096,7 @@ module.exports = function () {
|
|
|
1933
2096
|
return Day;
|
|
1934
2097
|
}();
|
|
1935
2098
|
|
|
1936
|
-
},{"./../collections/sorting/ComparatorBuilder":8,"./../collections/sorting/comparators":9,"./assert":
|
|
2099
|
+
},{"./../collections/sorting/ComparatorBuilder":8,"./../collections/sorting/comparators":9,"./assert":16,"./is":18}],12:[function(require,module,exports){
|
|
1937
2100
|
'use strict';
|
|
1938
2101
|
|
|
1939
2102
|
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; }; }();
|
|
@@ -2513,7 +2676,7 @@ module.exports = function () {
|
|
|
2513
2676
|
return Decimal;
|
|
2514
2677
|
}();
|
|
2515
2678
|
|
|
2516
|
-
},{"./Enum":
|
|
2679
|
+
},{"./Enum":14,"./assert":16,"./is":18,"big.js":20}],13:[function(require,module,exports){
|
|
2517
2680
|
'use strict';
|
|
2518
2681
|
|
|
2519
2682
|
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; }; }();
|
|
@@ -2662,7 +2825,7 @@ module.exports = function () {
|
|
|
2662
2825
|
return Disposable;
|
|
2663
2826
|
}();
|
|
2664
2827
|
|
|
2665
|
-
},{"./assert":
|
|
2828
|
+
},{"./assert":16}],14:[function(require,module,exports){
|
|
2666
2829
|
'use strict';
|
|
2667
2830
|
|
|
2668
2831
|
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; }; }();
|
|
@@ -2804,7 +2967,7 @@ module.exports = function () {
|
|
|
2804
2967
|
return Enum;
|
|
2805
2968
|
}();
|
|
2806
2969
|
|
|
2807
|
-
},{"./assert":
|
|
2970
|
+
},{"./assert":16}],15:[function(require,module,exports){
|
|
2808
2971
|
'use strict';
|
|
2809
2972
|
|
|
2810
2973
|
var assert = require('./assert'),
|
|
@@ -3185,7 +3348,7 @@ module.exports = function () {
|
|
|
3185
3348
|
};
|
|
3186
3349
|
}();
|
|
3187
3350
|
|
|
3188
|
-
},{"./assert":
|
|
3351
|
+
},{"./assert":16,"./is":18}],16:[function(require,module,exports){
|
|
3189
3352
|
'use strict';
|
|
3190
3353
|
|
|
3191
3354
|
var is = require('./is');
|
|
@@ -3333,7 +3496,72 @@ module.exports = function () {
|
|
|
3333
3496
|
};
|
|
3334
3497
|
}();
|
|
3335
3498
|
|
|
3336
|
-
},{"./is":
|
|
3499
|
+
},{"./is":18}],17:[function(require,module,exports){
|
|
3500
|
+
'use strict';
|
|
3501
|
+
|
|
3502
|
+
module.exports = function () {
|
|
3503
|
+
'use strict';
|
|
3504
|
+
|
|
3505
|
+
return {
|
|
3506
|
+
/**
|
|
3507
|
+
* Formats a number into a string for display purposes.
|
|
3508
|
+
*/
|
|
3509
|
+
numberToString: function numberToString(value, digits, thousandsSeparator, useParenthesis) {
|
|
3510
|
+
if (value === '' || value === undefined || value === null || isNaN(value)) {
|
|
3511
|
+
return '';
|
|
3512
|
+
}
|
|
3513
|
+
|
|
3514
|
+
var applyParenthesis = value < 0 && useParenthesis === true;
|
|
3515
|
+
|
|
3516
|
+
if (applyParenthesis) {
|
|
3517
|
+
value = 0 - value;
|
|
3518
|
+
}
|
|
3519
|
+
|
|
3520
|
+
var returnRef = value.toFixed(digits);
|
|
3521
|
+
|
|
3522
|
+
if (thousandsSeparator && !(value > -1000 && value < 1000)) {
|
|
3523
|
+
var length = returnRef.length;
|
|
3524
|
+
var negative = value < 0;
|
|
3525
|
+
|
|
3526
|
+
var found = digits === 0;
|
|
3527
|
+
var counter = 0;
|
|
3528
|
+
|
|
3529
|
+
var buffer = [];
|
|
3530
|
+
|
|
3531
|
+
for (var i = length - 1; !(i < 0); i--) {
|
|
3532
|
+
if (counter === 3 && !(negative && i === 0)) {
|
|
3533
|
+
buffer.unshift(thousandsSeparator);
|
|
3534
|
+
|
|
3535
|
+
counter = 0;
|
|
3536
|
+
}
|
|
3537
|
+
|
|
3538
|
+
var character = returnRef.charAt(i);
|
|
3539
|
+
|
|
3540
|
+
buffer.unshift(character);
|
|
3541
|
+
|
|
3542
|
+
if (found) {
|
|
3543
|
+
counter = counter + 1;
|
|
3544
|
+
} else if (character === '.') {
|
|
3545
|
+
found = true;
|
|
3546
|
+
}
|
|
3547
|
+
}
|
|
3548
|
+
|
|
3549
|
+
if (applyParenthesis) {
|
|
3550
|
+
buffer.unshift('(');
|
|
3551
|
+
buffer.push(')');
|
|
3552
|
+
}
|
|
3553
|
+
|
|
3554
|
+
returnRef = buffer.join('');
|
|
3555
|
+
} else if (applyParenthesis) {
|
|
3556
|
+
returnRef = '(' + returnRef + ')';
|
|
3557
|
+
}
|
|
3558
|
+
|
|
3559
|
+
return returnRef;
|
|
3560
|
+
}
|
|
3561
|
+
};
|
|
3562
|
+
}();
|
|
3563
|
+
|
|
3564
|
+
},{}],18:[function(require,module,exports){
|
|
3337
3565
|
'use strict';
|
|
3338
3566
|
|
|
3339
3567
|
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; };
|
|
@@ -3556,7 +3784,7 @@ module.exports = function () {
|
|
|
3556
3784
|
};
|
|
3557
3785
|
}();
|
|
3558
3786
|
|
|
3559
|
-
},{}],
|
|
3787
|
+
},{}],19:[function(require,module,exports){
|
|
3560
3788
|
'use strict';
|
|
3561
3789
|
|
|
3562
3790
|
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; }; }();
|
|
@@ -3728,7 +3956,7 @@ module.exports = function () {
|
|
|
3728
3956
|
return Event;
|
|
3729
3957
|
}();
|
|
3730
3958
|
|
|
3731
|
-
},{"./../lang/Disposable":
|
|
3959
|
+
},{"./../lang/Disposable":13,"./../lang/assert":16}],20:[function(require,module,exports){
|
|
3732
3960
|
/*
|
|
3733
3961
|
* big.js v5.0.3
|
|
3734
3962
|
* A small, fast, easy-to-use library for arbitrary-precision decimal arithmetic.
|
|
@@ -4669,7 +4897,7 @@ module.exports = function () {
|
|
|
4669
4897
|
}
|
|
4670
4898
|
})(this);
|
|
4671
4899
|
|
|
4672
|
-
},{}],
|
|
4900
|
+
},{}],21:[function(require,module,exports){
|
|
4673
4901
|
const Day = require('@barchart/common-js/lang/Day'),
|
|
4674
4902
|
Decimal = require('@barchart/common-js/lang/Decimal');
|
|
4675
4903
|
|
|
@@ -5026,8 +5254,9 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
|
5026
5254
|
});
|
|
5027
5255
|
});
|
|
5028
5256
|
|
|
5029
|
-
},{"./../../../lib/data/PositionSummaryFrame":1,"./../../../lib/data/TransactionType":2,"@barchart/common-js/lang/Day":
|
|
5030
|
-
const
|
|
5257
|
+
},{"./../../../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){
|
|
5258
|
+
const Currency = require('@barchart/common-js/lang/Currency'),
|
|
5259
|
+
Decimal = require('@barchart/common-js/lang/Decimal');
|
|
5031
5260
|
|
|
5032
5261
|
const PositionContainer = require('./../../../lib/processing/PositionContainer'),
|
|
5033
5262
|
PositionGroupDefinition = require('./../../../lib/processing/PositionGroupDefinition');
|
|
@@ -5037,13 +5266,14 @@ describe('When a position container data is gathered', () => {
|
|
|
5037
5266
|
|
|
5038
5267
|
let positionCounter = 0;
|
|
5039
5268
|
|
|
5040
|
-
function getPosition(portfolio, symbol) {
|
|
5269
|
+
function getPosition(portfolio, symbol, currency) {
|
|
5041
5270
|
return {
|
|
5042
5271
|
portfolio: portfolio,
|
|
5043
5272
|
position: (positionCounter++).toString(),
|
|
5044
5273
|
instrument: {
|
|
5045
5274
|
symbol: {
|
|
5046
|
-
barchart: symbol
|
|
5275
|
+
barchart: symbol,
|
|
5276
|
+
currency: currency || Currency.USD
|
|
5047
5277
|
}
|
|
5048
5278
|
},
|
|
5049
5279
|
snapshot: {
|
|
@@ -5122,4 +5352,4 @@ describe('When a position container data is gathered', () => {
|
|
|
5122
5352
|
});
|
|
5123
5353
|
});
|
|
5124
5354
|
|
|
5125
|
-
},{"./../../../lib/processing/PositionContainer":3,"./../../../lib/processing/PositionGroupDefinition":5,"@barchart/common-js/lang/Decimal":
|
|
5355
|
+
},{"./../../../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
|
|
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: {
|