@barchart/portfolio-api-common 1.2.52 → 1.2.56
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.
|
@@ -19,10 +19,11 @@ module.exports = (() => {
|
|
|
19
19
|
* @param {Boolean} canSwitchDirection
|
|
20
20
|
* @param {Boolean} usesSymbols
|
|
21
21
|
* @param {Boolean} hasCorporateActions
|
|
22
|
+
* @param {Number} closeFractional
|
|
22
23
|
* @param {Function} generator
|
|
23
24
|
*/
|
|
24
25
|
class InstrumentType extends Enum {
|
|
25
|
-
constructor(code, description, alternateDescription, canReinvest, canShort, canSwitchDirection, usesSymbols, hasCorporateActions, generator) {
|
|
26
|
+
constructor(code, description, alternateDescription, canReinvest, canShort, canSwitchDirection, usesSymbols, hasCorporateActions, closeFractional, generator) {
|
|
26
27
|
super(code, description);
|
|
27
28
|
|
|
28
29
|
assert.argumentIsRequired(alternateDescription, 'alternateDescription', String);
|
|
@@ -31,6 +32,7 @@ module.exports = (() => {
|
|
|
31
32
|
assert.argumentIsRequired(canSwitchDirection, 'canSwitchDirection', Boolean);
|
|
32
33
|
assert.argumentIsRequired(usesSymbols, 'usesSymbols', Boolean);
|
|
33
34
|
assert.argumentIsRequired(hasCorporateActions, 'hasCorporateActions', Boolean);
|
|
35
|
+
assert.argumentIsRequired(closeFractional, 'closeFractional', Boolean);
|
|
34
36
|
assert.argumentIsRequired(generator, 'generator', Function);
|
|
35
37
|
|
|
36
38
|
this._alternateDescription = alternateDescription;
|
|
@@ -39,6 +41,7 @@ module.exports = (() => {
|
|
|
39
41
|
this._canSwitchDirection = canSwitchDirection;
|
|
40
42
|
this._usesSymbols = usesSymbols;
|
|
41
43
|
this._hasCorporateActions = hasCorporateActions;
|
|
44
|
+
this._closeFractional = closeFractional;
|
|
42
45
|
|
|
43
46
|
this._generator = generator;
|
|
44
47
|
}
|
|
@@ -104,6 +107,17 @@ module.exports = (() => {
|
|
|
104
107
|
return this._hasCorporateActions;
|
|
105
108
|
}
|
|
106
109
|
|
|
110
|
+
/**
|
|
111
|
+
* Indicates if fractional shares should be closed when the position
|
|
112
|
+
* size is less than one (or some of the fractional shares are closed).
|
|
113
|
+
*
|
|
114
|
+
* @public
|
|
115
|
+
* @returns {Boolean}
|
|
116
|
+
*/
|
|
117
|
+
get closeFractional() {
|
|
118
|
+
return this._closeFractional;
|
|
119
|
+
}
|
|
120
|
+
|
|
107
121
|
/**
|
|
108
122
|
* Generates an identifier for the instrument.
|
|
109
123
|
*
|
|
@@ -201,10 +215,10 @@ module.exports = (() => {
|
|
|
201
215
|
}
|
|
202
216
|
}
|
|
203
217
|
|
|
204
|
-
const cash = new InstrumentType('CASH', 'cash', 'Cash', false, false, true, false, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.currency.code}`);
|
|
205
|
-
const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true, true, false, true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
206
|
-
const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true, false, false, true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
207
|
-
const other = new InstrumentType('OTHER', 'other', 'Other', false, false, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${uuid.v4()}`);
|
|
218
|
+
const cash = new InstrumentType('CASH', 'cash', 'Cash', false, false, true, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.currency.code}`);
|
|
219
|
+
const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true, true, false, true, true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
220
|
+
const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true, false, false, true, true, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
221
|
+
const other = new InstrumentType('OTHER', 'other', 'Other', false, false, false, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${uuid.v4()}`);
|
|
208
222
|
|
|
209
223
|
const map = { };
|
|
210
224
|
|
|
@@ -395,10 +395,10 @@ module.exports = (() => {
|
|
|
395
395
|
const sell = new TransactionType('S', 'Sell', 'Sell', 0, false, true, false, false, true, false, false, false, true);
|
|
396
396
|
const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', 0, true, false, false, false, true, false, false, false, true);
|
|
397
397
|
const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', 0, false, true, false, true, false, false, false, true, true);
|
|
398
|
-
const dividend = new TransactionType('DV', 'Dividend', 'Dividend',
|
|
398
|
+
const dividend = new TransactionType('DV', 'Dividend', 'Dividend', 1, false, false, true, false, false, false, true, false, false);
|
|
399
399
|
const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', 1, false, false, false, true, false, false, true, false, false);
|
|
400
400
|
const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', 1, false, false, false, true, false, false, true, false, false);
|
|
401
|
-
const split = new TransactionType('SP', 'Split', 'Split',
|
|
401
|
+
const split = new TransactionType('SP', 'Split', 'Split', 1, false, false, false, true, false, false, true, false, false);
|
|
402
402
|
const fee = new TransactionType('F', 'Fee', 'Fee', 0, false, false, false, false, false, true, false, false, false);
|
|
403
403
|
const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', 0, false, false, false, false, true, false, false, false, false);
|
|
404
404
|
|
|
@@ -82,7 +82,9 @@ module.exports = (() => {
|
|
|
82
82
|
static getInvalidIndex(transactions) {
|
|
83
83
|
assert.argumentIsArray(transactions, 'transactions');
|
|
84
84
|
|
|
85
|
-
return transactions.findIndex((t, i) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(
|
|
85
|
+
return transactions.findIndex((t, i, a) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(a[ i - 1 ].date)));
|
|
86
|
+
|
|
87
|
+
//return transactions.findIndex((t, i, a) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(a[ i - 1 ].date)) || (i !== 0 && t.date.getIsEqual(a[i - 1].date) && t.type.sequence < a[i - 1].type.sequence));
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
/**
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -20,10 +20,11 @@ module.exports = (() => {
|
|
|
20
20
|
* @param {Boolean} canSwitchDirection
|
|
21
21
|
* @param {Boolean} usesSymbols
|
|
22
22
|
* @param {Boolean} hasCorporateActions
|
|
23
|
+
* @param {Number} closeFractional
|
|
23
24
|
* @param {Function} generator
|
|
24
25
|
*/
|
|
25
26
|
class InstrumentType extends Enum {
|
|
26
|
-
constructor(code, description, alternateDescription, canReinvest, canShort, canSwitchDirection, usesSymbols, hasCorporateActions, generator) {
|
|
27
|
+
constructor(code, description, alternateDescription, canReinvest, canShort, canSwitchDirection, usesSymbols, hasCorporateActions, closeFractional, generator) {
|
|
27
28
|
super(code, description);
|
|
28
29
|
|
|
29
30
|
assert.argumentIsRequired(alternateDescription, 'alternateDescription', String);
|
|
@@ -32,6 +33,7 @@ module.exports = (() => {
|
|
|
32
33
|
assert.argumentIsRequired(canSwitchDirection, 'canSwitchDirection', Boolean);
|
|
33
34
|
assert.argumentIsRequired(usesSymbols, 'usesSymbols', Boolean);
|
|
34
35
|
assert.argumentIsRequired(hasCorporateActions, 'hasCorporateActions', Boolean);
|
|
36
|
+
assert.argumentIsRequired(closeFractional, 'closeFractional', Boolean);
|
|
35
37
|
assert.argumentIsRequired(generator, 'generator', Function);
|
|
36
38
|
|
|
37
39
|
this._alternateDescription = alternateDescription;
|
|
@@ -40,6 +42,7 @@ module.exports = (() => {
|
|
|
40
42
|
this._canSwitchDirection = canSwitchDirection;
|
|
41
43
|
this._usesSymbols = usesSymbols;
|
|
42
44
|
this._hasCorporateActions = hasCorporateActions;
|
|
45
|
+
this._closeFractional = closeFractional;
|
|
43
46
|
|
|
44
47
|
this._generator = generator;
|
|
45
48
|
}
|
|
@@ -105,6 +108,17 @@ module.exports = (() => {
|
|
|
105
108
|
return this._hasCorporateActions;
|
|
106
109
|
}
|
|
107
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Indicates if fractional shares should be closed when the position
|
|
113
|
+
* size is less than one (or some of the fractional shares are closed).
|
|
114
|
+
*
|
|
115
|
+
* @public
|
|
116
|
+
* @returns {Boolean}
|
|
117
|
+
*/
|
|
118
|
+
get closeFractional() {
|
|
119
|
+
return this._closeFractional;
|
|
120
|
+
}
|
|
121
|
+
|
|
108
122
|
/**
|
|
109
123
|
* Generates an identifier for the instrument.
|
|
110
124
|
*
|
|
@@ -202,10 +216,10 @@ module.exports = (() => {
|
|
|
202
216
|
}
|
|
203
217
|
}
|
|
204
218
|
|
|
205
|
-
const cash = new InstrumentType('CASH', 'cash', 'Cash', false, false, true, false, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.currency.code}`);
|
|
206
|
-
const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true, true, false, true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
207
|
-
const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true, false, false, true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
208
|
-
const other = new InstrumentType('OTHER', 'other', 'Other', false, false, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${uuid.v4()}`);
|
|
219
|
+
const cash = new InstrumentType('CASH', 'cash', 'Cash', false, false, true, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.currency.code}`);
|
|
220
|
+
const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true, true, false, true, true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
221
|
+
const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true, false, false, true, true, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
222
|
+
const other = new InstrumentType('OTHER', 'other', 'Other', false, false, false, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${uuid.v4()}`);
|
|
209
223
|
|
|
210
224
|
const map = { };
|
|
211
225
|
|
|
@@ -1018,10 +1032,10 @@ module.exports = (() => {
|
|
|
1018
1032
|
const sell = new TransactionType('S', 'Sell', 'Sell', 0, false, true, false, false, true, false, false, false, true);
|
|
1019
1033
|
const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', 0, true, false, false, false, true, false, false, false, true);
|
|
1020
1034
|
const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', 0, false, true, false, true, false, false, false, true, true);
|
|
1021
|
-
const dividend = new TransactionType('DV', 'Dividend', 'Dividend',
|
|
1035
|
+
const dividend = new TransactionType('DV', 'Dividend', 'Dividend', 1, false, false, true, false, false, false, true, false, false);
|
|
1022
1036
|
const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', 1, false, false, false, true, false, false, true, false, false);
|
|
1023
1037
|
const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', 1, false, false, false, true, false, false, true, false, false);
|
|
1024
|
-
const split = new TransactionType('SP', 'Split', 'Split',
|
|
1038
|
+
const split = new TransactionType('SP', 'Split', 'Split', 1, false, false, false, true, false, false, true, false, false);
|
|
1025
1039
|
const fee = new TransactionType('F', 'Fee', 'Fee', 0, false, false, false, false, false, true, false, false, false);
|
|
1026
1040
|
const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', 0, false, false, false, false, true, false, false, false, false);
|
|
1027
1041
|
|
|
@@ -1125,7 +1139,9 @@ module.exports = (() => {
|
|
|
1125
1139
|
static getInvalidIndex(transactions) {
|
|
1126
1140
|
assert.argumentIsArray(transactions, 'transactions');
|
|
1127
1141
|
|
|
1128
|
-
return transactions.findIndex((t, i) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(
|
|
1142
|
+
return transactions.findIndex((t, i, a) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(a[ i - 1 ].date)));
|
|
1143
|
+
|
|
1144
|
+
//return transactions.findIndex((t, i, a) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(a[ i - 1 ].date)) || (i !== 0 && t.date.getIsEqual(a[i - 1].date) && t.type.sequence < a[i - 1].type.sequence));
|
|
1129
1145
|
}
|
|
1130
1146
|
|
|
1131
1147
|
/**
|
|
@@ -17212,13 +17228,14 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
|
17212
17228
|
},{"./../../../lib/data/PositionSummaryFrame":3,"./../../../lib/data/TransactionType":4,"@barchart/common-js/lang/Day":21,"@barchart/common-js/lang/Decimal":22}],53:[function(require,module,exports){
|
|
17213
17229
|
const Day = require('@barchart/common-js/lang/Day');
|
|
17214
17230
|
|
|
17215
|
-
const
|
|
17231
|
+
const TransactionType = require('./../../../lib/data/TransactionType'),
|
|
17232
|
+
TransactionValidator = require('./../../../lib/data/TransactionValidator');
|
|
17216
17233
|
|
|
17217
17234
|
describe('When validating transaction order', () => {
|
|
17218
17235
|
'use strict';
|
|
17219
17236
|
|
|
17220
|
-
const build = (sequence, day) => {
|
|
17221
|
-
return { sequence: sequence, date: Day.parse(day) };
|
|
17237
|
+
const build = (sequence, day, type) => {
|
|
17238
|
+
return { sequence: sequence, date: Day.parse(day), type: (type || TransactionType.BUY ) };
|
|
17222
17239
|
};
|
|
17223
17240
|
|
|
17224
17241
|
it('An array of zero transactions should be valid', () => {
|
|
@@ -17229,8 +17246,18 @@ describe('When validating transaction order', () => {
|
|
|
17229
17246
|
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-04-30'), build(3, '2018-04-30') ])).toEqual(true);
|
|
17230
17247
|
});
|
|
17231
17248
|
|
|
17249
|
+
/*
|
|
17250
|
+
it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs last, should be valid', () => {
|
|
17251
|
+
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-04-30', TransactionType.DIVIDEND) ])).toEqual(true);
|
|
17252
|
+
});
|
|
17253
|
+
|
|
17254
|
+
it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs first, should not be valid', () => {
|
|
17255
|
+
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30', TransactionType.DIVIDEND), build(2, '2018-04-30') ])).toEqual(false);
|
|
17256
|
+
});
|
|
17257
|
+
*/
|
|
17258
|
+
|
|
17232
17259
|
it('An array of transactions with ordered sequences, on the sequential days should be valid', () => {
|
|
17233
|
-
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-05-01'), build(3, '2018-05-02') ])).toEqual(true);
|
|
17260
|
+
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-05-01'), build(3, '2018-05-02', TransactionType.DIVIDEND) ])).toEqual(true);
|
|
17234
17261
|
});
|
|
17235
17262
|
|
|
17236
17263
|
it('An array of transactions with ordered sequences (starting after one), on the same day should not be valid', () => {
|
|
@@ -17291,7 +17318,7 @@ describe('When requesting all the user-initiated transaction types', () => {
|
|
|
17291
17318
|
expect(userInitiated.length).toEqual(9);
|
|
17292
17319
|
});
|
|
17293
17320
|
});
|
|
17294
|
-
},{"./../../../lib/data/TransactionValidator":5,"@barchart/common-js/lang/Day":21}],54:[function(require,module,exports){
|
|
17321
|
+
},{"./../../../lib/data/TransactionType":4,"./../../../lib/data/TransactionValidator":5,"@barchart/common-js/lang/Day":21}],54:[function(require,module,exports){
|
|
17295
17322
|
const Currency = require('@barchart/common-js/lang/Currency'),
|
|
17296
17323
|
Decimal = require('@barchart/common-js/lang/Decimal');
|
|
17297
17324
|
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
const Day = require('@barchart/common-js/lang/Day');
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const TransactionType = require('./../../../lib/data/TransactionType'),
|
|
4
|
+
TransactionValidator = require('./../../../lib/data/TransactionValidator');
|
|
4
5
|
|
|
5
6
|
describe('When validating transaction order', () => {
|
|
6
7
|
'use strict';
|
|
7
8
|
|
|
8
|
-
const build = (sequence, day) => {
|
|
9
|
-
return { sequence: sequence, date: Day.parse(day) };
|
|
9
|
+
const build = (sequence, day, type) => {
|
|
10
|
+
return { sequence: sequence, date: Day.parse(day), type: (type || TransactionType.BUY ) };
|
|
10
11
|
};
|
|
11
12
|
|
|
12
13
|
it('An array of zero transactions should be valid', () => {
|
|
@@ -17,8 +18,18 @@ describe('When validating transaction order', () => {
|
|
|
17
18
|
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-04-30'), build(3, '2018-04-30') ])).toEqual(true);
|
|
18
19
|
});
|
|
19
20
|
|
|
21
|
+
/*
|
|
22
|
+
it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs last, should be valid', () => {
|
|
23
|
+
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-04-30', TransactionType.DIVIDEND) ])).toEqual(true);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs first, should not be valid', () => {
|
|
27
|
+
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30', TransactionType.DIVIDEND), build(2, '2018-04-30') ])).toEqual(false);
|
|
28
|
+
});
|
|
29
|
+
*/
|
|
30
|
+
|
|
20
31
|
it('An array of transactions with ordered sequences, on the sequential days should be valid', () => {
|
|
21
|
-
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-05-01'), build(3, '2018-05-02') ])).toEqual(true);
|
|
32
|
+
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-05-01'), build(3, '2018-05-02', TransactionType.DIVIDEND) ])).toEqual(true);
|
|
22
33
|
});
|
|
23
34
|
|
|
24
35
|
it('An array of transactions with ordered sequences (starting after one), on the same day should not be valid', () => {
|