@barchart/portfolio-api-common 1.2.45 → 1.2.49
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 +13 -0
- package/lib/data/TransactionValidator.js +3 -1
- package/lib/formatters/TransactionFormatter.js +20 -8
- package/lib/serialization/TransactionSchema.js +1 -2
- package/package.json +1 -1
- package/test/SpecRunner.js +8188 -244
- 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.
|
|
@@ -206,6 +218,7 @@ module.exports = (() => {
|
|
|
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
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;
|
|
@@ -146,13 +146,18 @@ module.exports = (() => {
|
|
|
146
146
|
});
|
|
147
147
|
|
|
148
148
|
formatters.set(TransactionType.DIVIDEND_STOCK, (t) => {
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
return {
|
|
149
|
+
const data = {
|
|
152
150
|
boughtSold: t.quantity,
|
|
153
|
-
|
|
154
|
-
rate: rate
|
|
151
|
+
fee: t.fee
|
|
155
152
|
};
|
|
153
|
+
|
|
154
|
+
if (t.dividend && t.dividend.rate && t.dividend.price) {
|
|
155
|
+
data.shares = t.snapshot.open.subtract(t.quantity);
|
|
156
|
+
data.price = t.dividend.price;
|
|
157
|
+
data.rate = t.dividend.rate;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return data;
|
|
156
161
|
});
|
|
157
162
|
|
|
158
163
|
formatters.set(TransactionType.DIVIDEND_REINVEST, (t) => {
|
|
@@ -174,15 +179,22 @@ module.exports = (() => {
|
|
|
174
179
|
});
|
|
175
180
|
|
|
176
181
|
formatters.set(TransactionType.DISTRIBUTION_FUND, (t) => {
|
|
177
|
-
|
|
178
|
-
|
|
182
|
+
const data = {
|
|
183
|
+
boughtSold: t.quantity,
|
|
179
184
|
fee: t.fee
|
|
180
185
|
};
|
|
186
|
+
|
|
187
|
+
if (t.dividend && t.dividend.rate && t.dividend.price) {
|
|
188
|
+
data.shares = t.snapshot.open.subtract(t.quantity);
|
|
189
|
+
data.price = t.dividend.price;
|
|
190
|
+
data.rate = t.dividend.rate;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return data;
|
|
181
194
|
});
|
|
182
195
|
|
|
183
196
|
formatters.set(TransactionType.DISTRIBUTION_REINVEST, (t) => {
|
|
184
197
|
return {
|
|
185
|
-
boughtSold: t.quantity,
|
|
186
198
|
shares: t.snapshot.open.subtract(t.quantity),
|
|
187
199
|
price: t.dividend.price,
|
|
188
200
|
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'),
|