@barchart/portfolio-api-common 1.0.210 → 1.0.214
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.
|
@@ -15,19 +15,26 @@ module.exports = (() => {
|
|
|
15
15
|
* @param {String} alternateDescription
|
|
16
16
|
* @param {String} code
|
|
17
17
|
* @param {Boolean} canReinvest
|
|
18
|
+
* @param {Boolean} canShort
|
|
19
|
+
* @param {Boolean} canSwitchDirection
|
|
18
20
|
* @param {Boolean} usesSymbols
|
|
21
|
+
* @param {Function} usesSymbols
|
|
19
22
|
*/
|
|
20
23
|
class InstrumentType extends Enum {
|
|
21
|
-
constructor(code, description, alternateDescription, canReinvest, usesSymbols, generator) {
|
|
24
|
+
constructor(code, description, alternateDescription, canReinvest, canShort, canSwitchDirection, usesSymbols, generator) {
|
|
22
25
|
super(code, description);
|
|
23
26
|
|
|
24
27
|
assert.argumentIsRequired(alternateDescription, 'alternateDescription', String);
|
|
25
28
|
assert.argumentIsRequired(canReinvest, 'canReinvest', Boolean);
|
|
29
|
+
assert.argumentIsRequired(canShort, 'canShort', Boolean);
|
|
30
|
+
assert.argumentIsRequired(canSwitchDirection, 'canSwitchDirection', Boolean);
|
|
26
31
|
assert.argumentIsRequired(usesSymbols, 'usesSymbols', Boolean);
|
|
27
32
|
assert.argumentIsRequired(generator, 'generator', Function);
|
|
28
33
|
|
|
29
34
|
this._alternateDescription = alternateDescription;
|
|
30
35
|
this._canReinvest = canReinvest;
|
|
36
|
+
this._canShort = canShort;
|
|
37
|
+
this._canSwitchDirection = canSwitchDirection;
|
|
31
38
|
this._usesSymbols = usesSymbols;
|
|
32
39
|
|
|
33
40
|
this._generator = generator;
|
|
@@ -53,6 +60,27 @@ module.exports = (() => {
|
|
|
53
60
|
return this._canReinvest;
|
|
54
61
|
}
|
|
55
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Indicates if short-selling is possible for this instrument type.
|
|
65
|
+
*
|
|
66
|
+
* @public
|
|
67
|
+
* @returns {Boolean}
|
|
68
|
+
*/
|
|
69
|
+
get canShort() {
|
|
70
|
+
return this._canShort;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Indicates if one transaction is allowed to switch a position size from
|
|
75
|
+
* positive to negative (or vice versa).
|
|
76
|
+
*
|
|
77
|
+
* @public
|
|
78
|
+
* @returns {Boolean}
|
|
79
|
+
*/
|
|
80
|
+
get canSwitchDirection() {
|
|
81
|
+
return this._canSwitchDirection;
|
|
82
|
+
}
|
|
83
|
+
|
|
56
84
|
/**
|
|
57
85
|
* Indicates if an instrument of this type can be represented by a symbol.
|
|
58
86
|
*
|
|
@@ -141,10 +169,10 @@ module.exports = (() => {
|
|
|
141
169
|
}
|
|
142
170
|
}
|
|
143
171
|
|
|
144
|
-
const cash = new InstrumentType('CASH', 'cash', 'Cash', false, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.currency.code}`);
|
|
145
|
-
const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
146
|
-
const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
147
|
-
const other = new InstrumentType('OTHER', 'other', 'Other', false, false, (instrument) => `BARCHART-${instrument.type.code}-${uuid.v4()}`);
|
|
172
|
+
const cash = new InstrumentType('CASH', 'cash', 'Cash', false, false, true, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.currency.code}`);
|
|
173
|
+
const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true, true, false, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
174
|
+
const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true, false, false, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
175
|
+
const other = new InstrumentType('OTHER', 'other', 'Other', false, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${uuid.v4()}`);
|
|
148
176
|
|
|
149
177
|
const map = { };
|
|
150
178
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
2
|
+
Decimal = require('@barchart/common-js/lang/Decimal'),
|
|
2
3
|
is = require('@barchart/common-js/lang/is'),
|
|
3
4
|
formatter = require('@barchart/common-js/lang/formatter');
|
|
4
5
|
|
|
@@ -53,7 +54,7 @@ module.exports = (() => {
|
|
|
53
54
|
const formattedTransaction = formatterFunction(transaction);
|
|
54
55
|
|
|
55
56
|
Object.keys(formattedTransaction).map((key) => {
|
|
56
|
-
if (!is.undefined(formattedTransaction[key]) &&
|
|
57
|
+
if (!is.undefined(formattedTransaction[key]) && formattedTransaction[key] instanceof Decimal) {
|
|
57
58
|
const precision = transaction.instrument.currency.precision;
|
|
58
59
|
|
|
59
60
|
formattedTransaction[key] = formatter.numberToString(formattedTransaction[key].toFloat(), precision, ',');
|
|
@@ -371,7 +371,7 @@ module.exports = (() => {
|
|
|
371
371
|
|
|
372
372
|
const descriptionSelector = this._definition.descriptionSelector;
|
|
373
373
|
|
|
374
|
-
this._description =
|
|
374
|
+
this._description = PositionLevelDefinition.getDescriptionForPortfolioGroup(portfolio);
|
|
375
375
|
|
|
376
376
|
this._dataActual.description = this._description;
|
|
377
377
|
this._dataFormat.description = this._description;
|
|
@@ -596,7 +596,7 @@ module.exports = (() => {
|
|
|
596
596
|
updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrent));
|
|
597
597
|
updates.summaryTotalPrevious = updates.summaryTotalPrevious.add(translate(item, item.data.summaryTotalPrevious));
|
|
598
598
|
|
|
599
|
-
if (item.position.type === InstrumentType.CASH) {
|
|
599
|
+
if (item.position.instrument.type === InstrumentType.CASH) {
|
|
600
600
|
updates.cashTotal = updates.cashTotal.add(translate(item, item.data.market));
|
|
601
601
|
}
|
|
602
602
|
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -16,19 +16,26 @@ module.exports = (() => {
|
|
|
16
16
|
* @param {String} alternateDescription
|
|
17
17
|
* @param {String} code
|
|
18
18
|
* @param {Boolean} canReinvest
|
|
19
|
+
* @param {Boolean} canShort
|
|
20
|
+
* @param {Boolean} canSwitchDirection
|
|
19
21
|
* @param {Boolean} usesSymbols
|
|
22
|
+
* @param {Function} usesSymbols
|
|
20
23
|
*/
|
|
21
24
|
class InstrumentType extends Enum {
|
|
22
|
-
constructor(code, description, alternateDescription, canReinvest, usesSymbols, generator) {
|
|
25
|
+
constructor(code, description, alternateDescription, canReinvest, canShort, canSwitchDirection, usesSymbols, generator) {
|
|
23
26
|
super(code, description);
|
|
24
27
|
|
|
25
28
|
assert.argumentIsRequired(alternateDescription, 'alternateDescription', String);
|
|
26
29
|
assert.argumentIsRequired(canReinvest, 'canReinvest', Boolean);
|
|
30
|
+
assert.argumentIsRequired(canShort, 'canShort', Boolean);
|
|
31
|
+
assert.argumentIsRequired(canSwitchDirection, 'canSwitchDirection', Boolean);
|
|
27
32
|
assert.argumentIsRequired(usesSymbols, 'usesSymbols', Boolean);
|
|
28
33
|
assert.argumentIsRequired(generator, 'generator', Function);
|
|
29
34
|
|
|
30
35
|
this._alternateDescription = alternateDescription;
|
|
31
36
|
this._canReinvest = canReinvest;
|
|
37
|
+
this._canShort = canShort;
|
|
38
|
+
this._canSwitchDirection = canSwitchDirection;
|
|
32
39
|
this._usesSymbols = usesSymbols;
|
|
33
40
|
|
|
34
41
|
this._generator = generator;
|
|
@@ -54,6 +61,27 @@ module.exports = (() => {
|
|
|
54
61
|
return this._canReinvest;
|
|
55
62
|
}
|
|
56
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Indicates if short-selling is possible for this instrument type.
|
|
66
|
+
*
|
|
67
|
+
* @public
|
|
68
|
+
* @returns {Boolean}
|
|
69
|
+
*/
|
|
70
|
+
get canShort() {
|
|
71
|
+
return this._canShort;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Indicates if one transaction is allowed to switch a position size from
|
|
76
|
+
* positive to negative (or vice versa).
|
|
77
|
+
*
|
|
78
|
+
* @public
|
|
79
|
+
* @returns {Boolean}
|
|
80
|
+
*/
|
|
81
|
+
get canSwitchDirection() {
|
|
82
|
+
return this._canSwitchDirection;
|
|
83
|
+
}
|
|
84
|
+
|
|
57
85
|
/**
|
|
58
86
|
* Indicates if an instrument of this type can be represented by a symbol.
|
|
59
87
|
*
|
|
@@ -142,10 +170,10 @@ module.exports = (() => {
|
|
|
142
170
|
}
|
|
143
171
|
}
|
|
144
172
|
|
|
145
|
-
const cash = new InstrumentType('CASH', 'cash', 'Cash', false, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.currency.code}`);
|
|
146
|
-
const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
147
|
-
const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
148
|
-
const other = new InstrumentType('OTHER', 'other', 'Other', false, false, (instrument) => `BARCHART-${instrument.type.code}-${uuid.v4()}`);
|
|
173
|
+
const cash = new InstrumentType('CASH', 'cash', 'Cash', false, false, true, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.currency.code}`);
|
|
174
|
+
const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true, true, false, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
175
|
+
const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true, false, false, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
176
|
+
const other = new InstrumentType('OTHER', 'other', 'Other', false, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${uuid.v4()}`);
|
|
149
177
|
|
|
150
178
|
const map = { };
|
|
151
179
|
|
|
@@ -2023,7 +2051,7 @@ module.exports = (() => {
|
|
|
2023
2051
|
|
|
2024
2052
|
const descriptionSelector = this._definition.descriptionSelector;
|
|
2025
2053
|
|
|
2026
|
-
this._description =
|
|
2054
|
+
this._description = PositionLevelDefinition.getDescriptionForPortfolioGroup(portfolio);
|
|
2027
2055
|
|
|
2028
2056
|
this._dataActual.description = this._description;
|
|
2029
2057
|
this._dataFormat.description = this._description;
|
|
@@ -2248,7 +2276,7 @@ module.exports = (() => {
|
|
|
2248
2276
|
updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrent));
|
|
2249
2277
|
updates.summaryTotalPrevious = updates.summaryTotalPrevious.add(translate(item, item.data.summaryTotalPrevious));
|
|
2250
2278
|
|
|
2251
|
-
if (item.position.type === InstrumentType.CASH) {
|
|
2279
|
+
if (item.position.instrument.type === InstrumentType.CASH) {
|
|
2252
2280
|
updates.cashTotal = updates.cashTotal.add(translate(item, item.data.market));
|
|
2253
2281
|
}
|
|
2254
2282
|
|