@barchart/portfolio-api-common 1.0.62 → 1.0.63
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.
|
@@ -6,6 +6,8 @@ const array = require('@barchart/common-js/lang/array'),
|
|
|
6
6
|
is = require('@barchart/common-js/lang/is'),
|
|
7
7
|
Tree = require('@barchart/common-js/collections/Tree');
|
|
8
8
|
|
|
9
|
+
const InstrumentType = require('./../data/InstrumentType');
|
|
10
|
+
|
|
9
11
|
const PositionGroup = require('./PositionGroup'),
|
|
10
12
|
PositionItem = require('./PositionItem');
|
|
11
13
|
|
|
@@ -16,7 +18,10 @@ module.exports = (() => {
|
|
|
16
18
|
* @public
|
|
17
19
|
*/
|
|
18
20
|
class PositionContainer {
|
|
19
|
-
constructor(portfolios, positions, summaries, definitions) {
|
|
21
|
+
constructor(portfolios, positions, summaries, definitions, defaultCurrency) {
|
|
22
|
+
this._definitions = definitions;
|
|
23
|
+
this._defaultCurrency = defaultCurrency || Currency.CAD;
|
|
24
|
+
|
|
20
25
|
this._portfolios = portfolios.reduce((map, portfolio) => {
|
|
21
26
|
map[portfolio.portfolio] = portfolio;
|
|
22
27
|
|
|
@@ -48,11 +53,10 @@ module.exports = (() => {
|
|
|
48
53
|
}, [ ]);
|
|
49
54
|
|
|
50
55
|
this._symbols = this._items.reduce((map, item) => {
|
|
51
|
-
|
|
52
|
-
let symbol = null;
|
|
56
|
+
const position = item.position;
|
|
53
57
|
|
|
54
58
|
if (position.instrument && position.instrument.symbol && position.instrument.symbol.barchart) {
|
|
55
|
-
symbol = position.instrument.symbol.barchart;
|
|
59
|
+
const symbol = position.instrument.symbol.barchart;
|
|
56
60
|
|
|
57
61
|
if (!map.hasOwnProperty(symbol)) {
|
|
58
62
|
map[symbol] = [ ];
|
|
@@ -64,7 +68,21 @@ module.exports = (() => {
|
|
|
64
68
|
return map;
|
|
65
69
|
}, { });
|
|
66
70
|
|
|
67
|
-
this.
|
|
71
|
+
this._currencies = this._items.reduce((map, item) => {
|
|
72
|
+
const position = item.position;
|
|
73
|
+
|
|
74
|
+
if (position.instrument && position.instrument.currency) {
|
|
75
|
+
const currency = position.instrument.currency;
|
|
76
|
+
|
|
77
|
+
if (!map.hasOwnProperty(currency)) {
|
|
78
|
+
map[currency] = [ ];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
map[currency].push(item);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return map;
|
|
85
|
+
}, { });
|
|
68
86
|
|
|
69
87
|
this._tree = new Tree();
|
|
70
88
|
|
|
@@ -131,6 +149,10 @@ module.exports = (() => {
|
|
|
131
149
|
createGroups(this._tree, this._items, this._definitions);
|
|
132
150
|
}
|
|
133
151
|
|
|
152
|
+
get defaultCurrency() {
|
|
153
|
+
return this._defaultCurrency;
|
|
154
|
+
}
|
|
155
|
+
|
|
134
156
|
getSymbols() {
|
|
135
157
|
return Object.keys(this._symbols);
|
|
136
158
|
}
|
|
@@ -141,6 +163,22 @@ module.exports = (() => {
|
|
|
141
163
|
}
|
|
142
164
|
}
|
|
143
165
|
|
|
166
|
+
getCurrencySymbols() {
|
|
167
|
+
const codes = Object.keys(this._currencies);
|
|
168
|
+
|
|
169
|
+
return codes.reduce((symbols, code) => {
|
|
170
|
+
if (code !== this._defaultCurrency) {
|
|
171
|
+
symbols.push(`^${this._defaultCurrency}${code}`);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return symbols;
|
|
175
|
+
}, [ ]);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
setExchangeRage(symbol, price) {
|
|
179
|
+
|
|
180
|
+
}
|
|
181
|
+
|
|
144
182
|
getGroup(keys) {
|
|
145
183
|
const node = keys.reduce((tree, key) => {
|
|
146
184
|
tree = tree.findChild(group => group.description === key);
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -612,6 +612,8 @@ const array = require('@barchart/common-js/lang/array'),
|
|
|
612
612
|
is = require('@barchart/common-js/lang/is'),
|
|
613
613
|
Tree = require('@barchart/common-js/collections/Tree');
|
|
614
614
|
|
|
615
|
+
const InstrumentType = require('./../data/InstrumentType');
|
|
616
|
+
|
|
615
617
|
const PositionGroup = require('./PositionGroup'),
|
|
616
618
|
PositionItem = require('./PositionItem');
|
|
617
619
|
|
|
@@ -622,7 +624,10 @@ module.exports = (() => {
|
|
|
622
624
|
* @public
|
|
623
625
|
*/
|
|
624
626
|
class PositionContainer {
|
|
625
|
-
constructor(portfolios, positions, summaries, definitions) {
|
|
627
|
+
constructor(portfolios, positions, summaries, definitions, defaultCurrency) {
|
|
628
|
+
this._definitions = definitions;
|
|
629
|
+
this._defaultCurrency = defaultCurrency || Currency.CAD;
|
|
630
|
+
|
|
626
631
|
this._portfolios = portfolios.reduce((map, portfolio) => {
|
|
627
632
|
map[portfolio.portfolio] = portfolio;
|
|
628
633
|
|
|
@@ -654,11 +659,10 @@ module.exports = (() => {
|
|
|
654
659
|
}, [ ]);
|
|
655
660
|
|
|
656
661
|
this._symbols = this._items.reduce((map, item) => {
|
|
657
|
-
|
|
658
|
-
let symbol = null;
|
|
662
|
+
const position = item.position;
|
|
659
663
|
|
|
660
664
|
if (position.instrument && position.instrument.symbol && position.instrument.symbol.barchart) {
|
|
661
|
-
symbol = position.instrument.symbol.barchart;
|
|
665
|
+
const symbol = position.instrument.symbol.barchart;
|
|
662
666
|
|
|
663
667
|
if (!map.hasOwnProperty(symbol)) {
|
|
664
668
|
map[symbol] = [ ];
|
|
@@ -670,7 +674,21 @@ module.exports = (() => {
|
|
|
670
674
|
return map;
|
|
671
675
|
}, { });
|
|
672
676
|
|
|
673
|
-
this.
|
|
677
|
+
this._currencies = this._items.reduce((map, item) => {
|
|
678
|
+
const position = item.position;
|
|
679
|
+
|
|
680
|
+
if (position.instrument && position.instrument.currency) {
|
|
681
|
+
const currency = position.instrument.currency;
|
|
682
|
+
|
|
683
|
+
if (!map.hasOwnProperty(currency)) {
|
|
684
|
+
map[currency] = [ ];
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
map[currency].push(item);
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
return map;
|
|
691
|
+
}, { });
|
|
674
692
|
|
|
675
693
|
this._tree = new Tree();
|
|
676
694
|
|
|
@@ -737,6 +755,10 @@ module.exports = (() => {
|
|
|
737
755
|
createGroups(this._tree, this._items, this._definitions);
|
|
738
756
|
}
|
|
739
757
|
|
|
758
|
+
get defaultCurrency() {
|
|
759
|
+
return this._defaultCurrency;
|
|
760
|
+
}
|
|
761
|
+
|
|
740
762
|
getSymbols() {
|
|
741
763
|
return Object.keys(this._symbols);
|
|
742
764
|
}
|
|
@@ -747,6 +769,22 @@ module.exports = (() => {
|
|
|
747
769
|
}
|
|
748
770
|
}
|
|
749
771
|
|
|
772
|
+
getCurrencySymbols() {
|
|
773
|
+
const codes = Object.keys(this._currencies);
|
|
774
|
+
|
|
775
|
+
return codes.reduce((symbols, code) => {
|
|
776
|
+
if (code !== this._defaultCurrency) {
|
|
777
|
+
symbols.push(`^${this._defaultCurrency}${code}`);
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
return symbols;
|
|
781
|
+
}, [ ]);
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
setExchangeRage(symbol, price) {
|
|
785
|
+
|
|
786
|
+
}
|
|
787
|
+
|
|
750
788
|
getGroup(keys) {
|
|
751
789
|
const node = keys.reduce((tree, key) => {
|
|
752
790
|
tree = tree.findChild(group => group.description === key);
|
|
@@ -775,7 +813,7 @@ module.exports = (() => {
|
|
|
775
813
|
return PositionContainer;
|
|
776
814
|
})();
|
|
777
815
|
|
|
778
|
-
},{"./PositionGroup":5,"./PositionItem":7,"@barchart/common-js/collections/Tree":8,"@barchart/common-js/collections/sorting/ComparatorBuilder":9,"@barchart/common-js/collections/sorting/comparators":10,"@barchart/common-js/lang/Currency":11,"@barchart/common-js/lang/array":16,"@barchart/common-js/lang/assert":17,"@barchart/common-js/lang/is":19}],5:[function(require,module,exports){
|
|
816
|
+
},{"./../data/InstrumentType":1,"./PositionGroup":5,"./PositionItem":7,"@barchart/common-js/collections/Tree":8,"@barchart/common-js/collections/sorting/ComparatorBuilder":9,"@barchart/common-js/collections/sorting/comparators":10,"@barchart/common-js/lang/Currency":11,"@barchart/common-js/lang/array":16,"@barchart/common-js/lang/assert":17,"@barchart/common-js/lang/is":19}],5:[function(require,module,exports){
|
|
779
817
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
780
818
|
Currency = require('@barchart/common-js/lang/Currency'),
|
|
781
819
|
Decimal = require('@barchart/common-js/lang/Decimal'),
|