@barchart/portfolio-api-common 1.3.5 → 1.3.9
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 +1 -1
- package/lib/data/CorporateActionType.js +20 -19
- package/lib/data/InstrumentType.js +1 -1
- package/lib/processing/PositionContainer.js +2 -3
- package/lib/processing/definitions/PositionLevelDefinition.js +17 -12
- package/lib/processing/definitions/PositionLevelType.js +30 -0
- package/lib/processing/definitions/PositionTreeDefinition.js +2 -2
- package/lib/websockets/WebsocketActionType.js +148 -0
- package/package.json +1 -1
- package/test/SpecRunner.js +2871 -3794
|
@@ -307,7 +307,7 @@ module.exports = (() => {
|
|
|
307
307
|
|
|
308
308
|
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).');
|
|
309
309
|
const transactionDeleteFailedNoTransaction = new FailureType('TRANSACTION_DELETE_FAILED_NO_TRANSACTION', 'Unable to delete transaction. The referenced transaction does not exist.');
|
|
310
|
-
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.');
|
|
310
|
+
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.', false);
|
|
311
311
|
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.');
|
|
312
312
|
const transactionDeleteFailedTypeReserved = new FailureType('TRANSACTION_DELETE_FAILED_TYPE_RESERVED', 'Unable to delete {U|type.description} transaction, this type of transaction is managed by the system.');
|
|
313
313
|
|
|
@@ -18,58 +18,58 @@ module.exports = (() => {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
22
|
-
* system purposes.
|
|
21
|
+
* A split.
|
|
23
22
|
*
|
|
24
23
|
* @public
|
|
25
|
-
* @
|
|
24
|
+
* @static
|
|
25
|
+
* @returns {CorporateActionType}
|
|
26
26
|
*/
|
|
27
|
-
get
|
|
28
|
-
return
|
|
27
|
+
static get SPLIT() {
|
|
28
|
+
return split;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
|
-
* A
|
|
32
|
+
* A dividend.
|
|
33
33
|
*
|
|
34
34
|
* @public
|
|
35
35
|
* @static
|
|
36
36
|
* @returns {CorporateActionType}
|
|
37
37
|
*/
|
|
38
|
-
static get
|
|
39
|
-
return
|
|
38
|
+
static get DIVIDEND() {
|
|
39
|
+
return dividend;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
|
-
* A
|
|
43
|
+
* A stock dividend.
|
|
44
44
|
*
|
|
45
45
|
* @public
|
|
46
46
|
* @static
|
|
47
47
|
* @returns {CorporateActionType}
|
|
48
48
|
*/
|
|
49
|
-
static get
|
|
50
|
-
return
|
|
49
|
+
static get STOCK_DIVIDEND() {
|
|
50
|
+
return stockDividend;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
|
-
* A
|
|
54
|
+
* A symbol change.
|
|
55
55
|
*
|
|
56
56
|
* @public
|
|
57
57
|
* @static
|
|
58
58
|
* @returns {CorporateActionType}
|
|
59
59
|
*/
|
|
60
|
-
static get
|
|
61
|
-
return
|
|
60
|
+
static get SYMBOL_CHANGE() {
|
|
61
|
+
return symbolChange;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
|
-
* A
|
|
65
|
+
* A name change.
|
|
66
66
|
*
|
|
67
67
|
* @public
|
|
68
68
|
* @static
|
|
69
69
|
* @returns {CorporateActionType}
|
|
70
70
|
*/
|
|
71
|
-
static get
|
|
72
|
-
return
|
|
71
|
+
static get NAME_CHANGE() {
|
|
72
|
+
return nameChange;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
/**
|
|
@@ -84,10 +84,11 @@ module.exports = (() => {
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
const split = new CorporateActionType('SPLIT', 'Split', false);
|
|
88
|
+
const dividend = new CorporateActionType('DIVIDEND', 'Dividend', false);
|
|
89
|
+
const stockDividend = new CorporateActionType('STOCK_DIVIDEND', 'Stock Dividend', false);
|
|
87
90
|
const symbolChange = new CorporateActionType('SYMBOL_CHANGE', 'Symbol Change', false);
|
|
88
91
|
const nameChange = new CorporateActionType('NAME_CHANGE', 'Name Change', false);
|
|
89
|
-
const dividend = new CorporateActionType('DIVIDEND', 'Dividend', false);
|
|
90
|
-
const split = new CorporateActionType('SPLIT', 'Split', false);
|
|
91
92
|
const delist = new CorporateActionType('DELIST', 'Delist', false);
|
|
92
93
|
|
|
93
94
|
return CorporateActionType;
|
|
@@ -41,8 +41,8 @@ module.exports = (() => {
|
|
|
41
41
|
* @public
|
|
42
42
|
* @param {PositionTreeDefinition[]} definitions
|
|
43
43
|
* @param {Object[]} portfolios - The portfolios.
|
|
44
|
-
* @param {Object[]} positions - The positions (for all of
|
|
45
|
-
* @param {Object[]} summaries - The positions summaries (for all of
|
|
44
|
+
* @param {Object[]} positions - The positions (for all of portfolios).
|
|
45
|
+
* @param {Object[]} summaries - The positions summaries (for all of positions).
|
|
46
46
|
* @param {PositionSummaryFrame=} reportFrame - If specified, locks the current (and previous) periods to a specific frame, use for reporting.
|
|
47
47
|
* @param {Day=} reportDate - The end date for the report frame.
|
|
48
48
|
*/
|
|
@@ -933,7 +933,6 @@ module.exports = (() => {
|
|
|
933
933
|
});
|
|
934
934
|
}
|
|
935
935
|
|
|
936
|
-
|
|
937
936
|
function updateEmptyPortfolioGroups(portfolio) {
|
|
938
937
|
Object.keys(this._trees).forEach((key) => {
|
|
939
938
|
this._trees[key].walk((group) => {
|
|
@@ -74,7 +74,7 @@ module.exports = (() => {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
/**
|
|
77
|
-
* A function, when given a {@link PositionItem} returns a string that is used
|
|
77
|
+
* A function, when given a {@link PositionItem}, returns a string that is used
|
|
78
78
|
* to group {@link PositionItem} instances into different groups.
|
|
79
79
|
*
|
|
80
80
|
* @public
|
|
@@ -85,7 +85,7 @@ module.exports = (() => {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
/**
|
|
88
|
-
* A function, when given a {@link PositionItem} returns a string used to describe the
|
|
88
|
+
* A function, when given a {@link PositionItem}, returns a string used to describe the
|
|
89
89
|
* group.
|
|
90
90
|
*
|
|
91
91
|
* @public
|
|
@@ -96,7 +96,7 @@ module.exports = (() => {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
/**
|
|
99
|
-
* A function, when given a {@link PositionItem} returns the {@link Currency} used to
|
|
99
|
+
* A function, when given a {@link PositionItem}, returns the {@link Currency} used to
|
|
100
100
|
* display values for the group.
|
|
101
101
|
*
|
|
102
102
|
* @public
|
|
@@ -111,7 +111,7 @@ module.exports = (() => {
|
|
|
111
111
|
* groups.
|
|
112
112
|
*
|
|
113
113
|
* @public
|
|
114
|
-
* @returns {
|
|
114
|
+
* @returns {String[]}
|
|
115
115
|
*/
|
|
116
116
|
get requiredGroups() {
|
|
117
117
|
return this._requiredGroups;
|
|
@@ -160,13 +160,16 @@ module.exports = (() => {
|
|
|
160
160
|
* @public
|
|
161
161
|
* @static
|
|
162
162
|
* @param {Object} portfolio
|
|
163
|
+
* @param {Currency=} currency
|
|
163
164
|
* @returns {PositionLevelDefinition~RequiredGroup}
|
|
164
165
|
*/
|
|
165
|
-
static buildRequiredGroupForPortfolio(portfolio) {
|
|
166
|
+
static buildRequiredGroupForPortfolio(portfolio, currency) {
|
|
167
|
+
assert.argumentIsOptional(currency, 'currency', Currency, 'Currency');
|
|
168
|
+
|
|
166
169
|
return {
|
|
167
170
|
key: PositionLevelDefinition.getKeyForPortfolioGroup(portfolio),
|
|
168
171
|
description: PositionLevelDefinition.getDescriptionForPortfolioGroup(portfolio),
|
|
169
|
-
currency: Currency.CAD
|
|
172
|
+
currency: (currency || Currency.CAD)
|
|
170
173
|
};
|
|
171
174
|
}
|
|
172
175
|
|
|
@@ -182,12 +185,12 @@ module.exports = (() => {
|
|
|
182
185
|
return portfolio.name;
|
|
183
186
|
}
|
|
184
187
|
|
|
185
|
-
static getRequiredGroupGeneratorForPortfolio() {
|
|
188
|
+
static getRequiredGroupGeneratorForPortfolio(currency) {
|
|
186
189
|
return (portfolio) => {
|
|
187
190
|
let requiredGroup;
|
|
188
191
|
|
|
189
192
|
if (is.object(portfolio) && is.string(portfolio.portfolio) && is.string(portfolio.name)) {
|
|
190
|
-
requiredGroup = PositionLevelDefinition.buildRequiredGroupForPortfolio(portfolio);
|
|
193
|
+
requiredGroup = PositionLevelDefinition.buildRequiredGroupForPortfolio(portfolio, currency);
|
|
191
194
|
} else {
|
|
192
195
|
requiredGroup = null;
|
|
193
196
|
}
|
|
@@ -203,12 +206,13 @@ module.exports = (() => {
|
|
|
203
206
|
* @static
|
|
204
207
|
* @param {InstrumentType} type
|
|
205
208
|
* @param {Currency} currency
|
|
209
|
+
* @param {Currency=} defaultCurrency
|
|
206
210
|
* @returns {PositionLevelDefinition~RequiredGroup}
|
|
207
211
|
*/
|
|
208
|
-
static buildRequiredGroupForAssetClass(type, currency) {
|
|
212
|
+
static buildRequiredGroupForAssetClass(type, currency, defaultCurrency) {
|
|
209
213
|
return {
|
|
210
214
|
key: PositionLevelDefinition.getKeyForAssetClassGroup(type, currency),
|
|
211
|
-
description: PositionLevelDefinition.getDescriptionForAssetClassGroup(type, currency),
|
|
215
|
+
description: PositionLevelDefinition.getDescriptionForAssetClassGroup(type, currency, defaultCurrency),
|
|
212
216
|
currency: currency
|
|
213
217
|
};
|
|
214
218
|
}
|
|
@@ -220,11 +224,12 @@ module.exports = (() => {
|
|
|
220
224
|
return `${type.code}|${currency.code}`;
|
|
221
225
|
}
|
|
222
226
|
|
|
223
|
-
static getDescriptionForAssetClassGroup(type, currency) {
|
|
227
|
+
static getDescriptionForAssetClassGroup(type, currency, defaultCurrency) {
|
|
224
228
|
assert.argumentIsRequired(type, 'type', InstrumentType, 'InstrumentType');
|
|
225
229
|
assert.argumentIsRequired(currency, 'currency', Currency, 'Currency');
|
|
230
|
+
assert.argumentIsOptional(defaultCurrency, 'defaultCurrency', Currency, 'Currency');
|
|
226
231
|
|
|
227
|
-
return `${type.alternateDescription}${currency
|
|
232
|
+
return `${type.alternateDescription}${currency === (defaultCurrency || Currency.CAD) ? '' : ` (${currency.alternateDescription})`}`;
|
|
228
233
|
}
|
|
229
234
|
|
|
230
235
|
toString() {
|
|
@@ -3,19 +3,49 @@ const Enum = require('@barchart/common-js/lang/Enum');
|
|
|
3
3
|
module.exports = (() => {
|
|
4
4
|
'use strict';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Describes the contents of a grouping level within a tree of positions.
|
|
8
|
+
* This is an attribute of a {@link PositionLevelDefinition}.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
* @extends {Enum}
|
|
12
|
+
*/
|
|
6
13
|
class PositionLevelType extends Enum {
|
|
7
14
|
constructor(code) {
|
|
8
15
|
super(code, code);
|
|
9
16
|
}
|
|
10
17
|
|
|
18
|
+
/**
|
|
19
|
+
* A level of grouping that represents an entire portfolio's contents.
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
* @static
|
|
23
|
+
* @returns {PositionLevelType}
|
|
24
|
+
*/
|
|
11
25
|
static get PORTFOLIO() {
|
|
12
26
|
return portfolio;
|
|
13
27
|
}
|
|
14
28
|
|
|
29
|
+
/**
|
|
30
|
+
* A level of grouping that represents a single positions (i.e. guaranteed to
|
|
31
|
+
* be a leaf node in a grouping tree).
|
|
32
|
+
*
|
|
33
|
+
* @public
|
|
34
|
+
* @static
|
|
35
|
+
* @return {PositionLevelType}
|
|
36
|
+
*/
|
|
15
37
|
static get POSITION() {
|
|
16
38
|
return position;
|
|
17
39
|
}
|
|
18
40
|
|
|
41
|
+
/**
|
|
42
|
+
* A level of grouping that is neither a portfolio or a position. This could be an
|
|
43
|
+
* intermediate level of grouping (e.g. an asset class within a portfolio).
|
|
44
|
+
*
|
|
45
|
+
* @public
|
|
46
|
+
* @static
|
|
47
|
+
* @return {PositionLevelType}
|
|
48
|
+
*/
|
|
19
49
|
static get OTHER() {
|
|
20
50
|
return other;
|
|
21
51
|
}
|
|
@@ -11,7 +11,7 @@ module.exports = (() => {
|
|
|
11
11
|
* @public
|
|
12
12
|
* @param {String} name
|
|
13
13
|
* @param {PositionLevelDefinition[]} definitions
|
|
14
|
-
* @
|
|
14
|
+
* @param {String[]=} exclusionDependencies
|
|
15
15
|
*/
|
|
16
16
|
class PositionTreeDefinitions {
|
|
17
17
|
constructor(name, definitions, exclusionDependencies) {
|
|
@@ -44,7 +44,7 @@ module.exports = (() => {
|
|
|
44
44
|
* bottom-most level of the tree (i.e. leaf nodes).
|
|
45
45
|
*
|
|
46
46
|
* @public
|
|
47
|
-
* @returns {PositionLevelDefinitions
|
|
47
|
+
* @returns {PositionLevelDefinitions[]}
|
|
48
48
|
*/
|
|
49
49
|
get definitions() {
|
|
50
50
|
return this._definitions;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
const assert = require('@barchart/common-js/lang/assert'),
|
|
2
|
+
Enum = require('@barchart/common-js/lang/Enum');
|
|
3
|
+
|
|
4
|
+
module.exports = (() => {
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Types of websocket response actions.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
* @extends {Enum}
|
|
12
|
+
* @param {String} code
|
|
13
|
+
* @param {String} description
|
|
14
|
+
* @param {String} action
|
|
15
|
+
*/
|
|
16
|
+
class WebsocketActionType extends Enum {
|
|
17
|
+
constructor(code, description, action) {
|
|
18
|
+
super(code, description);
|
|
19
|
+
|
|
20
|
+
assert.argumentIsRequired(action, 'action', String);
|
|
21
|
+
|
|
22
|
+
this._action = action;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* An action of websocket response
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
* @returns {String}
|
|
30
|
+
*/
|
|
31
|
+
get action() {
|
|
32
|
+
return this._action;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Action type for creating new portfolio.
|
|
37
|
+
*
|
|
38
|
+
* @public
|
|
39
|
+
* @static
|
|
40
|
+
* @returns {WebsocketActionType}
|
|
41
|
+
*/
|
|
42
|
+
static get PORTFOLIO_CREATE() {
|
|
43
|
+
return portfolioCreate;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Action type for deleting portfolio.
|
|
48
|
+
*
|
|
49
|
+
* @public
|
|
50
|
+
* @static
|
|
51
|
+
* @returns {WebsocketActionType}
|
|
52
|
+
*/
|
|
53
|
+
static get PORTFOLIO_DELETE() {
|
|
54
|
+
return portfolioDelete;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Action type for updating new portfolio.
|
|
59
|
+
*
|
|
60
|
+
* @public
|
|
61
|
+
* @static
|
|
62
|
+
* @returns {WebsocketActionType}
|
|
63
|
+
*/
|
|
64
|
+
static get PORTFOLIO_UPDATE() {
|
|
65
|
+
return portfolioUpdate;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Action type for creating new transaction.
|
|
70
|
+
*
|
|
71
|
+
* @public
|
|
72
|
+
* @static
|
|
73
|
+
* @returns {WebsocketActionType}
|
|
74
|
+
*/
|
|
75
|
+
static get TRANSACTION_CREATE() {
|
|
76
|
+
return transactionCreate;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Action type for deleting transaction.
|
|
81
|
+
*
|
|
82
|
+
* @public
|
|
83
|
+
* @static
|
|
84
|
+
* @returns {WebsocketActionType}
|
|
85
|
+
*/
|
|
86
|
+
static get TRANSACTION_DELETE() {
|
|
87
|
+
return transactionDelete;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Action type for editing transaction.
|
|
92
|
+
*
|
|
93
|
+
* @public
|
|
94
|
+
* @static
|
|
95
|
+
* @returns {WebsocketActionType}
|
|
96
|
+
*/
|
|
97
|
+
static get TRANSACTION_EDIT() {
|
|
98
|
+
return transactionEdit;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Action type for batching transaction.
|
|
103
|
+
*
|
|
104
|
+
* @public
|
|
105
|
+
* @static
|
|
106
|
+
* @returns {WebsocketActionType}
|
|
107
|
+
*/
|
|
108
|
+
static get TRANSACTION_BATCH() {
|
|
109
|
+
return transactionBatch;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Action type for deleting position.
|
|
114
|
+
*
|
|
115
|
+
* @public
|
|
116
|
+
* @static
|
|
117
|
+
* @returns {WebsocketActionType}
|
|
118
|
+
*/
|
|
119
|
+
static get POSITION_DELETE() {
|
|
120
|
+
return positionDelete;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Action type for updating position.
|
|
125
|
+
*
|
|
126
|
+
* @public
|
|
127
|
+
* @static
|
|
128
|
+
* @returns {WebsocketActionType}
|
|
129
|
+
*/
|
|
130
|
+
static get POSITION_UPDATE() {
|
|
131
|
+
return positionUpdate;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const portfolioCreate = new WebsocketActionType('PORTFOLIO_CREATE', 'Create portfolio action', 'portfolio/create');
|
|
136
|
+
const portfolioDelete = new WebsocketActionType('PORTFOLIO_DELETE', 'Delete portfolio action', 'portfolio/delete');
|
|
137
|
+
const portfolioUpdate = new WebsocketActionType('PORTFOLIO_UPDATE', 'Update portfolio action', 'portfolio/update');
|
|
138
|
+
|
|
139
|
+
const transactionCreate = new WebsocketActionType('TRANSACTION_CREATE', 'Create transaction action', 'transaction/create');
|
|
140
|
+
const transactionDelete = new WebsocketActionType('TRANSACTION_DELETE', 'Delete transaction action', 'transaction/delete');
|
|
141
|
+
const transactionEdit = new WebsocketActionType('TRANSACTION_EDIT', 'Edit transaction action', 'transaction/edit');
|
|
142
|
+
const transactionBatch = new WebsocketActionType('TRANSACTION_BATCH', 'Batch transaction action', 'transaction/batch');
|
|
143
|
+
|
|
144
|
+
const positionDelete = new WebsocketActionType('POSITION_DELETE', 'Delete position action', 'position/delete');
|
|
145
|
+
const positionUpdate = new WebsocketActionType('POSITION_UPDATE', 'Update position action', 'position/update');
|
|
146
|
+
|
|
147
|
+
return WebsocketActionType;
|
|
148
|
+
})();
|