@barchart/portfolio-api-common 1.0.50 → 1.0.54
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,7 @@
|
|
|
1
1
|
const array = require('@barchart/common-js/lang/array'),
|
|
2
2
|
ComparatorBuilder = require('@barchart/common-js/collections/sorting/ComparatorBuilder'),
|
|
3
3
|
comparators = require('@barchart/common-js/collections/sorting/comparators'),
|
|
4
|
+
Currency = require('@barchart/common-js/lang/Currency'),
|
|
4
5
|
assert = require('@barchart/common-js/lang/assert'),
|
|
5
6
|
is = require('@barchart/common-js/lang/is'),
|
|
6
7
|
Tree = require('@barchart/common-js/collections/Tree');
|
|
@@ -51,8 +52,8 @@ module.exports = (() => {
|
|
|
51
52
|
let position = item.position;
|
|
52
53
|
let symbol = null;
|
|
53
54
|
|
|
54
|
-
if (position.instrument && position.instrument.symbol && position.instrument.barchart) {
|
|
55
|
-
symbol = position.instrument.barchart;
|
|
55
|
+
if (position.instrument && position.instrument.symbol && position.instrument.symbol.barchart) {
|
|
56
|
+
symbol = position.instrument.symbol.barchart;
|
|
56
57
|
|
|
57
58
|
if (!map.hasOwnProperty(symbol)) {
|
|
58
59
|
map[symbol] = [ ];
|
|
@@ -64,7 +65,7 @@ module.exports = (() => {
|
|
|
64
65
|
return map;
|
|
65
66
|
}, { });
|
|
66
67
|
|
|
67
|
-
this._definitions = definitions
|
|
68
|
+
this._definitions = definitions;
|
|
68
69
|
|
|
69
70
|
this._tree = new Tree();
|
|
70
71
|
|
|
@@ -79,13 +80,13 @@ module.exports = (() => {
|
|
|
79
80
|
const populatedGroups = array.batchBy(items, currentDefinition.keySelector).map((items) => {
|
|
80
81
|
const first = items[0];
|
|
81
82
|
|
|
82
|
-
return new PositionGroup(items, currentDefinition.descriptionSelector(first), currentDefinition.single && items.length === 1);
|
|
83
|
+
return new PositionGroup(items, currentDefinition.currencySelector(first), currentDefinition.descriptionSelector(first), currentDefinition.single && items.length === 1);
|
|
83
84
|
});
|
|
84
85
|
|
|
85
|
-
const missingGroups = array.difference(currentDefinition.requiredGroups, populatedGroups.map(group => group.description));
|
|
86
|
+
const missingGroups = array.difference(currentDefinition.requiredGroups.map(group => group.description), populatedGroups.map(group => group.description));
|
|
86
87
|
|
|
87
88
|
const empty = missingGroups.map((description) => {
|
|
88
|
-
return new PositionGroup([ ], description);
|
|
89
|
+
return new PositionGroup([ ], currentDefinition.requiredGroups.find(group => group.description === description).currency, description);
|
|
89
90
|
});
|
|
90
91
|
|
|
91
92
|
const compositeGroups = populatedGroups.concat(empty);
|
|
@@ -11,9 +11,11 @@ module.exports = (() => {
|
|
|
11
11
|
* @public
|
|
12
12
|
*/
|
|
13
13
|
class PositionGroup {
|
|
14
|
-
constructor(items, description, single) {
|
|
15
|
-
this._description = description;
|
|
14
|
+
constructor(items, currency, description, single) {
|
|
16
15
|
this._items = items;
|
|
16
|
+
this._currency = currency;
|
|
17
|
+
|
|
18
|
+
this._description = description;
|
|
17
19
|
|
|
18
20
|
this._single = is.boolean(single) && single;
|
|
19
21
|
|
|
@@ -44,13 +46,21 @@ module.exports = (() => {
|
|
|
44
46
|
this._dataFormat.current = null;
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
calculateVariablePriceData(this, item
|
|
49
|
+
calculateVariablePriceData(this, item);
|
|
48
50
|
});
|
|
49
51
|
});
|
|
50
52
|
|
|
51
53
|
calculateStaticData(this);
|
|
52
54
|
}
|
|
53
55
|
|
|
56
|
+
get items() {
|
|
57
|
+
return this._items;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
get currency() {
|
|
61
|
+
return this._currency;
|
|
62
|
+
}
|
|
63
|
+
|
|
54
64
|
get description() {
|
|
55
65
|
return this._description;
|
|
56
66
|
}
|
|
@@ -59,10 +69,6 @@ module.exports = (() => {
|
|
|
59
69
|
return this._dataFormat;
|
|
60
70
|
}
|
|
61
71
|
|
|
62
|
-
get items() {
|
|
63
|
-
return this._items;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
72
|
get single() {
|
|
67
73
|
return this._single;
|
|
68
74
|
}
|
|
@@ -105,7 +111,7 @@ module.exports = (() => {
|
|
|
105
111
|
formatted.basis = format(updates.basis, Currency.USD);
|
|
106
112
|
}
|
|
107
113
|
|
|
108
|
-
function calculateVariablePriceData(group, item
|
|
114
|
+
function calculateVariablePriceData(group, item) {
|
|
109
115
|
|
|
110
116
|
}
|
|
111
117
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
2
|
+
Decimal = require('@barchart/common-js/lang/Decimal'),
|
|
2
3
|
Event = require('@barchart/common-js/messaging/Event'),
|
|
3
4
|
is = require('@barchart/common-js/lang/is');
|
|
4
5
|
|
|
@@ -21,6 +22,18 @@ module.exports = (() => {
|
|
|
21
22
|
|
|
22
23
|
const snapshot = this._position.snapshot;
|
|
23
24
|
|
|
25
|
+
this._data.basis = snapshot.basis || Decimal.ZERO;
|
|
26
|
+
|
|
27
|
+
/*
|
|
28
|
+
let market;
|
|
29
|
+
|
|
30
|
+
if (position.previous) {
|
|
31
|
+
market = snapshot.open.multiply(position.previous);
|
|
32
|
+
} else {
|
|
33
|
+
market = snapshot.value;
|
|
34
|
+
}
|
|
35
|
+
*/
|
|
36
|
+
|
|
24
37
|
this._priceChangeEvent = new Event(this);
|
|
25
38
|
}
|
|
26
39
|
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -516,6 +516,7 @@ module.exports = (() => {
|
|
|
516
516
|
const array = require('@barchart/common-js/lang/array'),
|
|
517
517
|
ComparatorBuilder = require('@barchart/common-js/collections/sorting/ComparatorBuilder'),
|
|
518
518
|
comparators = require('@barchart/common-js/collections/sorting/comparators'),
|
|
519
|
+
Currency = require('@barchart/common-js/lang/Currency'),
|
|
519
520
|
assert = require('@barchart/common-js/lang/assert'),
|
|
520
521
|
is = require('@barchart/common-js/lang/is'),
|
|
521
522
|
Tree = require('@barchart/common-js/collections/Tree');
|
|
@@ -566,8 +567,8 @@ module.exports = (() => {
|
|
|
566
567
|
let position = item.position;
|
|
567
568
|
let symbol = null;
|
|
568
569
|
|
|
569
|
-
if (position.instrument && position.instrument.symbol && position.instrument.barchart) {
|
|
570
|
-
symbol = position.instrument.barchart;
|
|
570
|
+
if (position.instrument && position.instrument.symbol && position.instrument.symbol.barchart) {
|
|
571
|
+
symbol = position.instrument.symbol.barchart;
|
|
571
572
|
|
|
572
573
|
if (!map.hasOwnProperty(symbol)) {
|
|
573
574
|
map[symbol] = [ ];
|
|
@@ -579,7 +580,7 @@ module.exports = (() => {
|
|
|
579
580
|
return map;
|
|
580
581
|
}, { });
|
|
581
582
|
|
|
582
|
-
this._definitions = definitions
|
|
583
|
+
this._definitions = definitions;
|
|
583
584
|
|
|
584
585
|
this._tree = new Tree();
|
|
585
586
|
|
|
@@ -594,13 +595,13 @@ module.exports = (() => {
|
|
|
594
595
|
const populatedGroups = array.batchBy(items, currentDefinition.keySelector).map((items) => {
|
|
595
596
|
const first = items[0];
|
|
596
597
|
|
|
597
|
-
return new PositionGroup(items, currentDefinition.descriptionSelector(first), currentDefinition.single && items.length === 1);
|
|
598
|
+
return new PositionGroup(items, currentDefinition.currencySelector(first), currentDefinition.descriptionSelector(first), currentDefinition.single && items.length === 1);
|
|
598
599
|
});
|
|
599
600
|
|
|
600
|
-
const missingGroups = array.difference(currentDefinition.requiredGroups, populatedGroups.map(group => group.description));
|
|
601
|
+
const missingGroups = array.difference(currentDefinition.requiredGroups.map(group => group.description), populatedGroups.map(group => group.description));
|
|
601
602
|
|
|
602
603
|
const empty = missingGroups.map((description) => {
|
|
603
|
-
return new PositionGroup([ ], description);
|
|
604
|
+
return new PositionGroup([ ], currentDefinition.requiredGroups.find(group => group.description === description).currency, description);
|
|
604
605
|
});
|
|
605
606
|
|
|
606
607
|
const compositeGroups = populatedGroups.concat(empty);
|
|
@@ -683,7 +684,7 @@ module.exports = (() => {
|
|
|
683
684
|
return PositionContainer;
|
|
684
685
|
})();
|
|
685
686
|
|
|
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){
|
|
687
|
+
},{"./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/Currency":10,"@barchart/common-js/lang/array":15,"@barchart/common-js/lang/assert":16,"@barchart/common-js/lang/is":18}],4:[function(require,module,exports){
|
|
687
688
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
688
689
|
Currency = require('@barchart/common-js/lang/Currency'),
|
|
689
690
|
Decimal = require('@barchart/common-js/lang/Decimal'),
|
|
@@ -697,9 +698,11 @@ module.exports = (() => {
|
|
|
697
698
|
* @public
|
|
698
699
|
*/
|
|
699
700
|
class PositionGroup {
|
|
700
|
-
constructor(items, description, single) {
|
|
701
|
-
this._description = description;
|
|
701
|
+
constructor(items, currency, description, single) {
|
|
702
702
|
this._items = items;
|
|
703
|
+
this._currency = currency;
|
|
704
|
+
|
|
705
|
+
this._description = description;
|
|
703
706
|
|
|
704
707
|
this._single = is.boolean(single) && single;
|
|
705
708
|
|
|
@@ -730,13 +733,21 @@ module.exports = (() => {
|
|
|
730
733
|
this._dataFormat.current = null;
|
|
731
734
|
}
|
|
732
735
|
|
|
733
|
-
calculateVariablePriceData(this, item
|
|
736
|
+
calculateVariablePriceData(this, item);
|
|
734
737
|
});
|
|
735
738
|
});
|
|
736
739
|
|
|
737
740
|
calculateStaticData(this);
|
|
738
741
|
}
|
|
739
742
|
|
|
743
|
+
get items() {
|
|
744
|
+
return this._items;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
get currency() {
|
|
748
|
+
return this._currency;
|
|
749
|
+
}
|
|
750
|
+
|
|
740
751
|
get description() {
|
|
741
752
|
return this._description;
|
|
742
753
|
}
|
|
@@ -745,10 +756,6 @@ module.exports = (() => {
|
|
|
745
756
|
return this._dataFormat;
|
|
746
757
|
}
|
|
747
758
|
|
|
748
|
-
get items() {
|
|
749
|
-
return this._items;
|
|
750
|
-
}
|
|
751
|
-
|
|
752
759
|
get single() {
|
|
753
760
|
return this._single;
|
|
754
761
|
}
|
|
@@ -791,7 +798,7 @@ module.exports = (() => {
|
|
|
791
798
|
formatted.basis = format(updates.basis, Currency.USD);
|
|
792
799
|
}
|
|
793
800
|
|
|
794
|
-
function calculateVariablePriceData(group, item
|
|
801
|
+
function calculateVariablePriceData(group, item) {
|
|
795
802
|
|
|
796
803
|
}
|
|
797
804
|
|
|
@@ -850,6 +857,7 @@ module.exports = (() => {
|
|
|
850
857
|
|
|
851
858
|
},{"@barchart/common-js/lang/assert":16,"@barchart/common-js/lang/is":18}],6:[function(require,module,exports){
|
|
852
859
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
860
|
+
Decimal = require('@barchart/common-js/lang/Decimal'),
|
|
853
861
|
Event = require('@barchart/common-js/messaging/Event'),
|
|
854
862
|
is = require('@barchart/common-js/lang/is');
|
|
855
863
|
|
|
@@ -872,6 +880,18 @@ module.exports = (() => {
|
|
|
872
880
|
|
|
873
881
|
const snapshot = this._position.snapshot;
|
|
874
882
|
|
|
883
|
+
this._data.basis = snapshot.basis || Decimal.ZERO;
|
|
884
|
+
|
|
885
|
+
/*
|
|
886
|
+
let market;
|
|
887
|
+
|
|
888
|
+
if (position.previous) {
|
|
889
|
+
market = snapshot.open.multiply(position.previous);
|
|
890
|
+
} else {
|
|
891
|
+
market = snapshot.value;
|
|
892
|
+
}
|
|
893
|
+
*/
|
|
894
|
+
|
|
875
895
|
this._priceChangeEvent = new Event(this);
|
|
876
896
|
}
|
|
877
897
|
|
|
@@ -909,7 +929,7 @@ module.exports = (() => {
|
|
|
909
929
|
return PositionItem;
|
|
910
930
|
})();
|
|
911
931
|
|
|
912
|
-
},{"@barchart/common-js/lang/assert":16,"@barchart/common-js/lang/is":18,"@barchart/common-js/messaging/Event":19}],7:[function(require,module,exports){
|
|
932
|
+
},{"@barchart/common-js/lang/Decimal":12,"@barchart/common-js/lang/assert":16,"@barchart/common-js/lang/is":18,"@barchart/common-js/messaging/Event":19}],7:[function(require,module,exports){
|
|
913
933
|
'use strict';
|
|
914
934
|
|
|
915
935
|
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; }; }();
|