@barchart/portfolio-api-common 1.0.100 → 1.0.104

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.
@@ -274,11 +274,7 @@ module.exports = (() => {
274
274
  }
275
275
 
276
276
  function findNode(tree, keys) {
277
- return keys.reduce((tree, key) => {
278
- tree = tree.findChild(group => group.description === key);
279
-
280
- return tree;
281
- }, tree);
277
+ return keys.reduce((tree, key) => tree.findChild(group => group.key === key), tree);
282
278
  }
283
279
 
284
280
  function getSummaryArray(ranges) {
@@ -35,6 +35,12 @@ module.exports = (() => {
35
35
  this._dataFormat.key = this._key;
36
36
  this._dataFormat.description = this._description;
37
37
 
38
+ if (this._single) {
39
+ this._dataFormat.instrument = items[0].position.instrument;
40
+ } else {
41
+ this._dataFormat.instrument = null;
42
+ }
43
+
38
44
  this._dataActual.currentPrice = null;
39
45
  this._dataActual.previousPrice = null;
40
46
  this._dataActual.basis = null;
@@ -68,7 +74,7 @@ module.exports = (() => {
68
74
  item.registerPriceChangeHandler((data, sender) => {
69
75
  if (this._single) {
70
76
  this._dataActual.currentPrice = data.currentPrice;
71
- this._dataFormat.currentPrice = formatCurrency(data.currentPrice, sender.position.instrument.currency);
77
+ this._dataFormat.currentPrice = formatCurrency(new Decimal(data.currentPrice), sender.position.instrument.currency);
72
78
  } else {
73
79
  this._dataActual.currentPrice = null;
74
80
  this._dataFormat.currentPrice = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.0.100",
3
+ "version": "1.0.104",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -990,11 +990,7 @@ module.exports = (() => {
990
990
  }
991
991
 
992
992
  function findNode(tree, keys) {
993
- return keys.reduce((tree, key) => {
994
- tree = tree.findChild(group => group.description === key);
995
-
996
- return tree;
997
- }, tree);
993
+ return keys.reduce((tree, key) => tree.findChild(group => group.key === key), tree);
998
994
  }
999
995
 
1000
996
  function getSummaryArray(ranges) {
@@ -1042,6 +1038,12 @@ module.exports = (() => {
1042
1038
  this._dataFormat.key = this._key;
1043
1039
  this._dataFormat.description = this._description;
1044
1040
 
1041
+ if (this._single) {
1042
+ this._dataFormat.instrument = items[0].position.instrument;
1043
+ } else {
1044
+ this._dataFormat.instrument = null;
1045
+ }
1046
+
1045
1047
  this._dataActual.currentPrice = null;
1046
1048
  this._dataActual.previousPrice = null;
1047
1049
  this._dataActual.basis = null;
@@ -1075,7 +1077,7 @@ module.exports = (() => {
1075
1077
  item.registerPriceChangeHandler((data, sender) => {
1076
1078
  if (this._single) {
1077
1079
  this._dataActual.currentPrice = data.currentPrice;
1078
- this._dataFormat.currentPrice = formatCurrency(data.currentPrice, sender.position.instrument.currency);
1080
+ this._dataFormat.currentPrice = formatCurrency(new Decimal(data.currentPrice), sender.position.instrument.currency);
1079
1081
  } else {
1080
1082
  this._dataActual.currentPrice = null;
1081
1083
  this._dataFormat.currentPrice = null;
@@ -6201,18 +6203,18 @@ describe('When a position container data is gathered', () => {
6201
6203
  beforeEach(() => {
6202
6204
  portfolios = [
6203
6205
  {
6204
- portfolio: 'a',
6206
+ portfolio: 'My First Portfolio',
6205
6207
  name: 'a'
6206
6208
  }, {
6207
- portfolio: 'b',
6209
+ portfolio: 'My Second Portfolio',
6208
6210
  name: 'b'
6209
6211
  }
6210
6212
  ];
6211
6213
 
6212
6214
  positions = [
6213
- getPosition('a', 'AAPL'),
6214
- getPosition('b', 'AAPL'),
6215
- getPosition('b', 'TSLA')
6215
+ getPosition('My First Portfolio', 'AAPL'),
6216
+ getPosition('My Second Portfolio', 'AAPL'),
6217
+ getPosition('My Second Portfolio', 'TSLA')
6216
6218
  ];
6217
6219
 
6218
6220
  summaries = [ ];
@@ -6226,7 +6228,7 @@ describe('When a position container data is gathered', () => {
6226
6228
  beforeEach(() => {
6227
6229
  definitions = [
6228
6230
  new PositionTreeDefinition(name = 'the only tree', [
6229
- new PositionLevelDefinition('Total', x => true, x => 'Total', x => Currency.CAD),
6231
+ new PositionLevelDefinition('Total', x => 'totals', x => 'Total', x => Currency.CAD),
6230
6232
  new PositionLevelDefinition('Portfolio', x => x.portfolio.portfolio, x => x.portfolio.name, x => Currency.CAD),
6231
6233
  new PositionLevelDefinition('Position', x => x.position.position, x => x.position.instrument.symbol.barchart, x => x.position.instrument.currency)
6232
6234
  ])
@@ -6240,27 +6242,27 @@ describe('When a position container data is gathered', () => {
6240
6242
  });
6241
6243
 
6242
6244
  it('the "Total" group should have two children groups', () => {
6243
- expect(container.getGroups(name, [ 'Total' ]).length).toEqual(2);
6245
+ expect(container.getGroups(name, [ 'totals' ]).length).toEqual(2);
6244
6246
  });
6245
6247
 
6246
6248
  it('the "Total" group should have three items', () => {
6247
- expect(container.getGroup(name, [ 'Total' ]).items.length).toEqual(3);
6249
+ expect(container.getGroup(name, [ 'totals' ]).items.length).toEqual(3);
6248
6250
  });
6249
6251
 
6250
6252
  it('The "a" portfolio group should have one child group', () => {
6251
- expect(container.getGroups(name, [ 'Total', 'a' ]).length).toEqual(1);
6253
+ expect(container.getGroups(name, [ 'totals', 'My First Portfolio' ]).length).toEqual(1);
6252
6254
  });
6253
6255
 
6254
6256
  it('the "a" portfolio group should have one item', () => {
6255
- expect(container.getGroup(name, [ 'Total', 'a' ]).items.length).toEqual(1);
6257
+ expect(container.getGroup(name, [ 'totals', 'My First Portfolio' ]).items.length).toEqual(1);
6256
6258
  });
6257
6259
 
6258
6260
  it('The "b" portfolio group should have two child groups', () => {
6259
- expect(container.getGroups(name, [ 'Total', 'b' ]).length).toEqual(2);
6261
+ expect(container.getGroups(name, [ 'totals', 'My Second Portfolio' ]).length).toEqual(2);
6260
6262
  });
6261
6263
 
6262
6264
  it('the "b" portfolio group should have two items', () => {
6263
- expect(container.getGroup(name, [ 'Total', 'b' ]).items.length).toEqual(2);
6265
+ expect(container.getGroup(name, [ 'totals', 'My Second Portfolio' ]).items.length).toEqual(2);
6264
6266
  });
6265
6267
  });
6266
6268
  });
@@ -41,18 +41,18 @@ describe('When a position container data is gathered', () => {
41
41
  beforeEach(() => {
42
42
  portfolios = [
43
43
  {
44
- portfolio: 'a',
44
+ portfolio: 'My First Portfolio',
45
45
  name: 'a'
46
46
  }, {
47
- portfolio: 'b',
47
+ portfolio: 'My Second Portfolio',
48
48
  name: 'b'
49
49
  }
50
50
  ];
51
51
 
52
52
  positions = [
53
- getPosition('a', 'AAPL'),
54
- getPosition('b', 'AAPL'),
55
- getPosition('b', 'TSLA')
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 => true, x => 'Total', x => Currency.CAD),
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, [ 'Total' ]).length).toEqual(2);
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, [ 'Total' ]).items.length).toEqual(3);
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, [ 'Total', 'a' ]).length).toEqual(1);
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, [ 'Total', 'a' ]).items.length).toEqual(1);
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, [ 'Total', 'b' ]).length).toEqual(2);
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, [ 'Total', 'b' ]).items.length).toEqual(2);
103
+ expect(container.getGroup(name, [ 'totals', 'My Second Portfolio' ]).items.length).toEqual(2);
104
104
  });
105
105
  });
106
106
  });