@barchart/portfolio-api-common 1.2.21 → 1.2.25
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.
|
@@ -18,10 +18,11 @@ module.exports = (() => {
|
|
|
18
18
|
* @param {Boolean} canShort
|
|
19
19
|
* @param {Boolean} canSwitchDirection
|
|
20
20
|
* @param {Boolean} usesSymbols
|
|
21
|
-
* @param {
|
|
21
|
+
* @param {Boolean} hasCorporateActions
|
|
22
|
+
* @param {Function} generator
|
|
22
23
|
*/
|
|
23
24
|
class InstrumentType extends Enum {
|
|
24
|
-
constructor(code, description, alternateDescription, canReinvest, canShort, canSwitchDirection, usesSymbols, generator) {
|
|
25
|
+
constructor(code, description, alternateDescription, canReinvest, canShort, canSwitchDirection, usesSymbols, hasCorporateActions, generator) {
|
|
25
26
|
super(code, description);
|
|
26
27
|
|
|
27
28
|
assert.argumentIsRequired(alternateDescription, 'alternateDescription', String);
|
|
@@ -29,6 +30,7 @@ module.exports = (() => {
|
|
|
29
30
|
assert.argumentIsRequired(canShort, 'canShort', Boolean);
|
|
30
31
|
assert.argumentIsRequired(canSwitchDirection, 'canSwitchDirection', Boolean);
|
|
31
32
|
assert.argumentIsRequired(usesSymbols, 'usesSymbols', Boolean);
|
|
33
|
+
assert.argumentIsRequired(hasCorporateActions, 'hasCorporateActions', Boolean);
|
|
32
34
|
assert.argumentIsRequired(generator, 'generator', Function);
|
|
33
35
|
|
|
34
36
|
this._alternateDescription = alternateDescription;
|
|
@@ -36,6 +38,7 @@ module.exports = (() => {
|
|
|
36
38
|
this._canShort = canShort;
|
|
37
39
|
this._canSwitchDirection = canSwitchDirection;
|
|
38
40
|
this._usesSymbols = usesSymbols;
|
|
41
|
+
this._hasCorporateActions = hasCorporateActions;
|
|
39
42
|
|
|
40
43
|
this._generator = generator;
|
|
41
44
|
}
|
|
@@ -91,6 +94,16 @@ module.exports = (() => {
|
|
|
91
94
|
return this._usesSymbols;
|
|
92
95
|
}
|
|
93
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Indicates if corporate actions are possible for this type of instrument.
|
|
99
|
+
*
|
|
100
|
+
* @public
|
|
101
|
+
* @returns {Boolean}
|
|
102
|
+
*/
|
|
103
|
+
get hasCorporateActions() {
|
|
104
|
+
return this._hasCorporateActions;
|
|
105
|
+
}
|
|
106
|
+
|
|
94
107
|
/**
|
|
95
108
|
* Generates an identifier for the instrument.
|
|
96
109
|
*
|
|
@@ -188,10 +201,10 @@ module.exports = (() => {
|
|
|
188
201
|
}
|
|
189
202
|
}
|
|
190
203
|
|
|
191
|
-
const cash = new InstrumentType('CASH', 'cash', 'Cash', false, false, true, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.currency.code}`);
|
|
192
|
-
const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true, true, false, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
193
|
-
const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true, false, false, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
194
|
-
const other = new InstrumentType('OTHER', 'other', 'Other', false, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${uuid.v4()}`);
|
|
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()}`);
|
|
195
208
|
|
|
196
209
|
const map = { };
|
|
197
210
|
|
|
@@ -406,15 +406,7 @@ module.exports = (() => {
|
|
|
406
406
|
|
|
407
407
|
const summary = item.currentSummary;
|
|
408
408
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
if (price) {
|
|
412
|
-
priceToUse = price;
|
|
413
|
-
} else {
|
|
414
|
-
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
if (summary) {
|
|
409
|
+
if (summary && position.instrument.type !== InstrumentType.CASH) {
|
|
418
410
|
let priceToUse;
|
|
419
411
|
|
|
420
412
|
if (price) {
|
|
@@ -433,7 +425,7 @@ module.exports = (() => {
|
|
|
433
425
|
let unrealized = summary.end.open.multiply(priceToUse).add(summary.end.basis);
|
|
434
426
|
let unrealizedChange;
|
|
435
427
|
|
|
436
|
-
if (data.
|
|
428
|
+
if (data.unrealized !== null) {
|
|
437
429
|
unrealizedChange = unrealized.subtract(data.unrealized);
|
|
438
430
|
} else {
|
|
439
431
|
unrealizedChange = Decimal.ZERO;
|
|
@@ -420,6 +420,8 @@ module.exports = (() => {
|
|
|
420
420
|
.withField('portfolio', DataType.STRING)
|
|
421
421
|
.withField('position', DataType.STRING)
|
|
422
422
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
423
|
+
.withField('instrument.type', DataType.forEnum(InstrumentType, 'InstrumentType'), true)
|
|
424
|
+
.withField('instrument.currency', DataType.forEnum(Currency, 'Currency'), true)
|
|
423
425
|
.withField('date', DataType.DAY)
|
|
424
426
|
.withField('amount', DataType.DECIMAL)
|
|
425
427
|
.withField('fee', DataType.DECIMAL, true)
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -19,10 +19,11 @@ module.exports = (() => {
|
|
|
19
19
|
* @param {Boolean} canShort
|
|
20
20
|
* @param {Boolean} canSwitchDirection
|
|
21
21
|
* @param {Boolean} usesSymbols
|
|
22
|
-
* @param {
|
|
22
|
+
* @param {Boolean} hasCorporateActions
|
|
23
|
+
* @param {Function} generator
|
|
23
24
|
*/
|
|
24
25
|
class InstrumentType extends Enum {
|
|
25
|
-
constructor(code, description, alternateDescription, canReinvest, canShort, canSwitchDirection, usesSymbols, generator) {
|
|
26
|
+
constructor(code, description, alternateDescription, canReinvest, canShort, canSwitchDirection, usesSymbols, hasCorporateActions, generator) {
|
|
26
27
|
super(code, description);
|
|
27
28
|
|
|
28
29
|
assert.argumentIsRequired(alternateDescription, 'alternateDescription', String);
|
|
@@ -30,6 +31,7 @@ module.exports = (() => {
|
|
|
30
31
|
assert.argumentIsRequired(canShort, 'canShort', Boolean);
|
|
31
32
|
assert.argumentIsRequired(canSwitchDirection, 'canSwitchDirection', Boolean);
|
|
32
33
|
assert.argumentIsRequired(usesSymbols, 'usesSymbols', Boolean);
|
|
34
|
+
assert.argumentIsRequired(hasCorporateActions, 'hasCorporateActions', Boolean);
|
|
33
35
|
assert.argumentIsRequired(generator, 'generator', Function);
|
|
34
36
|
|
|
35
37
|
this._alternateDescription = alternateDescription;
|
|
@@ -37,6 +39,7 @@ module.exports = (() => {
|
|
|
37
39
|
this._canShort = canShort;
|
|
38
40
|
this._canSwitchDirection = canSwitchDirection;
|
|
39
41
|
this._usesSymbols = usesSymbols;
|
|
42
|
+
this._hasCorporateActions = hasCorporateActions;
|
|
40
43
|
|
|
41
44
|
this._generator = generator;
|
|
42
45
|
}
|
|
@@ -92,6 +95,16 @@ module.exports = (() => {
|
|
|
92
95
|
return this._usesSymbols;
|
|
93
96
|
}
|
|
94
97
|
|
|
98
|
+
/**
|
|
99
|
+
* Indicates if corporate actions are possible for this type of instrument.
|
|
100
|
+
*
|
|
101
|
+
* @public
|
|
102
|
+
* @returns {Boolean}
|
|
103
|
+
*/
|
|
104
|
+
get hasCorporateActions() {
|
|
105
|
+
return this._hasCorporateActions;
|
|
106
|
+
}
|
|
107
|
+
|
|
95
108
|
/**
|
|
96
109
|
* Generates an identifier for the instrument.
|
|
97
110
|
*
|
|
@@ -189,10 +202,10 @@ module.exports = (() => {
|
|
|
189
202
|
}
|
|
190
203
|
}
|
|
191
204
|
|
|
192
|
-
const cash = new InstrumentType('CASH', 'cash', 'Cash', false, false, true, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.currency.code}`);
|
|
193
|
-
const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true, true, false, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
194
|
-
const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true, false, false, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
195
|
-
const other = new InstrumentType('OTHER', 'other', 'Other', false, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${uuid.v4()}`);
|
|
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()}`);
|
|
196
209
|
|
|
197
210
|
const map = { };
|
|
198
211
|
|
|
@@ -3460,15 +3473,7 @@ module.exports = (() => {
|
|
|
3460
3473
|
|
|
3461
3474
|
const summary = item.currentSummary;
|
|
3462
3475
|
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
if (price) {
|
|
3466
|
-
priceToUse = price;
|
|
3467
|
-
} else {
|
|
3468
|
-
|
|
3469
|
-
}
|
|
3470
|
-
|
|
3471
|
-
if (summary) {
|
|
3476
|
+
if (summary && position.instrument.type !== InstrumentType.CASH) {
|
|
3472
3477
|
let priceToUse;
|
|
3473
3478
|
|
|
3474
3479
|
if (price) {
|
|
@@ -3487,7 +3492,7 @@ module.exports = (() => {
|
|
|
3487
3492
|
let unrealized = summary.end.open.multiply(priceToUse).add(summary.end.basis);
|
|
3488
3493
|
let unrealizedChange;
|
|
3489
3494
|
|
|
3490
|
-
if (data.
|
|
3495
|
+
if (data.unrealized !== null) {
|
|
3491
3496
|
unrealizedChange = unrealized.subtract(data.unrealized);
|
|
3492
3497
|
} else {
|
|
3493
3498
|
unrealizedChange = Decimal.ZERO;
|