@barchart/portfolio-api-common 1.3.3 → 1.3.7

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 ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "validthis": true
3
+ }
@@ -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.');
@@ -307,7 +307,7 @@ module.exports = (() => {
307
307
 
308
308
  const transactionDeleteFailedOutOfSequence = new FailureType('TRANSACTION_DELETE_FAILED_OUT_OF_SEQUENCE', 'Deleting any transaction, except for the most recent, will cause transaction history to be re-written. Please confirm your intent to re-write transaction history (which could take some time and alter the historical results for this position).');
309
309
  const transactionDeleteFailedNoTransaction = new FailureType('TRANSACTION_DELETE_FAILED_NO_TRANSACTION', 'Unable to delete transaction. The referenced transaction does not exist.');
310
- const transactionDeleteFailedDirectionSwitchOnRewrite = new FailureType('TRANSACTION_DELETE_FAILED_DIRECTION_SWITCH_ON_REWRITE', 'Deleting this transaction would cause your history to be re-written and the position to switch from long to short (i.e. positive to negative) or vice versa.');
310
+ const transactionDeleteFailedDirectionSwitchOnRewrite = new FailureType('TRANSACTION_DELETE_FAILED_DIRECTION_SWITCH_ON_REWRITE', 'Deleting this transaction would cause your history to be re-written and the position to switch from long to short (i.e. positive to negative) or vice versa.', false);
311
311
  const transactionDeleteFailedPositionLocked = new FailureType('TRANSACTION_DELETE_FAILED_POSITION_LOCKED', 'Unable to delete transaction, your {L|description} history is being recalculated. Please wait a minute or two and retry.');
312
312
  const transactionDeleteFailedTypeReserved = new FailureType('TRANSACTION_DELETE_FAILED_TYPE_RESERVED', 'Unable to delete {U|type.description} transaction, this type of transaction is managed by the system.');
313
313
 
@@ -45,7 +45,7 @@ module.exports = (() => {
45
45
  *
46
46
  * @public
47
47
  * @static
48
- * @param {Array.<Object>} transactions
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 {Array.<Object>} transactions
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 {Array.<Object>} transactions
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 {Array.<TransactionType>}
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 {Array.<TransactionType>}
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 (or
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 {Array.<Object>} transactions
32
- * @param {Array.<Object>} positions
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 {Array.<Object>} transactions
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 {Array.<PositionTreeDefinition>} definitions
43
- * @param {Array.<Object>} portfolios - The portfolios.
44
- * @param {Array.<Object>} positions - The positions (for all of the portfolios).
45
- * @param {Array.<Object>} summaries - The positions summaries (for all of the positions).
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 {Array.<Object>} summaries
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 {Array.<String>}
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 {Array.<Object>} positionQuotes
455
- * @param {Array.<Object>} forexQuotes
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 {Array.<String>}
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 {Array.<Object>}
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 {Array.<String>} keys
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 {Array.<String>} keys
606
- * @returns {Array.<PositionGroup>}
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 {Array.<Object>}
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 {Array.<Object>}
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 {Array.<PositionItem>} items
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 {Array.<Object>} items
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 {Array.<Rate>} rate
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 {Array.<Object>} previousSummaries
23
+ * @param {Object[]} previousSummaries
24
24
  * @param {Boolean} reporting
25
25
  */
26
26
  class PositionItem extends Disposable {
@@ -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 {Array.<PositionLevelDefinition~RequiredGroup>=} requiredGroups
22
+ * @param {PositionLevelDefinition~RequiredGroup[]=} requiredGroups
23
23
  * @param {Boolean=} aggregateCash
24
24
  * @param {Function=} requiredGroupGenerator
25
25
  */
@@ -160,13 +160,16 @@ module.exports = (() => {
160
160
  * @public
161
161
  * @static
162
162
  * @param {Object} portfolio
163
+ * @param {Currency=} currency
163
164
  * @returns {PositionLevelDefinition~RequiredGroup}
164
165
  */
165
- static buildRequiredGroupForPortfolio(portfolio) {
166
+ static buildRequiredGroupForPortfolio(portfolio, currency) {
167
+ assert.argumentIsOptional(currency, 'currency', Currency, 'Currency');
168
+
166
169
  return {
167
170
  key: PositionLevelDefinition.getKeyForPortfolioGroup(portfolio),
168
171
  description: PositionLevelDefinition.getDescriptionForPortfolioGroup(portfolio),
169
- currency: Currency.CAD
172
+ currency: (currency || Currency.CAD)
170
173
  };
171
174
  }
172
175
 
@@ -182,12 +185,12 @@ module.exports = (() => {
182
185
  return portfolio.name;
183
186
  }
184
187
 
185
- static getRequiredGroupGeneratorForPortfolio() {
188
+ static getRequiredGroupGeneratorForPortfolio(currency) {
186
189
  return (portfolio) => {
187
190
  let requiredGroup;
188
191
 
189
192
  if (is.object(portfolio) && is.string(portfolio.portfolio) && is.string(portfolio.name)) {
190
- requiredGroup = PositionLevelDefinition.buildRequiredGroupForPortfolio(portfolio);
193
+ requiredGroup = PositionLevelDefinition.buildRequiredGroupForPortfolio(portfolio, currency);
191
194
  } else {
192
195
  requiredGroup = null;
193
196
  }
@@ -203,12 +206,13 @@ module.exports = (() => {
203
206
  * @static
204
207
  * @param {InstrumentType} type
205
208
  * @param {Currency} currency
209
+ * @param {Currency=} defaultCurrency
206
210
  * @returns {PositionLevelDefinition~RequiredGroup}
207
211
  */
208
- static buildRequiredGroupForAssetClass(type, currency) {
212
+ static buildRequiredGroupForAssetClass(type, currency, defaultCurrency) {
209
213
  return {
210
214
  key: PositionLevelDefinition.getKeyForAssetClassGroup(type, currency),
211
- description: PositionLevelDefinition.getDescriptionForAssetClassGroup(type, currency),
215
+ description: PositionLevelDefinition.getDescriptionForAssetClassGroup(type, currency, defaultCurrency),
212
216
  currency: currency
213
217
  };
214
218
  }
@@ -220,11 +224,12 @@ module.exports = (() => {
220
224
  return `${type.code}|${currency.code}`;
221
225
  }
222
226
 
223
- static getDescriptionForAssetClassGroup(type, currency) {
227
+ static getDescriptionForAssetClassGroup(type, currency, defaultCurrency) {
224
228
  assert.argumentIsRequired(type, 'type', InstrumentType, 'InstrumentType');
225
229
  assert.argumentIsRequired(currency, 'currency', Currency, 'Currency');
230
+ assert.argumentIsOptional(defaultCurrency, 'defaultCurrency', Currency, 'Currency');
226
231
 
227
- return `${type.alternateDescription}${currency.code === 'CAD' ? '' : ` (${currency.alternateDescription})`}`;
232
+ return `${type.alternateDescription}${currency === (defaultCurrency || Currency.CAD) ? '' : ` (${currency.alternateDescription})`}`;
228
233
  }
229
234
 
230
235
  toString() {
@@ -10,8 +10,8 @@ module.exports = (() => {
10
10
  *
11
11
  * @public
12
12
  * @param {String} name
13
- * @param {Array.<PositionLevelDefinition>} definitions
14
- * @oaram {Array.<String>=} exclusionDependencies
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 {Array.<PositionLevelDefinitions>}
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 {Array.<String>}
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",
3
+ "version": "1.3.7",
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": "~1.6.0",
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",
@@ -1232,7 +1232,7 @@ module.exports = (() => {
1232
1232
  *
1233
1233
  * @public
1234
1234
  * @static
1235
- * @param {Array.<Object>} transactions
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 {Array.<Object>} transactions
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 {Array.<Object>} transactions
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 {Array.<TransactionType>}
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 {Array.<TransactionType>}
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 {Array.<PositionTreeDefinition>} definitions
1529
- * @param {Array.<Object>} portfolios - The portfolios.
1530
- * @param {Array.<Object>} positions - The positions (for all of the portfolios).
1531
- * @param {Array.<Object>} summaries - The positions summaries (for all of the positions).
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 {Array.<Object>} summaries
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 {Array.<String>}
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 {Array.<Object>} positionQuotes
1941
- * @param {Array.<Object>} forexQuotes
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 {Array.<String>}
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 {Array.<Object>}
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 {Array.<String>} keys
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 {Array.<String>} keys
2092
- * @returns {Array.<PositionGroup>}
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 {Array.<Object>}
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 {Array.<Object>}
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 {Array.<PositionItem>} items
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 {Array.<Object>} items
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 {Array.<Rate>} rate
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 {Array.<Object>} previousSummaries
3612
+ * @param {Object[]} previousSummaries
3566
3613
  * @param {Boolean} reporting
3567
3614
  */
3568
3615
  class PositionItem extends Disposable {
@@ -4298,7 +4345,7 @@ module.exports = (() => {
4298
4345
  * @param {PositionLevelDefinition~keySelector} keySelector
4299
4346
  * @param {PositionLevelDefinition~descriptionSelector} descriptionSelector
4300
4347
  * @param {PositionLevelDefinition~currencySelector} currencySelector
4301
- * @param {Array.<PositionLevelDefinition~RequiredGroup>=} requiredGroups
4348
+ * @param {PositionLevelDefinition~RequiredGroup[]=} requiredGroups
4302
4349
  * @param {Boolean=} aggregateCash
4303
4350
  * @param {Function=} requiredGroupGenerator
4304
4351
  */
@@ -4439,13 +4486,16 @@ module.exports = (() => {
4439
4486
  * @public
4440
4487
  * @static
4441
4488
  * @param {Object} portfolio
4489
+ * @param {Currency=} currency
4442
4490
  * @returns {PositionLevelDefinition~RequiredGroup}
4443
4491
  */
4444
- static buildRequiredGroupForPortfolio(portfolio) {
4492
+ static buildRequiredGroupForPortfolio(portfolio, currency) {
4493
+ assert.argumentIsOptional(currency, 'currency', Currency, 'Currency');
4494
+
4445
4495
  return {
4446
4496
  key: PositionLevelDefinition.getKeyForPortfolioGroup(portfolio),
4447
4497
  description: PositionLevelDefinition.getDescriptionForPortfolioGroup(portfolio),
4448
- currency: Currency.CAD
4498
+ currency: (currency || Currency.CAD)
4449
4499
  };
4450
4500
  }
4451
4501
 
@@ -4461,12 +4511,12 @@ module.exports = (() => {
4461
4511
  return portfolio.name;
4462
4512
  }
4463
4513
 
4464
- static getRequiredGroupGeneratorForPortfolio() {
4514
+ static getRequiredGroupGeneratorForPortfolio(currency) {
4465
4515
  return (portfolio) => {
4466
4516
  let requiredGroup;
4467
4517
 
4468
4518
  if (is.object(portfolio) && is.string(portfolio.portfolio) && is.string(portfolio.name)) {
4469
- requiredGroup = PositionLevelDefinition.buildRequiredGroupForPortfolio(portfolio);
4519
+ requiredGroup = PositionLevelDefinition.buildRequiredGroupForPortfolio(portfolio, currency);
4470
4520
  } else {
4471
4521
  requiredGroup = null;
4472
4522
  }
@@ -4482,12 +4532,13 @@ module.exports = (() => {
4482
4532
  * @static
4483
4533
  * @param {InstrumentType} type
4484
4534
  * @param {Currency} currency
4535
+ * @param {Currency=} defaultCurrency
4485
4536
  * @returns {PositionLevelDefinition~RequiredGroup}
4486
4537
  */
4487
- static buildRequiredGroupForAssetClass(type, currency) {
4538
+ static buildRequiredGroupForAssetClass(type, currency, defaultCurrency) {
4488
4539
  return {
4489
4540
  key: PositionLevelDefinition.getKeyForAssetClassGroup(type, currency),
4490
- description: PositionLevelDefinition.getDescriptionForAssetClassGroup(type, currency),
4541
+ description: PositionLevelDefinition.getDescriptionForAssetClassGroup(type, currency, defaultCurrency),
4491
4542
  currency: currency
4492
4543
  };
4493
4544
  }
@@ -4499,11 +4550,12 @@ module.exports = (() => {
4499
4550
  return `${type.code}|${currency.code}`;
4500
4551
  }
4501
4552
 
4502
- static getDescriptionForAssetClassGroup(type, currency) {
4553
+ static getDescriptionForAssetClassGroup(type, currency, defaultCurrency) {
4503
4554
  assert.argumentIsRequired(type, 'type', InstrumentType, 'InstrumentType');
4504
4555
  assert.argumentIsRequired(currency, 'currency', Currency, 'Currency');
4556
+ assert.argumentIsOptional(defaultCurrency, 'defaultCurrency', Currency, 'Currency');
4505
4557
 
4506
- return `${type.alternateDescription}${currency.code === 'CAD' ? '' : ` (${currency.alternateDescription})`}`;
4558
+ return `${type.alternateDescription}${currency === (defaultCurrency || Currency.CAD) ? '' : ` (${currency.alternateDescription})`}`;
4507
4559
  }
4508
4560
 
4509
4561
  toString() {
@@ -4599,8 +4651,8 @@ module.exports = (() => {
4599
4651
  *
4600
4652
  * @public
4601
4653
  * @param {String} name
4602
- * @param {Array.<PositionLevelDefinition>} definitions
4603
- * @oaram {Array.<String>=} exclusionDependencies
4654
+ * @param {PositionLevelDefinition[]} definitions
4655
+ * @oaram {String[]=} exclusionDependencies
4604
4656
  */
4605
4657
  class PositionTreeDefinitions {
4606
4658
  constructor(name, definitions, exclusionDependencies) {
@@ -4633,7 +4685,7 @@ module.exports = (() => {
4633
4685
  * bottom-most level of the tree (i.e. leaf nodes).
4634
4686
  *
4635
4687
  * @public
4636
- * @returns {Array.<PositionLevelDefinitions>}
4688
+ * @returns {PositionLevelDefinitions>[]}
4637
4689
  */
4638
4690
  get definitions() {
4639
4691
  return this._definitions;
@@ -4644,7 +4696,7 @@ module.exports = (() => {
4644
4696
  * group (from the current tree) is excluded.
4645
4697
  *
4646
4698
  * @public
4647
- * @returns {Array.<String>}
4699
+ * @returns {String[]}
4648
4700
  */
4649
4701
  get exclusionDependencies() {
4650
4702
  return this._exclusionDependencies;
@@ -5283,7 +5335,7 @@ module.exports = function () {
5283
5335
  *
5284
5336
  * @public
5285
5337
  * @param {*} value - The value of the node.
5286
- * @param {Tree} parent - The parent node. If not supplied, this will be the root node.
5338
+ * @param {Tree=} parent - The parent node. If not supplied, this will be the root node.
5287
5339
  */
5288
5340
 
5289
5341
  var Tree = function () {
@@ -6429,7 +6481,20 @@ module.exports = function () {
6429
6481
  }
6430
6482
 
6431
6483
  /**
6432
- * Returns a new Day instance for the end of the month of the current instance.
6484
+ * Returns a new {@link Day} instance for the start of the month referenced by the current instance.
6485
+ *
6486
+ * @public
6487
+ * @returns {Day}
6488
+ */
6489
+
6490
+ }, {
6491
+ key: 'getStartOfMonth',
6492
+ value: function getStartOfMonth() {
6493
+ return new Day(this.year, this.month, 1);
6494
+ }
6495
+
6496
+ /**
6497
+ * Returns a new instance for the {@link Day} end of the month referenced by the current instance.
6433
6498
  *
6434
6499
  * @public
6435
6500
  * @returns {Day}
@@ -6581,7 +6646,7 @@ module.exports = function () {
6581
6646
  return this._month;
6582
6647
  }
6583
6648
 
6584
- /**
6649
+ /**day
6585
6650
  * The day of the month.
6586
6651
  *
6587
6652
  * @public
@@ -6602,7 +6667,7 @@ module.exports = function () {
6602
6667
  }
6603
6668
 
6604
6669
  /**
6605
- * Converts a string (which matches the output of {@link Day#format} into
6670
+ * Converts a string (which matches the output of {@link Day#format}) into
6606
6671
  * a {@link Day} instance.
6607
6672
  *
6608
6673
  * @public
@@ -6873,6 +6938,24 @@ module.exports = function () {
6873
6938
  return new Decimal(this._big.div(getBig(other)));
6874
6939
  }
6875
6940
 
6941
+ /**
6942
+ * Returns a new {@link Decimal} instance with a value that results
6943
+ * from raising the current instance to the power of the exponent
6944
+ * provided.
6945
+ *
6946
+ * @public
6947
+ * @param {Decimal|Number|String} exponent
6948
+ * @returns {Decimal}
6949
+ */
6950
+
6951
+ }, {
6952
+ key: 'raise',
6953
+ value: function raise(exponent) {
6954
+ assert.argumentIsRequired(exponent, 'exponent', Number);
6955
+
6956
+ return new Decimal(this._big.pow(exponent));
6957
+ }
6958
+
6876
6959
  /**
6877
6960
  * Returns a new {@link Decimal} with a value resulting from a rounding
6878
6961
  * operation on the current value.
@@ -7037,6 +7120,28 @@ module.exports = function () {
7037
7120
  return this._big.eq(getBig(other));
7038
7121
  }
7039
7122
 
7123
+ /**
7124
+ * Returns true is close to another value.
7125
+ *
7126
+ * @public
7127
+ * @param {Decimal|Number|String} other - The value to compare.
7128
+ * @param {Number} places - The significant digits.
7129
+ * @returns {Boolean}
7130
+ */
7131
+
7132
+ }, {
7133
+ key: 'getIsApproximate',
7134
+ value: function getIsApproximate(other, places) {
7135
+ if (places === 0) {
7136
+ return this.getIsEqual(other);
7137
+ }
7138
+
7139
+ var difference = this.subtract(other).absolute();
7140
+ var tolerance = Decimal.ONE.divide(new Decimal(10).raise(places));
7141
+
7142
+ return difference.getIsLessThan(tolerance);
7143
+ }
7144
+
7040
7145
  /**
7041
7146
  * Returns true if the current instance is an integer (i.e. has no decimal
7042
7147
  * component).
@@ -8720,8 +8825,62 @@ module.exports = function () {
8720
8825
  }
8721
8826
 
8722
8827
  return found;
8828
+ },
8829
+
8830
+
8831
+ /**
8832
+ * Inserts an item into an array using a binary search is used to determine the
8833
+ * proper point for insertion and returns the same array.
8834
+ *
8835
+ * @static
8836
+ * @public
8837
+ * @param {Array} a
8838
+ * @param {*} item
8839
+ * @param {Function} comparator
8840
+ * @returns {Array}
8841
+ */
8842
+ insert: function insert(a, item, comparator) {
8843
+ assert.argumentIsArray(a, 'a');
8844
+ assert.argumentIsRequired(comparator, 'comparator', Function);
8845
+
8846
+ if (a.length === 0 || !(comparator(item, a[a.length - 1]) < 0)) {
8847
+ a.push(item);
8848
+ } else if (comparator(item, a[0]) < 0) {
8849
+ a.unshift(item);
8850
+ } else {
8851
+ a.splice(binarySearch(a, item, comparator, 0, a.length - 1), 0, item);
8852
+ }
8853
+
8854
+ return a;
8723
8855
  }
8724
8856
  };
8857
+
8858
+ function binarySearch(array, item, comparator, start, end) {
8859
+ var size = end - start;
8860
+
8861
+ var midpointIndex = start + Math.floor(size / 2);
8862
+ var midpointItem = array[midpointIndex];
8863
+
8864
+ var comparison = comparator(item, midpointItem) > 0;
8865
+
8866
+ if (size < 2) {
8867
+ if (comparison > 0) {
8868
+ var finalIndex = array.length - 1;
8869
+
8870
+ if (end === finalIndex && comparator(item, array[finalIndex]) > 0) {
8871
+ return end + 1;
8872
+ } else {
8873
+ return end;
8874
+ }
8875
+ } else {
8876
+ return start;
8877
+ }
8878
+ } else if (comparison > 0) {
8879
+ return binarySearch(array, item, comparator, midpointIndex, end);
8880
+ } else {
8881
+ return binarySearch(array, item, comparator, start, midpointIndex);
8882
+ }
8883
+ }
8725
8884
  }();
8726
8885
 
8727
8886
  },{"./assert":29,"./is":33}],29:[function(require,module,exports){
@@ -8937,9 +9096,10 @@ module.exports = function () {
8937
9096
  /**
8938
9097
  * Checks to see if an attribute exists on the target object.
8939
9098
  *
9099
+ * @public
8940
9100
  * @static
8941
9101
  * @param {Object} target - The object to check for existence of the property.
8942
- * @param {String|Array.<String>} propertyNames - The property to check -- either a string with separators, or an array of strings (already split by separator).
9102
+ * @param {String|String[]} propertyNames - The property to check -- either a string with separators, or an array of strings (already split by separator).
8943
9103
  * @param {String=} separator - The separator (defaults to a period character).
8944
9104
  * @returns {boolean}
8945
9105
  */
@@ -8963,9 +9123,10 @@ module.exports = function () {
8963
9123
  * Returns a value from the target object. If the property doesn't exist; undefined
8964
9124
  * is returned.
8965
9125
  *
9126
+ * @public
8966
9127
  * @static
8967
9128
  * @param {Object} target - The object to read from.
8968
- * @param {String|Array.<String>} propertyNames - The property to read -- either a string with separators, or an array of strings (already split by separator).
9129
+ * @param {String|String[]} propertyNames - The property to read -- either a string with separators, or an array of strings (already split by separator).
8969
9130
  * @param {String=} separator - The separator (defaults to a period character).
8970
9131
  * @returns {*}
8971
9132
  */
@@ -8998,9 +9159,10 @@ module.exports = function () {
8998
9159
  /**
8999
9160
  * Writes a value to the target object.
9000
9161
  *
9162
+ * @public
9001
9163
  * @static
9002
9164
  * @param {Object} target - The object to write to.
9003
- * @param {String|Array.<String>} propertyNames - The property to write -- either a string with separators, or an array of strings (already split by separator).
9165
+ * @param {String|String[]} propertyNames - The property to write -- either a string with separators, or an array of strings (already split by separator).
9004
9166
  * @param {*} value - The value to assign.
9005
9167
  * @param {String=} separator - The separator (defaults to a period character).
9006
9168
  */
@@ -9025,9 +9187,10 @@ module.exports = function () {
9025
9187
  /**
9026
9188
  * Erases a property from the target object.
9027
9189
  *
9190
+ * @public
9028
9191
  * @static
9029
9192
  * @param {Object} target - The object to erase a property from.
9030
- * @param {String|Array.<String>} propertyNames - The property to write -- either a string with separators, or an array of strings (already split by separator).
9193
+ * @param {String|String} propertyNames - The property to write -- either a string with separators, or an array of strings (already split by separator).
9031
9194
  * @param {String=} separator - The separator (defaults to a period character).
9032
9195
  */
9033
9196
  erase: function erase(target, propertyNames, separator) {
@@ -9242,7 +9405,7 @@ module.exports = function () {
9242
9405
  * @static
9243
9406
  * @public
9244
9407
  * @param {*} candidate
9245
- * @returns {*|boolean}
9408
+ * @returns {boolean}
9246
9409
  */
9247
9410
  negative: function negative(candidate) {
9248
9411
  return this.number(candidate) && candidate < 0;
@@ -9953,6 +10116,20 @@ module.exports = function () {
9953
10116
  return dataTypeObject;
9954
10117
  }
9955
10118
 
10119
+ /**
10120
+ * References an array.
10121
+ *
10122
+ * @public
10123
+ * @static
10124
+ * @returns {DataType}
10125
+ */
10126
+
10127
+ }, {
10128
+ key: 'ARRAY',
10129
+ get: function get() {
10130
+ return dataTypeArray;
10131
+ }
10132
+
9956
10133
  /**
9957
10134
  * References a {@link Decimal} instance.
9958
10135
  *
@@ -10021,6 +10198,7 @@ module.exports = function () {
10021
10198
  var dataTypeNumber = new DataType('Number', null, null, is.number);
10022
10199
  var dataTypeBoolean = new DataType('Boolean', null, null, is.boolean);
10023
10200
  var dataTypeObject = new DataType('Object', null, null, is.object);
10201
+ var dataTypeArray = new DataType('Array', null, null, is.array);
10024
10202
 
10025
10203
  var dataTypeDecimal = new DataType('Decimal', null, function (x) {
10026
10204
  return Decimal.parse(x);
@@ -10043,7 +10221,7 @@ module.exports = function () {
10043
10221
  return x instanceof AdHoc;
10044
10222
  }, getBuilder(buildAdHoc));
10045
10223
 
10046
- var dataTypes = [dataTypeString, dataTypeNumber, dataTypeBoolean, dataTypeObject, dataTypeDecimal, dataTypeDay, dataTypeTimestamp, dataTypeAdHoc];
10224
+ var dataTypes = [dataTypeString, dataTypeNumber, dataTypeBoolean, dataTypeObject, dataTypeArray, dataTypeDecimal, dataTypeDay, dataTypeTimestamp, dataTypeAdHoc];
10047
10225
 
10048
10226
  function getBuilder(builder) {
10049
10227
  return function (data) {