@barchart/portfolio-api-common 1.0.49 → 1.0.53
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.find(group => group.description === description).currency, description);
|
|
89
90
|
});
|
|
90
91
|
|
|
91
92
|
const compositeGroups = populatedGroups.concat(empty);
|
|
@@ -100,7 +101,11 @@ module.exports = (() => {
|
|
|
100
101
|
}, { });
|
|
101
102
|
|
|
102
103
|
const getIndex = (description) => {
|
|
103
|
-
|
|
104
|
+
if (ordering.hasOwnProperty(description)) {
|
|
105
|
+
return ordering[description];
|
|
106
|
+
} else {
|
|
107
|
+
return Number.MAX_VALUE;
|
|
108
|
+
}
|
|
104
109
|
};
|
|
105
110
|
|
|
106
111
|
builder = ComparatorBuilder.startWith((a, b) => {
|
|
@@ -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.find(group => group.description === description).currency, description);
|
|
604
605
|
});
|
|
605
606
|
|
|
606
607
|
const compositeGroups = populatedGroups.concat(empty);
|
|
@@ -615,7 +616,11 @@ module.exports = (() => {
|
|
|
615
616
|
}, { });
|
|
616
617
|
|
|
617
618
|
const getIndex = (description) => {
|
|
618
|
-
|
|
619
|
+
if (ordering.hasOwnProperty(description)) {
|
|
620
|
+
return ordering[description];
|
|
621
|
+
} else {
|
|
622
|
+
return Number.MAX_VALUE;
|
|
623
|
+
}
|
|
619
624
|
};
|
|
620
625
|
|
|
621
626
|
builder = ComparatorBuilder.startWith((a, b) => {
|
|
@@ -679,7 +684,7 @@ module.exports = (() => {
|
|
|
679
684
|
return PositionContainer;
|
|
680
685
|
})();
|
|
681
686
|
|
|
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){
|
|
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){
|
|
683
688
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
684
689
|
Currency = require('@barchart/common-js/lang/Currency'),
|
|
685
690
|
Decimal = require('@barchart/common-js/lang/Decimal'),
|
|
@@ -693,9 +698,11 @@ module.exports = (() => {
|
|
|
693
698
|
* @public
|
|
694
699
|
*/
|
|
695
700
|
class PositionGroup {
|
|
696
|
-
constructor(items, description, single) {
|
|
697
|
-
this._description = description;
|
|
701
|
+
constructor(items, currency, description, single) {
|
|
698
702
|
this._items = items;
|
|
703
|
+
this._currency = currency;
|
|
704
|
+
|
|
705
|
+
this._description = description;
|
|
699
706
|
|
|
700
707
|
this._single = is.boolean(single) && single;
|
|
701
708
|
|
|
@@ -726,13 +733,21 @@ module.exports = (() => {
|
|
|
726
733
|
this._dataFormat.current = null;
|
|
727
734
|
}
|
|
728
735
|
|
|
729
|
-
calculateVariablePriceData(this, item
|
|
736
|
+
calculateVariablePriceData(this, item);
|
|
730
737
|
});
|
|
731
738
|
});
|
|
732
739
|
|
|
733
740
|
calculateStaticData(this);
|
|
734
741
|
}
|
|
735
742
|
|
|
743
|
+
get items() {
|
|
744
|
+
return this._items;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
get currency() {
|
|
748
|
+
return this._currency;
|
|
749
|
+
}
|
|
750
|
+
|
|
736
751
|
get description() {
|
|
737
752
|
return this._description;
|
|
738
753
|
}
|
|
@@ -741,10 +756,6 @@ module.exports = (() => {
|
|
|
741
756
|
return this._dataFormat;
|
|
742
757
|
}
|
|
743
758
|
|
|
744
|
-
get items() {
|
|
745
|
-
return this._items;
|
|
746
|
-
}
|
|
747
|
-
|
|
748
759
|
get single() {
|
|
749
760
|
return this._single;
|
|
750
761
|
}
|
|
@@ -787,7 +798,7 @@ module.exports = (() => {
|
|
|
787
798
|
formatted.basis = format(updates.basis, Currency.USD);
|
|
788
799
|
}
|
|
789
800
|
|
|
790
|
-
function calculateVariablePriceData(group, item
|
|
801
|
+
function calculateVariablePriceData(group, item) {
|
|
791
802
|
|
|
792
803
|
}
|
|
793
804
|
|
|
@@ -846,6 +857,7 @@ module.exports = (() => {
|
|
|
846
857
|
|
|
847
858
|
},{"@barchart/common-js/lang/assert":16,"@barchart/common-js/lang/is":18}],6:[function(require,module,exports){
|
|
848
859
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
860
|
+
Decimal = require('@barchart/common-js/lang/Decimal'),
|
|
849
861
|
Event = require('@barchart/common-js/messaging/Event'),
|
|
850
862
|
is = require('@barchart/common-js/lang/is');
|
|
851
863
|
|
|
@@ -868,6 +880,18 @@ module.exports = (() => {
|
|
|
868
880
|
|
|
869
881
|
const snapshot = this._position.snapshot;
|
|
870
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
|
+
|
|
871
895
|
this._priceChangeEvent = new Event(this);
|
|
872
896
|
}
|
|
873
897
|
|
|
@@ -905,7 +929,7 @@ module.exports = (() => {
|
|
|
905
929
|
return PositionItem;
|
|
906
930
|
})();
|
|
907
931
|
|
|
908
|
-
},{"@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){
|
|
909
933
|
'use strict';
|
|
910
934
|
|
|
911
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; }; }();
|