@barchart/portfolio-api-common 1.0.196 → 1.0.200

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.
@@ -15,6 +15,7 @@ module.exports = (() => {
15
15
  /**
16
16
  * The transaction would occur before an existing transaction.
17
17
  *
18
+ * @public
18
19
  * @static
19
20
  * @returns {FailureType}
20
21
  */
@@ -22,12 +23,49 @@ module.exports = (() => {
22
23
  return transactionCreateFailedOutOfSequence;
23
24
  }
24
25
 
26
+ /**
27
+ * The transaction would cause the position to change (from long to
28
+ * short, or vice versa).
29
+ *
30
+ * @public
31
+ * @static
32
+ * @returns {FailureType}
33
+ */
34
+ static get TRANSACTION_CREATE_FAILED_DIRECTION_SWITCH() {
35
+ return transactionCreateFailedDirectionSwitch;
36
+ }
37
+
38
+ static get TRANSACTION_CREATE_REWRITE_UNSUPPORTED() {
39
+ return transactionCreateRewriteUnsupported;
40
+ }
41
+
42
+ /**
43
+ * Deleting any transaction except for the most recent requires
44
+ * re-writing transaction history.
45
+ *
46
+ * @public
47
+ * @static
48
+ * @returns {FailureType}
49
+ */
50
+ static get TRANSACTION_DELETE_FAILED_OUT_OF_SEQUENCE() {
51
+ return transactionDeleteFailedOutOfSequence;
52
+ }
53
+
54
+ static get TRANSACTION_DELETE_UNSUPPORTED() {
55
+ return transactionDeleteUnsupported;
56
+ }
57
+
25
58
  toString() {
26
59
  return '[PortfolioFailureType]';
27
60
  }
28
61
  }
29
62
 
30
- const transactionCreateFailedOutOfSequence = new FailureType('TRANSACTION_CREATE_FAILED_OUT_OF_SEQUENCE', 'Unable to create transaction, the transaction date is out-of-sequence (i.e. it would occur before an existing transaction). Please confirm your intent to re-write transaction history.');
63
+ const transactionCreateFailedOutOfSequence = new FailureType('TRANSACTION_CREATE_FAILED_OUT_OF_SEQUENCE', 'Unable to create 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).');
64
+ const transactionCreateFailedDirectionSwitch = new FailureType('TRANSACTION_CREATE_FAILED_DIRECTION_SWITCH', 'Unable to create transaction, because the position direction would be switched (from long to short or vice versa). Please close the position (to a zero balance) first, then enter a second transaction.');
65
+ const transactionCreateRewriteUnsupported = new FailureType('TRANSACTION_CREATE_REWRITE_UNSUPPORTED', 'Unable to re-write transaction history. This operation is not currently supported (but will be implemented soon).');
66
+
67
+ 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).');
68
+ const transactionDeleteUnsupported = new FailureType('TRANSACTION_DELETE_UNSUPPORTED', 'Unable to delete transaction. This operation is not currently supported (but will be implemented soon).');
31
69
 
32
70
  return PortfolioFailureType;
33
71
  })();
