@barchart/portfolio-api-common 1.0.186 → 1.0.190

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.
@@ -248,7 +248,7 @@ module.exports = (() => {
248
248
  addSummaryPrevious(this._summariesPrevious, summary, this._previousSummaryFrame, this._previousSummaryRanges);
249
249
  });
250
250
 
251
- const item = createPositionItem(position);
251
+ const item = createPositionItem.call(this, position);
252
252
 
253
253
  addBarchartSymbol(this._symbols, item);
254
254
  addDisplaySymbol(this._symbolsDisplay, item);
@@ -256,19 +256,23 @@ module.exports = (() => {
256
256
  this._items.push(item);
257
257
 
258
258
  const createGroupOrInjectItem = (parentTree, treeDefinition, levelDefinitions) => {
259
+ if (levelDefinitions.length === 0) {
260
+ return;
261
+ }
262
+
259
263
  const levelDefinition = levelDefinitions[0];
260
264
  const levelKey = levelDefinition.keySelector(item);
261
265
 
262
266
  let groupTree;
263
267
 
264
268
  if (parentTree.getChildren().length > 0) {
265
- groupTree = parentTree.getChildren().findChild(childGroup => childGroup.key === levelKey) || null;
269
+ groupTree = parentTree.findChild(childGroup => childGroup.key === levelKey) || null;
266
270
  } else {
267
271
  groupTree = null;
268
272
  }
269
273
 
270
274
  if (groupTree !== null) {
271
- groupTree.addItem(item);
275
+ groupTree.getValue().addItem(item);
272
276
 
273
277
  createGroupOrInjectItem(groupTree, treeDefinition, array.dropLeft(levelDefinitions));
274
278
  } 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.186",
3
+ "version": "1.0.190",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -964,7 +964,7 @@ module.exports = (() => {
964
964
  addSummaryPrevious(this._summariesPrevious, summary, this._previousSummaryFrame, this._previousSummaryRanges);
965
965
  });
966
966
 
967
- const item = createPositionItem(position);
967
+ const item = createPositionItem.call(this, position);
968
968
 
969
969
  addBarchartSymbol(this._symbols, item);
970
970
  addDisplaySymbol(this._symbolsDisplay, item);
@@ -972,19 +972,23 @@ module.exports = (() => {
972
972
  this._items.push(item);
973
973
 
974
974
  const createGroupOrInjectItem = (parentTree, treeDefinition, levelDefinitions) => {
975
+ if (levelDefinitions.length === 0) {
976
+ return;
977
+ }
978
+
975
979
  const levelDefinition = levelDefinitions[0];
976
980
  const levelKey = levelDefinition.keySelector(item);
977
981
 
978
982
  let groupTree;
979
983
 
980
984
  if (parentTree.getChildren().length > 0) {
981
- groupTree = parentTree.getChildren().findChild(childGroup => childGroup.key === levelKey) || null;
985
+ groupTree = parentTree.findChild(childGroup => childGroup.key === levelKey) || null;
982
986
  } else {
983
987
  groupTree = null;
984
988
  }
985
989
 
986
990
  if (groupTree !== null) {
987
- groupTree.addItem(item);
991
+ groupTree.getValue().addItem(item);
988
992
 
989
993
  createGroupOrInjectItem(groupTree, treeDefinition, array.dropLeft(levelDefinitions));
990
994
  } else {
@@ -1588,7 +1592,7 @@ module.exports = (() => {
1588
1592
 
1589
1593
  this._excludedItems = [ ];
1590
1594
  this._excludedItemMap = { };
1591
- this._consideredItems = this._items;
1595
+ this._consideredItems = this._items.slice(0);
1592
1596
 
1593
1597
  this._dataFormat = { };
1594
1598
  this._dataActual = { };
@@ -1677,76 +1681,7 @@ module.exports = (() => {
1677
1681
  this._dataFormat.portfolioType = null;
1678
1682
 
1679
1683
  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
- }));
1684
+ bindItem.call(this, item);
1750
1685
  });
1751
1686
 
1752
1687
  this.refresh();
@@ -1864,6 +1799,10 @@ module.exports = (() => {
1864
1799
  * @param {PositionItem} item
1865
1800
  */
1866
1801
  addItem(item) {
1802
+ this._items.push(item);
1803
+ this._consideredItems.push(item);
1804
+
1805
+ bindItem.call(this, item);
1867
1806
 
1868
1807
  this.refresh();
1869
1808
  }
@@ -1997,6 +1936,79 @@ module.exports = (() => {
1997
1936
  }
1998
1937
  }
1999
1938
 
1939
+ function bindItem(item) {
1940
+ const quoteBinding = item.registerQuoteChangeHandler((quote, sender) => {
1941
+ if (this._single) {
1942
+ const precision = sender.position.instrument.currency.precision;
1943
+
1944
+ this._dataActual.currentPrice = quote.lastPrice;
1945
+ this._dataFormat.currentPrice = formatNumber(this._dataActual.currentPrice, precision);
1946
+
1947
+ this._dataActual.quoteLast = quote.previousPrice;
1948
+ this._dataActual.quoteOpen = quote.openPrice;
1949
+ this._dataActual.quoteHigh = quote.highPrice;
1950
+ this._dataActual.quoteLow = quote.lowPrice;
1951
+ this._dataActual.quoteChange = quote.priceChange;
1952
+ this._dataActual.quoteChangePercent = quote.percentChange;
1953
+ this._dataActual.quoteTime = quote.timeDisplay;
1954
+ this._dataActual.quoteVolume = quote.volume;
1955
+
1956
+ this._dataFormat.quoteLast = formatNumber(this._dataActual.quoteLast , precision);
1957
+ this._dataFormat.quoteOpen = formatNumber(this._dataActual.quoteOpen, precision);
1958
+ this._dataFormat.quoteHigh = formatNumber(this._dataActual.quoteHigh, precision);
1959
+ this._dataFormat.quoteLow = formatNumber(this._dataActual.quoteLow, precision);
1960
+ this._dataFormat.quoteChange = formatNumber(this._dataActual.quoteChange, precision);
1961
+ this._dataFormat.quoteChangePercent = formatPercent(new Decimal(this._dataActual.quoteChangePercent || 0), 2);
1962
+ this._dataFormat.quoteTime = this._dataActual.quoteTime;
1963
+ this._dataFormat.quoteVolume = formatNumber(this._dataActual.quoteVolume, 0);
1964
+
1965
+ const quoteChangePositive = quote.lastPriceDirection === 'up';
1966
+ const quoteChangeNegative = quote.lastPriceDirection === 'down';
1967
+
1968
+ setTimeout(() => this._dataFormat.quoteChangeDirection = { up: quoteChangePositive, down: quoteChangeNegative }, 0);
1969
+
1970
+ this._dataFormat.quoteChangeNegative = is.number(this._dataActual.quoteChange) && this._dataActual.quoteChange < 0;
1971
+ } else {
1972
+ this._dataActual.currentPrice = null;
1973
+ this._dataFormat.currentPrice = null;
1974
+ }
1975
+
1976
+ calculatePriceData(this, this._container.getForexQuotes(), sender, false);
1977
+ });
1978
+
1979
+ let newsBinding = Disposable.getEmpty();
1980
+ let fundamentalBinding = Disposable.getEmpty();
1981
+
1982
+ if (this._single) {
1983
+ newsBinding = item.registerNewsExistsChangeHandler((exists, sender) => {
1984
+ this._dataActual.newsExists = exists;
1985
+ this._dataFormat.newsExists = exists;
1986
+ });
1987
+
1988
+ fundamentalBinding = item.registerFundamentalDataChangeHandler((data, sender) => {
1989
+ this._dataFormat.fundamental = data;
1990
+ });
1991
+ }
1992
+
1993
+ this._disposeStack.push(quoteBinding);
1994
+ this._disposeStack.push(newsBinding);
1995
+ this._disposeStack.push(fundamentalBinding);
1996
+
1997
+ this._disposeStack.push(item.registerPositionItemDisposeHandler(() => {
1998
+ quoteBinding.dispose();
1999
+ newsBinding.dispose();
2000
+ fundamentalBinding.dispose();
2001
+
2002
+ array.remove(this._items, i => i === item);
2003
+ array.remove(this._excludedItems, i => i === item);
2004
+ array.remove(this._consideredItems, i => i === item);
2005
+
2006
+ delete this._excludedItemMap[item.position.position];
2007
+
2008
+ this.refresh();
2009
+ }));
2010
+ }
2011
+
2000
2012
  function formatNumber(number, precision) {
2001
2013
  if (is.number(number)) {
2002
2014
  return formatter.numberToString(number, precision, ',', false);