@barchart/portfolio-api-common 1.5.1 → 1.8.0

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.
@@ -0,0 +1,4 @@
1
+ **Technical Enhancements**
2
+
3
+ * Added a `transaction` field into `basicFormatter` function for the `TransactionFormatter` class.
4
+ * Changed the way to add and remove a portfolio in `PositionContainer` to support reactive changes.
@@ -0,0 +1,3 @@
1
+ **New Features**
2
+
3
+ * Added a new `PortfolioFailureType` for attempting to edit a transaction's type.
@@ -0,0 +1,3 @@
1
+ **New Features**
2
+
3
+ * Added a new `PortfolioFailureType` for attempting to reinvest a dividend when the position is short.
@@ -0,0 +1,3 @@
1
+ **New Features**
2
+
3
+ * Added a new `PortfolioFailureType` for attempts to switch to dividend reinvestment when the position is short.
@@ -212,6 +212,18 @@ module.exports = (() => {
212
212
  return transactionCreateFailedReinvestPriceUnavailable;
213
213
  }
214
214
 
215
+ /**
216
+ * The transaction failed because a dividends cannot be re-invested
217
+ * for short positions.
218
+ *
219
+ * @public
220
+ * @static
221
+ * @returns {FailureType}
222
+ */
223
+ static get TRANSACTION_CREATE_FAILED_REINVEST_INVALID() {
224
+ return transactionCreateFailedReinvestInvalid;
225
+ }
226
+
215
227
  /**
216
228
  * The transaction failed because a related position is locked.
217
229
  *
@@ -326,6 +338,40 @@ module.exports = (() => {
326
338
  return transactionEditFailedTypeReserved;
327
339
  }
328
340
 
341
+ /**
342
+ * A transaction's type cannot be changed.
343
+ *
344
+ * @public
345
+ * @static
346
+ * @returns {FailureType}
347
+ */
348
+ static get TRANSACTION_EDIT_FAILED_TYPE_CHANGED() {
349
+ return transactionEditFailedTypeChanged;
350
+ }
351
+
352
+ /**
353
+ * Conversion of transaction type is unsupported.
354
+ *
355
+ * @public
356
+ * @static
357
+ * @returns {FailureType}
358
+ */
359
+ static get TRANSACTION_SWITCH_FAILED_INVALID_CONVERSION() {
360
+ return transactionSwitchFailedInvalidConversion;
361
+ }
362
+
363
+ /**
364
+ * Conversion of transaction type is not allowed. Dividends (or distributions)
365
+ * cannot be reinvested when the position is short.
366
+ *
367
+ * @public
368
+ * @static
369
+ * @returns {FailureType}
370
+ */
371
+ static get TRANSACTION_SWITCH_FAILED_INVALID_REINVEST() {
372
+ return transactionSwitchFailedInvalidReinvest;
373
+ }
374
+
329
375
  toString() {
330
376
  return '[PortfolioFailureType]';
331
377
  }
@@ -352,6 +398,7 @@ module.exports = (() => {
352
398
 
353
399
  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.');
354
400
  const transactionCreateFailedReinvestPriceUnavailable = new FailureType('TRANSACTION_CREATE_FAILED_REINVEST_PRICE_UNAVAILABLE', 'Unable to create transaction, a dividend was paid on {L|day}; however no historical price is available for this day. To successfully create this transaction, please turn off dividend reinvestment for this position.');
401
+ const transactionCreateFailedReinvestInvalid = new FailureType('TRANSACTION_CREATE_FAILED_REINVEST_INVALID', 'Unable to create transaction, short positions do not allow dividends to be reinvested.');
355
402
  const transactionCreateFailedPositionLocked = new FailureType('TRANSACTION_CREATE_FAILED_POSITION_LOCKED', 'Unable to create transaction, your {L|description} history is being recalculated. Please re-enter this transaction in a minute or two.');
356
403
  const transactionCreateFailedInstrumentCorrupt = new FailureType('TRANSACTION_CREATE_FAILED_INSTRUMENT_CORRUPT', 'Unable to create transaction, corporate action history for {U|symbol} cannot be located. The issue should be corrected within 24 to 48 hours.');
357
404
 
@@ -364,6 +411,10 @@ module.exports = (() => {
364
411
  const transactionEditFailedInvalidDate = new FailureType('TRANSACTION_EDIT_FAILED_INVALID_DATE', 'Unable to edit transaction with given date.');
365
412
  const transactionEditFailedNoTransaction = new FailureType('TRANSACTION_EDIT_FAILED_NO_TRANSACTION', 'Unable to edit transaction. The referenced transaction does not exist.', false);
366
413
  const transactionEditFailedTypeReserved = new FailureType('TRANSACTION_EDIT_FAILED_TYPE_RESERVED', 'Unable to edit {U|type.description} transaction, this type of transaction is managed by the system.');
414
+ const transactionEditFailedTypeChanged = new FailureType('TRANSACTION_EDIT_FAILED_TYPE_CHANGED', 'Changing a transaction type is forbidden. You must delete the existing transaction and then create a new transaction.');
415
+
416
+ const transactionSwitchFailedInvalidConversion = new FailureType('TRANSACTION_SWITCH_FAILED_INVALID_CONVERSION', 'Unable to convert transaction from {U|existing.description} to {U|desired.description}. This conversion is not supported.');
417
+ const transactionSwitchFailedInvalidReinvest = new FailureType('TRANSACTION_SWITCH_FAILED_INVALID_REINVEST', 'Unable to convert transaction from {U|existing.description} to {U|desired.description}. Reinvestment is not supported for short positions.');
367
418
 
368
419
  return PortfolioFailureType;
369
420
  })();
@@ -1,7 +1,6 @@
1
1
  const assert = require('@barchart/common-js/lang/assert'),
2
2
  array = require('@barchart/common-js/lang/array'),
3
- is = require('@barchart/common-js/lang/is'),
4
- Day = require('@barchart/common-js/lang/Day');
3
+ is = require('@barchart/common-js/lang/is');
5
4
 
6
5
  const InstrumentType = require('./InstrumentType'),
7
6
  PositionDirection = require('./PositionDirection'),
@@ -127,6 +127,7 @@ module.exports = (() => {
127
127
  f.sequence = t.sequence;
128
128
  f.position = t.position;
129
129
  f.open = t.snapshot.open;
130
+ f.transaction = t.transaction;
130
131
  };
131
132
 
132
133
  const averageCostFormatter = (t, f) => {
@@ -234,7 +234,7 @@ module.exports = (() => {
234
234
  const key = portfolio.portfolio;
235
235
 
236
236
  if (!this._portfolios.hasOwnProperty(key)) {
237
- this._portfolios[key] = portfolio;
237
+ this._portfolios = Object.assign({}, this._portfolios, { [key]: portfolio });
238
238
 
239
239
  this._definitions.forEach((treeDefinition) => {
240
240
  const tree = this._trees[treeDefinition.name];
@@ -314,6 +314,8 @@ module.exports = (() => {
314
314
 
315
315
  delete this._portfolios[portfolio.portfolio];
316
316
 
317
+ this._portfolios = Object.assign({}, this._portfolios);
318
+
317
319
  Object.keys(this._trees).forEach((key) => {
318
320
  this._trees[key].walk((group, groupNode) => {
319
321
  if (group.definition.type === PositionLevelType.PORTFOLIO && group.key === PositionLevelDefinition.getKeyForPortfolioGroup(portfolio)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.5.1",
3
+ "version": "1.8.0",
4
4
  "description": "Common code used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -1291,8 +1291,7 @@ module.exports = (() => {
1291
1291
  },{"@barchart/common-js/lang/Enum":26,"@barchart/common-js/lang/assert":31}],5:[function(require,module,exports){
1292
1292
  const assert = require('@barchart/common-js/lang/assert'),
1293
1293
  array = require('@barchart/common-js/lang/array'),
1294
- is = require('@barchart/common-js/lang/is'),
1295
- Day = require('@barchart/common-js/lang/Day');
1294
+ is = require('@barchart/common-js/lang/is');
1296
1295
 
1297
1296
  const InstrumentType = require('./InstrumentType'),
1298
1297
  PositionDirection = require('./PositionDirection'),
@@ -1595,7 +1594,7 @@ module.exports = (() => {
1595
1594
  return TransactionValidator;
1596
1595
  })();
1597
1596
 
1598
- },{"./InstrumentType":1,"./PositionDirection":2,"./TransactionType":4,"@barchart/common-js/lang/Day":23,"@barchart/common-js/lang/array":30,"@barchart/common-js/lang/assert":31,"@barchart/common-js/lang/is":35}],6:[function(require,module,exports){
1597
+ },{"./InstrumentType":1,"./PositionDirection":2,"./TransactionType":4,"@barchart/common-js/lang/array":30,"@barchart/common-js/lang/assert":31,"@barchart/common-js/lang/is":35}],6:[function(require,module,exports){
1599
1598
  const Enum = require('@barchart/common-js/lang/Enum');
1600
1599
 
1601
1600
  module.exports = (() => {
@@ -1893,7 +1892,7 @@ module.exports = (() => {
1893
1892
  const key = portfolio.portfolio;
1894
1893
 
1895
1894
  if (!this._portfolios.hasOwnProperty(key)) {
1896
- this._portfolios[key] = portfolio;
1895
+ this._portfolios = Object.assign({}, this._portfolios, { [key]: portfolio });
1897
1896
 
1898
1897
  this._definitions.forEach((treeDefinition) => {
1899
1898
  const tree = this._trees[treeDefinition.name];
@@ -1973,6 +1972,8 @@ module.exports = (() => {
1973
1972
 
1974
1973
  delete this._portfolios[portfolio.portfolio];
1975
1974
 
1975
+ this._portfolios = Object.assign({}, this._portfolios);
1976
+
1976
1977
  Object.keys(this._trees).forEach((key) => {
1977
1978
  this._trees[key].walk((group, groupNode) => {
1978
1979
  if (group.definition.type === PositionLevelType.PORTFOLIO && group.key === PositionLevelDefinition.getKeyForPortfolioGroup(portfolio)) {