@barchart/portfolio-api-common 1.0.158 → 1.0.162
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.
|
@@ -292,6 +292,22 @@ module.exports = (() => {
|
|
|
292
292
|
}, { });
|
|
293
293
|
}
|
|
294
294
|
|
|
295
|
+
addPortfolio(portfolio) {
|
|
296
|
+
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
removePortfolio(portfolio) {
|
|
300
|
+
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
mutatePosition(position, summary) {
|
|
304
|
+
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
removePosition(position) {
|
|
308
|
+
|
|
309
|
+
}
|
|
310
|
+
|
|
295
311
|
/**
|
|
296
312
|
* Returns a distinct list of all symbols used by the positions
|
|
297
313
|
* within the container.
|
|
@@ -123,7 +123,6 @@ module.exports = (() => {
|
|
|
123
123
|
this._dataActual.summaryTotalPrevious = null;
|
|
124
124
|
this._dataActual.cashTotal = null;
|
|
125
125
|
|
|
126
|
-
this._dataFormat.type = null;
|
|
127
126
|
this._dataFormat.currentPrice = null;
|
|
128
127
|
this._dataFormat.previousPrice = null;
|
|
129
128
|
this._dataFormat.basis = null;
|
|
@@ -144,6 +143,7 @@ module.exports = (() => {
|
|
|
144
143
|
this._dataFormat.summaryTotalPrevious = null;
|
|
145
144
|
this._dataFormat.summaryTotalPreviousNegative = false;
|
|
146
145
|
this._dataFormat.cashTotal = null;
|
|
146
|
+
this._dataFormat.portfolioType = null;
|
|
147
147
|
|
|
148
148
|
this._items.forEach((item) => {
|
|
149
149
|
this._disposeStack.push(item.registerQuoteChangeHandler((quote, sender) => {
|
|
@@ -171,8 +171,8 @@ module.exports = (() => {
|
|
|
171
171
|
this._dataFormat.quoteTime = this._dataActual.quoteTime;
|
|
172
172
|
this._dataFormat.quoteVolume = formatNumber(this._dataActual.quoteVolume, 0);
|
|
173
173
|
|
|
174
|
-
const quoteChangePositive =
|
|
175
|
-
const quoteChangeNegative =
|
|
174
|
+
const quoteChangePositive = quote.lastPriceDirection === 'up';
|
|
175
|
+
const quoteChangeNegative = quote.lastPriceDirection === 'down';
|
|
176
176
|
|
|
177
177
|
setTimeout(() => this._dataFormat.quoteChangeDirection = { up: quoteChangePositive, down: quoteChangeNegative }, 0);
|
|
178
178
|
this._dataFormat.quoteChangeNegative = quoteChangeNegative;
|
|
@@ -294,6 +294,16 @@ module.exports = (() => {
|
|
|
294
294
|
return this._excluded;
|
|
295
295
|
}
|
|
296
296
|
|
|
297
|
+
addItems(items) {
|
|
298
|
+
|
|
299
|
+
this.refresh();
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
removeItems(items) {
|
|
303
|
+
|
|
304
|
+
this.refresh();
|
|
305
|
+
}
|
|
306
|
+
|
|
297
307
|
/**
|
|
298
308
|
* Sets the list of items which are excluded from group aggregation calculations.
|
|
299
309
|
*
|
|
@@ -509,14 +519,28 @@ module.exports = (() => {
|
|
|
509
519
|
if (group.single) {
|
|
510
520
|
const item = group._items[0];
|
|
511
521
|
|
|
512
|
-
format.type = item.data.type || null;
|
|
513
|
-
|
|
514
522
|
actual.quantity = item.position.snapshot.open;
|
|
515
523
|
actual.basisPrice = item.data.basisPrice;
|
|
516
524
|
|
|
517
525
|
format.quantity = formatDecimal(actual.quantity, 2);
|
|
518
526
|
format.basisPrice = formatCurrency(actual.basisPrice, currency);
|
|
519
527
|
}
|
|
528
|
+
|
|
529
|
+
const groupItems = group._items;
|
|
530
|
+
|
|
531
|
+
let portfolioType = null;
|
|
532
|
+
|
|
533
|
+
if (groupItems.length > 0) {
|
|
534
|
+
const portfolio = groupItems[0].portfolio;
|
|
535
|
+
|
|
536
|
+
if (groupItems.every(i => i.portfolio.portfolio === portfolio.portfolio)) {
|
|
537
|
+
if (portfolio.miscellany && portfolio.miscellany.data.type && portfolio.miscellany.data.type.value) {
|
|
538
|
+
portfolioType = portfolio.miscellany.data.type.value;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
format.portfolioType = portfolioType;
|
|
520
544
|
}
|
|
521
545
|
|
|
522
546
|
function calculatePriceData(group, rates, item, forceRefresh) {
|
|
@@ -61,8 +61,6 @@ module.exports = (() => {
|
|
|
61
61
|
this._data.newsExists = false;
|
|
62
62
|
this._data.fundamental = { };
|
|
63
63
|
|
|
64
|
-
this._data.type = null;
|
|
65
|
-
|
|
66
64
|
calculateStaticData(this);
|
|
67
65
|
calculatePriceData(this, null);
|
|
68
66
|
|
|
@@ -237,10 +235,6 @@ module.exports = (() => {
|
|
|
237
235
|
|
|
238
236
|
const data = item._data;
|
|
239
237
|
|
|
240
|
-
if (portfolio.miscellany && portfolio.miscellany.data.type && portfolio.miscellany.data.type.value) {
|
|
241
|
-
data.type = portfolio.miscellany.data.type.value;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
238
|
data.previousPrice = position.previous || null;
|
|
245
239
|
|
|
246
240
|
let basis;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
2
|
+
Currency = require('@barchart/common-js/lang/Currency'),
|
|
2
3
|
is = require('@barchart/common-js/lang/is');
|
|
3
4
|
|
|
5
|
+
const InstrumentType = require('./../../data/InstrumentType');
|
|
6
|
+
|
|
4
7
|
module.exports = (() => {
|
|
5
8
|
'use strict';
|
|
6
9
|
|
|
@@ -15,7 +18,6 @@ module.exports = (() => {
|
|
|
15
18
|
* @param {PositionLevelDefinition~descriptionSelector} descriptionSelector
|
|
16
19
|
* @param {PositionLevelDefinition~currencySelector} currencySelector
|
|
17
20
|
* @param {Array.<PositionLevelDefinition~RequiredGroup>=} requiredGroups
|
|
18
|
-
* @param {Array.<PositionLevelDefinition~RequiredGroup>=} requiredGroups
|
|
19
21
|
* @param {Boolean=} single
|
|
20
22
|
* @param {Boolean=} aggregateCash
|
|
21
23
|
*/
|
|
@@ -118,6 +120,67 @@ module.exports = (() => {
|
|
|
118
120
|
return this._aggregateCash;
|
|
119
121
|
}
|
|
120
122
|
|
|
123
|
+
/**
|
|
124
|
+
* Builds a {@link PositionLevelDefinition~RequiredGroup} for a portfolio.
|
|
125
|
+
*
|
|
126
|
+
* @public
|
|
127
|
+
* @static
|
|
128
|
+
* @param {Object} portfolio
|
|
129
|
+
* @return {PositionLevelDefinition~RequiredGroup}
|
|
130
|
+
*/
|
|
131
|
+
static buildRequiredGroupForPortfolio(portfolio) {
|
|
132
|
+
return {
|
|
133
|
+
key: PositionLevelDefinition.getKeyForPortfolioGroup(portfolio),
|
|
134
|
+
description: PositionLevelDefinition.getDescriptionForPortfolioGroup(portfolio),
|
|
135
|
+
currency: Currency.CAD
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
static getKeyForPortfolioGroup(portfolio) {
|
|
141
|
+
assert.argumentIsRequired(portfolio, 'portfolio', Object);
|
|
142
|
+
|
|
143
|
+
return portfolio.portfolio;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
static getDescriptionForPortfolioGroup(portfolio) {
|
|
147
|
+
assert.argumentIsRequired(portfolio, 'portfolio', Object);
|
|
148
|
+
|
|
149
|
+
return portfolio.name;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Builds a {@link PositionLevelDefinition~RequiredGroup} for an asset class.
|
|
154
|
+
*
|
|
155
|
+
* @public
|
|
156
|
+
* @static
|
|
157
|
+
* @param {InstrumentType} type
|
|
158
|
+
* @param {Currency} currency
|
|
159
|
+
* @return {PositionLevelDefinition~RequiredGroup}
|
|
160
|
+
*/
|
|
161
|
+
static buildRequiredGroupForAssetClass(type, currency) {
|
|
162
|
+
return {
|
|
163
|
+
key: PositionLevelDefinition.getKeyForAssetClassGroup(type, currency),
|
|
164
|
+
description: PositionLevelDefinition.getDescriptionForAssetClassGroup(type, currency),
|
|
165
|
+
currency: currency
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
static getKeyForAssetClassGroup(type, currency) {
|
|
171
|
+
assert.argumentIsRequired(type, 'type', InstrumentType, 'InstrumentType');
|
|
172
|
+
assert.argumentIsRequired(currency, 'currency', Currency, 'Currency');
|
|
173
|
+
|
|
174
|
+
return `${type.code}|${currency.code}`;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
static getDescriptionForAssetClassGroup(type, currency) {
|
|
178
|
+
assert.argumentIsRequired(type, 'type', InstrumentType, 'InstrumentType');
|
|
179
|
+
assert.argumentIsRequired(currency, 'currency', Currency, 'Currency');
|
|
180
|
+
|
|
181
|
+
return `${type.alternateDescription}${currency.code === 'CAD' ? '' : ` (${currency.alternateDescription})`}`;
|
|
182
|
+
}
|
|
183
|
+
|
|
121
184
|
toString() {
|
|
122
185
|
return '[PositionLevelDefinition]';
|
|
123
186
|
}
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -1008,6 +1008,22 @@ module.exports = (() => {
|
|
|
1008
1008
|
}, { });
|
|
1009
1009
|
}
|
|
1010
1010
|
|
|
1011
|
+
addPortfolio(portfolio) {
|
|
1012
|
+
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
removePortfolio(portfolio) {
|
|
1016
|
+
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
mutatePosition(position, summary) {
|
|
1020
|
+
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
removePosition(position) {
|
|
1024
|
+
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1011
1027
|
/**
|
|
1012
1028
|
* Returns a distinct list of all symbols used by the positions
|
|
1013
1029
|
* within the container.
|
|
@@ -1368,7 +1384,6 @@ module.exports = (() => {
|
|
|
1368
1384
|
this._dataActual.summaryTotalPrevious = null;
|
|
1369
1385
|
this._dataActual.cashTotal = null;
|
|
1370
1386
|
|
|
1371
|
-
this._dataFormat.type = null;
|
|
1372
1387
|
this._dataFormat.currentPrice = null;
|
|
1373
1388
|
this._dataFormat.previousPrice = null;
|
|
1374
1389
|
this._dataFormat.basis = null;
|
|
@@ -1389,6 +1404,7 @@ module.exports = (() => {
|
|
|
1389
1404
|
this._dataFormat.summaryTotalPrevious = null;
|
|
1390
1405
|
this._dataFormat.summaryTotalPreviousNegative = false;
|
|
1391
1406
|
this._dataFormat.cashTotal = null;
|
|
1407
|
+
this._dataFormat.portfolioType = null;
|
|
1392
1408
|
|
|
1393
1409
|
this._items.forEach((item) => {
|
|
1394
1410
|
this._disposeStack.push(item.registerQuoteChangeHandler((quote, sender) => {
|
|
@@ -1416,8 +1432,8 @@ module.exports = (() => {
|
|
|
1416
1432
|
this._dataFormat.quoteTime = this._dataActual.quoteTime;
|
|
1417
1433
|
this._dataFormat.quoteVolume = formatNumber(this._dataActual.quoteVolume, 0);
|
|
1418
1434
|
|
|
1419
|
-
const quoteChangePositive =
|
|
1420
|
-
const quoteChangeNegative =
|
|
1435
|
+
const quoteChangePositive = quote.lastPriceDirection === 'up';
|
|
1436
|
+
const quoteChangeNegative = quote.lastPriceDirection === 'down';
|
|
1421
1437
|
|
|
1422
1438
|
setTimeout(() => this._dataFormat.quoteChangeDirection = { up: quoteChangePositive, down: quoteChangeNegative }, 0);
|
|
1423
1439
|
this._dataFormat.quoteChangeNegative = quoteChangeNegative;
|
|
@@ -1539,6 +1555,16 @@ module.exports = (() => {
|
|
|
1539
1555
|
return this._excluded;
|
|
1540
1556
|
}
|
|
1541
1557
|
|
|
1558
|
+
addItems(items) {
|
|
1559
|
+
|
|
1560
|
+
this.refresh();
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
removeItems(items) {
|
|
1564
|
+
|
|
1565
|
+
this.refresh();
|
|
1566
|
+
}
|
|
1567
|
+
|
|
1542
1568
|
/**
|
|
1543
1569
|
* Sets the list of items which are excluded from group aggregation calculations.
|
|
1544
1570
|
*
|
|
@@ -1754,14 +1780,28 @@ module.exports = (() => {
|
|
|
1754
1780
|
if (group.single) {
|
|
1755
1781
|
const item = group._items[0];
|
|
1756
1782
|
|
|
1757
|
-
format.type = item.data.type || null;
|
|
1758
|
-
|
|
1759
1783
|
actual.quantity = item.position.snapshot.open;
|
|
1760
1784
|
actual.basisPrice = item.data.basisPrice;
|
|
1761
1785
|
|
|
1762
1786
|
format.quantity = formatDecimal(actual.quantity, 2);
|
|
1763
1787
|
format.basisPrice = formatCurrency(actual.basisPrice, currency);
|
|
1764
1788
|
}
|
|
1789
|
+
|
|
1790
|
+
const groupItems = group._items;
|
|
1791
|
+
|
|
1792
|
+
let portfolioType = null;
|
|
1793
|
+
|
|
1794
|
+
if (groupItems.length > 0) {
|
|
1795
|
+
const portfolio = groupItems[0].portfolio;
|
|
1796
|
+
|
|
1797
|
+
if (groupItems.every(i => i.portfolio.portfolio === portfolio.portfolio)) {
|
|
1798
|
+
if (portfolio.miscellany && portfolio.miscellany.data.type && portfolio.miscellany.data.type.value) {
|
|
1799
|
+
portfolioType = portfolio.miscellany.data.type.value;
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
format.portfolioType = portfolioType;
|
|
1765
1805
|
}
|
|
1766
1806
|
|
|
1767
1807
|
function calculatePriceData(group, rates, item, forceRefresh) {
|
|
@@ -1975,8 +2015,6 @@ module.exports = (() => {
|
|
|
1975
2015
|
this._data.newsExists = false;
|
|
1976
2016
|
this._data.fundamental = { };
|
|
1977
2017
|
|
|
1978
|
-
this._data.type = null;
|
|
1979
|
-
|
|
1980
2018
|
calculateStaticData(this);
|
|
1981
2019
|
calculatePriceData(this, null);
|
|
1982
2020
|
|
|
@@ -2151,10 +2189,6 @@ module.exports = (() => {
|
|
|
2151
2189
|
|
|
2152
2190
|
const data = item._data;
|
|
2153
2191
|
|
|
2154
|
-
if (portfolio.miscellany && portfolio.miscellany.data.type && portfolio.miscellany.data.type.value) {
|
|
2155
|
-
data.type = portfolio.miscellany.data.type.value;
|
|
2156
|
-
}
|
|
2157
|
-
|
|
2158
2192
|
data.previousPrice = position.previous || null;
|
|
2159
2193
|
|
|
2160
2194
|
let basis;
|
|
@@ -2287,8 +2321,11 @@ module.exports = (() => {
|
|
|
2287
2321
|
|
|
2288
2322
|
},{"./../data/InstrumentType":1,"@barchart/common-js/lang/Currency":14,"@barchart/common-js/lang/Decimal":16,"@barchart/common-js/lang/array":20,"@barchart/common-js/lang/assert":21,"@barchart/common-js/lang/is":23,"@barchart/common-js/messaging/Event":25}],7:[function(require,module,exports){
|
|
2289
2323
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
2324
|
+
Currency = require('@barchart/common-js/lang/Currency'),
|
|
2290
2325
|
is = require('@barchart/common-js/lang/is');
|
|
2291
2326
|
|
|
2327
|
+
const InstrumentType = require('./../../data/InstrumentType');
|
|
2328
|
+
|
|
2292
2329
|
module.exports = (() => {
|
|
2293
2330
|
'use strict';
|
|
2294
2331
|
|
|
@@ -2303,7 +2340,6 @@ module.exports = (() => {
|
|
|
2303
2340
|
* @param {PositionLevelDefinition~descriptionSelector} descriptionSelector
|
|
2304
2341
|
* @param {PositionLevelDefinition~currencySelector} currencySelector
|
|
2305
2342
|
* @param {Array.<PositionLevelDefinition~RequiredGroup>=} requiredGroups
|
|
2306
|
-
* @param {Array.<PositionLevelDefinition~RequiredGroup>=} requiredGroups
|
|
2307
2343
|
* @param {Boolean=} single
|
|
2308
2344
|
* @param {Boolean=} aggregateCash
|
|
2309
2345
|
*/
|
|
@@ -2406,6 +2442,67 @@ module.exports = (() => {
|
|
|
2406
2442
|
return this._aggregateCash;
|
|
2407
2443
|
}
|
|
2408
2444
|
|
|
2445
|
+
/**
|
|
2446
|
+
* Builds a {@link PositionLevelDefinition~RequiredGroup} for a portfolio.
|
|
2447
|
+
*
|
|
2448
|
+
* @public
|
|
2449
|
+
* @static
|
|
2450
|
+
* @param {Object} portfolio
|
|
2451
|
+
* @return {PositionLevelDefinition~RequiredGroup}
|
|
2452
|
+
*/
|
|
2453
|
+
static buildRequiredGroupForPortfolio(portfolio) {
|
|
2454
|
+
return {
|
|
2455
|
+
key: PositionLevelDefinition.getKeyForPortfolioGroup(portfolio),
|
|
2456
|
+
description: PositionLevelDefinition.getDescriptionForPortfolioGroup(portfolio),
|
|
2457
|
+
currency: Currency.CAD
|
|
2458
|
+
};
|
|
2459
|
+
}
|
|
2460
|
+
|
|
2461
|
+
|
|
2462
|
+
static getKeyForPortfolioGroup(portfolio) {
|
|
2463
|
+
assert.argumentIsRequired(portfolio, 'portfolio', Object);
|
|
2464
|
+
|
|
2465
|
+
return portfolio.portfolio;
|
|
2466
|
+
}
|
|
2467
|
+
|
|
2468
|
+
static getDescriptionForPortfolioGroup(portfolio) {
|
|
2469
|
+
assert.argumentIsRequired(portfolio, 'portfolio', Object);
|
|
2470
|
+
|
|
2471
|
+
return portfolio.name;
|
|
2472
|
+
}
|
|
2473
|
+
|
|
2474
|
+
/**
|
|
2475
|
+
* Builds a {@link PositionLevelDefinition~RequiredGroup} for an asset class.
|
|
2476
|
+
*
|
|
2477
|
+
* @public
|
|
2478
|
+
* @static
|
|
2479
|
+
* @param {InstrumentType} type
|
|
2480
|
+
* @param {Currency} currency
|
|
2481
|
+
* @return {PositionLevelDefinition~RequiredGroup}
|
|
2482
|
+
*/
|
|
2483
|
+
static buildRequiredGroupForAssetClass(type, currency) {
|
|
2484
|
+
return {
|
|
2485
|
+
key: PositionLevelDefinition.getKeyForAssetClassGroup(type, currency),
|
|
2486
|
+
description: PositionLevelDefinition.getDescriptionForAssetClassGroup(type, currency),
|
|
2487
|
+
currency: currency
|
|
2488
|
+
}
|
|
2489
|
+
}
|
|
2490
|
+
|
|
2491
|
+
|
|
2492
|
+
static getKeyForAssetClassGroup(type, currency) {
|
|
2493
|
+
assert.argumentIsRequired(type, 'type', InstrumentType, 'InstrumentType');
|
|
2494
|
+
assert.argumentIsRequired(currency, 'currency', Currency, 'Currency');
|
|
2495
|
+
|
|
2496
|
+
return `${type.code}|${currency.code}`;
|
|
2497
|
+
}
|
|
2498
|
+
|
|
2499
|
+
static getDescriptionForAssetClassGroup(type, currency) {
|
|
2500
|
+
assert.argumentIsRequired(type, 'type', InstrumentType, 'InstrumentType');
|
|
2501
|
+
assert.argumentIsRequired(currency, 'currency', Currency, 'Currency');
|
|
2502
|
+
|
|
2503
|
+
return `${type.alternateDescription}${currency.code === 'CAD' ? '' : ` (${currency.alternateDescription})`}`;
|
|
2504
|
+
}
|
|
2505
|
+
|
|
2409
2506
|
toString() {
|
|
2410
2507
|
return '[PositionLevelDefinition]';
|
|
2411
2508
|
}
|
|
@@ -2455,7 +2552,7 @@ module.exports = (() => {
|
|
|
2455
2552
|
return PositionLevelDefinition;
|
|
2456
2553
|
})();
|
|
2457
2554
|
|
|
2458
|
-
},{"@barchart/common-js/lang/assert":21,"@barchart/common-js/lang/is":23}],8:[function(require,module,exports){
|
|
2555
|
+
},{"./../../data/InstrumentType":1,"@barchart/common-js/lang/Currency":14,"@barchart/common-js/lang/assert":21,"@barchart/common-js/lang/is":23}],8:[function(require,module,exports){
|
|
2459
2556
|
const assert = require('@barchart/common-js/lang/assert');
|
|
2460
2557
|
|
|
2461
2558
|
const PositionLevelDefinition = require('./PositionLevelDefinition');
|