@barchart/portfolio-api-common 1.0.207 → 1.0.211
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.
|
@@ -142,6 +142,8 @@ module.exports = (() => {
|
|
|
142
142
|
|
|
143
143
|
return map;
|
|
144
144
|
}, { });
|
|
145
|
+
|
|
146
|
+
Object.keys(this._portfolios).forEach(key => updateEmptyPortfolioGroups.call(this, this._portfolios[key]));
|
|
145
147
|
}
|
|
146
148
|
|
|
147
149
|
/**
|
|
@@ -203,6 +205,8 @@ module.exports = (() => {
|
|
|
203
205
|
});
|
|
204
206
|
}
|
|
205
207
|
});
|
|
208
|
+
|
|
209
|
+
updateEmptyPortfolioGroups.call(this, portfolio);
|
|
206
210
|
}
|
|
207
211
|
}
|
|
208
212
|
|
|
@@ -218,6 +222,8 @@ module.exports = (() => {
|
|
|
218
222
|
|
|
219
223
|
this.startTransaction(() => {
|
|
220
224
|
getPositionItemsForPortfolio(this._items, portfolio.portfolio).forEach(item => item.updatePortfolio(portfolio));
|
|
225
|
+
|
|
226
|
+
updateEmptyPortfolioGroups.call(this, portfolio);
|
|
221
227
|
});
|
|
222
228
|
}
|
|
223
229
|
|
|
@@ -754,6 +760,17 @@ module.exports = (() => {
|
|
|
754
760
|
});
|
|
755
761
|
}
|
|
756
762
|
|
|
763
|
+
|
|
764
|
+
function updateEmptyPortfolioGroups(portfolio) {
|
|
765
|
+
Object.keys(this._trees).forEach((key) => {
|
|
766
|
+
this._trees[key].walk((group) => {
|
|
767
|
+
if (group.definition.type === PositionLevelType.PORTFOLIO && group.key === PositionLevelDefinition.getKeyForPortfolioGroup(portfolio) && group.getIsEmpty()) {
|
|
768
|
+
group.updatePortfolio(portfolio);
|
|
769
|
+
}
|
|
770
|
+
}, true, false);
|
|
771
|
+
});
|
|
772
|
+
}
|
|
773
|
+
|
|
757
774
|
function getPositionItemsForPortfolio(items, portfolio) {
|
|
758
775
|
return items.reduce((positionItems, item) => {
|
|
759
776
|
if (item.position.portfolio === portfolio) {
|
|
@@ -11,6 +11,9 @@ const array = require('@barchart/common-js/lang/array'),
|
|
|
11
11
|
|
|
12
12
|
const InstrumentType = require('./../data/InstrumentType');
|
|
13
13
|
|
|
14
|
+
const PositionLevelDefinition = require('./definitions/PositionLevelDefinition'),
|
|
15
|
+
PositionLevelType = require('./definitions/PositionLevelType');
|
|
16
|
+
|
|
14
17
|
module.exports = (() => {
|
|
15
18
|
'use strict';
|
|
16
19
|
|
|
@@ -354,6 +357,36 @@ module.exports = (() => {
|
|
|
354
357
|
}
|
|
355
358
|
}
|
|
356
359
|
|
|
360
|
+
/**
|
|
361
|
+
* Updates the portfolio data. For example, a portfolio's name might change. This
|
|
362
|
+
* function only affects {@link PositionLevelType.PORTFOLIO} groups.
|
|
363
|
+
*
|
|
364
|
+
* @public
|
|
365
|
+
* @param {Object} portfolio
|
|
366
|
+
*/
|
|
367
|
+
updatePortfolio(portfolio) {
|
|
368
|
+
if (this._definition.type !== PositionLevelType.PORTFOLIO || this._key !== PositionLevelDefinition.getKeyForPortfolioGroup(portfolio) || !this.getIsEmpty()) {
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const descriptionSelector = this._definition.descriptionSelector;
|
|
373
|
+
|
|
374
|
+
this._description = PositionLevelDefinition.getDescriptionForPortfolioGroup(portfolio);
|
|
375
|
+
|
|
376
|
+
this._dataActual.description = this._description;
|
|
377
|
+
this._dataFormat.description = this._description;
|
|
378
|
+
|
|
379
|
+
let portfolioType;
|
|
380
|
+
|
|
381
|
+
if (portfolio.miscellany && portfolio.miscellany.data.type && portfolio.miscellany.data.type.value) {
|
|
382
|
+
portfolioType = portfolio.miscellany.data.type.value;
|
|
383
|
+
} else {
|
|
384
|
+
portfolioType = null;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
this._dataFormat.portfolioType = portfolioType;
|
|
388
|
+
}
|
|
389
|
+
|
|
357
390
|
/**
|
|
358
391
|
* Causes all aggregated data to be recalculated (assuming the group has not
|
|
359
392
|
* been suspended).
|
|
@@ -381,6 +414,16 @@ module.exports = (() => {
|
|
|
381
414
|
calculateMarketPercent(this, this._container.getForexQuotes(), true);
|
|
382
415
|
}
|
|
383
416
|
|
|
417
|
+
/**
|
|
418
|
+
* Indicates if the group contains any items.
|
|
419
|
+
*
|
|
420
|
+
* @public
|
|
421
|
+
* @returns {boolean}
|
|
422
|
+
*/
|
|
423
|
+
getIsEmpty() {
|
|
424
|
+
return this._items.length === 0;
|
|
425
|
+
}
|
|
426
|
+
|
|
384
427
|
/**
|
|
385
428
|
* Adds an observer for change in the market percentage of the group.
|
|
386
429
|
*
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -899,6 +899,8 @@ module.exports = (() => {
|
|
|
899
899
|
|
|
900
900
|
return map;
|
|
901
901
|
}, { });
|
|
902
|
+
|
|
903
|
+
Object.keys(this._portfolios).forEach(key => updateEmptyPortfolioGroups.call(this, this._portfolios[key]));
|
|
902
904
|
}
|
|
903
905
|
|
|
904
906
|
/**
|
|
@@ -960,6 +962,8 @@ module.exports = (() => {
|
|
|
960
962
|
});
|
|
961
963
|
}
|
|
962
964
|
});
|
|
965
|
+
|
|
966
|
+
updateEmptyPortfolioGroups.call(this, portfolio);
|
|
963
967
|
}
|
|
964
968
|
}
|
|
965
969
|
|
|
@@ -975,6 +979,8 @@ module.exports = (() => {
|
|
|
975
979
|
|
|
976
980
|
this.startTransaction(() => {
|
|
977
981
|
getPositionItemsForPortfolio(this._items, portfolio.portfolio).forEach(item => item.updatePortfolio(portfolio));
|
|
982
|
+
|
|
983
|
+
updateEmptyPortfolioGroups.call(this, portfolio);
|
|
978
984
|
});
|
|
979
985
|
}
|
|
980
986
|
|
|
@@ -1511,6 +1517,17 @@ module.exports = (() => {
|
|
|
1511
1517
|
});
|
|
1512
1518
|
}
|
|
1513
1519
|
|
|
1520
|
+
|
|
1521
|
+
function updateEmptyPortfolioGroups(portfolio) {
|
|
1522
|
+
Object.keys(this._trees).forEach((key) => {
|
|
1523
|
+
this._trees[key].walk((group) => {
|
|
1524
|
+
if (group.definition.type === PositionLevelType.PORTFOLIO && group.key === PositionLevelDefinition.getKeyForPortfolioGroup(portfolio) && group.getIsEmpty()) {
|
|
1525
|
+
group.updatePortfolio(portfolio);
|
|
1526
|
+
}
|
|
1527
|
+
}, true, false);
|
|
1528
|
+
});
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1514
1531
|
function getPositionItemsForPortfolio(items, portfolio) {
|
|
1515
1532
|
return items.reduce((positionItems, item) => {
|
|
1516
1533
|
if (item.position.portfolio === portfolio) {
|
|
@@ -1646,6 +1663,9 @@ const array = require('@barchart/common-js/lang/array'),
|
|
|
1646
1663
|
|
|
1647
1664
|
const InstrumentType = require('./../data/InstrumentType');
|
|
1648
1665
|
|
|
1666
|
+
const PositionLevelDefinition = require('./definitions/PositionLevelDefinition'),
|
|
1667
|
+
PositionLevelType = require('./definitions/PositionLevelType');
|
|
1668
|
+
|
|
1649
1669
|
module.exports = (() => {
|
|
1650
1670
|
'use strict';
|
|
1651
1671
|
|
|
@@ -1989,6 +2009,36 @@ module.exports = (() => {
|
|
|
1989
2009
|
}
|
|
1990
2010
|
}
|
|
1991
2011
|
|
|
2012
|
+
/**
|
|
2013
|
+
* Updates the portfolio data. For example, a portfolio's name might change. This
|
|
2014
|
+
* function only affects {@link PositionLevelType.PORTFOLIO} groups.
|
|
2015
|
+
*
|
|
2016
|
+
* @public
|
|
2017
|
+
* @param {Object} portfolio
|
|
2018
|
+
*/
|
|
2019
|
+
updatePortfolio(portfolio) {
|
|
2020
|
+
if (this._definition.type !== PositionLevelType.PORTFOLIO || this._key !== PositionLevelDefinition.getKeyForPortfolioGroup(portfolio) || !this.getIsEmpty()) {
|
|
2021
|
+
return;
|
|
2022
|
+
}
|
|
2023
|
+
|
|
2024
|
+
const descriptionSelector = this._definition.descriptionSelector;
|
|
2025
|
+
|
|
2026
|
+
this._description = PositionLevelDefinition.getDescriptionForPortfolioGroup(portfolio);
|
|
2027
|
+
|
|
2028
|
+
this._dataActual.description = this._description;
|
|
2029
|
+
this._dataFormat.description = this._description;
|
|
2030
|
+
|
|
2031
|
+
let portfolioType;
|
|
2032
|
+
|
|
2033
|
+
if (portfolio.miscellany && portfolio.miscellany.data.type && portfolio.miscellany.data.type.value) {
|
|
2034
|
+
portfolioType = portfolio.miscellany.data.type.value;
|
|
2035
|
+
} else {
|
|
2036
|
+
portfolioType = null;
|
|
2037
|
+
}
|
|
2038
|
+
|
|
2039
|
+
this._dataFormat.portfolioType = portfolioType;
|
|
2040
|
+
}
|
|
2041
|
+
|
|
1992
2042
|
/**
|
|
1993
2043
|
* Causes all aggregated data to be recalculated (assuming the group has not
|
|
1994
2044
|
* been suspended).
|
|
@@ -2016,6 +2066,16 @@ module.exports = (() => {
|
|
|
2016
2066
|
calculateMarketPercent(this, this._container.getForexQuotes(), true);
|
|
2017
2067
|
}
|
|
2018
2068
|
|
|
2069
|
+
/**
|
|
2070
|
+
* Indicates if the group contains any items.
|
|
2071
|
+
*
|
|
2072
|
+
* @public
|
|
2073
|
+
* @returns {boolean}
|
|
2074
|
+
*/
|
|
2075
|
+
getIsEmpty() {
|
|
2076
|
+
return this._items.length === 0;
|
|
2077
|
+
}
|
|
2078
|
+
|
|
2019
2079
|
/**
|
|
2020
2080
|
* Adds an observer for change in the market percentage of the group.
|
|
2021
2081
|
*
|
|
@@ -2400,7 +2460,7 @@ module.exports = (() => {
|
|
|
2400
2460
|
return PositionGroup;
|
|
2401
2461
|
})();
|
|
2402
2462
|
|
|
2403
|
-
},{"./../data/InstrumentType":1,"@barchart/common-js/collections/specialized/DisposableStack":14,"@barchart/common-js/lang/Currency":15,"@barchart/common-js/lang/Decimal":17,"@barchart/common-js/lang/Disposable":18,"@barchart/common-js/lang/Rate":20,"@barchart/common-js/lang/array":21,"@barchart/common-js/lang/assert":22,"@barchart/common-js/lang/formatter":23,"@barchart/common-js/lang/is":24,"@barchart/common-js/messaging/Event":26}],6:[function(require,module,exports){
|
|
2463
|
+
},{"./../data/InstrumentType":1,"./definitions/PositionLevelDefinition":7,"./definitions/PositionLevelType":8,"@barchart/common-js/collections/specialized/DisposableStack":14,"@barchart/common-js/lang/Currency":15,"@barchart/common-js/lang/Decimal":17,"@barchart/common-js/lang/Disposable":18,"@barchart/common-js/lang/Rate":20,"@barchart/common-js/lang/array":21,"@barchart/common-js/lang/assert":22,"@barchart/common-js/lang/formatter":23,"@barchart/common-js/lang/is":24,"@barchart/common-js/messaging/Event":26}],6:[function(require,module,exports){
|
|
2404
2464
|
const array = require('@barchart/common-js/lang/array'),
|
|
2405
2465
|
assert = require('@barchart/common-js/lang/assert'),
|
|
2406
2466
|
Currency = require('@barchart/common-js/lang/Currency'),
|