@barchart/portfolio-api-common 1.0.126 → 1.0.130

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.
@@ -276,15 +276,22 @@ module.exports = (() => {
276
276
  this._forexQuotes[index] = rate;
277
277
  }
278
278
 
279
- this._trees.forEach((tree) => {
280
- tree.walk(group => group.setForexRate(rate), true, false);
281
- });
279
+ Object.keys(this._trees).forEach(key => this._trees[key].walk(group => group.setForexRate(rate), true, false));
282
280
  }
283
281
 
284
- setPositionFundamentals(data) {
282
+ setPositionFundamentals(symbol, data) {
285
283
  return;
286
284
  }
287
285
 
286
+ setNewsArticleExists(symbol, exists) {
287
+ assert.argumentIsRequired(symbol, 'symbol', String);
288
+ assert.argumentIsRequired(exists, 'exists', Boolean);
289
+
290
+ if (this._symbols.hasOwnProperty(symbol)) {
291
+ this._symbols[symbol].forEach(item => item.setNewsArticleExists(exists));
292
+ }
293
+ }
294
+
288
295
  getGroup(name, keys) {
289
296
  assert.argumentIsRequired(name, 'name', String);
290
297
  assert.argumentIsArray(keys, 'keys', Number);
@@ -36,8 +36,15 @@ module.exports = (() => {
36
36
 
37
37
  this._dataFormat.key = this._key;
38
38
  this._dataFormat.description = this._description;
39
-
39
+ this._dataFormat.newsExists = false;
40
40
  this._dataFormat.quantity = null;
41
+ this._dataFormat.basisPrice = null;
42
+
43
+ this._dataActual.key = this._key;
44
+ this._dataActual.description = this._description;
45
+ this._dataActual.newsExists = false;
46
+ this._dataActual.quantity = null;
47
+ this._dataActual.basisPrice = null;
41
48
 
42
49
  if (this._single) {
43
50
  const item = items[0];
@@ -116,6 +123,13 @@ module.exports = (() => {
116
123
 
117
124
  calculatePriceData(this, this._container.getForexQuotes(), sender, false);
118
125
  });
126
+
127
+ if (this._single) {
128
+ item.registerNewsExistsChangeHandler((exists, sender) => {
129
+ this._dataFormat.newsExists = exists;
130
+ this._dataFormat.newsExists = exists;
131
+ });
132
+ }
119
133
  });
120
134
 
121
135
  this.refresh();
@@ -245,7 +259,7 @@ module.exports = (() => {
245
259
 
246
260
  const items = group._items;
247
261
 
248
- group._bypassCurrencyTranslation = items.some(item => item.currency !== currency);
262
+ group._bypassCurrencyTranslation = items.every(item => item.currency === currency);
249
263
 
250
264
  const translate = (item, value) => {
251
265
  let translated;
@@ -297,8 +311,11 @@ module.exports = (() => {
297
311
  if (group.single) {
298
312
  const item = group._items[0];
299
313
 
300
- format.quantity = formatDecimal(item.position.snapshot.open, 2);
301
- format.basisPrice = formatCurrency(item.data.basisPrice, currency);
314
+ actual.quantity = item.position.snapshot.open;
315
+ actual.basisPrice = item.data.basisPrice;
316
+
317
+ format.quantity = formatDecimal(actual.quantity, 2);
318
+ format.basisPrice = formatCurrency(actual.basisPrice, currency);
302
319
  }
303
320
  }
304
321
 
@@ -50,6 +50,8 @@ module.exports = (() => {
50
50
  this._data.income = null;
51
51
  this._data.basisPrice = null;
52
52
 
53
+ this._data.newsExists = false;
54
+
53
55
  this._excluded = false;
54
56
 
55
57
  calculateStaticData(this);
@@ -57,6 +59,7 @@ module.exports = (() => {
57
59
 
58
60
  this._quoteChangedEvent = new Event(this);
59
61
  this._excludedChangeEvent = new Event(this);
62
+ this._newsExistsChangedEvent = new Event(this);
60
63
  }
61
64
 
62
65
  get portfolio() {
@@ -112,6 +115,14 @@ module.exports = (() => {
112
115
  }
113
116
  }
114
117
 
118
+ setNewsArticleExists(value) {
119
+ assert.argumentIsRequired(value, 'value', Boolean);
120
+
121
+ if (this._data.newsExists !== value) {
122
+ this._newsExistsChangedEvent.fire(this._data.newsExists = value);
123
+ }
124
+ }
125
+
115
126
  registerQuoteChangeHandler(handler) {
116
127
  this._quoteChangedEvent.register(handler);
117
128
  }
@@ -120,6 +131,10 @@ module.exports = (() => {
120
131
  this._excludedChangeEvent.register(handler);
121
132
  }
122
133
 
134
+ registerNewsExistsChangeHandler(handler) {
135
+ this._newsExistsChangedEvent.register(handler);
136
+ }
137
+
123
138
  toString() {
124
139
  return '[PositionItem]';
125
140
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.0.126",
3
+ "version": "1.0.130",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -992,15 +992,22 @@ module.exports = (() => {
992
992
  this._forexQuotes[index] = rate;
993
993
  }
994
994
 
995
- this._trees.forEach((tree) => {
996
- tree.walk(group => group.setForexRate(rate), true, false);
997
- });
995
+ Object.keys(this._trees).forEach(key => this._trees[key].walk(group => group.setForexRate(rate), true, false));
998
996
  }
999
997
 
1000
- setPositionFundamentals(data) {
998
+ setPositionFundamentals(symbol, data) {
1001
999
  return;
1002
1000
  }
1003
1001
 
1002
+ setNewsArticleExists(symbol, exists) {
1003
+ assert.argumentIsRequired(symbol, 'symbol', String);
1004
+ assert.argumentIsRequired(exists, 'exists', Boolean);
1005
+
1006
+ if (this._symbols.hasOwnProperty(symbol)) {
1007
+ this._symbols[symbol].forEach(item => item.setNewsArticleExists(exists));
1008
+ }
1009
+ }
1010
+
1004
1011
  getGroup(name, keys) {
1005
1012
  assert.argumentIsRequired(name, 'name', String);
1006
1013
  assert.argumentIsArray(keys, 'keys', Number);
@@ -1100,8 +1107,15 @@ module.exports = (() => {
1100
1107
 
1101
1108
  this._dataFormat.key = this._key;
1102
1109
  this._dataFormat.description = this._description;
1103
-
1110
+ this._dataFormat.newsExists = false;
1104
1111
  this._dataFormat.quantity = null;
1112
+ this._dataFormat.basisPrice = null;
1113
+
1114
+ this._dataActual.key = this._key;
1115
+ this._dataActual.description = this._description;
1116
+ this._dataActual.newsExists = false;
1117
+ this._dataActual.quantity = null;
1118
+ this._dataActual.basisPrice = null;
1105
1119
 
1106
1120
  if (this._single) {
1107
1121
  const item = items[0];
@@ -1180,6 +1194,13 @@ module.exports = (() => {
1180
1194
 
1181
1195
  calculatePriceData(this, this._container.getForexQuotes(), sender, false);
1182
1196
  });
1197
+
1198
+ if (this._single) {
1199
+ item.registerNewsExistsChangeHandler((exists, sender) => {
1200
+ this._dataFormat.newsExists = exists;
1201
+ this._dataFormat.newsExists = exists;
1202
+ });
1203
+ }
1183
1204
  });
1184
1205
 
1185
1206
  this.refresh();
@@ -1309,7 +1330,7 @@ module.exports = (() => {
1309
1330
 
1310
1331
  const items = group._items;
1311
1332
 
1312
- group._bypassCurrencyTranslation = items.some(item => item.currency !== currency);
1333
+ group._bypassCurrencyTranslation = items.every(item => item.currency === currency);
1313
1334
 
1314
1335
  const translate = (item, value) => {
1315
1336
  let translated;
@@ -1361,8 +1382,11 @@ module.exports = (() => {
1361
1382
  if (group.single) {
1362
1383
  const item = group._items[0];
1363
1384
 
1364
- format.quantity = formatDecimal(item.position.snapshot.open, 2);
1365
- format.basisPrice = formatCurrency(item.data.basisPrice, currency);
1385
+ actual.quantity = item.position.snapshot.open;
1386
+ actual.basisPrice = item.data.basisPrice;
1387
+
1388
+ format.quantity = formatDecimal(actual.quantity, 2);
1389
+ format.basisPrice = formatCurrency(actual.basisPrice, currency);
1366
1390
  }
1367
1391
  }
1368
1392
 
@@ -1575,6 +1599,8 @@ module.exports = (() => {
1575
1599
  this._data.income = null;
1576
1600
  this._data.basisPrice = null;
1577
1601
 
1602
+ this._data.newsExists = false;
1603
+
1578
1604
  this._excluded = false;
1579
1605
 
1580
1606
  calculateStaticData(this);
@@ -1582,6 +1608,7 @@ module.exports = (() => {
1582
1608
 
1583
1609
  this._quoteChangedEvent = new Event(this);
1584
1610
  this._excludedChangeEvent = new Event(this);
1611
+ this._newsExistsChangedEvent = new Event(this);
1585
1612
  }
1586
1613
 
1587
1614
  get portfolio() {
@@ -1637,6 +1664,14 @@ module.exports = (() => {
1637
1664
  }
1638
1665
  }
1639
1666
 
1667
+ setNewsArticleExists(value) {
1668
+ assert.argumentIsRequired(value, 'value', Boolean);
1669
+
1670
+ if (this._data.newsExists !== value) {
1671
+ this._newsExistsChangedEvent.fire(this._data.newsExists = value);
1672
+ }
1673
+ }
1674
+
1640
1675
  registerQuoteChangeHandler(handler) {
1641
1676
  this._quoteChangedEvent.register(handler);
1642
1677
  }
@@ -1645,6 +1680,10 @@ module.exports = (() => {
1645
1680
  this._excludedChangeEvent.register(handler);
1646
1681
  }
1647
1682
 
1683
+ registerNewsExistsChangeHandler(handler) {
1684
+ this._newsExistsChangedEvent.register(handler);
1685
+ }
1686
+
1648
1687
  toString() {
1649
1688
  return '[PositionItem]';
1650
1689
  }