@barchart/portfolio-api-common 1.0.220 → 1.0.221

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.
@@ -35,15 +35,21 @@ module.exports = (() => {
35
35
  }
36
36
 
37
37
  /**
38
- * The transaction type is not valid, given the current position size
39
- * (e.g. sell is invalid for a short position, sell short must be used).
40
- *
41
38
  * @public
42
39
  * @static
43
40
  * @returns {FailureType}
44
41
  */
45
- static get TRANSACTION_CREATE_FAILED_TYPE_INVALID_FOR_POSITION() {
46
- return transactionCreateFailedTypeInvalidForPosition;
42
+ static get TRANSACTION_CREATE_FAILED_TYPE_INVALID_FOR_INSTRUMENT() {
43
+ return transactionCreateFailedTypeInvalidForInstrument;
44
+ }
45
+
46
+ /**
47
+ * @public
48
+ * @static
49
+ * @returns {FailureType}
50
+ */
51
+ static get TRANSACTION_CREATE_FAILED_TYPE_INVALID_FOR_DIRECTION() {
52
+ return transactionCreateFailedTypeInvalidForDirection;
47
53
  }
48
54
 
49
55
  /**
@@ -54,12 +60,8 @@ module.exports = (() => {
54
60
  * @static
55
61
  * @returns {FailureType}
56
62
  */
57
- static get TRANSACTION_CREATE_FAILED_DIRECTION_SWITCH() {
58
- return transactionCreateFailedDirectionSwitch;
59
- }
60
-
61
- static get TRANSACTION_CREATE_REWRITE_UNSUPPORTED() {
62
- return transactionCreateRewriteUnsupported;
63
+ static get TRANSACTION_CREATE_FAILED_INVALID_DIRECTION_SWITCH() {
64
+ return transactionCreateFailedInvalidDirectionSwitch;
63
65
  }
64
66
 
65
67
  /**
@@ -86,9 +88,9 @@ module.exports = (() => {
86
88
  const positionCreateFailedNoPortfolio = new FailureType('POSITION_CREATE_FAILED_NO_PORTFOLIO', 'Unable to create transaction. The referenced portfolio does not exist. Has it been deleted?');
87
89
 
88
90
  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).');
89
- const transactionCreateFailedTypeInvalidForPosition = new FailureType('TRANSACTION_CREATE_FAILED_INVALID_FOR_POSITION', 'A {L|type.description} are not allowed. At the time of the transaction, your position is {L|direction} (i.e. {L|sign}).');
90
- 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), then enter a second transaction.');
91
- 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).');
91
+ const transactionCreateFailedTypeInvalidForInstrument = new FailureType('TRANSACTION_CREATE_FAILED_TYPE_INVALID_FOR_INSTRUMENT', '{L|transactionType.description} are not allowed for {L|instrumentType.description}');
92
+ const transactionCreateFailedTypeInvalidForDirection = new FailureType('TRANSACTION_CREATE_FAILED_TYPE_INVALID_FOR_DIRECTION', 'A {L|type.description} are not allowed. At the time of the transaction, your position is {L|direction} (i.e. {L|sign}).');
93
+ const transactionCreateFailedInvalidDirectionSwitch = new FailureType('TRANSACTION_CREATE_FAILED_INVALID_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), then enter a second transaction.');
92
94
 
93
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).');
94
96
  const transactionDeleteUnsupported = new FailureType('TRANSACTION_DELETE_UNSUPPORTED', 'Unable to delete transaction. This operation is not currently supported (but will be implemented soon).');
@@ -19,7 +19,7 @@ module.exports = (() => {
19
19
  constructor(code, description, sign) {
20
20
  super(code, description);
21
21
 
22
- assert.argumentIsString(sign, 'sign', String);
22
+ assert.argumentIsRequired(sign, 'sign', String);
23
23
 
24
24
  this._sign = sign;
25
25
  }
@@ -24,9 +24,10 @@ module.exports = (() => {
24
24
  * @public
25
25
  * @param {InstrumentType} instrumentType
26
26
  * @param {Boolean=} userInitiated
27
+ * @pararm {PositionDirection=} currentDirection
27
28
  * @return {Array.<TransactionType>}
28
29
  */
29
- static getTransactionTypesFor(instrumentType, userInitiated) {
30
+ static getTransactionTypesFor(instrumentType, userInitiated, currentDirection) {
30
31
  assert.argumentIsRequired(instrumentType, 'instrumentType', InstrumentType, 'InstrumentType');
31
32
  assert.argumentIsOptional(userInitiated, 'userInitiated', Boolean);
32
33
 
@@ -96,7 +97,7 @@ module.exports = (() => {
96
97
 
97
98
  const validTransactionTypes = { };
98
99
 
99
- function associateTypes(instrumentType, transactionType, userInitiated) {
100
+ function associateTypes(instrumentType, transactionType, userInitiated, directions) {
100
101
  const instrumentTypeCode = instrumentType.code;
101
102
 
102
103
  if (!validTransactionTypes.hasOwnProperty(instrumentTypeCode)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.0.220",
3
+ "version": "1.0.221",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",