@barchart/portfolio-api-common 1.0.188 → 1.0.189

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.
@@ -262,13 +262,13 @@ module.exports = (() => {
262
262
  let groupTree;
263
263
 
264
264
  if (parentTree.getChildren().length > 0) {
265
- groupTree = parentTree.getChildren().find(childGroup => childGroup.key === levelKey) || null;
265
+ groupTree = parentTree.findChild(childGroup => childGroup.key === levelKey) || null;
266
266
  } else {
267
267
  groupTree = null;
268
268
  }
269
269
 
270
270
  if (groupTree !== null) {
271
- groupTree.addItem(item);
271
+ groupTree.getValue().addItem(item);
272
272
 
273
273
  createGroupOrInjectItem(groupTree, treeDefinition, array.dropLeft(levelDefinitions));
274
274
  } else {
@@ -60,7 +60,7 @@ module.exports = (() => {
60
60
 
61
61
  this._excludedItems = [ ];
62
62
  this._excludedItemMap = { };
63
- this._consideredItems = this._items;
63
+ this._consideredItems = this._items.slice(0);
64
64
 
65
65
  this._dataFormat = { };
66
66
  this._dataActual = { };
@@ -149,76 +149,7 @@ module.exports = (() => {
149
149
  this._dataFormat.portfolioType = null;
150
150
 
151
151
  this._items.forEach((item) => {
152
- const quoteBinding = item.registerQuoteChangeHandler((quote, sender) => {
153
- if (this._single) {
154
- const precision = sender.position.instrument.currency.precision;
155
-
156
- this._dataActual.currentPrice = quote.lastPrice;
157
- this._dataFormat.currentPrice = formatNumber(this._dataActual.currentPrice, precision);
158
-
159
- this._dataActual.quoteLast = quote.previousPrice;
160
- this._dataActual.quoteOpen = quote.openPrice;
161
- this._dataActual.quoteHigh = quote.highPrice;
162
- this._dataActual.quoteLow = quote.lowPrice;
163
- this._dataActual.quoteChange = quote.priceChange;
164
- this._dataActual.quoteChangePercent = quote.percentChange;
165
- this._dataActual.quoteTime = quote.timeDisplay;
166
- this._dataActual.quoteVolume = quote.volume;
167
-
168
- this._dataFormat.quoteLast = formatNumber(this._dataActual.quoteLast , precision);
169
- this._dataFormat.quoteOpen = formatNumber(this._dataActual.quoteOpen, precision);
170
- this._dataFormat.quoteHigh = formatNumber(this._dataActual.quoteHigh, precision);
171
- this._dataFormat.quoteLow = formatNumber(this._dataActual.quoteLow, precision);
172
- this._dataFormat.quoteChange = formatNumber(this._dataActual.quoteChange, precision);
173
- this._dataFormat.quoteChangePercent = formatPercent(new Decimal(this._dataActual.quoteChangePercent || 0), 2);
174
- this._dataFormat.quoteTime = this._dataActual.quoteTime;
175
- this._dataFormat.quoteVolume = formatNumber(this._dataActual.quoteVolume, 0);
176
-
177
- const quoteChangePositive = quote.lastPriceDirection === 'up';
178
- const quoteChangeNegative = quote.lastPriceDirection === 'down';
179
-
180
- setTimeout(() => this._dataFormat.quoteChangeDirection = { up: quoteChangePositive, down: quoteChangeNegative }, 0);
181
-
182
- this._dataFormat.quoteChangeNegative = is.number(this._dataActual.quoteChange) && this._dataActual.quoteChange < 0;
183
- } else {
184
- this._dataActual.currentPrice = null;
185
- this._dataFormat.currentPrice = null;
186
- }
187
-
188
- calculatePriceData(this, this._container.getForexQuotes(), sender, false);
189
- });
190
-
191
- let newsBinding = Disposable.getEmpty();
192
- let fundamentalBinding = Disposable.getEmpty();
193
-
194
- if (this._single) {
195
- newsBinding = item.registerNewsExistsChangeHandler((exists, sender) => {
196
- this._dataActual.newsExists = exists;
197
- this._dataFormat.newsExists = exists;
198
- });
199
-
200
- fundamentalBinding = item.registerFundamentalDataChangeHandler((data, sender) => {
201
- this._dataFormat.fundamental = data;
202
- });
203
- }
204
-
205
- this._disposeStack.push(quoteBinding);
206
- this._disposeStack.push(newsBinding);
207
- this._disposeStack.push(fundamentalBinding);
208
-
209
- this._disposeStack.push(item.registerPositionItemDisposeHandler(() => {
210
- quoteBinding.dispose();
211
- newsBinding.dispose();
212
- fundamentalBinding.dispose();
213
-
214
- array.remove(this._items, i => i === item);
215
- array.remove(this._excludedItems, i => i === item);
216
- array.remove(this._consideredItems, i => i === item);
217
-
218
- delete this._excludedItemMap[item.position.position];
219
-
220
- this.refresh();
221
- }));
152
+ bindItem.call(this, item);
222
153
  });
223
154
 
224
155
  this.refresh();
@@ -336,6 +267,10 @@ module.exports = (() => {
336
267
  * @param {PositionItem} item
337
268
  */
338
269
  addItem(item) {
270
+ this._items.push(item);
271
+ this._consideredItems.push(item);
272
+
273
+ bindItem.call(this, item);
339
274
 
340
275
  this.refresh();
341
276
  }
@@ -469,6 +404,79 @@ module.exports = (() => {
469
404
  }
470
405
  }
471
406
 
407
+ function bindItem(item) {
408
+ const quoteBinding = item.registerQuoteChangeHandler((quote, sender) => {
409
+ if (this._single) {
410
+ const precision = sender.position.instrument.currency.precision;
411
+
412
+ this._dataActual.currentPrice = quote.lastPrice;
413
+ this._dataFormat.currentPrice = formatNumber(this._dataActual.currentPrice, precision);
414
+
415
+ this._dataActual.quoteLast = quote.previousPrice;
416
+ this._dataActual.quoteOpen = quote.openPrice;
417
+ this._dataActual.quoteHigh = quote.highPrice;
418
+ this._dataActual.quoteLow = quote.lowPrice;
419
+ this._dataActual.quoteChange = quote.priceChange;
420
+ this._dataActual.quoteChangePercent = quote.percentChange;
421
+ this._dataActual.quoteTime = quote.timeDisplay;
422
+ this._dataActual.quoteVolume = quote.volume;
423
+
424
+ this._dataFormat.quoteLast = formatNumber(this._dataActual.quoteLast , precision);
425
+ this._dataFormat.quoteOpen = formatNumber(this._dataActual.quoteOpen, precision);
426
+ this._dataFormat.quoteHigh = formatNumber(this._dataActual.quoteHigh, precision);
427
+ this._dataFormat.quoteLow = formatNumber(this._dataActual.quoteLow, precision);
428
+ this._dataFormat.quoteChange = formatNumber(this._dataActual.quoteChange, precision);
429
+ this._dataFormat.quoteChangePercent = formatPercent(new Decimal(this._dataActual.quoteChangePercent || 0), 2);
430
+ this._dataFormat.quoteTime = this._dataActual.quoteTime;
431
+ this._dataFormat.quoteVolume = formatNumber(this._dataActual.quoteVolume, 0);
432
+
433
+ const quoteChangePositive = quote.lastPriceDirection === 'up';
434
+ const quoteChangeNegative = quote.lastPriceDirection === 'down';
435
+
436
+ setTimeout(() => this._dataFormat.quoteChangeDirection = { up: quoteChangePositive, down: quoteChangeNegative }, 0);
437
+
438
+ this._dataFormat.quoteChangeNegative = is.number(this._dataActual.quoteChange) && this._dataActual.quoteChange < 0;
439
+ } else {
440
+ this._dataActual.currentPrice = null;
441
+ this._dataFormat.currentPrice = null;
442
+ }
443
+
444
+ calculatePriceData(this, this._container.getForexQuotes(), sender, false);
445
+ });
446
+
447
+ let newsBinding = Disposable.getEmpty();
448
+ let fundamentalBinding = Disposable.getEmpty();
449
+
450
+ if (this._single) {
451
+ newsBinding = item.registerNewsExistsChangeHandler((exists, sender) => {
452
+ this._dataActual.newsExists = exists;
453
+ this._dataFormat.newsExists = exists;
454
+ });
455
+
456
+ fundamentalBinding = item.registerFundamentalDataChangeHandler((data, sender) => {
457
+ this._dataFormat.fundamental = data;
458
+ });
459
+ }
460
+
461
+ this._disposeStack.push(quoteBinding);
462
+ this._disposeStack.push(newsBinding);
463
+ this._disposeStack.push(fundamentalBinding);
464
+
465
+ this._disposeStack.push(item.registerPositionItemDisposeHandler(() => {
466
+ quoteBinding.dispose();
467
+ newsBinding.dispose();
468
+ fundamentalBinding.dispose();
469
+
470
+ array.remove(this._items, i => i === item);
471
+ array.remove(this._excludedItems, i => i === item);
472
+ array.remove(this._consideredItems, i => i === item);
473
+
474
+ delete this._excludedItemMap[item.position.position];
475
+
476
+ this.refresh();
477
+ }));
478
+ }
479
+
472
480
  function formatNumber(number, precision) {
473
481
  if (is.number(number)) {
474
482
  return formatter.numberToString(number, precision, ',', false);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.0.188",
3
+ "version": "1.0.189",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -978,13 +978,13 @@ module.exports = (() => {
978
978
  let groupTree;
979
979
 
980
980
  if (parentTree.getChildren().length > 0) {
981
- groupTree = parentTree.getChildren().find(childGroup => childGroup.key === levelKey) || null;
981
+ groupTree = parentTree.findChild(childGroup => childGroup.key === levelKey) || null;
982
982
  } else {
983
983
  groupTree = null;
984
984
  }
985
985
 
986
986
  if (groupTree !== null) {
987
- groupTree.addItem(item);
987
+ groupTree.getValue().addItem(item);
988
988
 
989
989
  createGroupOrInjectItem(groupTree, treeDefinition, array.dropLeft(levelDefinitions));
990
990
  } else {
@@ -1588,7 +1588,7 @@ module.exports = (() => {
1588
1588
 
1589
1589
  this._excludedItems = [ ];
1590
1590
  this._excludedItemMap = { };
1591
- this._consideredItems = this._items;
1591
+ this._consideredItems = this._items.slice(0);
1592
1592
 
1593
1593
  this._dataFormat = { };
1594
1594
  this._dataActual = { };
@@ -1677,76 +1677,7 @@ module.exports = (() => {
1677
1677
  this._dataFormat.portfolioType = null;
1678
1678
 
1679
1679
  this._items.forEach((item) => {
1680
- const quoteBinding = item.registerQuoteChangeHandler((quote, sender) => {
1681
- if (this._single) {
1682
- const precision = sender.position.instrument.currency.precision;
1683
-
1684
- this._dataActual.currentPrice = quote.lastPrice;
1685
- this._dataFormat.currentPrice = formatNumber(this._dataActual.currentPrice, precision);
1686
-
1687
- this._dataActual.quoteLast = quote.previousPrice;
1688
- this._dataActual.quoteOpen = quote.openPrice;
1689
- this._dataActual.quoteHigh = quote.highPrice;
1690
- this._dataActual.quoteLow = quote.lowPrice;
1691
- this._dataActual.quoteChange = quote.priceChange;
1692
- this._dataActual.quoteChangePercent = quote.percentChange;
1693
- this._dataActual.quoteTime = quote.timeDisplay;
1694
- this._dataActual.quoteVolume = quote.volume;
1695
-
1696
- this._dataFormat.quoteLast = formatNumber(this._dataActual.quoteLast , precision);
1697
- this._dataFormat.quoteOpen = formatNumber(this._dataActual.quoteOpen, precision);
1698
- this._dataFormat.quoteHigh = formatNumber(this._dataActual.quoteHigh, precision);
1699
- this._dataFormat.quoteLow = formatNumber(this._dataActual.quoteLow, precision);
1700
- this._dataFormat.quoteChange = formatNumber(this._dataActual.quoteChange, precision);
1701
- this._dataFormat.quoteChangePercent = formatPercent(new Decimal(this._dataActual.quoteChangePercent || 0), 2);
1702
- this._dataFormat.quoteTime = this._dataActual.quoteTime;
1703
- this._dataFormat.quoteVolume = formatNumber(this._dataActual.quoteVolume, 0);
1704
-
1705
- const quoteChangePositive = quote.lastPriceDirection === 'up';
1706
- const quoteChangeNegative = quote.lastPriceDirection === 'down';
1707
-
1708
- setTimeout(() => this._dataFormat.quoteChangeDirection = { up: quoteChangePositive, down: quoteChangeNegative }, 0);
1709
-
1710
- this._dataFormat.quoteChangeNegative = is.number(this._dataActual.quoteChange) && this._dataActual.quoteChange < 0;
1711
- } else {
1712
- this._dataActual.currentPrice = null;
1713
- this._dataFormat.currentPrice = null;
1714
- }
1715
-
1716
- calculatePriceData(this, this._container.getForexQuotes(), sender, false);
1717
- });
1718
-
1719
- let newsBinding = Disposable.getEmpty();
1720
- let fundamentalBinding = Disposable.getEmpty();
1721
-
1722
- if (this._single) {
1723
- newsBinding = item.registerNewsExistsChangeHandler((exists, sender) => {
1724
- this._dataActual.newsExists = exists;
1725
- this._dataFormat.newsExists = exists;
1726
- });
1727
-
1728
- fundamentalBinding = item.registerFundamentalDataChangeHandler((data, sender) => {
1729
- this._dataFormat.fundamental = data;
1730
- });
1731
- }
1732
-
1733
- this._disposeStack.push(quoteBinding);
1734
- this._disposeStack.push(newsBinding);
1735
- this._disposeStack.push(fundamentalBinding);
1736
-
1737
- this._disposeStack.push(item.registerPositionItemDisposeHandler(() => {
1738
- quoteBinding.dispose();
1739
- newsBinding.dispose();
1740
- fundamentalBinding.dispose();
1741
-
1742
- array.remove(this._items, i => i === item);
1743
- array.remove(this._excludedItems, i => i === item);
1744
- array.remove(this._consideredItems, i => i === item);
1745
-
1746
- delete this._excludedItemMap[item.position.position];
1747
-
1748
- this.refresh();
1749
- }));
1680
+ bindItem.call(this, item);
1750
1681
  });
1751
1682
 
1752
1683
  this.refresh();
@@ -1864,6 +1795,10 @@ module.exports = (() => {
1864
1795
  * @param {PositionItem} item
1865
1796
  */
1866
1797
  addItem(item) {
1798
+ this._items.push(item);
1799
+ this._consideredItems.push(item);
1800
+
1801
+ bindItem.call(this, item);
1867
1802
 
1868
1803
  this.refresh();
1869
1804
  }
@@ -1997,6 +1932,79 @@ module.exports = (() => {
1997
1932
  }
1998
1933
  }
1999
1934
 
1935
+ function bindItem(item) {
1936
+ const quoteBinding = item.registerQuoteChangeHandler((quote, sender) => {
1937
+ if (this._single) {
1938
+ const precision = sender.position.instrument.currency.precision;
1939
+
1940
+ this._dataActual.currentPrice = quote.lastPrice;
1941
+ this._dataFormat.currentPrice = formatNumber(this._dataActual.currentPrice, precision);
1942
+
1943
+ this._dataActual.quoteLast = quote.previousPrice;
1944
+ this._dataActual.quoteOpen = quote.openPrice;
1945
+ this._dataActual.quoteHigh = quote.highPrice;
1946
+ this._dataActual.quoteLow = quote.lowPrice;
1947
+ this._dataActual.quoteChange = quote.priceChange;
1948
+ this._dataActual.quoteChangePercent = quote.percentChange;
1949
+ this._dataActual.quoteTime = quote.timeDisplay;
1950
+ this._dataActual.quoteVolume = quote.volume;
1951
+
1952
+ this._dataFormat.quoteLast = formatNumber(this._dataActual.quoteLast , precision);
1953
+ this._dataFormat.quoteOpen = formatNumber(this._dataActual.quoteOpen, precision);
1954
+ this._dataFormat.quoteHigh = formatNumber(this._dataActual.quoteHigh, precision);
1955
+ this._dataFormat.quoteLow = formatNumber(this._dataActual.quoteLow, precision);
1956
+ this._dataFormat.quoteChange = formatNumber(this._dataActual.quoteChange, precision);
1957
+ this._dataFormat.quoteChangePercent = formatPercent(new Decimal(this._dataActual.quoteChangePercent || 0), 2);
1958
+ this._dataFormat.quoteTime = this._dataActual.quoteTime;
1959
+ this._dataFormat.quoteVolume = formatNumber(this._dataActual.quoteVolume, 0);
1960
+
1961
+ const quoteChangePositive = quote.lastPriceDirection === 'up';
1962
+ const quoteChangeNegative = quote.lastPriceDirection === 'down';
1963
+
1964
+ setTimeout(() => this._dataFormat.quoteChangeDirection = { up: quoteChangePositive, down: quoteChangeNegative }, 0);
1965
+
1966
+ this._dataFormat.quoteChangeNegative = is.number(this._dataActual.quoteChange) && this._dataActual.quoteChange < 0;
1967
+ } else {
1968
+ this._dataActual.currentPrice = null;
1969
+ this._dataFormat.currentPrice = null;
1970
+ }
1971
+
1972
+ calculatePriceData(this, this._container.getForexQuotes(), sender, false);
1973
+ });
1974
+
1975
+ let newsBinding = Disposable.getEmpty();
1976
+ let fundamentalBinding = Disposable.getEmpty();
1977
+
1978
+ if (this._single) {
1979
+ newsBinding = item.registerNewsExistsChangeHandler((exists, sender) => {
1980
+ this._dataActual.newsExists = exists;
1981
+ this._dataFormat.newsExists = exists;
1982
+ });
1983
+
1984
+ fundamentalBinding = item.registerFundamentalDataChangeHandler((data, sender) => {
1985
+ this._dataFormat.fundamental = data;
1986
+ });
1987
+ }
1988
+
1989
+ this._disposeStack.push(quoteBinding);
1990
+ this._disposeStack.push(newsBinding);
1991
+ this._disposeStack.push(fundamentalBinding);
1992
+
1993
+ this._disposeStack.push(item.registerPositionItemDisposeHandler(() => {
1994
+ quoteBinding.dispose();
1995
+ newsBinding.dispose();
1996
+ fundamentalBinding.dispose();
1997
+
1998
+ array.remove(this._items, i => i === item);
1999
+ array.remove(this._excludedItems, i => i === item);
2000
+ array.remove(this._consideredItems, i => i === item);
2001
+
2002
+ delete this._excludedItemMap[item.position.position];
2003
+
2004
+ this.refresh();
2005
+ }));
2006
+ }
2007
+
2000
2008
  function formatNumber(number, precision) {
2001
2009
  if (is.number(number)) {
2002
2010
  return formatter.numberToString(number, precision, ',', false);