@@ -24,6 +24,11 @@ module.exports = (() => {
24
24
 
25
25
  const DEFAULT_CURRENCY = Currency.CAD;
26
26
 
27
+ const REQUIRED_CURRENCIES = [
28
+ Currency.CAD,
29
+ Currency.USD
30
+ ];
31
+
27
32
  /**
28
33
  * A container for positions which groups the positions into one or more
29
34
  * trees for aggregation and display purposes. For example, positions could be
@@ -114,7 +119,9 @@ module.exports = (() => {
114
119
  return map;
115
120
  }, { });
116
121
 
117
- this._forexSymbols = Object.keys(this._currencies).reduce((symbols, code) => {
122
+ const forexCurrencyCodes = array.unique(Object.keys(this._currencies).concat(REQUIRED_CURRENCIES.map(c => c.code)));
123
+
124
+ this._forexSymbols = forexCurrencyCodes.reduce((symbols, code) => {
118
125
  if (code !== DEFAULT_CURRENCY.code) {
119
126
  symbols.push(`^${DEFAULT_CURRENCY.code}${code}`);
120
127
  }
@@ -254,6 +254,7 @@ module.exports = (() => {
254
254
  .withField('price', DataType.DECIMAL)
255
255
  .withField('quantity', DataType.DECIMAL)
256
256
  .withField('fee', DataType.DECIMAL, true)
257
+ .withField('force', DataType.BOOLEAN, true)
257
258
  .schema
258
259
  );
259
260
 
@@ -265,6 +266,7 @@ module.exports = (() => {
265
266
  .withField('price', DataType.DECIMAL)
266
267
  .withField('quantity', DataType.DECIMAL)
267
268
  .withField('fee', DataType.DECIMAL, true)
269
+ .withField('force', DataType.BOOLEAN, true)
268
270
  .schema
269
271
  );
270
272
 
@@ -276,6 +278,7 @@ module.exports = (() => {
276
278
  .withField('price', DataType.DECIMAL)
277
279
  .withField('quantity', DataType.DECIMAL)
278
280
  .withField('fee', DataType.DECIMAL, true)
281
+ .withField('force', DataType.BOOLEAN, true)
279
282
  .schema
280
283
  );
281
284
 
@@ -292,6 +295,7 @@ module.exports = (() => {
292
295
  .withField('price', DataType.DECIMAL)
293
296
  .withField('quantity', DataType.DECIMAL)
294
297
  .withField('fee', DataType.DECIMAL, true)
298
+ .withField('force', DataType.BOOLEAN, true)
295
299
  .schema
296
300
  );
297
301
 
@@ -303,6 +307,7 @@ module.exports = (() => {
303
307
  .withField('rate', DataType.DECIMAL)
304
308
  .withField('effective', DataType.DAY)
305
309
  .withField('fee', DataType.DECIMAL, true)
310
+ .withField('force', DataType.BOOLEAN, true)
306
311
  .schema
307
312
  );
308
313
 
@@ -315,6 +320,7 @@ module.exports = (() => {
315
320
  .withField('effective', DataType.DAY)
316
321
  .withField('price', DataType.DECIMAL)
317
322
  .withField('fee', DataType.DECIMAL, true)
323
+ .withField('force', DataType.BOOLEAN, true)
318
324
  .schema
319
325
  );
320
326
 
@@ -327,6 +333,7 @@ module.exports = (() => {
327
333
  .withField('effective', DataType.DAY)
328
334
  .withField('price', DataType.DECIMAL)
329
335
  .withField('fee', DataType.DECIMAL, true)
336
+ .withField('force', DataType.BOOLEAN, true)
330
337
  .schema
331
338
  );
332
339
 
@@ -338,6 +345,7 @@ module.exports = (() => {
338
345
  .withField('rate', DataType.DECIMAL)
339
346
  .withField('effective', DataType.DAY)
340
347
  .withField('fee', DataType.DECIMAL, true)
348
+ .withField('force', DataType.BOOLEAN, true)
341
349
  .schema
342
350
  );
343
351
 
@@ -350,6 +358,7 @@ module.exports = (() => {
350
358
  .withField('effective', DataType.DAY)
351
359
  .withField('price', DataType.DECIMAL)
352
360
  .withField('fee', DataType.DECIMAL, true)
361
+ .withField('force', DataType.BOOLEAN, true)
353
362
  .schema
354
363
  );
355
364
 
@@ -362,6 +371,7 @@ module.exports = (() => {
362
371
  .withField('denominator', DataType.DECIMAL)
363
372
  .withField('effective', DataType.DAY)
364
373
  .withField('fee', DataType.DECIMAL, true)
374
+ .withField('force', DataType.BOOLEAN, true)
365
375
  .schema
366
376
  );
367
377
 
@@ -371,6 +381,7 @@ module.exports = (() => {
371
381
  .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
372
382
  .withField('date', DataType.DAY)
373
383
  .withField('fee', DataType.DECIMAL)
384
+ .withField('force', DataType.BOOLEAN, true)
374
385
  .schema
375
386
  );
376
387
 
@@ -381,6 +392,7 @@ module.exports = (() => {
381
392
  .withField('date', DataType.DAY)
382
393
  .withField('fee', DataType.DECIMAL)
383
394
  .withField('price', DataType.DECIMAL)
395
+ .withField('force', DataType.BOOLEAN, true)
384
396
  .schema
385
397
  );
386
398
 
@@ -393,6 +405,7 @@ module.exports = (() => {
393
405
  .withField('date', DataType.DAY)
394
406
  .withField('amount', DataType.DECIMAL)
395
407
  .withField('fee', DataType.DECIMAL, true)
408
+ .withField('force', DataType.BOOLEAN, true)
396
409
  .schema
397
410
  );
398
411
 
@@ -403,6 +416,7 @@ module.exports = (() => {
403
416
  .withField('date', DataType.DAY)
404
417
  .withField('amount', DataType.DECIMAL)
405
418
  .withField('fee', DataType.DECIMAL, true)
419
+ .withField('force', DataType.BOOLEAN, true)
406
420
  .schema
407
421
  );
408
422
 
@@ -413,6 +427,7 @@ module.exports = (() => {
413
427
  .withField('date', DataType.DAY)
414
428
  .withField('amount', DataType.DECIMAL)
415
429
  .withField('fee', DataType.DECIMAL, true)
430
+ .withField('force', DataType.BOOLEAN, true)
416
431
  .schema
417
432
  );
418
433
 
@@ -423,6 +438,7 @@ module.exports = (() => {
423
438
  .withField('date', DataType.DAY)
424
439
  .withField('amount', DataType.DECIMAL)
425
440
  .withField('fee', DataType.DECIMAL, true)
441
+ .withField('force', DataType.BOOLEAN, true)
426
442
  .schema
427
443
  );
428
444
 
@@ -433,6 +449,7 @@ module.exports = (() => {
433
449
  .withField('date', DataType.DAY)
434
450
  .withField('value', DataType.DECIMAL)
435
451
  .withField('fee', DataType.DECIMAL, true)
452
+ .withField('force', DataType.BOOLEAN, true)
436
453
  .schema
437
454
  );
438
455
 
@@ -443,6 +460,7 @@ module.exports = (() => {
443
460
  .withField('date', DataType.DAY)
444
461
  .withField('income', DataType.DECIMAL)
445
462
  .withField('fee', DataType.DECIMAL, true)
463
+ .withField('force', DataType.BOOLEAN, true)
446
464
  .schema
447
465
  );
448
466
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.0.196",
3
+ "version": "1.0.200",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -740,6 +740,11 @@ module.exports = (() => {
740
740
 
741
741
  const DEFAULT_CURRENCY = Currency.CAD;
742
742
 
743
+ const REQUIRED_CURRENCIES = [
744
+ Currency.CAD,
745
+ Currency.USD
746
+ ];
747
+
743
748
  /**
744
749
  * A container for positions which groups the positions into one or more
745
750
  * trees for aggregation and display purposes. For example, positions could be
@@ -830,7 +835,9 @@ module.exports = (() => {
830
835
  return map;
831
836
  }, { });
832
837
 
833
- this._forexSymbols = Object.keys(this._currencies).reduce((symbols, code) => {
838
+ const forexCurrencyCodes = array.unique(Object.keys(this._currencies).concat(REQUIRED_CURRENCIES.map(c => c.code)));
839
+
840
+ this._forexSymbols = forexCurrencyCodes.reduce((symbols, code) => {
834
841
  if (code !== DEFAULT_CURRENCY.code) {
835
842
  symbols.push(`^${DEFAULT_CURRENCY.code}${code}`);
836
843
  }