@barchart/portfolio-api-common 1.3.1 → 1.3.5
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/.jshintrc +3 -0
- package/lib/api/failures/PortfolioFailureType.js +2 -2
- package/lib/data/TransactionValidator.js +5 -5
- package/lib/formatters/TransactionFormatter.js +4 -5
- package/lib/processing/PositionContainer.js +62 -15
- package/lib/processing/PositionGroup.js +3 -3
- package/lib/processing/PositionItem.js +3 -5
- package/lib/processing/definitions/PositionLevelDefinition.js +1 -1
- package/lib/processing/definitions/PositionTreeDefinition.js +4 -4
- package/package.json +2 -2
- package/test/SpecRunner.js +102 -38
package/.jshintrc
ADDED
|
@@ -296,8 +296,8 @@ module.exports = (() => {
|
|
|
296
296
|
const transactionCreateFailedOutOfSequence = new FailureType('TRANSACTION_CREATE_FAILED_OUT_OF_SEQUENCE', 'Unable to process transaction, because the transaction date is out-of-sequence. In other words, it would occur before an existing transaction. Please confirm your intent to re-write transaction history (which could take some time and alter the historical results for this position).');
|
|
297
297
|
const transactionCreateFailedInvalidDate = new FailureType('TRANSACTION_CREATE_FAILED_INVALID_DATE', 'Unable to process transaction with given date.');
|
|
298
298
|
const transactionCreateFailedTypeInvalidForInstrument = new FailureType('TRANSACTION_CREATE_FAILED_TYPE_INVALID_FOR_INSTRUMENT', 'Unable to process transaction, {L|transactionType.description} transactions cannot be used with {L|instrumentType.description} positions.');
|
|
299
|
-
const transactionCreateFailedTypeInvalidForDirection = new FailureType('TRANSACTION_CREATE_FAILED_TYPE_INVALID_FOR_DIRECTION', 'Unable to process transaction, a {L|positionDirection.description} position would be created (i.e. you would have {L|positionDirection.sign} shares/units). {u|instrumentType.description} positions cannot have {L|positionDirection.description} positions.');
|
|
300
|
-
const transactionCreateFailedInvalidDirectionSwitch = new FailureType('TRANSACTION_CREATE_FAILED_INVALID_DIRECTION_SWITCH', 'Unable to process transaction, the transaction would switch the position from {L|currentDirection.description} to {L|proposedDirection.description} (i.e. {L|currentDirection.sign} to {L|proposedDirection.sign} shares/units). This is not allowed. Please close the current position (i.e. zero it out) and then enter a second transaction.');
|
|
299
|
+
const transactionCreateFailedTypeInvalidForDirection = new FailureType('TRANSACTION_CREATE_FAILED_TYPE_INVALID_FOR_DIRECTION', 'Unable to process transaction, a {L|positionDirection.description} position would be created (i.e. you would have {L|positionDirection.sign} shares/units). {u|instrumentType.description} positions cannot have {L|positionDirection.description} positions.', false);
|
|
300
|
+
const transactionCreateFailedInvalidDirectionSwitch = new FailureType('TRANSACTION_CREATE_FAILED_INVALID_DIRECTION_SWITCH', 'Unable to process transaction, the transaction would switch the position from {L|currentDirection.description} to {L|proposedDirection.description} (i.e. {L|currentDirection.sign} to {L|proposedDirection.sign} shares/units). This is not allowed. Please close the current position (i.e. zero it out) and then enter a second transaction.', false);
|
|
301
301
|
const transactionCreateFailedInvalidInitialType = new FailureType('TRANSACTION_CREATE_FAILED_INVALID_INITIAL_TYPE', 'Unable to process operation because the first transaction would to be a {U|transactionType.description}, which is not allowed -- since {U|transactionType.description} transactions cannot open a position.');
|
|
302
302
|
|
|
303
303
|
const transactionCreateFailedTypeReserved = new FailureType('TRANSACTION_CREATE_FAILED_TYPE_RESERVED', 'Unable to create {U|type.description} transaction, this type of transaction is managed by the system.');
|
|
@@ -45,7 +45,7 @@ module.exports = (() => {
|
|
|
45
45
|
*
|
|
46
46
|
* @public
|
|
47
47
|
* @static
|
|
48
|
-
* @param {
|
|
48
|
+
* @param {Object[]} transactions
|
|
49
49
|
* @param {Boolean=} strict
|
|
50
50
|
* @returns {Boolean}
|
|
51
51
|
*/
|
|
@@ -59,7 +59,7 @@ module.exports = (() => {
|
|
|
59
59
|
*
|
|
60
60
|
* @public
|
|
61
61
|
* @static
|
|
62
|
-
* @param {
|
|
62
|
+
* @param {Object[]} transactions
|
|
63
63
|
* @returns {Boolean}
|
|
64
64
|
*/
|
|
65
65
|
static validateReferences(transactions) {
|
|
@@ -97,7 +97,7 @@ module.exports = (() => {
|
|
|
97
97
|
*
|
|
98
98
|
* @public
|
|
99
99
|
* @static
|
|
100
|
-
* @param {
|
|
100
|
+
* @param {Object[]} transactions
|
|
101
101
|
* @param {Boolean=} strict
|
|
102
102
|
* @returns {Number}
|
|
103
103
|
*/
|
|
@@ -116,7 +116,7 @@ module.exports = (() => {
|
|
|
116
116
|
* @param {InstrumentType} instrumentType
|
|
117
117
|
* @param {Boolean=} userInitiated
|
|
118
118
|
* @param {PositionDirection=} currentDirection
|
|
119
|
-
* @returns {
|
|
119
|
+
* @returns {TransactionType[]}
|
|
120
120
|
*/
|
|
121
121
|
static getTransactionTypesFor(instrumentType, userInitiated, currentDirection) {
|
|
122
122
|
assert.argumentIsRequired(instrumentType, 'instrumentType', InstrumentType, 'InstrumentType');
|
|
@@ -141,7 +141,7 @@ module.exports = (() => {
|
|
|
141
141
|
*
|
|
142
142
|
* @public
|
|
143
143
|
* @static
|
|
144
|
-
* @returns {
|
|
144
|
+
* @returns {TransactionType[]}
|
|
145
145
|
*/
|
|
146
146
|
static getUserInitiatedTransactionTypes() {
|
|
147
147
|
return array.unique(Object.keys(validTransactionTypes).reduce((types, key) => {
|
|
@@ -23,13 +23,12 @@ module.exports = (() => {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
-
* Maps transaction objects into new objects whose properties are human-readable
|
|
27
|
-
* mutates the original objects, adding a "formatted" property to each transaction).
|
|
26
|
+
* Maps transaction objects into new objects whose properties are human-readable.
|
|
28
27
|
*
|
|
29
28
|
* @public
|
|
30
29
|
* @static
|
|
31
|
-
* @param {
|
|
32
|
-
* @param {
|
|
30
|
+
* @param {Object[]} transactions
|
|
31
|
+
* @param {Object[]} positions
|
|
33
32
|
* @param {Boolean=} descending
|
|
34
33
|
* @returns {Array}
|
|
35
34
|
*/
|
|
@@ -97,7 +96,7 @@ module.exports = (() => {
|
|
|
97
96
|
*
|
|
98
97
|
* @public
|
|
99
98
|
* @static
|
|
100
|
-
* @param {
|
|
99
|
+
* @param {Object[]} transactions
|
|
101
100
|
* @param {Boolean=} descending
|
|
102
101
|
* @returns {Array}
|
|
103
102
|
*/
|
|
@@ -39,10 +39,10 @@ module.exports = (() => {
|
|
|
39
39
|
* changes) for each level of grouping.
|
|
40
40
|
*
|
|
41
41
|
* @public
|
|
42
|
-
* @param {
|
|
43
|
-
* @param {
|
|
44
|
-
* @param {
|
|
45
|
-
* @param {
|
|
42
|
+
* @param {PositionTreeDefinition[]} definitions
|
|
43
|
+
* @param {Object[]} portfolios - The portfolios.
|
|
44
|
+
* @param {Object[]} positions - The positions (for all of the portfolios).
|
|
45
|
+
* @param {Object[]} summaries - The positions summaries (for all of the positions).
|
|
46
46
|
* @param {PositionSummaryFrame=} reportFrame - If specified, locks the current (and previous) periods to a specific frame, use for reporting.
|
|
47
47
|
* @param {Day=} reportDate - The end date for the report frame.
|
|
48
48
|
*/
|
|
@@ -172,6 +172,53 @@ module.exports = (() => {
|
|
|
172
172
|
recalculatePercentages.call(this);
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
+
/**
|
|
176
|
+
* Returns Barchart's user identifier for the container's portfolios. If
|
|
177
|
+
* the container has no portfolios, a null value is returned.
|
|
178
|
+
*
|
|
179
|
+
* @public
|
|
180
|
+
* @returns {String|null}
|
|
181
|
+
*/
|
|
182
|
+
getBarchartUserId() {
|
|
183
|
+
let returnRef = null;
|
|
184
|
+
|
|
185
|
+
const keys = Object.keys(this._portfolios);
|
|
186
|
+
|
|
187
|
+
if (keys.length > 0) {
|
|
188
|
+
const firstKey = keys[0];
|
|
189
|
+
const firstPortfolio = this._portfolios[firstKey];
|
|
190
|
+
|
|
191
|
+
returnRef = firstPortfolio.user;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return returnRef;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Returns customer's user identifier for the container's portfolios. If
|
|
199
|
+
* the container has no portfolios, or if the portfolio(s) are not owned
|
|
200
|
+
* by a remote customer, a null value is returned.
|
|
201
|
+
*
|
|
202
|
+
* @public
|
|
203
|
+
* @returns {String|null}
|
|
204
|
+
*/
|
|
205
|
+
getCustomerUserId() {
|
|
206
|
+
let returnRef = null;
|
|
207
|
+
|
|
208
|
+
const keys = Object.keys(this._portfolios);
|
|
209
|
+
|
|
210
|
+
if (keys.length > 0) {
|
|
211
|
+
const firstKey = keys[0];
|
|
212
|
+
const firstPortfolio = this._portfolios[firstKey];
|
|
213
|
+
|
|
214
|
+
if (firstPortfolio.legacy && firstPortfolio.legacy.user) {
|
|
215
|
+
returnRef = firstPortfolio.legacy.user;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return returnRef;
|
|
220
|
+
}
|
|
221
|
+
|
|
175
222
|
/**
|
|
176
223
|
* Adds a new portfolio to the container, injecting it into aggregation
|
|
177
224
|
* trees, as necessary.
|
|
@@ -284,7 +331,7 @@ module.exports = (() => {
|
|
|
284
331
|
*
|
|
285
332
|
* @public
|
|
286
333
|
* @param {Object} position
|
|
287
|
-
* @param {
|
|
334
|
+
* @param {Object>[]} summaries
|
|
288
335
|
*/
|
|
289
336
|
updatePosition(position, summaries) {
|
|
290
337
|
assert.argumentIsRequired(position, 'position', Object);
|
|
@@ -387,7 +434,7 @@ module.exports = (() => {
|
|
|
387
434
|
*
|
|
388
435
|
* @public
|
|
389
436
|
* @param {Boolean} display - If true, all "display" symbols are returned; otherwise Barchart symbols are returned.
|
|
390
|
-
* @returns {
|
|
437
|
+
* @returns {String[]}
|
|
391
438
|
*/
|
|
392
439
|
getPositionSymbols(display) {
|
|
393
440
|
const symbols = this._items.reduce((symbols, item) => {
|
|
@@ -451,8 +498,8 @@ module.exports = (() => {
|
|
|
451
498
|
* triggering updates to position(s) and data aggregation(s).
|
|
452
499
|
*
|
|
453
500
|
* @public
|
|
454
|
-
* @param {
|
|
455
|
-
* @param {
|
|
501
|
+
* @param {Object[]} positionQuotes
|
|
502
|
+
* @param {Object[]} forexQuotes
|
|
456
503
|
*/
|
|
457
504
|
setQuotes(positionQuotes, forexQuotes) {
|
|
458
505
|
assert.argumentIsArray(positionQuotes, 'positionQuotes');
|
|
@@ -514,7 +561,7 @@ module.exports = (() => {
|
|
|
514
561
|
* Returns all forex symbols that are required to do currency translations.
|
|
515
562
|
*
|
|
516
563
|
* @public
|
|
517
|
-
* @returns {
|
|
564
|
+
* @returns {String[]}
|
|
518
565
|
*/
|
|
519
566
|
getForexSymbols() {
|
|
520
567
|
return this._forexSymbols;
|
|
@@ -524,7 +571,7 @@ module.exports = (() => {
|
|
|
524
571
|
* Returns all current forex quotes.
|
|
525
572
|
*
|
|
526
573
|
* @public
|
|
527
|
-
* @returns {
|
|
574
|
+
* @returns {Object[]}
|
|
528
575
|
*/
|
|
529
576
|
getForexQuotes() {
|
|
530
577
|
return this._forexQuotes;
|
|
@@ -586,7 +633,7 @@ module.exports = (() => {
|
|
|
586
633
|
*
|
|
587
634
|
* @public
|
|
588
635
|
* @param {String} name
|
|
589
|
-
* @param {
|
|
636
|
+
* @param {String[]} keys
|
|
590
637
|
* @returns {PositionGroup}
|
|
591
638
|
*/
|
|
592
639
|
getGroup(name, keys) {
|
|
@@ -602,8 +649,8 @@ module.exports = (() => {
|
|
|
602
649
|
*
|
|
603
650
|
* @public
|
|
604
651
|
* @param {String} name
|
|
605
|
-
* @param {
|
|
606
|
-
* @returns {
|
|
652
|
+
* @param {String[]} keys
|
|
653
|
+
* @returns {PositionGroup[]}
|
|
607
654
|
*/
|
|
608
655
|
getGroups(name, keys) {
|
|
609
656
|
assert.argumentIsRequired(name, 'name', String);
|
|
@@ -642,7 +689,7 @@ module.exports = (() => {
|
|
|
642
689
|
* Returns all portfolios in the container.
|
|
643
690
|
*
|
|
644
691
|
* @public
|
|
645
|
-
* @returns {
|
|
692
|
+
* @returns {Object[]}
|
|
646
693
|
*/
|
|
647
694
|
getPortfolios() {
|
|
648
695
|
return Object.keys(this._portfolios).map(id => this._portfolios[id]);
|
|
@@ -653,7 +700,7 @@ module.exports = (() => {
|
|
|
653
700
|
*
|
|
654
701
|
* @public
|
|
655
702
|
* @param {String} portfolio
|
|
656
|
-
* @returns {
|
|
703
|
+
* @returns {Object[]}
|
|
657
704
|
*/
|
|
658
705
|
getPositions(portfolio) {
|
|
659
706
|
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
@@ -26,7 +26,7 @@ module.exports = (() => {
|
|
|
26
26
|
* @public
|
|
27
27
|
* @param {PositionContainer} container
|
|
28
28
|
* @param {LevelDefinition} definition
|
|
29
|
-
* @param {
|
|
29
|
+
* @param {PositionItem[]} items
|
|
30
30
|
* @param {Currency} currency
|
|
31
31
|
* @param {String} key
|
|
32
32
|
* @param {String} description
|
|
@@ -361,7 +361,7 @@ module.exports = (() => {
|
|
|
361
361
|
* Sets the list of items which are excluded from group aggregation calculations.
|
|
362
362
|
*
|
|
363
363
|
* @public
|
|
364
|
-
* @param {
|
|
364
|
+
* @param {Object[]} items
|
|
365
365
|
*/
|
|
366
366
|
setExcludedItems(items) {
|
|
367
367
|
this._excludedItems = items;
|
|
@@ -382,7 +382,7 @@ module.exports = (() => {
|
|
|
382
382
|
* Causes aggregated data to be recalculated using a new exchange rate.
|
|
383
383
|
*
|
|
384
384
|
* @public
|
|
385
|
-
* @param {
|
|
385
|
+
* @param {Rate[]} rates
|
|
386
386
|
*/
|
|
387
387
|
setForexRates(rates) {
|
|
388
388
|
this._rates = rates;
|
|
@@ -20,7 +20,7 @@ module.exports = (() => {
|
|
|
20
20
|
* @param {Object} portfolio
|
|
21
21
|
* @param {Object} position
|
|
22
22
|
* @param {Object} currentSummary
|
|
23
|
-
* @param {
|
|
23
|
+
* @param {Object[]} previousSummaries
|
|
24
24
|
* @param {Boolean} reporting
|
|
25
25
|
*/
|
|
26
26
|
class PositionItem extends Disposable {
|
|
@@ -570,15 +570,13 @@ module.exports = (() => {
|
|
|
570
570
|
data.periodUnrealized = periodUnrealized;
|
|
571
571
|
data.periodUnrealizedChange = periodUnrealizedChange;
|
|
572
572
|
} else {
|
|
573
|
-
data.unrealized = Decimal.ZERO;
|
|
574
573
|
data.unrealizedChange = Decimal.ZERO;
|
|
575
|
-
|
|
574
|
+
data.periodUnrealizedChange = Decimal.ZERO;
|
|
576
575
|
data.periodGainChange = Decimal.ZERO;
|
|
577
576
|
}
|
|
578
577
|
} else {
|
|
579
|
-
data.unrealized = Decimal.ZERO;
|
|
580
578
|
data.unrealizedChange = Decimal.ZERO;
|
|
581
|
-
|
|
579
|
+
data.periodUnrealizedChange = Decimal.ZERO;
|
|
582
580
|
data.periodGainChange = Decimal.ZERO;
|
|
583
581
|
}
|
|
584
582
|
}
|
|
@@ -19,7 +19,7 @@ module.exports = (() => {
|
|
|
19
19
|
* @param {PositionLevelDefinition~keySelector} keySelector
|
|
20
20
|
* @param {PositionLevelDefinition~descriptionSelector} descriptionSelector
|
|
21
21
|
* @param {PositionLevelDefinition~currencySelector} currencySelector
|
|
22
|
-
* @param {
|
|
22
|
+
* @param {PositionLevelDefinition~RequiredGroup[]=} requiredGroups
|
|
23
23
|
* @param {Boolean=} aggregateCash
|
|
24
24
|
* @param {Function=} requiredGroupGenerator
|
|
25
25
|
*/
|
|
@@ -10,8 +10,8 @@ module.exports = (() => {
|
|
|
10
10
|
*
|
|
11
11
|
* @public
|
|
12
12
|
* @param {String} name
|
|
13
|
-
* @param {
|
|
14
|
-
* @oaram {
|
|
13
|
+
* @param {PositionLevelDefinition[]} definitions
|
|
14
|
+
* @oaram {String[]=} exclusionDependencies
|
|
15
15
|
*/
|
|
16
16
|
class PositionTreeDefinitions {
|
|
17
17
|
constructor(name, definitions, exclusionDependencies) {
|
|
@@ -44,7 +44,7 @@ module.exports = (() => {
|
|
|
44
44
|
* bottom-most level of the tree (i.e. leaf nodes).
|
|
45
45
|
*
|
|
46
46
|
* @public
|
|
47
|
-
* @returns {
|
|
47
|
+
* @returns {PositionLevelDefinitions>[]}
|
|
48
48
|
*/
|
|
49
49
|
get definitions() {
|
|
50
50
|
return this._definitions;
|
|
@@ -55,7 +55,7 @@ module.exports = (() => {
|
|
|
55
55
|
* group (from the current tree) is excluded.
|
|
56
56
|
*
|
|
57
57
|
* @public
|
|
58
|
-
* @returns {
|
|
58
|
+
* @returns {String[]}
|
|
59
59
|
*/
|
|
60
60
|
get exclusionDependencies() {
|
|
61
61
|
return this._exclusionDependencies;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barchart/portfolio-api-common",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.5",
|
|
4
4
|
"description": "Common classes used by the Portfolio system",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Bryan Ingle",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"glob": "^6.0.1",
|
|
22
22
|
"gulp": "~3.9.0",
|
|
23
23
|
"gulp-bump": "~1.0.0",
|
|
24
|
-
"gulp-git": "
|
|
24
|
+
"gulp-git": "^2.5.1",
|
|
25
25
|
"gulp-jasmine": "^2.2.1",
|
|
26
26
|
"gulp-jshint": "~2.1.0",
|
|
27
27
|
"gulp-util": "^3.0.7",
|
package/test/SpecRunner.js
CHANGED
|
@@ -1232,7 +1232,7 @@ module.exports = (() => {
|
|
|
1232
1232
|
*
|
|
1233
1233
|
* @public
|
|
1234
1234
|
* @static
|
|
1235
|
-
* @param {
|
|
1235
|
+
* @param {Object[]} transactions
|
|
1236
1236
|
* @param {Boolean=} strict
|
|
1237
1237
|
* @returns {Boolean}
|
|
1238
1238
|
*/
|
|
@@ -1246,7 +1246,7 @@ module.exports = (() => {
|
|
|
1246
1246
|
*
|
|
1247
1247
|
* @public
|
|
1248
1248
|
* @static
|
|
1249
|
-
* @param {
|
|
1249
|
+
* @param {Object[]} transactions
|
|
1250
1250
|
* @returns {Boolean}
|
|
1251
1251
|
*/
|
|
1252
1252
|
static validateReferences(transactions) {
|
|
@@ -1284,7 +1284,7 @@ module.exports = (() => {
|
|
|
1284
1284
|
*
|
|
1285
1285
|
* @public
|
|
1286
1286
|
* @static
|
|
1287
|
-
* @param {
|
|
1287
|
+
* @param {Object[]} transactions
|
|
1288
1288
|
* @param {Boolean=} strict
|
|
1289
1289
|
* @returns {Number}
|
|
1290
1290
|
*/
|
|
@@ -1303,7 +1303,7 @@ module.exports = (() => {
|
|
|
1303
1303
|
* @param {InstrumentType} instrumentType
|
|
1304
1304
|
* @param {Boolean=} userInitiated
|
|
1305
1305
|
* @param {PositionDirection=} currentDirection
|
|
1306
|
-
* @returns {
|
|
1306
|
+
* @returns {TransactionType[]}
|
|
1307
1307
|
*/
|
|
1308
1308
|
static getTransactionTypesFor(instrumentType, userInitiated, currentDirection) {
|
|
1309
1309
|
assert.argumentIsRequired(instrumentType, 'instrumentType', InstrumentType, 'InstrumentType');
|
|
@@ -1328,7 +1328,7 @@ module.exports = (() => {
|
|
|
1328
1328
|
*
|
|
1329
1329
|
* @public
|
|
1330
1330
|
* @static
|
|
1331
|
-
* @returns {
|
|
1331
|
+
* @returns {TransactionType[]}
|
|
1332
1332
|
*/
|
|
1333
1333
|
static getUserInitiatedTransactionTypes() {
|
|
1334
1334
|
return array.unique(Object.keys(validTransactionTypes).reduce((types, key) => {
|
|
@@ -1525,10 +1525,10 @@ module.exports = (() => {
|
|
|
1525
1525
|
* changes) for each level of grouping.
|
|
1526
1526
|
*
|
|
1527
1527
|
* @public
|
|
1528
|
-
* @param {
|
|
1529
|
-
* @param {
|
|
1530
|
-
* @param {
|
|
1531
|
-
* @param {
|
|
1528
|
+
* @param {PositionTreeDefinition[]} definitions
|
|
1529
|
+
* @param {Object[]} portfolios - The portfolios.
|
|
1530
|
+
* @param {Object[]} positions - The positions (for all of the portfolios).
|
|
1531
|
+
* @param {Object[]} summaries - The positions summaries (for all of the positions).
|
|
1532
1532
|
* @param {PositionSummaryFrame=} reportFrame - If specified, locks the current (and previous) periods to a specific frame, use for reporting.
|
|
1533
1533
|
* @param {Day=} reportDate - The end date for the report frame.
|
|
1534
1534
|
*/
|
|
@@ -1658,6 +1658,53 @@ module.exports = (() => {
|
|
|
1658
1658
|
recalculatePercentages.call(this);
|
|
1659
1659
|
}
|
|
1660
1660
|
|
|
1661
|
+
/**
|
|
1662
|
+
* Returns Barchart's user identifier for the container's portfolios. If
|
|
1663
|
+
* the container has no portfolios, a null value is returned.
|
|
1664
|
+
*
|
|
1665
|
+
* @public
|
|
1666
|
+
* @returns {String|null}
|
|
1667
|
+
*/
|
|
1668
|
+
getBarchartUserId() {
|
|
1669
|
+
let returnRef = null;
|
|
1670
|
+
|
|
1671
|
+
const keys = Object.keys(this._portfolios);
|
|
1672
|
+
|
|
1673
|
+
if (keys.length > 0) {
|
|
1674
|
+
const firstKey = keys[0];
|
|
1675
|
+
const firstPortfolio = this._portfolios[firstKey];
|
|
1676
|
+
|
|
1677
|
+
returnRef = firstPortfolio.user;
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
return returnRef;
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1683
|
+
/**
|
|
1684
|
+
* Returns customer's user identifier for the container's portfolios. If
|
|
1685
|
+
* the container has no portfolios, or if the portfolio(s) are not owned
|
|
1686
|
+
* by a remote customer, a null value is returned.
|
|
1687
|
+
*
|
|
1688
|
+
* @public
|
|
1689
|
+
* @returns {String|null}
|
|
1690
|
+
*/
|
|
1691
|
+
getCustomerUserId() {
|
|
1692
|
+
let returnRef = null;
|
|
1693
|
+
|
|
1694
|
+
const keys = Object.keys(this._portfolios);
|
|
1695
|
+
|
|
1696
|
+
if (keys.length > 0) {
|
|
1697
|
+
const firstKey = keys[0];
|
|
1698
|
+
const firstPortfolio = this._portfolios[firstKey];
|
|
1699
|
+
|
|
1700
|
+
if (firstPortfolio.legacy && firstPortfolio.legacy.user) {
|
|
1701
|
+
returnRef = firstPortfolio.legacy.user;
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
|
|
1705
|
+
return returnRef;
|
|
1706
|
+
}
|
|
1707
|
+
|
|
1661
1708
|
/**
|
|
1662
1709
|
* Adds a new portfolio to the container, injecting it into aggregation
|
|
1663
1710
|
* trees, as necessary.
|
|
@@ -1770,7 +1817,7 @@ module.exports = (() => {
|
|
|
1770
1817
|
*
|
|
1771
1818
|
* @public
|
|
1772
1819
|
* @param {Object} position
|
|
1773
|
-
* @param {
|
|
1820
|
+
* @param {Object>[]} summaries
|
|
1774
1821
|
*/
|
|
1775
1822
|
updatePosition(position, summaries) {
|
|
1776
1823
|
assert.argumentIsRequired(position, 'position', Object);
|
|
@@ -1873,7 +1920,7 @@ module.exports = (() => {
|
|
|
1873
1920
|
*
|
|
1874
1921
|
* @public
|
|
1875
1922
|
* @param {Boolean} display - If true, all "display" symbols are returned; otherwise Barchart symbols are returned.
|
|
1876
|
-
* @returns {
|
|
1923
|
+
* @returns {String[]}
|
|
1877
1924
|
*/
|
|
1878
1925
|
getPositionSymbols(display) {
|
|
1879
1926
|
const symbols = this._items.reduce((symbols, item) => {
|
|
@@ -1937,8 +1984,8 @@ module.exports = (() => {
|
|
|
1937
1984
|
* triggering updates to position(s) and data aggregation(s).
|
|
1938
1985
|
*
|
|
1939
1986
|
* @public
|
|
1940
|
-
* @param {
|
|
1941
|
-
* @param {
|
|
1987
|
+
* @param {Object[]} positionQuotes
|
|
1988
|
+
* @param {Object[]} forexQuotes
|
|
1942
1989
|
*/
|
|
1943
1990
|
setQuotes(positionQuotes, forexQuotes) {
|
|
1944
1991
|
assert.argumentIsArray(positionQuotes, 'positionQuotes');
|
|
@@ -2000,7 +2047,7 @@ module.exports = (() => {
|
|
|
2000
2047
|
* Returns all forex symbols that are required to do currency translations.
|
|
2001
2048
|
*
|
|
2002
2049
|
* @public
|
|
2003
|
-
* @returns {
|
|
2050
|
+
* @returns {String[]}
|
|
2004
2051
|
*/
|
|
2005
2052
|
getForexSymbols() {
|
|
2006
2053
|
return this._forexSymbols;
|
|
@@ -2010,7 +2057,7 @@ module.exports = (() => {
|
|
|
2010
2057
|
* Returns all current forex quotes.
|
|
2011
2058
|
*
|
|
2012
2059
|
* @public
|
|
2013
|
-
* @returns {
|
|
2060
|
+
* @returns {Object[]}
|
|
2014
2061
|
*/
|
|
2015
2062
|
getForexQuotes() {
|
|
2016
2063
|
return this._forexQuotes;
|
|
@@ -2072,7 +2119,7 @@ module.exports = (() => {
|
|
|
2072
2119
|
*
|
|
2073
2120
|
* @public
|
|
2074
2121
|
* @param {String} name
|
|
2075
|
-
* @param {
|
|
2122
|
+
* @param {String[]} keys
|
|
2076
2123
|
* @returns {PositionGroup}
|
|
2077
2124
|
*/
|
|
2078
2125
|
getGroup(name, keys) {
|
|
@@ -2088,8 +2135,8 @@ module.exports = (() => {
|
|
|
2088
2135
|
*
|
|
2089
2136
|
* @public
|
|
2090
2137
|
* @param {String} name
|
|
2091
|
-
* @param {
|
|
2092
|
-
* @returns {
|
|
2138
|
+
* @param {String[]} keys
|
|
2139
|
+
* @returns {PositionGroup[]}
|
|
2093
2140
|
*/
|
|
2094
2141
|
getGroups(name, keys) {
|
|
2095
2142
|
assert.argumentIsRequired(name, 'name', String);
|
|
@@ -2128,7 +2175,7 @@ module.exports = (() => {
|
|
|
2128
2175
|
* Returns all portfolios in the container.
|
|
2129
2176
|
*
|
|
2130
2177
|
* @public
|
|
2131
|
-
* @returns {
|
|
2178
|
+
* @returns {Object[]}
|
|
2132
2179
|
*/
|
|
2133
2180
|
getPortfolios() {
|
|
2134
2181
|
return Object.keys(this._portfolios).map(id => this._portfolios[id]);
|
|
@@ -2139,7 +2186,7 @@ module.exports = (() => {
|
|
|
2139
2186
|
*
|
|
2140
2187
|
* @public
|
|
2141
2188
|
* @param {String} portfolio
|
|
2142
|
-
* @returns {
|
|
2189
|
+
* @returns {Object[]}
|
|
2143
2190
|
*/
|
|
2144
2191
|
getPositions(portfolio) {
|
|
2145
2192
|
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
@@ -2548,7 +2595,7 @@ module.exports = (() => {
|
|
|
2548
2595
|
* @public
|
|
2549
2596
|
* @param {PositionContainer} container
|
|
2550
2597
|
* @param {LevelDefinition} definition
|
|
2551
|
-
* @param {
|
|
2598
|
+
* @param {PositionItem[]} items
|
|
2552
2599
|
* @param {Currency} currency
|
|
2553
2600
|
* @param {String} key
|
|
2554
2601
|
* @param {String} description
|
|
@@ -2883,7 +2930,7 @@ module.exports = (() => {
|
|
|
2883
2930
|
* Sets the list of items which are excluded from group aggregation calculations.
|
|
2884
2931
|
*
|
|
2885
2932
|
* @public
|
|
2886
|
-
* @param {
|
|
2933
|
+
* @param {Object[]} items
|
|
2887
2934
|
*/
|
|
2888
2935
|
setExcludedItems(items) {
|
|
2889
2936
|
this._excludedItems = items;
|
|
@@ -2904,7 +2951,7 @@ module.exports = (() => {
|
|
|
2904
2951
|
* Causes aggregated data to be recalculated using a new exchange rate.
|
|
2905
2952
|
*
|
|
2906
2953
|
* @public
|
|
2907
|
-
* @param {
|
|
2954
|
+
* @param {Rate[]} rates
|
|
2908
2955
|
*/
|
|
2909
2956
|
setForexRates(rates) {
|
|
2910
2957
|
this._rates = rates;
|
|
@@ -3562,7 +3609,7 @@ module.exports = (() => {
|
|
|
3562
3609
|
* @param {Object} portfolio
|
|
3563
3610
|
* @param {Object} position
|
|
3564
3611
|
* @param {Object} currentSummary
|
|
3565
|
-
* @param {
|
|
3612
|
+
* @param {Object[]} previousSummaries
|
|
3566
3613
|
* @param {Boolean} reporting
|
|
3567
3614
|
*/
|
|
3568
3615
|
class PositionItem extends Disposable {
|
|
@@ -4112,15 +4159,13 @@ module.exports = (() => {
|
|
|
4112
4159
|
data.periodUnrealized = periodUnrealized;
|
|
4113
4160
|
data.periodUnrealizedChange = periodUnrealizedChange;
|
|
4114
4161
|
} else {
|
|
4115
|
-
data.unrealized = Decimal.ZERO;
|
|
4116
4162
|
data.unrealizedChange = Decimal.ZERO;
|
|
4117
|
-
|
|
4163
|
+
data.periodUnrealizedChange = Decimal.ZERO;
|
|
4118
4164
|
data.periodGainChange = Decimal.ZERO;
|
|
4119
4165
|
}
|
|
4120
4166
|
} else {
|
|
4121
|
-
data.unrealized = Decimal.ZERO;
|
|
4122
4167
|
data.unrealizedChange = Decimal.ZERO;
|
|
4123
|
-
|
|
4168
|
+
data.periodUnrealizedChange = Decimal.ZERO;
|
|
4124
4169
|
data.periodGainChange = Decimal.ZERO;
|
|
4125
4170
|
}
|
|
4126
4171
|
}
|
|
@@ -4300,7 +4345,7 @@ module.exports = (() => {
|
|
|
4300
4345
|
* @param {PositionLevelDefinition~keySelector} keySelector
|
|
4301
4346
|
* @param {PositionLevelDefinition~descriptionSelector} descriptionSelector
|
|
4302
4347
|
* @param {PositionLevelDefinition~currencySelector} currencySelector
|
|
4303
|
-
* @param {
|
|
4348
|
+
* @param {PositionLevelDefinition~RequiredGroup[]=} requiredGroups
|
|
4304
4349
|
* @param {Boolean=} aggregateCash
|
|
4305
4350
|
* @param {Function=} requiredGroupGenerator
|
|
4306
4351
|
*/
|
|
@@ -4601,8 +4646,8 @@ module.exports = (() => {
|
|
|
4601
4646
|
*
|
|
4602
4647
|
* @public
|
|
4603
4648
|
* @param {String} name
|
|
4604
|
-
* @param {
|
|
4605
|
-
* @oaram {
|
|
4649
|
+
* @param {PositionLevelDefinition[]} definitions
|
|
4650
|
+
* @oaram {String[]=} exclusionDependencies
|
|
4606
4651
|
*/
|
|
4607
4652
|
class PositionTreeDefinitions {
|
|
4608
4653
|
constructor(name, definitions, exclusionDependencies) {
|
|
@@ -4635,7 +4680,7 @@ module.exports = (() => {
|
|
|
4635
4680
|
* bottom-most level of the tree (i.e. leaf nodes).
|
|
4636
4681
|
*
|
|
4637
4682
|
* @public
|
|
4638
|
-
* @returns {
|
|
4683
|
+
* @returns {PositionLevelDefinitions>[]}
|
|
4639
4684
|
*/
|
|
4640
4685
|
get definitions() {
|
|
4641
4686
|
return this._definitions;
|
|
@@ -4646,7 +4691,7 @@ module.exports = (() => {
|
|
|
4646
4691
|
* group (from the current tree) is excluded.
|
|
4647
4692
|
*
|
|
4648
4693
|
* @public
|
|
4649
|
-
* @returns {
|
|
4694
|
+
* @returns {String[]}
|
|
4650
4695
|
*/
|
|
4651
4696
|
get exclusionDependencies() {
|
|
4652
4697
|
return this._exclusionDependencies;
|
|
@@ -9046,9 +9091,10 @@ module.exports = function () {
|
|
|
9046
9091
|
/**
|
|
9047
9092
|
* Checks to see if an attribute exists on the target object.
|
|
9048
9093
|
*
|
|
9094
|
+
* @public
|
|
9049
9095
|
* @static
|
|
9050
9096
|
* @param {Object} target - The object to check for existence of the property.
|
|
9051
|
-
* @param {String|
|
|
9097
|
+
* @param {String|String[]} propertyNames - The property to check -- either a string with separators, or an array of strings (already split by separator).
|
|
9052
9098
|
* @param {String=} separator - The separator (defaults to a period character).
|
|
9053
9099
|
* @returns {boolean}
|
|
9054
9100
|
*/
|
|
@@ -9072,9 +9118,10 @@ module.exports = function () {
|
|
|
9072
9118
|
* Returns a value from the target object. If the property doesn't exist; undefined
|
|
9073
9119
|
* is returned.
|
|
9074
9120
|
*
|
|
9121
|
+
* @public
|
|
9075
9122
|
* @static
|
|
9076
9123
|
* @param {Object} target - The object to read from.
|
|
9077
|
-
* @param {String|
|
|
9124
|
+
* @param {String|String[]} propertyNames - The property to read -- either a string with separators, or an array of strings (already split by separator).
|
|
9078
9125
|
* @param {String=} separator - The separator (defaults to a period character).
|
|
9079
9126
|
* @returns {*}
|
|
9080
9127
|
*/
|
|
@@ -9107,9 +9154,10 @@ module.exports = function () {
|
|
|
9107
9154
|
/**
|
|
9108
9155
|
* Writes a value to the target object.
|
|
9109
9156
|
*
|
|
9157
|
+
* @public
|
|
9110
9158
|
* @static
|
|
9111
9159
|
* @param {Object} target - The object to write to.
|
|
9112
|
-
* @param {String|
|
|
9160
|
+
* @param {String|String[]} propertyNames - The property to write -- either a string with separators, or an array of strings (already split by separator).
|
|
9113
9161
|
* @param {*} value - The value to assign.
|
|
9114
9162
|
* @param {String=} separator - The separator (defaults to a period character).
|
|
9115
9163
|
*/
|
|
@@ -9134,9 +9182,10 @@ module.exports = function () {
|
|
|
9134
9182
|
/**
|
|
9135
9183
|
* Erases a property from the target object.
|
|
9136
9184
|
*
|
|
9185
|
+
* @public
|
|
9137
9186
|
* @static
|
|
9138
9187
|
* @param {Object} target - The object to erase a property from.
|
|
9139
|
-
* @param {String|
|
|
9188
|
+
* @param {String|String} propertyNames - The property to write -- either a string with separators, or an array of strings (already split by separator).
|
|
9140
9189
|
* @param {String=} separator - The separator (defaults to a period character).
|
|
9141
9190
|
*/
|
|
9142
9191
|
erase: function erase(target, propertyNames, separator) {
|
|
@@ -10062,6 +10111,20 @@ module.exports = function () {
|
|
|
10062
10111
|
return dataTypeObject;
|
|
10063
10112
|
}
|
|
10064
10113
|
|
|
10114
|
+
/**
|
|
10115
|
+
* References an array.
|
|
10116
|
+
*
|
|
10117
|
+
* @public
|
|
10118
|
+
* @static
|
|
10119
|
+
* @returns {DataType}
|
|
10120
|
+
*/
|
|
10121
|
+
|
|
10122
|
+
}, {
|
|
10123
|
+
key: 'ARRAY',
|
|
10124
|
+
get: function get() {
|
|
10125
|
+
return dataTypeArray;
|
|
10126
|
+
}
|
|
10127
|
+
|
|
10065
10128
|
/**
|
|
10066
10129
|
* References a {@link Decimal} instance.
|
|
10067
10130
|
*
|
|
@@ -10130,6 +10193,7 @@ module.exports = function () {
|
|
|
10130
10193
|
var dataTypeNumber = new DataType('Number', null, null, is.number);
|
|
10131
10194
|
var dataTypeBoolean = new DataType('Boolean', null, null, is.boolean);
|
|
10132
10195
|
var dataTypeObject = new DataType('Object', null, null, is.object);
|
|
10196
|
+
var dataTypeArray = new DataType('Array', null, null, is.array);
|
|
10133
10197
|
|
|
10134
10198
|
var dataTypeDecimal = new DataType('Decimal', null, function (x) {
|
|
10135
10199
|
return Decimal.parse(x);
|
|
@@ -10152,7 +10216,7 @@ module.exports = function () {
|
|
|
10152
10216
|
return x instanceof AdHoc;
|
|
10153
10217
|
}, getBuilder(buildAdHoc));
|
|
10154
10218
|
|
|
10155
|
-
var dataTypes = [dataTypeString, dataTypeNumber, dataTypeBoolean, dataTypeObject, dataTypeDecimal, dataTypeDay, dataTypeTimestamp, dataTypeAdHoc];
|
|
10219
|
+
var dataTypes = [dataTypeString, dataTypeNumber, dataTypeBoolean, dataTypeObject, dataTypeArray, dataTypeDecimal, dataTypeDay, dataTypeTimestamp, dataTypeAdHoc];
|
|
10156
10220
|
|
|
10157
10221
|
function getBuilder(builder) {
|
|
10158
10222
|
return function (data) {
|