@barchart/portfolio-api-common 1.2.106 → 1.2.110
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 +27 -3
- package/lib/formatters/TransactionFormatter.js +1 -0
- package/lib/processing/PositionContainer.js +8 -4
- package/lib/processing/PositionGroup.js +1 -1
- package/lib/processing/PositionItem.js +2 -1
- package/package.json +1 -1
- package/test/SpecRunner.js +110 -15
|
@@ -56,6 +56,17 @@ module.exports = (() => {
|
|
|
56
56
|
return positionUpdateFailedNoPosition;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Unable to delete, a related position is locked.
|
|
61
|
+
*
|
|
62
|
+
* @public
|
|
63
|
+
* @static
|
|
64
|
+
* @returns {FailureType}
|
|
65
|
+
*/
|
|
66
|
+
static get POSITION_DELETE_FAILED_POSITION_LOCKED() {
|
|
67
|
+
return positionDeleteFailedPositionLocked;
|
|
68
|
+
}
|
|
69
|
+
|
|
59
70
|
/**
|
|
60
71
|
* The position does not exist.
|
|
61
72
|
*
|
|
@@ -97,8 +108,8 @@ module.exports = (() => {
|
|
|
97
108
|
}
|
|
98
109
|
|
|
99
110
|
/**
|
|
100
|
-
* The transaction would cause the position to change
|
|
101
|
-
* short, or vice versa
|
|
111
|
+
* The transaction would cause the position direction to change
|
|
112
|
+
* from long to short, or vice versa.
|
|
102
113
|
*
|
|
103
114
|
* @public
|
|
104
115
|
* @static
|
|
@@ -144,7 +155,7 @@ module.exports = (() => {
|
|
|
144
155
|
}
|
|
145
156
|
|
|
146
157
|
/**
|
|
147
|
-
* The transaction failed because
|
|
158
|
+
* The transaction failed because a related position is locked.
|
|
148
159
|
*
|
|
149
160
|
* @public
|
|
150
161
|
* @static
|
|
@@ -188,6 +199,17 @@ module.exports = (() => {
|
|
|
188
199
|
return transactionDeleteFailedDirectionSwitchOnRewrite;
|
|
189
200
|
}
|
|
190
201
|
|
|
202
|
+
/**
|
|
203
|
+
* Unable to delete, a related position is locked.
|
|
204
|
+
*
|
|
205
|
+
* @public
|
|
206
|
+
* @static
|
|
207
|
+
* @returns {FailureType}
|
|
208
|
+
*/
|
|
209
|
+
static get TRANSACTION_DELETE_FAILED_POSITION_LOCKED() {
|
|
210
|
+
return transactionDeleteFailedPositionLocked;
|
|
211
|
+
}
|
|
212
|
+
|
|
191
213
|
/**
|
|
192
214
|
* Unable to edit, the transaction doesn't exist.
|
|
193
215
|
*
|
|
@@ -221,6 +243,7 @@ module.exports = (() => {
|
|
|
221
243
|
|
|
222
244
|
const positionCreateFailedNoPortfolio = new FailureType('POSITION_CREATE_FAILED_NO_PORTFOLIO', 'Unable to create transaction. The portfolio does not exist, has it been deleted?');
|
|
223
245
|
const positionUpdateFailedNoPosition = new FailureType('POSITION_UPDATE_FAILED_NO_POSITION', 'Unable to update preferences for position. The position does not exist, has it been deleted?');
|
|
246
|
+
const positionDeleteFailedPositionLocked = new FailureType('POSITION_DELETE_FAILED_POSITION_LOCKED', 'Unable to delete position, your {L|description} history is being recalculated. Please wait a minute or two and retry.');
|
|
224
247
|
|
|
225
248
|
const transactionCreateFailedNoPosition = new FailureType('TRANSACTION_CREATE_FAILED_NO_POSITION', 'Unable to create transaction. The referenced position does not exist. Has it been deleted?');
|
|
226
249
|
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).');
|
|
@@ -235,6 +258,7 @@ module.exports = (() => {
|
|
|
235
258
|
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).');
|
|
236
259
|
const transactionDeleteFailedNoTransaction = new FailureType('TRANSACTION_DELETE_FAILED_NO_TRANSACTION', 'Unable to delete transaction. The referenced transaction does not exist.');
|
|
237
260
|
const transactionDeleteFailedDirectionSwitchOnRewrite = new FailureType('TRANSACTION_DELETE_FAILED_DIRECTION_SWITCH_ON_REWRITE', 'Deleting this transaction would cause your history to be re-written and the position to switch from long to short (i.e. positive to negative) or vice versa.');
|
|
261
|
+
const transactionDeleteFailedPositionLocked = new FailureType('TRANSACTION_DELETE_FAILED_POSITION_LOCKED', 'Unable to delete transaction, your {L|description} history is being recalculated. Please wait a minute or two and retry.');
|
|
238
262
|
|
|
239
263
|
const transactionEditFailedNoTransaction = new FailureType('TRANSACTION_EDIT_FAILED_NO_TRANSACTION', 'Unable to edit transaction. The referenced transaction does not exist.');
|
|
240
264
|
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.');
|
|
@@ -104,7 +104,7 @@ module.exports = (() => {
|
|
|
104
104
|
}, { });
|
|
105
105
|
|
|
106
106
|
this._items = positions.reduce((items, position) => {
|
|
107
|
-
const item = createPositionItem.call(this, position);
|
|
107
|
+
const item = createPositionItem.call(this, position, reportFrame ? true : false);
|
|
108
108
|
|
|
109
109
|
if (item) {
|
|
110
110
|
items.push(item);
|
|
@@ -313,7 +313,7 @@ module.exports = (() => {
|
|
|
313
313
|
addSummaryPrevious(this._summariesPrevious, summary, this._previousSummaryFrame, this._previousSummaryRanges);
|
|
314
314
|
});
|
|
315
315
|
|
|
316
|
-
const item = createPositionItem.call(this, position);
|
|
316
|
+
const item = createPositionItem.call(this, position, false);
|
|
317
317
|
|
|
318
318
|
addBarchartSymbol(this._symbols, item);
|
|
319
319
|
addDisplaySymbol(this._symbolsDisplay, item);
|
|
@@ -959,7 +959,7 @@ module.exports = (() => {
|
|
|
959
959
|
}
|
|
960
960
|
}
|
|
961
961
|
|
|
962
|
-
function createPositionItem(position,
|
|
962
|
+
function createPositionItem(position, requireCurrentSummary) {
|
|
963
963
|
const portfolio = this._portfolios[position.portfolio];
|
|
964
964
|
|
|
965
965
|
let returnRef;
|
|
@@ -968,7 +968,11 @@ module.exports = (() => {
|
|
|
968
968
|
const currentSummary = this._summariesCurrent[ position.position ] || null;
|
|
969
969
|
const previousSummaries = this._summariesPrevious[ position.position ] || getSummaryArray(this._previousSummaryRanges);
|
|
970
970
|
|
|
971
|
-
|
|
971
|
+
if (!requireCurrentSummary || currentSummary !== null) {
|
|
972
|
+
returnRef = new PositionItem(portfolio, position, currentSummary, previousSummaries, this._reporting);
|
|
973
|
+
} else {
|
|
974
|
+
returnRef = null;
|
|
975
|
+
}
|
|
972
976
|
} else {
|
|
973
977
|
returnRef = null;
|
|
974
978
|
}
|
|
@@ -734,7 +734,7 @@ module.exports = (() => {
|
|
|
734
734
|
if (group.single && group._items.length === 1) {
|
|
735
735
|
const item = group._items[0];
|
|
736
736
|
|
|
737
|
-
actual.quantity = item.
|
|
737
|
+
actual.quantity = item.data.quantity;
|
|
738
738
|
actual.quantityPrevious = item.data.quantityPrevious;
|
|
739
739
|
|
|
740
740
|
actual.basisPrice = item.data.basisPrice;
|
|
@@ -71,8 +71,8 @@ module.exports = (() => {
|
|
|
71
71
|
this._data.marketPrevious = null;
|
|
72
72
|
this._data.marketPrevious2 = null;
|
|
73
73
|
|
|
74
|
+
this._data.quantity = null;
|
|
74
75
|
this._data.quantityPrevious = null;
|
|
75
|
-
this._data.quantityPrevious2 = null;
|
|
76
76
|
|
|
77
77
|
this._data.realized = null;
|
|
78
78
|
this._data.income = null;
|
|
@@ -385,6 +385,7 @@ module.exports = (() => {
|
|
|
385
385
|
|
|
386
386
|
const data = item._data;
|
|
387
387
|
|
|
388
|
+
data.quantity = snapshot.open;
|
|
388
389
|
data.previousPrice = position.previous || null;
|
|
389
390
|
|
|
390
391
|
let basis;
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -1528,7 +1528,7 @@ module.exports = (() => {
|
|
|
1528
1528
|
}, { });
|
|
1529
1529
|
|
|
1530
1530
|
this._items = positions.reduce((items, position) => {
|
|
1531
|
-
const item = createPositionItem.call(this, position);
|
|
1531
|
+
const item = createPositionItem.call(this, position, reportFrame ? true : false);
|
|
1532
1532
|
|
|
1533
1533
|
if (item) {
|
|
1534
1534
|
items.push(item);
|
|
@@ -1737,7 +1737,7 @@ module.exports = (() => {
|
|
|
1737
1737
|
addSummaryPrevious(this._summariesPrevious, summary, this._previousSummaryFrame, this._previousSummaryRanges);
|
|
1738
1738
|
});
|
|
1739
1739
|
|
|
1740
|
-
const item = createPositionItem.call(this, position);
|
|
1740
|
+
const item = createPositionItem.call(this, position, false);
|
|
1741
1741
|
|
|
1742
1742
|
addBarchartSymbol(this._symbols, item);
|
|
1743
1743
|
addDisplaySymbol(this._symbolsDisplay, item);
|
|
@@ -2383,7 +2383,7 @@ module.exports = (() => {
|
|
|
2383
2383
|
}
|
|
2384
2384
|
}
|
|
2385
2385
|
|
|
2386
|
-
function createPositionItem(position,
|
|
2386
|
+
function createPositionItem(position, requireCurrentSummary) {
|
|
2387
2387
|
const portfolio = this._portfolios[position.portfolio];
|
|
2388
2388
|
|
|
2389
2389
|
let returnRef;
|
|
@@ -2392,7 +2392,11 @@ module.exports = (() => {
|
|
|
2392
2392
|
const currentSummary = this._summariesCurrent[ position.position ] || null;
|
|
2393
2393
|
const previousSummaries = this._summariesPrevious[ position.position ] || getSummaryArray(this._previousSummaryRanges);
|
|
2394
2394
|
|
|
2395
|
-
|
|
2395
|
+
if (!requireCurrentSummary || currentSummary !== null) {
|
|
2396
|
+
returnRef = new PositionItem(portfolio, position, currentSummary, previousSummaries, this._reporting);
|
|
2397
|
+
} else {
|
|
2398
|
+
returnRef = null;
|
|
2399
|
+
}
|
|
2396
2400
|
} else {
|
|
2397
2401
|
returnRef = null;
|
|
2398
2402
|
}
|
|
@@ -3190,7 +3194,7 @@ module.exports = (() => {
|
|
|
3190
3194
|
if (group.single && group._items.length === 1) {
|
|
3191
3195
|
const item = group._items[0];
|
|
3192
3196
|
|
|
3193
|
-
actual.quantity = item.
|
|
3197
|
+
actual.quantity = item.data.quantity;
|
|
3194
3198
|
actual.quantityPrevious = item.data.quantityPrevious;
|
|
3195
3199
|
|
|
3196
3200
|
actual.basisPrice = item.data.basisPrice;
|
|
@@ -3468,8 +3472,8 @@ module.exports = (() => {
|
|
|
3468
3472
|
this._data.marketPrevious = null;
|
|
3469
3473
|
this._data.marketPrevious2 = null;
|
|
3470
3474
|
|
|
3475
|
+
this._data.quantity = null;
|
|
3471
3476
|
this._data.quantityPrevious = null;
|
|
3472
|
-
this._data.quantityPrevious2 = null;
|
|
3473
3477
|
|
|
3474
3478
|
this._data.realized = null;
|
|
3475
3479
|
this._data.income = null;
|
|
@@ -3782,6 +3786,7 @@ module.exports = (() => {
|
|
|
3782
3786
|
|
|
3783
3787
|
const data = item._data;
|
|
3784
3788
|
|
|
3789
|
+
data.quantity = snapshot.open;
|
|
3785
3790
|
data.previousPrice = position.previous || null;
|
|
3786
3791
|
|
|
3787
3792
|
let basis;
|
|
@@ -6295,12 +6300,11 @@ module.exports = function () {
|
|
|
6295
6300
|
}
|
|
6296
6301
|
|
|
6297
6302
|
/**
|
|
6298
|
-
*
|
|
6299
|
-
* a {@link Day} instance.
|
|
6303
|
+
* Clones a {@link Day} instance.
|
|
6300
6304
|
*
|
|
6301
6305
|
* @public
|
|
6302
6306
|
* @static
|
|
6303
|
-
* @param {
|
|
6307
|
+
* @param {Day} value
|
|
6304
6308
|
* @returns {Day}
|
|
6305
6309
|
*/
|
|
6306
6310
|
|
|
@@ -6341,6 +6345,24 @@ module.exports = function () {
|
|
|
6341
6345
|
return this._day;
|
|
6342
6346
|
}
|
|
6343
6347
|
}], [{
|
|
6348
|
+
key: 'clone',
|
|
6349
|
+
value: function clone(value) {
|
|
6350
|
+
assert.argumentIsRequired(value, 'value', Day, 'Day');
|
|
6351
|
+
|
|
6352
|
+
return new Day(value.year, value.month, value.day);
|
|
6353
|
+
}
|
|
6354
|
+
|
|
6355
|
+
/**
|
|
6356
|
+
* Converts a string (which matches the output of {@link Day#format} into
|
|
6357
|
+
* a {@link Day} instance.
|
|
6358
|
+
*
|
|
6359
|
+
* @public
|
|
6360
|
+
* @static
|
|
6361
|
+
* @param {String} value
|
|
6362
|
+
* @returns {Day}
|
|
6363
|
+
*/
|
|
6364
|
+
|
|
6365
|
+
}, {
|
|
6344
6366
|
key: 'parse',
|
|
6345
6367
|
value: function parse(value) {
|
|
6346
6368
|
assert.argumentIsRequired(value, 'value', String);
|
|
@@ -6657,15 +6679,17 @@ module.exports = function () {
|
|
|
6657
6679
|
*
|
|
6658
6680
|
* @public
|
|
6659
6681
|
* @param {Boolean=} approximate
|
|
6682
|
+
* @param {Number=} places
|
|
6660
6683
|
* @returns {Boolean}
|
|
6661
6684
|
*/
|
|
6662
6685
|
|
|
6663
6686
|
}, {
|
|
6664
6687
|
key: 'getIsZero',
|
|
6665
|
-
value: function getIsZero(approximate) {
|
|
6688
|
+
value: function getIsZero(approximate, places) {
|
|
6666
6689
|
assert.argumentIsOptional(approximate, 'approximate', Boolean);
|
|
6690
|
+
assert.argumentIsOptional(places, 'places', Number);
|
|
6667
6691
|
|
|
6668
|
-
return this._big.eq(zero) || is.boolean(approximate) && approximate && this.round(
|
|
6692
|
+
return this._big.eq(zero) || is.boolean(approximate) && approximate && this.round(places || Big.DP, RoundingMode.NORMAL).getIsZero();
|
|
6669
6693
|
}
|
|
6670
6694
|
|
|
6671
6695
|
/**
|
|
@@ -6764,6 +6788,43 @@ module.exports = function () {
|
|
|
6764
6788
|
return this._big.eq(getBig(other));
|
|
6765
6789
|
}
|
|
6766
6790
|
|
|
6791
|
+
/**
|
|
6792
|
+
* Returns true if the current instance is an integer (i.e. has no decimal
|
|
6793
|
+
* component).
|
|
6794
|
+
*
|
|
6795
|
+
* @public
|
|
6796
|
+
* @return {Boolean}
|
|
6797
|
+
*/
|
|
6798
|
+
|
|
6799
|
+
}, {
|
|
6800
|
+
key: 'getIsInteger',
|
|
6801
|
+
value: function getIsInteger() {
|
|
6802
|
+
return this.getIsEqual(this.round(0));
|
|
6803
|
+
}
|
|
6804
|
+
|
|
6805
|
+
/**
|
|
6806
|
+
* Returns the number of decimal places used.
|
|
6807
|
+
*
|
|
6808
|
+
* @public
|
|
6809
|
+
* @returns {Number}
|
|
6810
|
+
*/
|
|
6811
|
+
|
|
6812
|
+
}, {
|
|
6813
|
+
key: 'getDecimalPlaces',
|
|
6814
|
+
value: function getDecimalPlaces() {
|
|
6815
|
+
var matches = this.toFixed().match(/-?\d*\.(\d*)/);
|
|
6816
|
+
|
|
6817
|
+
var returnVal = void 0;
|
|
6818
|
+
|
|
6819
|
+
if (matches === null) {
|
|
6820
|
+
returnVal = 0;
|
|
6821
|
+
} else {
|
|
6822
|
+
returnVal = matches[1].length;
|
|
6823
|
+
}
|
|
6824
|
+
|
|
6825
|
+
return returnVal;
|
|
6826
|
+
}
|
|
6827
|
+
|
|
6767
6828
|
/**
|
|
6768
6829
|
* Emits a floating point value that approximates the value of the current
|
|
6769
6830
|
* instance.
|
|
@@ -6812,10 +6873,11 @@ module.exports = function () {
|
|
|
6812
6873
|
}
|
|
6813
6874
|
|
|
6814
6875
|
/**
|
|
6815
|
-
*
|
|
6876
|
+
* Clones a {@link Decimal} instance.
|
|
6816
6877
|
*
|
|
6817
6878
|
* @public
|
|
6818
|
-
* @
|
|
6879
|
+
* @static
|
|
6880
|
+
* @param {Decimal} value
|
|
6819
6881
|
* @returns {Decimal}
|
|
6820
6882
|
*/
|
|
6821
6883
|
|
|
@@ -6825,6 +6887,22 @@ module.exports = function () {
|
|
|
6825
6887
|
return '[Decimal]';
|
|
6826
6888
|
}
|
|
6827
6889
|
}], [{
|
|
6890
|
+
key: 'clone',
|
|
6891
|
+
value: function clone(value) {
|
|
6892
|
+
assert.argumentIsRequired(value, 'value', Decimal, 'Decimal');
|
|
6893
|
+
|
|
6894
|
+
return new Decimal(value._big);
|
|
6895
|
+
}
|
|
6896
|
+
|
|
6897
|
+
/**
|
|
6898
|
+
* Parses the value emitted by {@link Decimal#toJSON}.
|
|
6899
|
+
*
|
|
6900
|
+
* @public
|
|
6901
|
+
* @param {String} value
|
|
6902
|
+
* @returns {Decimal}
|
|
6903
|
+
*/
|
|
6904
|
+
|
|
6905
|
+
}, {
|
|
6828
6906
|
key: 'parse',
|
|
6829
6907
|
value: function parse(value) {
|
|
6830
6908
|
return new Decimal(value);
|
|
@@ -7846,10 +7924,11 @@ module.exports = function () {
|
|
|
7846
7924
|
}
|
|
7847
7925
|
|
|
7848
7926
|
/**
|
|
7849
|
-
*
|
|
7927
|
+
* Clones a {@link Timestamp} instance.
|
|
7850
7928
|
*
|
|
7851
7929
|
* @public
|
|
7852
|
-
* @
|
|
7930
|
+
* @static
|
|
7931
|
+
* @param {Timestamp} value
|
|
7853
7932
|
* @returns {Timestamp}
|
|
7854
7933
|
*/
|
|
7855
7934
|
|
|
@@ -7885,6 +7964,22 @@ module.exports = function () {
|
|
|
7885
7964
|
return this._moment;
|
|
7886
7965
|
}
|
|
7887
7966
|
}], [{
|
|
7967
|
+
key: 'clone',
|
|
7968
|
+
value: function clone(value) {
|
|
7969
|
+
assert.argumentIsRequired(value, 'value', Timestamp, 'Timestamp');
|
|
7970
|
+
|
|
7971
|
+
return new Timestamp(value._timestamp, value._timezone);
|
|
7972
|
+
}
|
|
7973
|
+
|
|
7974
|
+
/**
|
|
7975
|
+
* Parses the value emitted by {@link Timestamp#toJSON}.
|
|
7976
|
+
*
|
|
7977
|
+
* @public
|
|
7978
|
+
* @param {Number} value
|
|
7979
|
+
* @returns {Timestamp}
|
|
7980
|
+
*/
|
|
7981
|
+
|
|
7982
|
+
}, {
|
|
7888
7983
|
key: 'parse',
|
|
7889
7984
|
value: function parse(value) {
|
|
7890
7985
|
return new Timestamp(value);
|