@barchart/portfolio-api-common 1.3.8 → 1.3.12
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/data/CorporateActionType.js +20 -19
- package/lib/formatters/TransactionFormatter.js +65 -27
- package/lib/websockets/WebsocketActionType.js +144 -119
- package/package.json +1 -1
- package/test/SpecRunner.js +2821 -3780
|
@@ -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;
|
|
@@ -126,6 +126,7 @@ module.exports = (() => {
|
|
|
126
126
|
f.code = t.type.code;
|
|
127
127
|
f.sequence = t.sequence;
|
|
128
128
|
f.position = t.position;
|
|
129
|
+
f.open = t.snapshot.open;
|
|
129
130
|
};
|
|
130
131
|
|
|
131
132
|
const averageCostFormatter = (t, f) => {
|
|
@@ -151,53 +152,87 @@ module.exports = (() => {
|
|
|
151
152
|
};
|
|
152
153
|
|
|
153
154
|
const dividendFormatter = (t, f) => {
|
|
154
|
-
f.shares = t.snapshot.open;
|
|
155
155
|
f.total = t.dividend.amount;
|
|
156
156
|
f.rate = t.dividend.rate;
|
|
157
|
+
|
|
158
|
+
f.shares = t.dividend.amount.divide(t.dividend.rate);
|
|
157
159
|
};
|
|
158
160
|
|
|
159
|
-
const
|
|
160
|
-
f.
|
|
161
|
-
f.
|
|
161
|
+
const distributionCashFormatter = (t, f) => {
|
|
162
|
+
f.total = t.dividend.amount;
|
|
163
|
+
f.rate = t.dividend.rate;
|
|
162
164
|
|
|
163
|
-
|
|
164
|
-
f.shares = t.snapshot.open.subtract(t.quantity);
|
|
165
|
-
f.price = t.dividend.price;
|
|
166
|
-
f.rate = t.dividend.rate;
|
|
167
|
-
}
|
|
165
|
+
f.shares = t.dividend.amount.divide(t.dividend.rate);
|
|
168
166
|
};
|
|
169
167
|
|
|
170
168
|
const dividendReinvestFormatter = (t, f) => {
|
|
171
169
|
f.boughtSold = t.quantity;
|
|
172
|
-
|
|
170
|
+
|
|
171
|
+
if (f.fee && !f.fee.getIsZero()) {
|
|
172
|
+
f.fee = t.fee;
|
|
173
|
+
}
|
|
174
|
+
|
|
173
175
|
f.price = t.dividend.price;
|
|
174
|
-
f.fee = t.fee;
|
|
175
176
|
f.rate = t.dividend.rate;
|
|
177
|
+
|
|
178
|
+
f.shares = t.snapshot.open.subtract(t.quantity);
|
|
176
179
|
};
|
|
177
180
|
|
|
178
|
-
const
|
|
179
|
-
f.
|
|
180
|
-
|
|
181
|
+
const distributionReinvestFormatter = (t, f) => {
|
|
182
|
+
f.boughtSold = t.quantity;
|
|
183
|
+
|
|
184
|
+
if (f.fee && !f.fee.getIsZero()) {
|
|
185
|
+
f.fee = t.fee;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
f.price = t.dividend.price;
|
|
181
189
|
f.rate = t.dividend.rate;
|
|
190
|
+
|
|
191
|
+
f.shares = t.snapshot.open.subtract(t.quantity);
|
|
182
192
|
};
|
|
183
193
|
|
|
184
|
-
const
|
|
185
|
-
f.boughtSold =t.quantity;
|
|
186
|
-
|
|
194
|
+
const dividendStockFormatter = (t, f) => {
|
|
195
|
+
f.boughtSold = t.quantity;
|
|
196
|
+
|
|
197
|
+
if (f.fee && !f.fee.getIsZero()) {
|
|
198
|
+
f.fee = t.fee;
|
|
199
|
+
}
|
|
187
200
|
|
|
188
|
-
if (t.dividend
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
201
|
+
if (t.dividend) {
|
|
202
|
+
if (t.dividend.numerator && t.dividend.denominator) {
|
|
203
|
+
f.rate = `${t.dividend.numerator.round(4).toFixed()} for ${t.dividend.denominator.toFixed()}`;
|
|
204
|
+
} else if (t.dividend.rate) {
|
|
205
|
+
f.rate = t.dividend.rate;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (t.dividend.price) {
|
|
209
|
+
f.price = t.dividend.price;
|
|
210
|
+
}
|
|
192
211
|
}
|
|
212
|
+
|
|
213
|
+
f.shares = t.snapshot.open.subtract(t.quantity);
|
|
193
214
|
};
|
|
194
215
|
|
|
195
|
-
const
|
|
216
|
+
const distributionFundFormatter = (t, f) => {
|
|
196
217
|
f.boughtSold = t.quantity;
|
|
218
|
+
|
|
219
|
+
if (f.fee && !f.fee.getIsZero()) {
|
|
220
|
+
f.fee = t.fee;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (t.dividend) {
|
|
224
|
+
if (t.dividend.numerator && t.dividend.denominator) {
|
|
225
|
+
f.rate = `${t.dividend.numerator.round(4).toFixed()} for ${t.dividend.denominator.toFixed()}`;
|
|
226
|
+
} else if (t.dividend.rate) {
|
|
227
|
+
f.rate = t.dividend.rate;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (t.dividend.price) {
|
|
231
|
+
f.price = t.dividend.price;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
197
235
|
f.shares = t.snapshot.open.subtract(t.quantity);
|
|
198
|
-
f.price = t.dividend.price;
|
|
199
|
-
f.fee = t.fee;
|
|
200
|
-
f.rate = t.dividend.rate;
|
|
201
236
|
};
|
|
202
237
|
|
|
203
238
|
const incomeFormatter = (t, f) => {
|
|
@@ -214,8 +249,11 @@ module.exports = (() => {
|
|
|
214
249
|
};
|
|
215
250
|
|
|
216
251
|
const splitFormatter = (t, f) => {
|
|
217
|
-
f.
|
|
218
|
-
|
|
252
|
+
f.boughtSold = t.quantity;
|
|
253
|
+
|
|
254
|
+
f.rate = `${t.dividend.numerator.round(4).toFixed()} for ${t.dividend.denominator.toFixed()}`;
|
|
255
|
+
|
|
256
|
+
f.shares = t.snapshot.open.subtract(t.quantity);
|
|
219
257
|
};
|
|
220
258
|
|
|
221
259
|
const valuationFormatter = (t, f) => {
|
|
@@ -1,123 +1,148 @@
|
|
|
1
1
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
2
|
-
|
|
2
|
+
Enum = require('@barchart/common-js/lang/Enum');
|
|
3
3
|
|
|
4
4
|
module.exports = (() => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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;
|
|
123
148
|
})();
|