@barchart/portfolio-api-common 1.0.188 → 1.0.192
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.
- package/lib/processing/PositionContainer.js +11 -4
- package/lib/processing/PositionGroup.js +84 -71
- package/package.json +1 -1
- package/test/SpecRunner.js +95 -75
|
@@ -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.
|
|
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 {
|
|
@@ -486,7 +490,10 @@ module.exports = (() => {
|
|
|
486
490
|
getPositions(portfolio) {
|
|
487
491
|
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
488
492
|
|
|
489
|
-
return getPositionItemsForPortfolio(this._items, portfolio)
|
|
493
|
+
return getPositionItemsForPortfolio(this._items, portfolio)
|
|
494
|
+
.map((item) => {
|
|
495
|
+
return item.position;
|
|
496
|
+
});
|
|
490
497
|
}
|
|
491
498
|
|
|
492
499
|
/**
|
|
@@ -691,7 +698,7 @@ module.exports = (() => {
|
|
|
691
698
|
function getPositionItemsForPortfolio(items, portfolio) {
|
|
692
699
|
return items.reduce((positionItems, item) => {
|
|
693
700
|
if (item.position.portfolio === portfolio) {
|
|
694
|
-
positionItems.push(item
|
|
701
|
+
positionItems.push(item);
|
|
695
702
|
}
|
|
696
703
|
|
|
697
704
|
return positionItems;
|
|
@@ -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
|
-
|
|
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,8 +267,17 @@ 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();
|
|
276
|
+
|
|
277
|
+
if (this._excluded) {
|
|
278
|
+
this.setExcluded(false);
|
|
279
|
+
this.setExcluded(true);
|
|
280
|
+
}
|
|
341
281
|
}
|
|
342
282
|
|
|
343
283
|
/**
|
|
@@ -469,6 +409,79 @@ module.exports = (() => {
|
|
|
469
409
|
}
|
|
470
410
|
}
|
|
471
411
|
|
|
412
|
+
function bindItem(item) {
|
|
413
|
+
const quoteBinding = item.registerQuoteChangeHandler((quote, sender) => {
|
|
414
|
+
if (this._single) {
|
|
415
|
+
const precision = sender.position.instrument.currency.precision;
|
|
416
|
+
|
|
417
|
+
this._dataActual.currentPrice = quote.lastPrice;
|
|
418
|
+
this._dataFormat.currentPrice = formatNumber(this._dataActual.currentPrice, precision);
|
|
419
|
+
|
|
420
|
+
this._dataActual.quoteLast = quote.previousPrice;
|
|
421
|
+
this._dataActual.quoteOpen = quote.openPrice;
|
|
422
|
+
this._dataActual.quoteHigh = quote.highPrice;
|
|
423
|
+
this._dataActual.quoteLow = quote.lowPrice;
|
|
424
|
+
this._dataActual.quoteChange = quote.priceChange;
|
|
425
|
+
this._dataActual.quoteChangePercent = quote.percentChange;
|
|
426
|
+
this._dataActual.quoteTime = quote.timeDisplay;
|
|
427
|
+
this._dataActual.quoteVolume = quote.volume;
|
|
428
|
+
|
|
429
|
+
this._dataFormat.quoteLast = formatNumber(this._dataActual.quoteLast , precision);
|
|
430
|
+
this._dataFormat.quoteOpen = formatNumber(this._dataActual.quoteOpen, precision);
|
|
431
|
+
this._dataFormat.quoteHigh = formatNumber(this._dataActual.quoteHigh, precision);
|
|
432
|
+
this._dataFormat.quoteLow = formatNumber(this._dataActual.quoteLow, precision);
|
|
433
|
+
this._dataFormat.quoteChange = formatNumber(this._dataActual.quoteChange, precision);
|
|
434
|
+
this._dataFormat.quoteChangePercent = formatPercent(new Decimal(this._dataActual.quoteChangePercent || 0), 2);
|
|
435
|
+
this._dataFormat.quoteTime = this._dataActual.quoteTime;
|
|
436
|
+
this._dataFormat.quoteVolume = formatNumber(this._dataActual.quoteVolume, 0);
|
|
437
|
+
|
|
438
|
+
const quoteChangePositive = quote.lastPriceDirection === 'up';
|
|
439
|
+
const quoteChangeNegative = quote.lastPriceDirection === 'down';
|
|
440
|
+
|
|
441
|
+
setTimeout(() => this._dataFormat.quoteChangeDirection = { up: quoteChangePositive, down: quoteChangeNegative }, 0);
|
|
442
|
+
|
|
443
|
+
this._dataFormat.quoteChangeNegative = is.number(this._dataActual.quoteChange) && this._dataActual.quoteChange < 0;
|
|
444
|
+
} else {
|
|
445
|
+
this._dataActual.currentPrice = null;
|
|
446
|
+
this._dataFormat.currentPrice = null;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
calculatePriceData(this, this._container.getForexQuotes(), sender, false);
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
let newsBinding = Disposable.getEmpty();
|
|
453
|
+
let fundamentalBinding = Disposable.getEmpty();
|
|
454
|
+
|
|
455
|
+
if (this._single) {
|
|
456
|
+
newsBinding = item.registerNewsExistsChangeHandler((exists, sender) => {
|
|
457
|
+
this._dataActual.newsExists = exists;
|
|
458
|
+
this._dataFormat.newsExists = exists;
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
fundamentalBinding = item.registerFundamentalDataChangeHandler((data, sender) => {
|
|
462
|
+
this._dataFormat.fundamental = data;
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
this._disposeStack.push(quoteBinding);
|
|
467
|
+
this._disposeStack.push(newsBinding);
|
|
468
|
+
this._disposeStack.push(fundamentalBinding);
|
|
469
|
+
|
|
470
|
+
this._disposeStack.push(item.registerPositionItemDisposeHandler(() => {
|
|
471
|
+
quoteBinding.dispose();
|
|
472
|
+
newsBinding.dispose();
|
|
473
|
+
fundamentalBinding.dispose();
|
|
474
|
+
|
|
475
|
+
array.remove(this._items, i => i === item);
|
|
476
|
+
array.remove(this._excludedItems, i => i === item);
|
|
477
|
+
array.remove(this._consideredItems, i => i === item);
|
|
478
|
+
|
|
479
|
+
delete this._excludedItemMap[item.position.position];
|
|
480
|
+
|
|
481
|
+
this.refresh();
|
|
482
|
+
}));
|
|
483
|
+
}
|
|
484
|
+
|
|
472
485
|
function formatNumber(number, precision) {
|
|
473
486
|
if (is.number(number)) {
|
|
474
487
|
return formatter.numberToString(number, precision, ',', false);
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -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.
|
|
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 {
|
|
@@ -1202,7 +1206,10 @@ module.exports = (() => {
|
|
|
1202
1206
|
getPositions(portfolio) {
|
|
1203
1207
|
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
1204
1208
|
|
|
1205
|
-
return getPositionItemsForPortfolio(this._items, portfolio)
|
|
1209
|
+
return getPositionItemsForPortfolio(this._items, portfolio)
|
|
1210
|
+
.map((item) => {
|
|
1211
|
+
return item.position;
|
|
1212
|
+
});
|
|
1206
1213
|
}
|
|
1207
1214
|
|
|
1208
1215
|
/**
|
|
@@ -1407,7 +1414,7 @@ module.exports = (() => {
|
|
|
1407
1414
|
function getPositionItemsForPortfolio(items, portfolio) {
|
|
1408
1415
|
return items.reduce((positionItems, item) => {
|
|
1409
1416
|
if (item.position.portfolio === portfolio) {
|
|
1410
|
-
positionItems.push(item
|
|
1417
|
+
positionItems.push(item);
|
|
1411
1418
|
}
|
|
1412
1419
|
|
|
1413
1420
|
return positionItems;
|
|
@@ -1588,7 +1595,7 @@ module.exports = (() => {
|
|
|
1588
1595
|
|
|
1589
1596
|
this._excludedItems = [ ];
|
|
1590
1597
|
this._excludedItemMap = { };
|
|
1591
|
-
this._consideredItems = this._items;
|
|
1598
|
+
this._consideredItems = this._items.slice(0);
|
|
1592
1599
|
|
|
1593
1600
|
this._dataFormat = { };
|
|
1594
1601
|
this._dataActual = { };
|
|
@@ -1677,76 +1684,7 @@ module.exports = (() => {
|
|
|
1677
1684
|
this._dataFormat.portfolioType = null;
|
|
1678
1685
|
|
|
1679
1686
|
this._items.forEach((item) => {
|
|
1680
|
-
|
|
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
|
-
}));
|
|
1687
|
+
bindItem.call(this, item);
|
|
1750
1688
|
});
|
|
1751
1689
|
|
|
1752
1690
|
this.refresh();
|
|
@@ -1864,8 +1802,17 @@ module.exports = (() => {
|
|
|
1864
1802
|
* @param {PositionItem} item
|
|
1865
1803
|
*/
|
|
1866
1804
|
addItem(item) {
|
|
1805
|
+
this._items.push(item);
|
|
1806
|
+
this._consideredItems.push(item);
|
|
1807
|
+
|
|
1808
|
+
bindItem.call(this, item);
|
|
1867
1809
|
|
|
1868
1810
|
this.refresh();
|
|
1811
|
+
|
|
1812
|
+
if (this._excluded) {
|
|
1813
|
+
this.setExcluded(false);
|
|
1814
|
+
this.setExcluded(true);
|
|
1815
|
+
}
|
|
1869
1816
|
}
|
|
1870
1817
|
|
|
1871
1818
|
/**
|
|
@@ -1997,6 +1944,79 @@ module.exports = (() => {
|
|
|
1997
1944
|
}
|
|
1998
1945
|
}
|
|
1999
1946
|
|
|
1947
|
+
function bindItem(item) {
|
|
1948
|
+
const quoteBinding = item.registerQuoteChangeHandler((quote, sender) => {
|
|
1949
|
+
if (this._single) {
|
|
1950
|
+
const precision = sender.position.instrument.currency.precision;
|
|
1951
|
+
|
|
1952
|
+
this._dataActual.currentPrice = quote.lastPrice;
|
|
1953
|
+
this._dataFormat.currentPrice = formatNumber(this._dataActual.currentPrice, precision);
|
|
1954
|
+
|
|
1955
|
+
this._dataActual.quoteLast = quote.previousPrice;
|
|
1956
|
+
this._dataActual.quoteOpen = quote.openPrice;
|
|
1957
|
+
this._dataActual.quoteHigh = quote.highPrice;
|
|
1958
|
+
this._dataActual.quoteLow = quote.lowPrice;
|
|
1959
|
+
this._dataActual.quoteChange = quote.priceChange;
|
|
1960
|
+
this._dataActual.quoteChangePercent = quote.percentChange;
|
|
1961
|
+
this._dataActual.quoteTime = quote.timeDisplay;
|
|
1962
|
+
this._dataActual.quoteVolume = quote.volume;
|
|
1963
|
+
|
|
1964
|
+
this._dataFormat.quoteLast = formatNumber(this._dataActual.quoteLast , precision);
|
|
1965
|
+
this._dataFormat.quoteOpen = formatNumber(this._dataActual.quoteOpen, precision);
|
|
1966
|
+
this._dataFormat.quoteHigh = formatNumber(this._dataActual.quoteHigh, precision);
|
|
1967
|
+
this._dataFormat.quoteLow = formatNumber(this._dataActual.quoteLow, precision);
|
|
1968
|
+
this._dataFormat.quoteChange = formatNumber(this._dataActual.quoteChange, precision);
|
|
1969
|
+
this._dataFormat.quoteChangePercent = formatPercent(new Decimal(this._dataActual.quoteChangePercent || 0), 2);
|
|
1970
|
+
this._dataFormat.quoteTime = this._dataActual.quoteTime;
|
|
1971
|
+
this._dataFormat.quoteVolume = formatNumber(this._dataActual.quoteVolume, 0);
|
|
1972
|
+
|
|
1973
|
+
const quoteChangePositive = quote.lastPriceDirection === 'up';
|
|
1974
|
+
const quoteChangeNegative = quote.lastPriceDirection === 'down';
|
|
1975
|
+
|
|
1976
|
+
setTimeout(() => this._dataFormat.quoteChangeDirection = { up: quoteChangePositive, down: quoteChangeNegative }, 0);
|
|
1977
|
+
|
|
1978
|
+
this._dataFormat.quoteChangeNegative = is.number(this._dataActual.quoteChange) && this._dataActual.quoteChange < 0;
|
|
1979
|
+
} else {
|
|
1980
|
+
this._dataActual.currentPrice = null;
|
|
1981
|
+
this._dataFormat.currentPrice = null;
|
|
1982
|
+
}
|
|
1983
|
+
|
|
1984
|
+
calculatePriceData(this, this._container.getForexQuotes(), sender, false);
|
|
1985
|
+
});
|
|
1986
|
+
|
|
1987
|
+
let newsBinding = Disposable.getEmpty();
|
|
1988
|
+
let fundamentalBinding = Disposable.getEmpty();
|
|
1989
|
+
|
|
1990
|
+
if (this._single) {
|
|
1991
|
+
newsBinding = item.registerNewsExistsChangeHandler((exists, sender) => {
|
|
1992
|
+
this._dataActual.newsExists = exists;
|
|
1993
|
+
this._dataFormat.newsExists = exists;
|
|
1994
|
+
});
|
|
1995
|
+
|
|
1996
|
+
fundamentalBinding = item.registerFundamentalDataChangeHandler((data, sender) => {
|
|
1997
|
+
this._dataFormat.fundamental = data;
|
|
1998
|
+
});
|
|
1999
|
+
}
|
|
2000
|
+
|
|
2001
|
+
this._disposeStack.push(quoteBinding);
|
|
2002
|
+
this._disposeStack.push(newsBinding);
|
|
2003
|
+
this._disposeStack.push(fundamentalBinding);
|
|
2004
|
+
|
|
2005
|
+
this._disposeStack.push(item.registerPositionItemDisposeHandler(() => {
|
|
2006
|
+
quoteBinding.dispose();
|
|
2007
|
+
newsBinding.dispose();
|
|
2008
|
+
fundamentalBinding.dispose();
|
|
2009
|
+
|
|
2010
|
+
array.remove(this._items, i => i === item);
|
|
2011
|
+
array.remove(this._excludedItems, i => i === item);
|
|
2012
|
+
array.remove(this._consideredItems, i => i === item);
|
|
2013
|
+
|
|
2014
|
+
delete this._excludedItemMap[item.position.position];
|
|
2015
|
+
|
|
2016
|
+
this.refresh();
|
|
2017
|
+
}));
|
|
2018
|
+
}
|
|
2019
|
+
|
|
2000
2020
|
function formatNumber(number, precision) {
|
|
2001
2021
|
if (is.number(number)) {
|
|
2002
2022
|
return formatter.numberToString(number, precision, ',', false);
|