@barchart/portfolio-api-common 1.9.1 → 1.10.0
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.
|
@@ -154,6 +154,17 @@ module.exports = (() => {
|
|
|
154
154
|
return transactionCreateFailedInvalidInitialType;
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
+
/**
|
|
158
|
+
* A transaction quantity cannot have a negative amount.
|
|
159
|
+
*
|
|
160
|
+
* @public
|
|
161
|
+
* @static
|
|
162
|
+
* @returns {FailureType}
|
|
163
|
+
*/
|
|
164
|
+
static get TRANSACTION_CREATE_FAILED_QUANTITY_NEGATIVE() {
|
|
165
|
+
return transactionCreateFailedQuantityNegative;
|
|
166
|
+
}
|
|
167
|
+
|
|
157
168
|
/**
|
|
158
169
|
* A valuation transaction cannot have a negative rate (or amount).
|
|
159
170
|
*
|
|
@@ -348,7 +359,7 @@ module.exports = (() => {
|
|
|
348
359
|
static get TRANSACTION_EDIT_FAILED_TYPE_CHANGED() {
|
|
349
360
|
return transactionEditFailedTypeChanged;
|
|
350
361
|
}
|
|
351
|
-
|
|
362
|
+
|
|
352
363
|
/**
|
|
353
364
|
* Conversion of transaction type is unsupported.
|
|
354
365
|
*
|
|
@@ -371,7 +382,7 @@ module.exports = (() => {
|
|
|
371
382
|
static get TRANSACTION_SWITCH_FAILED_INVALID_REINVEST() {
|
|
372
383
|
return transactionSwitchFailedInvalidReinvest;
|
|
373
384
|
}
|
|
374
|
-
|
|
385
|
+
|
|
375
386
|
toString() {
|
|
376
387
|
return '[PortfolioFailureType]';
|
|
377
388
|
}
|
|
@@ -392,6 +403,7 @@ module.exports = (() => {
|
|
|
392
403
|
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.', false);
|
|
393
404
|
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.', false);
|
|
394
405
|
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.', false);
|
|
406
|
+
const transactionCreateFailedQuantityNegative = new FailureType('TRANSACTION_CREATE_FAILED_QUANTITY_NEGATIVE', 'Unable to process transaction, quantity cannot be negative.');
|
|
395
407
|
const transactionCreateFailedValuationNegative = new FailureType('TRANSACTION_CREATE_FAILED_VALUATION_NEGATIVE', 'Unable to process operation, valuations cannot be negative.', false);
|
|
396
408
|
const transactionCreateFailedInvalidTermination = new FailureType('TRANSACTION_CREATE_FAILED_INVALID_TERMINATION', 'Unable to process operation, a {U|transactionType.description} must be the final transaction in the position history.', false);
|
|
397
409
|
const transactionCreateFailedAfterTermination = new FailureType('TRANSACTION_CREATE_FAILED_AFTER_TERMINATION', 'Unable to process operation, one or more transactions would exist after {L|termination}, the final day of trading for this instrument', false);
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -5694,7 +5694,7 @@ module.exports = (() => {
|
|
|
5694
5694
|
|
|
5695
5695
|
|
|
5696
5696
|
push(item) {
|
|
5697
|
-
this._array.
|
|
5697
|
+
this._array.push(item);
|
|
5698
5698
|
|
|
5699
5699
|
return item;
|
|
5700
5700
|
}
|
|
@@ -5711,7 +5711,7 @@ module.exports = (() => {
|
|
|
5711
5711
|
throw new Error('Stack is empty');
|
|
5712
5712
|
}
|
|
5713
5713
|
|
|
5714
|
-
return this._array.
|
|
5714
|
+
return this._array.pop();
|
|
5715
5715
|
}
|
|
5716
5716
|
/**
|
|
5717
5717
|
* Returns the next item in the stack (without removing it). Throws if the stack is empty.
|
|
@@ -5726,7 +5726,7 @@ module.exports = (() => {
|
|
|
5726
5726
|
throw new Error('Stack is empty');
|
|
5727
5727
|
}
|
|
5728
5728
|
|
|
5729
|
-
return this._array[
|
|
5729
|
+
return this._array[this._array.length - 1];
|
|
5730
5730
|
}
|
|
5731
5731
|
/**
|
|
5732
5732
|
* Returns true if the queue is empty; otherwise false.
|
|
@@ -5750,10 +5750,12 @@ module.exports = (() => {
|
|
|
5750
5750
|
scan(action) {
|
|
5751
5751
|
assert.argumentIsRequired(action, 'action', Function);
|
|
5752
5752
|
|
|
5753
|
-
this._array.
|
|
5753
|
+
for (let i = this._array.length - 1; i >= 0; i--) {
|
|
5754
|
+
action(this._array[i]);
|
|
5755
|
+
}
|
|
5754
5756
|
}
|
|
5755
5757
|
/**
|
|
5756
|
-
* Outputs an array of the
|
|
5758
|
+
* Outputs an array of the stack's items; without affecting the
|
|
5757
5759
|
* queue's internal state;
|
|
5758
5760
|
*
|
|
5759
5761
|
* @public
|
|
@@ -5762,7 +5764,7 @@ module.exports = (() => {
|
|
|
5762
5764
|
|
|
5763
5765
|
|
|
5764
5766
|
toArray() {
|
|
5765
|
-
return this._array.slice(0);
|
|
5767
|
+
return this._array.slice(0).reverse();
|
|
5766
5768
|
}
|
|
5767
5769
|
|
|
5768
5770
|
toString() {
|
|
@@ -17621,8 +17623,8 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
|
17621
17623
|
ranges = PositionSummaryFrame.YEARLY.getRanges(transactions);
|
|
17622
17624
|
});
|
|
17623
17625
|
|
|
17624
|
-
it('should have
|
|
17625
|
-
expect(ranges.length).toEqual(
|
|
17626
|
+
it('should have six ranges (assuming the current year is 2021)', () => {
|
|
17627
|
+
expect(ranges.length).toEqual(6);
|
|
17626
17628
|
});
|
|
17627
17629
|
|
|
17628
17630
|
it('the first range should be from 12-31-2014 to 12-31-2015', () => {
|
|
@@ -18008,7 +18010,7 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
|
18008
18010
|
});
|
|
18009
18011
|
});
|
|
18010
18012
|
|
|
18011
|
-
describe('and a year-to-date position summary ranges are processed for a transaction set that opened last year and has not yet closed (assuming its
|
|
18013
|
+
describe('and a year-to-date position summary ranges are processed for a transaction set that opened last year and has not yet closed (assuming its 2021)', () => {
|
|
18012
18014
|
let ranges;
|
|
18013
18015
|
|
|
18014
18016
|
beforeEach(() => {
|
|
@@ -18029,9 +18031,9 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
|
18029
18031
|
expect(ranges.length).toEqual(1);
|
|
18030
18032
|
});
|
|
18031
18033
|
|
|
18032
|
-
it('the first range should be from 12-31-
|
|
18033
|
-
expect(ranges[0].start.format()).toEqual('
|
|
18034
|
-
expect(ranges[0].end.format()).toEqual('
|
|
18034
|
+
it('the first range should be from 12-31-2020 to 12-31-2021', () => {
|
|
18035
|
+
expect(ranges[0].start.format()).toEqual('2020-12-31');
|
|
18036
|
+
expect(ranges[0].end.format()).toEqual('2021-12-31');
|
|
18035
18037
|
});
|
|
18036
18038
|
});
|
|
18037
18039
|
|
|
@@ -18041,14 +18043,14 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
|
18041
18043
|
beforeEach(() => {
|
|
18042
18044
|
const transactions = [
|
|
18043
18045
|
{
|
|
18044
|
-
date: new Day(
|
|
18046
|
+
date: new Day(2021, 1, 1),
|
|
18045
18047
|
snapshot: {
|
|
18046
18048
|
open: new Decimal(1)
|
|
18047
18049
|
},
|
|
18048
18050
|
type: TransactionType.BUY
|
|
18049
18051
|
},
|
|
18050
18052
|
{
|
|
18051
|
-
date: new Day(
|
|
18053
|
+
date: new Day(2021, 1, 2),
|
|
18052
18054
|
snapshot: {
|
|
18053
18055
|
open: new Decimal(0)
|
|
18054
18056
|
},
|
|
@@ -18063,9 +18065,9 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
|
18063
18065
|
expect(ranges.length).toEqual(1);
|
|
18064
18066
|
});
|
|
18065
18067
|
|
|
18066
|
-
it('the first range should be from 12-31-
|
|
18067
|
-
expect(ranges[0].start.format()).toEqual('
|
|
18068
|
-
expect(ranges[0].end.format()).toEqual('
|
|
18068
|
+
it('the first range should be from 12-31-2020 to 12-31-2021', () => {
|
|
18069
|
+
expect(ranges[0].start.format()).toEqual('2020-12-31');
|
|
18070
|
+
expect(ranges[0].end.format()).toEqual('2021-12-31');
|
|
18069
18071
|
});
|
|
18070
18072
|
});
|
|
18071
18073
|
|
|
@@ -31,8 +31,8 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
|
31
31
|
ranges = PositionSummaryFrame.YEARLY.getRanges(transactions);
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
it('should have
|
|
35
|
-
expect(ranges.length).toEqual(
|
|
34
|
+
it('should have six ranges (assuming the current year is 2021)', () => {
|
|
35
|
+
expect(ranges.length).toEqual(6);
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
it('the first range should be from 12-31-2014 to 12-31-2015', () => {
|
|
@@ -418,7 +418,7 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
|
418
418
|
});
|
|
419
419
|
});
|
|
420
420
|
|
|
421
|
-
describe('and a year-to-date position summary ranges are processed for a transaction set that opened last year and has not yet closed (assuming its
|
|
421
|
+
describe('and a year-to-date position summary ranges are processed for a transaction set that opened last year and has not yet closed (assuming its 2021)', () => {
|
|
422
422
|
let ranges;
|
|
423
423
|
|
|
424
424
|
beforeEach(() => {
|
|
@@ -439,9 +439,9 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
|
439
439
|
expect(ranges.length).toEqual(1);
|
|
440
440
|
});
|
|
441
441
|
|
|
442
|
-
it('the first range should be from 12-31-
|
|
443
|
-
expect(ranges[0].start.format()).toEqual('
|
|
444
|
-
expect(ranges[0].end.format()).toEqual('
|
|
442
|
+
it('the first range should be from 12-31-2020 to 12-31-2021', () => {
|
|
443
|
+
expect(ranges[0].start.format()).toEqual('2020-12-31');
|
|
444
|
+
expect(ranges[0].end.format()).toEqual('2021-12-31');
|
|
445
445
|
});
|
|
446
446
|
});
|
|
447
447
|
|
|
@@ -451,14 +451,14 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
|
451
451
|
beforeEach(() => {
|
|
452
452
|
const transactions = [
|
|
453
453
|
{
|
|
454
|
-
date: new Day(
|
|
454
|
+
date: new Day(2021, 1, 1),
|
|
455
455
|
snapshot: {
|
|
456
456
|
open: new Decimal(1)
|
|
457
457
|
},
|
|
458
458
|
type: TransactionType.BUY
|
|
459
459
|
},
|
|
460
460
|
{
|
|
461
|
-
date: new Day(
|
|
461
|
+
date: new Day(2021, 1, 2),
|
|
462
462
|
snapshot: {
|
|
463
463
|
open: new Decimal(0)
|
|
464
464
|
},
|
|
@@ -473,9 +473,9 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
|
473
473
|
expect(ranges.length).toEqual(1);
|
|
474
474
|
});
|
|
475
475
|
|
|
476
|
-
it('the first range should be from 12-31-
|
|
477
|
-
expect(ranges[0].start.format()).toEqual('
|
|
478
|
-
expect(ranges[0].end.format()).toEqual('
|
|
476
|
+
it('the first range should be from 12-31-2020 to 12-31-2021', () => {
|
|
477
|
+
expect(ranges[0].start.format()).toEqual('2020-12-31');
|
|
478
|
+
expect(ranges[0].end.format()).toEqual('2021-12-31');
|
|
479
479
|
});
|
|
480
480
|
});
|
|
481
481
|
|