@barchart/portfolio-api-common 1.0.225 → 1.0.229

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.
@@ -90,7 +90,7 @@ module.exports = (() => {
90
90
  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).');
91
91
  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.');
92
92
  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.');
93
- const transactionCreateFailedInvalidDirectionSwitch = new FailureType('TRANSACTION_CREATE_FAILED_INVALID_DIRECTION_SWITCH', 'Unable to process transaction, the transaction would switch the position from {L|previousDirection.description} to {L|proposedDirection.description} (i.e. {L|previousDirection.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.');
93
+ 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.');
94
94
 
95
95
  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).');
96
96
  const transactionDeleteUnsupported = new FailureType('TRANSACTION_DELETE_UNSUPPORTED', 'Unable to delete transaction. This operation is not currently supported (but will be implemented soon).');
@@ -91,7 +91,7 @@ module.exports = (() => {
91
91
  * @return {Boolean}
92
92
  */
93
93
  static validateDirectionSwitch(instrumentType, currentDirection, proposedDirection) {
94
- return currentDirection === null || instrumentType.canSwitchDirection || (!currentDirection.closed && !proposedDirection.closed && currentDirection.positive !== proposedDirection.positive);
94
+ return currentDirection === null || instrumentType.canSwitchDirection || (currentDirection.closed || proposedDirection.closed || currentDirection.positive === proposedDirection.positive);
95
95
  }
96
96
 
97
97
  toString() {
@@ -132,7 +132,7 @@ module.exports = (() => {
132
132
  associateTypes(InstrumentType.OTHER, TransactionType.SELL, true, [ PositionDirection.LONG ]);
133
133
  associateTypes(InstrumentType.OTHER, TransactionType.INCOME, true, [ PositionDirection.LONG ]);
134
134
  associateTypes(InstrumentType.OTHER, TransactionType.FEE, true, [ PositionDirection.LONG ]);
135
- associateTypes(InstrumentType.OTHER, TransactionType.VALUATION, true);
135
+ associateTypes(InstrumentType.OTHER, TransactionType.VALUATION, true, [ PositionDirection.LONG ]);
136
136
 
137
137
  associateTypes(InstrumentType.CASH, TransactionType.DEPOSIT, true);
138
138
  associateTypes(InstrumentType.CASH, TransactionType.WITHDRAWAL, true);
@@ -152,19 +152,19 @@ module.exports = (() => {
152
152
  validDirections[instrumentTypeCode].push(positionDirection);
153
153
  }
154
154
 
155
- associateTypes(InstrumentType.EQUITY, PositionDirection.EVEN);
156
- associateTypes(InstrumentType.EQUITY, PositionDirection.LONG);
157
- associateTypes(InstrumentType.EQUITY, PositionDirection.SHORT);
155
+ associateDirections(InstrumentType.EQUITY, PositionDirection.EVEN);
156
+ associateDirections(InstrumentType.EQUITY, PositionDirection.LONG);
157
+ associateDirections(InstrumentType.EQUITY, PositionDirection.SHORT);
158
158
 
159
- associateTypes(InstrumentType.FUND, PositionDirection.EVEN);
160
- associateTypes(InstrumentType.FUND, PositionDirection.LONG);
159
+ associateDirections(InstrumentType.FUND, PositionDirection.EVEN);
160
+ associateDirections(InstrumentType.FUND, PositionDirection.LONG);
161
161
 
162
- associateTypes(InstrumentType.OTHER, PositionDirection.EVEN);
163
- associateTypes(InstrumentType.OTHER, PositionDirection.LONG);
162
+ associateDirections(InstrumentType.OTHER, PositionDirection.EVEN);
163
+ associateDirections(InstrumentType.OTHER, PositionDirection.LONG);
164
164
 
165
- associateTypes(InstrumentType.CASH, PositionDirection.EVEN);
166
- associateTypes(InstrumentType.CASH, PositionDirection.LONG);
167
- associateTypes(InstrumentType.CASH, PositionDirection.SHORT);
165
+ associateDirections(InstrumentType.CASH, PositionDirection.EVEN);
166
+ associateDirections(InstrumentType.CASH, PositionDirection.LONG);
167
+ associateDirections(InstrumentType.CASH, PositionDirection.SHORT);
168
168
 
169
169
  return TransactionValidator;
170
170
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.0.225",
3
+ "version": "1.0.229",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",