@barchart/portfolio-api-common 1.2.44 → 1.2.48
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/lib/api/failures/PortfolioFailureType.js +14 -1
- package/lib/data/TransactionValidator.js +3 -1
- package/lib/formatters/TransactionFormatter.js +1 -2
- package/lib/serialization/TransactionSchema.js +1 -2
- package/package.json +1 -1
- package/test/SpecRunner.js +8164 -211
- package/test/specs/serialization/TransactionSchemaSpec.js +67 -0
|
@@ -131,6 +131,18 @@ module.exports = (() => {
|
|
|
131
131
|
return transactionCreateFailedTypeReserved;
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
/**
|
|
135
|
+
* The transaction failed because a dividend would be reinvested on
|
|
136
|
+
* a day for which no historical price is available.
|
|
137
|
+
*
|
|
138
|
+
* @public
|
|
139
|
+
* @static
|
|
140
|
+
* @returns {FailureType}
|
|
141
|
+
*/
|
|
142
|
+
static get TRANSACTION_CREATE_FAILED_REINVEST_PRICE_UNAVAILABLE() {
|
|
143
|
+
return transactionCreateFailedReinvestPriceUnavailable;
|
|
144
|
+
}
|
|
145
|
+
|
|
134
146
|
/**
|
|
135
147
|
* Deleting any transaction except for the most recent requires
|
|
136
148
|
* re-writing transaction history.
|
|
@@ -204,8 +216,9 @@ module.exports = (() => {
|
|
|
204
216
|
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.');
|
|
205
217
|
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.');
|
|
206
218
|
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.');
|
|
207
|
-
const transactionCreateFailedInvalidInitialType = new FailureType('
|
|
219
|
+
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.');
|
|
208
220
|
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.');
|
|
221
|
+
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.');
|
|
209
222
|
|
|
210
223
|
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).');
|
|
211
224
|
const transactionDeleteFailedNoTransaction = new FailureType('TRANSACTION_DELETE_FAILED_NO_TRANSACTION', 'Unable to delete transaction. The referenced transaction does not exist.');
|
|
@@ -92,7 +92,7 @@ module.exports = (() => {
|
|
|
92
92
|
* @public
|
|
93
93
|
* @param {InstrumentType} instrumentType
|
|
94
94
|
* @param {Boolean=} userInitiated
|
|
95
|
-
* @
|
|
95
|
+
* @param {PositionDirection=} currentDirection
|
|
96
96
|
* @returns {Array.<TransactionType>}
|
|
97
97
|
*/
|
|
98
98
|
static getTransactionTypesFor(instrumentType, userInitiated, currentDirection) {
|
|
@@ -156,7 +156,9 @@ module.exports = (() => {
|
|
|
156
156
|
* Determines if a transaction type is valid as the first transaction of
|
|
157
157
|
* a position.
|
|
158
158
|
*
|
|
159
|
+
* @public
|
|
159
160
|
* @param {TransactionType} transactionType
|
|
161
|
+
* @returns {Boolean}
|
|
160
162
|
*/
|
|
161
163
|
static validateInitialTransactionType(transactionType) {
|
|
162
164
|
return transactionType.initial;
|
|
@@ -175,14 +175,13 @@ module.exports = (() => {
|
|
|
175
175
|
|
|
176
176
|
formatters.set(TransactionType.DISTRIBUTION_FUND, (t) => {
|
|
177
177
|
return {
|
|
178
|
-
shares: t.
|
|
178
|
+
shares: t.quantity,
|
|
179
179
|
fee: t.fee
|
|
180
180
|
};
|
|
181
181
|
});
|
|
182
182
|
|
|
183
183
|
formatters.set(TransactionType.DISTRIBUTION_REINVEST, (t) => {
|
|
184
184
|
return {
|
|
185
|
-
boughtSold: t.quantity,
|
|
186
185
|
shares: t.snapshot.open.subtract(t.quantity),
|
|
187
186
|
price: t.dividend.price,
|
|
188
187
|
fee: t.fee,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
const
|
|
2
|
-
is = require('@barchart/common-js/lang/is'),
|
|
1
|
+
const is = require('@barchart/common-js/lang/is'),
|
|
3
2
|
Currency = require('@barchart/common-js/lang/Currency'),
|
|
4
3
|
DataType = require('@barchart/common-js/serialization/json/DataType'),
|
|
5
4
|
Enum = require('@barchart/common-js/lang/Enum'),
|