@barchart/portfolio-api-common 1.0.99 → 1.0.103
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.
|
@@ -145,10 +145,13 @@ module.exports = (() => {
|
|
|
145
145
|
return list;
|
|
146
146
|
}, [ ]);
|
|
147
147
|
|
|
148
|
-
const missingGroups = array.difference(levelDefinition.requiredGroups.map(group => group.
|
|
148
|
+
const missingGroups = array.difference(levelDefinition.requiredGroups.map(group => group.key), populatedGroups.map(group => group.key))
|
|
149
|
+
.map((key) => {
|
|
150
|
+
return levelDefinition.requiredGroups.find(g => g.key === key);
|
|
151
|
+
});
|
|
149
152
|
|
|
150
|
-
const empty = missingGroups.map((
|
|
151
|
-
return new PositionGroup(this, parent, [ ],
|
|
153
|
+
const empty = missingGroups.map((group) => {
|
|
154
|
+
return new PositionGroup(this, parent, [ ], group.currency, group.key, group.description);
|
|
152
155
|
});
|
|
153
156
|
|
|
154
157
|
const compositeGroups = populatedGroups.concat(empty);
|
|
@@ -271,11 +274,7 @@ module.exports = (() => {
|
|
|
271
274
|
}
|
|
272
275
|
|
|
273
276
|
function findNode(tree, keys) {
|
|
274
|
-
return keys.reduce((tree, key) =>
|
|
275
|
-
tree = tree.findChild(group => group.description === key);
|
|
276
|
-
|
|
277
|
-
return tree;
|
|
278
|
-
}, tree);
|
|
277
|
+
return keys.reduce((tree, key) => tree.findChild(group => group.key === key), tree);
|
|
279
278
|
}
|
|
280
279
|
|
|
281
280
|
function getSummaryArray(ranges) {
|
|
@@ -31,9 +31,16 @@ module.exports = (() => {
|
|
|
31
31
|
|
|
32
32
|
this._dataFormat = { };
|
|
33
33
|
this._dataActual = { };
|
|
34
|
-
|
|
34
|
+
|
|
35
|
+
this._dataFormat.key = this._key;
|
|
35
36
|
this._dataFormat.description = this._description;
|
|
36
|
-
|
|
37
|
+
|
|
38
|
+
if (this._single) {
|
|
39
|
+
this._dataFormat.instrument = items[0].position.instrument;
|
|
40
|
+
} else {
|
|
41
|
+
this._dataFormat.instrument = null;
|
|
42
|
+
}
|
|
43
|
+
|
|
37
44
|
this._dataActual.currentPrice = null;
|
|
38
45
|
this._dataActual.previousPrice = null;
|
|
39
46
|
this._dataActual.basis = null;
|
|
@@ -14,7 +14,7 @@ module.exports = (() => {
|
|
|
14
14
|
* @param {PositionLevelDefinition~keySelector} keySelector
|
|
15
15
|
* @param {PositionLevelDefinition~descriptionSelector} descriptionSelector
|
|
16
16
|
* @param {PositionLevelDefinition~currencySelector} currencySelector
|
|
17
|
-
* @param {Array.<
|
|
17
|
+
* @param {Array.<PositionLevelDefinition~RequiredGroup>=} requiredGroups
|
|
18
18
|
* @param {Boolean=} single
|
|
19
19
|
*/
|
|
20
20
|
class PositionLevelDefinition {
|
|
@@ -139,5 +139,16 @@ module.exports = (() => {
|
|
|
139
139
|
* @returns {Currency}
|
|
140
140
|
*/
|
|
141
141
|
|
|
142
|
+
/**
|
|
143
|
+
* The data required to construct a group.
|
|
144
|
+
*
|
|
145
|
+
* @public
|
|
146
|
+
* @typedef PositionLevelDefinition~RequiredGroup
|
|
147
|
+
* @type {Object}
|
|
148
|
+
* @property {String} key
|
|
149
|
+
* @property {String} description
|
|
150
|
+
* @property {Currency} currency
|
|
151
|
+
*/
|
|
152
|
+
|
|
142
153
|
return PositionLevelDefinition;
|
|
143
154
|
})();
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -861,10 +861,13 @@ module.exports = (() => {
|
|
|
861
861
|
return list;
|
|
862
862
|
}, [ ]);
|
|
863
863
|
|
|
864
|
-
const missingGroups = array.difference(levelDefinition.requiredGroups.map(group => group.
|
|
864
|
+
const missingGroups = array.difference(levelDefinition.requiredGroups.map(group => group.key), populatedGroups.map(group => group.key))
|
|
865
|
+
.map((key) => {
|
|
866
|
+
return levelDefinition.requiredGroups.find(g => g.key === key);
|
|
867
|
+
});
|
|
865
868
|
|
|
866
|
-
const empty = missingGroups.map((
|
|
867
|
-
return new PositionGroup(this, parent, [ ],
|
|
869
|
+
const empty = missingGroups.map((group) => {
|
|
870
|
+
return new PositionGroup(this, parent, [ ], group.currency, group.key, group.description);
|
|
868
871
|
});
|
|
869
872
|
|
|
870
873
|
const compositeGroups = populatedGroups.concat(empty);
|
|
@@ -987,11 +990,7 @@ module.exports = (() => {
|
|
|
987
990
|
}
|
|
988
991
|
|
|
989
992
|
function findNode(tree, keys) {
|
|
990
|
-
return keys.reduce((tree, key) =>
|
|
991
|
-
tree = tree.findChild(group => group.description === key);
|
|
992
|
-
|
|
993
|
-
return tree;
|
|
994
|
-
}, tree);
|
|
993
|
+
return keys.reduce((tree, key) => tree.findChild(group => group.key === key), tree);
|
|
995
994
|
}
|
|
996
995
|
|
|
997
996
|
function getSummaryArray(ranges) {
|
|
@@ -1035,9 +1034,16 @@ module.exports = (() => {
|
|
|
1035
1034
|
|
|
1036
1035
|
this._dataFormat = { };
|
|
1037
1036
|
this._dataActual = { };
|
|
1038
|
-
|
|
1037
|
+
|
|
1038
|
+
this._dataFormat.key = this._key;
|
|
1039
1039
|
this._dataFormat.description = this._description;
|
|
1040
|
-
|
|
1040
|
+
|
|
1041
|
+
if (this._single) {
|
|
1042
|
+
this._dataFormat.instrument = items[0].position.instrument;
|
|
1043
|
+
} else {
|
|
1044
|
+
this._dataFormat.instrument = null;
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1041
1047
|
this._dataActual.currentPrice = null;
|
|
1042
1048
|
this._dataActual.previousPrice = null;
|
|
1043
1049
|
this._dataActual.basis = null;
|
|
@@ -1578,7 +1584,7 @@ module.exports = (() => {
|
|
|
1578
1584
|
* @param {PositionLevelDefinition~keySelector} keySelector
|
|
1579
1585
|
* @param {PositionLevelDefinition~descriptionSelector} descriptionSelector
|
|
1580
1586
|
* @param {PositionLevelDefinition~currencySelector} currencySelector
|
|
1581
|
-
* @param {Array.<
|
|
1587
|
+
* @param {Array.<PositionLevelDefinition~RequiredGroup>=} requiredGroups
|
|
1582
1588
|
* @param {Boolean=} single
|
|
1583
1589
|
*/
|
|
1584
1590
|
class PositionLevelDefinition {
|
|
@@ -1703,6 +1709,17 @@ module.exports = (() => {
|
|
|
1703
1709
|
* @returns {Currency}
|
|
1704
1710
|
*/
|
|
1705
1711
|
|
|
1712
|
+
/**
|
|
1713
|
+
* The data required to construct a group.
|
|
1714
|
+
*
|
|
1715
|
+
* @public
|
|
1716
|
+
* @typedef PositionLevelDefinition~RequiredGroup
|
|
1717
|
+
* @type {Object}
|
|
1718
|
+
* @property {String} key
|
|
1719
|
+
* @property {String} description
|
|
1720
|
+
* @property {Currency} currency
|
|
1721
|
+
*/
|
|
1722
|
+
|
|
1706
1723
|
return PositionLevelDefinition;
|
|
1707
1724
|
})();
|
|
1708
1725
|
|
|
@@ -6186,18 +6203,18 @@ describe('When a position container data is gathered', () => {
|
|
|
6186
6203
|
beforeEach(() => {
|
|
6187
6204
|
portfolios = [
|
|
6188
6205
|
{
|
|
6189
|
-
portfolio: '
|
|
6206
|
+
portfolio: 'My First Portfolio',
|
|
6190
6207
|
name: 'a'
|
|
6191
6208
|
}, {
|
|
6192
|
-
portfolio: '
|
|
6209
|
+
portfolio: 'My Second Portfolio',
|
|
6193
6210
|
name: 'b'
|
|
6194
6211
|
}
|
|
6195
6212
|
];
|
|
6196
6213
|
|
|
6197
6214
|
positions = [
|
|
6198
|
-
getPosition('
|
|
6199
|
-
getPosition('
|
|
6200
|
-
getPosition('
|
|
6215
|
+
getPosition('My First Portfolio', 'AAPL'),
|
|
6216
|
+
getPosition('My Second Portfolio', 'AAPL'),
|
|
6217
|
+
getPosition('My Second Portfolio', 'TSLA')
|
|
6201
6218
|
];
|
|
6202
6219
|
|
|
6203
6220
|
summaries = [ ];
|
|
@@ -6211,7 +6228,7 @@ describe('When a position container data is gathered', () => {
|
|
|
6211
6228
|
beforeEach(() => {
|
|
6212
6229
|
definitions = [
|
|
6213
6230
|
new PositionTreeDefinition(name = 'the only tree', [
|
|
6214
|
-
new PositionLevelDefinition('Total', x =>
|
|
6231
|
+
new PositionLevelDefinition('Total', x => 'totals', x => 'Total', x => Currency.CAD),
|
|
6215
6232
|
new PositionLevelDefinition('Portfolio', x => x.portfolio.portfolio, x => x.portfolio.name, x => Currency.CAD),
|
|
6216
6233
|
new PositionLevelDefinition('Position', x => x.position.position, x => x.position.instrument.symbol.barchart, x => x.position.instrument.currency)
|
|
6217
6234
|
])
|
|
@@ -6225,27 +6242,27 @@ describe('When a position container data is gathered', () => {
|
|
|
6225
6242
|
});
|
|
6226
6243
|
|
|
6227
6244
|
it('the "Total" group should have two children groups', () => {
|
|
6228
|
-
expect(container.getGroups(name, [ '
|
|
6245
|
+
expect(container.getGroups(name, [ 'totals' ]).length).toEqual(2);
|
|
6229
6246
|
});
|
|
6230
6247
|
|
|
6231
6248
|
it('the "Total" group should have three items', () => {
|
|
6232
|
-
expect(container.getGroup(name, [ '
|
|
6249
|
+
expect(container.getGroup(name, [ 'totals' ]).items.length).toEqual(3);
|
|
6233
6250
|
});
|
|
6234
6251
|
|
|
6235
6252
|
it('The "a" portfolio group should have one child group', () => {
|
|
6236
|
-
expect(container.getGroups(name, [ '
|
|
6253
|
+
expect(container.getGroups(name, [ 'totals', 'My First Portfolio' ]).length).toEqual(1);
|
|
6237
6254
|
});
|
|
6238
6255
|
|
|
6239
6256
|
it('the "a" portfolio group should have one item', () => {
|
|
6240
|
-
expect(container.getGroup(name, [ '
|
|
6257
|
+
expect(container.getGroup(name, [ 'totals', 'My First Portfolio' ]).items.length).toEqual(1);
|
|
6241
6258
|
});
|
|
6242
6259
|
|
|
6243
6260
|
it('The "b" portfolio group should have two child groups', () => {
|
|
6244
|
-
expect(container.getGroups(name, [ '
|
|
6261
|
+
expect(container.getGroups(name, [ 'totals', 'My Second Portfolio' ]).length).toEqual(2);
|
|
6245
6262
|
});
|
|
6246
6263
|
|
|
6247
6264
|
it('the "b" portfolio group should have two items', () => {
|
|
6248
|
-
expect(container.getGroup(name, [ '
|
|
6265
|
+
expect(container.getGroup(name, [ 'totals', 'My Second Portfolio' ]).items.length).toEqual(2);
|
|
6249
6266
|
});
|
|
6250
6267
|
});
|
|
6251
6268
|
});
|
|
@@ -41,18 +41,18 @@ describe('When a position container data is gathered', () => {
|
|
|
41
41
|
beforeEach(() => {
|
|
42
42
|
portfolios = [
|
|
43
43
|
{
|
|
44
|
-
portfolio: '
|
|
44
|
+
portfolio: 'My First Portfolio',
|
|
45
45
|
name: 'a'
|
|
46
46
|
}, {
|
|
47
|
-
portfolio: '
|
|
47
|
+
portfolio: 'My Second Portfolio',
|
|
48
48
|
name: 'b'
|
|
49
49
|
}
|
|
50
50
|
];
|
|
51
51
|
|
|
52
52
|
positions = [
|
|
53
|
-
getPosition('
|
|
54
|
-
getPosition('
|
|
55
|
-
getPosition('
|
|
53
|
+
getPosition('My First Portfolio', 'AAPL'),
|
|
54
|
+
getPosition('My Second Portfolio', 'AAPL'),
|
|
55
|
+
getPosition('My Second Portfolio', 'TSLA')
|
|
56
56
|
];
|
|
57
57
|
|
|
58
58
|
summaries = [ ];
|
|
@@ -66,7 +66,7 @@ describe('When a position container data is gathered', () => {
|
|
|
66
66
|
beforeEach(() => {
|
|
67
67
|
definitions = [
|
|
68
68
|
new PositionTreeDefinition(name = 'the only tree', [
|
|
69
|
-
new PositionLevelDefinition('Total', x =>
|
|
69
|
+
new PositionLevelDefinition('Total', x => 'totals', x => 'Total', x => Currency.CAD),
|
|
70
70
|
new PositionLevelDefinition('Portfolio', x => x.portfolio.portfolio, x => x.portfolio.name, x => Currency.CAD),
|
|
71
71
|
new PositionLevelDefinition('Position', x => x.position.position, x => x.position.instrument.symbol.barchart, x => x.position.instrument.currency)
|
|
72
72
|
])
|
|
@@ -80,27 +80,27 @@ describe('When a position container data is gathered', () => {
|
|
|
80
80
|
});
|
|
81
81
|
|
|
82
82
|
it('the "Total" group should have two children groups', () => {
|
|
83
|
-
expect(container.getGroups(name, [ '
|
|
83
|
+
expect(container.getGroups(name, [ 'totals' ]).length).toEqual(2);
|
|
84
84
|
});
|
|
85
85
|
|
|
86
86
|
it('the "Total" group should have three items', () => {
|
|
87
|
-
expect(container.getGroup(name, [ '
|
|
87
|
+
expect(container.getGroup(name, [ 'totals' ]).items.length).toEqual(3);
|
|
88
88
|
});
|
|
89
89
|
|
|
90
90
|
it('The "a" portfolio group should have one child group', () => {
|
|
91
|
-
expect(container.getGroups(name, [ '
|
|
91
|
+
expect(container.getGroups(name, [ 'totals', 'My First Portfolio' ]).length).toEqual(1);
|
|
92
92
|
});
|
|
93
93
|
|
|
94
94
|
it('the "a" portfolio group should have one item', () => {
|
|
95
|
-
expect(container.getGroup(name, [ '
|
|
95
|
+
expect(container.getGroup(name, [ 'totals', 'My First Portfolio' ]).items.length).toEqual(1);
|
|
96
96
|
});
|
|
97
97
|
|
|
98
98
|
it('The "b" portfolio group should have two child groups', () => {
|
|
99
|
-
expect(container.getGroups(name, [ '
|
|
99
|
+
expect(container.getGroups(name, [ 'totals', 'My Second Portfolio' ]).length).toEqual(2);
|
|
100
100
|
});
|
|
101
101
|
|
|
102
102
|
it('the "b" portfolio group should have two items', () => {
|
|
103
|
-
expect(container.getGroup(name, [ '
|
|
103
|
+
expect(container.getGroup(name, [ 'totals', 'My Second Portfolio' ]).items.length).toEqual(2);
|
|
104
104
|
});
|
|
105
105
|
});
|
|
106
106
|
});
|