@barchart/portfolio-api-common 1.0.131 → 1.0.135
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.
|
@@ -108,6 +108,20 @@ module.exports = (() => {
|
|
|
108
108
|
return map;
|
|
109
109
|
}, { });
|
|
110
110
|
|
|
111
|
+
this._symbolsDisplay = this._items.reduce((map, item) => {
|
|
112
|
+
const symbol = extractSymbolForDisplay(item.position);
|
|
113
|
+
|
|
114
|
+
if (symbol) {
|
|
115
|
+
if (!map.hasOwnProperty(symbol)) {
|
|
116
|
+
map[symbol] = [ ];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
map[symbol].push(item);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return map;
|
|
123
|
+
}, { });
|
|
124
|
+
|
|
111
125
|
this._currencies = this._items.reduce((map, item) => {
|
|
112
126
|
const position = item.position;
|
|
113
127
|
|
|
@@ -319,7 +333,12 @@ module.exports = (() => {
|
|
|
319
333
|
* @param {Object} data
|
|
320
334
|
*/
|
|
321
335
|
setPositionFundamentalData(symbol, data) {
|
|
322
|
-
|
|
336
|
+
assert.argumentIsRequired(symbol, 'symbol', String);
|
|
337
|
+
assert.argumentIsRequired(data, 'data', Object);
|
|
338
|
+
|
|
339
|
+
if (this._symbols.hasOwnProperty(symbol)) {
|
|
340
|
+
this._symbols[symbol].forEach(item => item.setPositionFundamentalData(data));
|
|
341
|
+
}
|
|
323
342
|
}
|
|
324
343
|
|
|
325
344
|
/**
|
|
@@ -327,14 +346,24 @@ module.exports = (() => {
|
|
|
327
346
|
*
|
|
328
347
|
* @public
|
|
329
348
|
* @param {String} symbol
|
|
349
|
+
* @param {Boolean} display
|
|
330
350
|
* @param {Boolean} exists
|
|
331
351
|
*/
|
|
332
|
-
setNewsArticleExists(symbol, exists) {
|
|
352
|
+
setNewsArticleExists(symbol, display, exists) {
|
|
333
353
|
assert.argumentIsRequired(symbol, 'symbol', String);
|
|
354
|
+
assert.argumentIsRequired(display, 'display', Boolean);
|
|
334
355
|
assert.argumentIsRequired(exists, 'exists', Boolean);
|
|
335
356
|
|
|
336
|
-
|
|
337
|
-
|
|
357
|
+
let map;
|
|
358
|
+
|
|
359
|
+
if (display) {
|
|
360
|
+
map = this._symbolsDisplay;
|
|
361
|
+
} else {
|
|
362
|
+
map = this._symbols;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
if (map.hasOwnProperty(symbol)) {
|
|
366
|
+
map[symbol].forEach(item => item.setNewsArticleExists(exists));
|
|
338
367
|
}
|
|
339
368
|
}
|
|
340
369
|
|
|
@@ -38,8 +38,11 @@ module.exports = (() => {
|
|
|
38
38
|
|
|
39
39
|
this._excluded = false;
|
|
40
40
|
this._suspended = false;
|
|
41
|
+
this._showClosedPositions = false;
|
|
41
42
|
|
|
42
43
|
this._marketPercentChangeEvent = new Event(this);
|
|
44
|
+
this._excludedChangeEvent = new Event(this);
|
|
45
|
+
this._showClosedPositionsChangeEvent = new Event(this);
|
|
43
46
|
|
|
44
47
|
this._dataFormat = { };
|
|
45
48
|
this._dataActual = { };
|
|
@@ -62,10 +65,12 @@ module.exports = (() => {
|
|
|
62
65
|
this._dataFormat.portfolio = item.portfolio.portfolio;
|
|
63
66
|
this._dataFormat.position = item.position.position;
|
|
64
67
|
this._dataFormat.instrument = item.position.instrument;
|
|
68
|
+
this._dataFormat.fundamental = item.fundamental || { };
|
|
65
69
|
} else {
|
|
66
70
|
this._dataFormat.portfolio = null;
|
|
67
71
|
this._dataFormat.position = null;
|
|
68
72
|
this._dataFormat.instrument = null;
|
|
73
|
+
this._dataFormat.fundamental = { };
|
|
69
74
|
}
|
|
70
75
|
|
|
71
76
|
this._dataFormat.quoteLast = null;
|
|
@@ -136,8 +141,12 @@ module.exports = (() => {
|
|
|
136
141
|
|
|
137
142
|
if (this._single) {
|
|
138
143
|
item.registerNewsExistsChangeHandler((exists, sender) => {
|
|
144
|
+
this._dataActual.newsExists = exists;
|
|
139
145
|
this._dataFormat.newsExists = exists;
|
|
140
|
-
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
item._fundamentalDataChangeEvent((data, sender) => {
|
|
149
|
+
this._dataFormat.fundamental = data;
|
|
141
150
|
});
|
|
142
151
|
}
|
|
143
152
|
});
|
|
@@ -246,11 +255,15 @@ module.exports = (() => {
|
|
|
246
255
|
assert.argumentIsRequired(value, 'value', Boolean);
|
|
247
256
|
|
|
248
257
|
if (this._excluded !== value) {
|
|
249
|
-
this.
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
258
|
+
this._excludedChangeEvent(this._excluded = value);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
setShowClosedPositions(value) {
|
|
263
|
+
assert.argumentIsRequired(value, 'value', Boolean);
|
|
264
|
+
|
|
265
|
+
if (this._showClosedPositions !== value) {
|
|
266
|
+
this._showClosedPositionsChangeEvent(this._showClosedPositions = value);
|
|
254
267
|
}
|
|
255
268
|
}
|
|
256
269
|
|
|
@@ -50,7 +50,7 @@ module.exports = (() => {
|
|
|
50
50
|
|
|
51
51
|
this._data.unrealized = null;
|
|
52
52
|
this._data.unrealizedChange = null;
|
|
53
|
-
|
|
53
|
+
|
|
54
54
|
this._data.summaryTotalCurrent = null;
|
|
55
55
|
this._data.summaryTotalCurrentChange = null;
|
|
56
56
|
|
|
@@ -61,15 +61,14 @@ module.exports = (() => {
|
|
|
61
61
|
this._data.basisPrice = null;
|
|
62
62
|
|
|
63
63
|
this._data.newsExists = false;
|
|
64
|
-
|
|
65
|
-
this._excluded = false;
|
|
64
|
+
this._data.fundamental = { };
|
|
66
65
|
|
|
67
66
|
calculateStaticData(this);
|
|
68
67
|
calculatePriceData(this, null);
|
|
69
68
|
|
|
70
69
|
this._quoteChangedEvent = new Event(this);
|
|
71
|
-
this._excludedChangeEvent = new Event(this);
|
|
72
70
|
this._newsExistsChangedEvent = new Event(this);
|
|
71
|
+
this._fundamentalDataChangeEvent = new Event(this);
|
|
73
72
|
}
|
|
74
73
|
|
|
75
74
|
/**
|
|
@@ -142,10 +141,6 @@ module.exports = (() => {
|
|
|
142
141
|
return this._currentQuote;
|
|
143
142
|
}
|
|
144
143
|
|
|
145
|
-
get excluded() {
|
|
146
|
-
return this._excluded;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
144
|
/**
|
|
150
145
|
* Sets the current quote -- causing position-level data (e.g. market value) to
|
|
151
146
|
* be recalculated.
|
|
@@ -168,12 +163,16 @@ module.exports = (() => {
|
|
|
168
163
|
}
|
|
169
164
|
}
|
|
170
165
|
|
|
171
|
-
|
|
172
|
-
|
|
166
|
+
/**
|
|
167
|
+
* Sets fundamental data for the position.
|
|
168
|
+
*
|
|
169
|
+
* @public
|
|
170
|
+
* @param {Object} data
|
|
171
|
+
*/
|
|
172
|
+
setPositionFundamentalData(data) {
|
|
173
|
+
assert.argumentIsRequired(data, 'data', Object);
|
|
173
174
|
|
|
174
|
-
|
|
175
|
-
this._excludedChangeEvent.fire(this._excluded = value);
|
|
176
|
-
}
|
|
175
|
+
this._fundamentalDataChangeEvent(this._data.fundamental = data);
|
|
177
176
|
}
|
|
178
177
|
|
|
179
178
|
/**
|
|
@@ -202,8 +201,14 @@ module.exports = (() => {
|
|
|
202
201
|
this._quoteChangedEvent.register(handler);
|
|
203
202
|
}
|
|
204
203
|
|
|
205
|
-
|
|
206
|
-
|
|
204
|
+
/**
|
|
205
|
+
* Registers an observer for fundamental data changes.
|
|
206
|
+
*
|
|
207
|
+
* @public
|
|
208
|
+
* @param {Function} handler
|
|
209
|
+
*/
|
|
210
|
+
registerFundamentalDataChangeHandler(handler) {
|
|
211
|
+
this._fundamentalDataChangeEvent.register(handler);
|
|
207
212
|
}
|
|
208
213
|
|
|
209
214
|
/**
|
|
@@ -340,10 +345,10 @@ module.exports = (() => {
|
|
|
340
345
|
data.unrealizedChange = Decimal.ZERO;
|
|
341
346
|
}
|
|
342
347
|
}
|
|
343
|
-
|
|
348
|
+
|
|
344
349
|
function calculateSummaryTotal(summary) {
|
|
345
350
|
let returnRef;
|
|
346
|
-
|
|
351
|
+
|
|
347
352
|
if (summary) {
|
|
348
353
|
const period = summary.period;
|
|
349
354
|
|
|
@@ -351,7 +356,7 @@ module.exports = (() => {
|
|
|
351
356
|
} else {
|
|
352
357
|
returnRef = Decimal.ZERO;
|
|
353
358
|
}
|
|
354
|
-
|
|
359
|
+
|
|
355
360
|
return returnRef;
|
|
356
361
|
}
|
|
357
362
|
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -824,6 +824,20 @@ module.exports = (() => {
|
|
|
824
824
|
return map;
|
|
825
825
|
}, { });
|
|
826
826
|
|
|
827
|
+
this._symbolsDisplay = this._items.reduce((map, item) => {
|
|
828
|
+
const symbol = extractSymbolForDisplay(item.position);
|
|
829
|
+
|
|
830
|
+
if (symbol) {
|
|
831
|
+
if (!map.hasOwnProperty(symbol)) {
|
|
832
|
+
map[symbol] = [ ];
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
map[symbol].push(item);
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
return map;
|
|
839
|
+
}, { });
|
|
840
|
+
|
|
827
841
|
this._currencies = this._items.reduce((map, item) => {
|
|
828
842
|
const position = item.position;
|
|
829
843
|
|
|
@@ -1035,7 +1049,12 @@ module.exports = (() => {
|
|
|
1035
1049
|
* @param {Object} data
|
|
1036
1050
|
*/
|
|
1037
1051
|
setPositionFundamentalData(symbol, data) {
|
|
1038
|
-
|
|
1052
|
+
assert.argumentIsRequired(symbol, 'symbol', String);
|
|
1053
|
+
assert.argumentIsRequired(data, 'data', Object);
|
|
1054
|
+
|
|
1055
|
+
if (this._symbols.hasOwnProperty(symbol)) {
|
|
1056
|
+
this._symbols[symbol].forEach(item => item.setPositionFundamentalData(data));
|
|
1057
|
+
}
|
|
1039
1058
|
}
|
|
1040
1059
|
|
|
1041
1060
|
/**
|
|
@@ -1043,14 +1062,24 @@ module.exports = (() => {
|
|
|
1043
1062
|
*
|
|
1044
1063
|
* @public
|
|
1045
1064
|
* @param {String} symbol
|
|
1065
|
+
* @param {Boolean} display
|
|
1046
1066
|
* @param {Boolean} exists
|
|
1047
1067
|
*/
|
|
1048
|
-
setNewsArticleExists(symbol, exists) {
|
|
1068
|
+
setNewsArticleExists(symbol, display, exists) {
|
|
1049
1069
|
assert.argumentIsRequired(symbol, 'symbol', String);
|
|
1070
|
+
assert.argumentIsRequired(display, 'display', Boolean);
|
|
1050
1071
|
assert.argumentIsRequired(exists, 'exists', Boolean);
|
|
1051
1072
|
|
|
1052
|
-
|
|
1053
|
-
|
|
1073
|
+
let map;
|
|
1074
|
+
|
|
1075
|
+
if (display) {
|
|
1076
|
+
map = this._symbolsDisplay;
|
|
1077
|
+
} else {
|
|
1078
|
+
map = this._symbols;
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
if (map.hasOwnProperty(symbol)) {
|
|
1082
|
+
map[symbol].forEach(item => item.setNewsArticleExists(exists));
|
|
1054
1083
|
}
|
|
1055
1084
|
}
|
|
1056
1085
|
|
|
@@ -1168,8 +1197,11 @@ module.exports = (() => {
|
|
|
1168
1197
|
|
|
1169
1198
|
this._excluded = false;
|
|
1170
1199
|
this._suspended = false;
|
|
1200
|
+
this._showClosedPositions = false;
|
|
1171
1201
|
|
|
1172
1202
|
this._marketPercentChangeEvent = new Event(this);
|
|
1203
|
+
this._excludedChangeEvent = new Event(this);
|
|
1204
|
+
this._showClosedPositionsChangeEvent = new Event(this);
|
|
1173
1205
|
|
|
1174
1206
|
this._dataFormat = { };
|
|
1175
1207
|
this._dataActual = { };
|
|
@@ -1192,10 +1224,12 @@ module.exports = (() => {
|
|
|
1192
1224
|
this._dataFormat.portfolio = item.portfolio.portfolio;
|
|
1193
1225
|
this._dataFormat.position = item.position.position;
|
|
1194
1226
|
this._dataFormat.instrument = item.position.instrument;
|
|
1227
|
+
this._dataFormat.fundamental = item.fundamental || { };
|
|
1195
1228
|
} else {
|
|
1196
1229
|
this._dataFormat.portfolio = null;
|
|
1197
1230
|
this._dataFormat.position = null;
|
|
1198
1231
|
this._dataFormat.instrument = null;
|
|
1232
|
+
this._dataFormat.fundamental = { };
|
|
1199
1233
|
}
|
|
1200
1234
|
|
|
1201
1235
|
this._dataFormat.quoteLast = null;
|
|
@@ -1266,9 +1300,13 @@ module.exports = (() => {
|
|
|
1266
1300
|
|
|
1267
1301
|
if (this._single) {
|
|
1268
1302
|
item.registerNewsExistsChangeHandler((exists, sender) => {
|
|
1269
|
-
this.
|
|
1303
|
+
this._dataActual.newsExists = exists;
|
|
1270
1304
|
this._dataFormat.newsExists = exists;
|
|
1271
1305
|
});
|
|
1306
|
+
|
|
1307
|
+
item._fundamentalDataChangeEvent((data, sender) => {
|
|
1308
|
+
this._dataFormat.fundamental = data;
|
|
1309
|
+
});
|
|
1272
1310
|
}
|
|
1273
1311
|
});
|
|
1274
1312
|
|
|
@@ -1376,11 +1414,15 @@ module.exports = (() => {
|
|
|
1376
1414
|
assert.argumentIsRequired(value, 'value', Boolean);
|
|
1377
1415
|
|
|
1378
1416
|
if (this._excluded !== value) {
|
|
1379
|
-
this.
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1417
|
+
this._excludedChangeEvent(this._excluded = value);
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
setShowClosedPositions(value) {
|
|
1422
|
+
assert.argumentIsRequired(value, 'value', Boolean);
|
|
1423
|
+
|
|
1424
|
+
if (this._showClosedPositions !== value) {
|
|
1425
|
+
this._showClosedPositionsChangeEvent(this._showClosedPositions = value);
|
|
1384
1426
|
}
|
|
1385
1427
|
}
|
|
1386
1428
|
|
|
@@ -1734,7 +1776,7 @@ module.exports = (() => {
|
|
|
1734
1776
|
|
|
1735
1777
|
this._data.unrealized = null;
|
|
1736
1778
|
this._data.unrealizedChange = null;
|
|
1737
|
-
|
|
1779
|
+
|
|
1738
1780
|
this._data.summaryTotalCurrent = null;
|
|
1739
1781
|
this._data.summaryTotalCurrentChange = null;
|
|
1740
1782
|
|
|
@@ -1745,15 +1787,14 @@ module.exports = (() => {
|
|
|
1745
1787
|
this._data.basisPrice = null;
|
|
1746
1788
|
|
|
1747
1789
|
this._data.newsExists = false;
|
|
1748
|
-
|
|
1749
|
-
this._excluded = false;
|
|
1790
|
+
this._data.fundamental = { };
|
|
1750
1791
|
|
|
1751
1792
|
calculateStaticData(this);
|
|
1752
1793
|
calculatePriceData(this, null);
|
|
1753
1794
|
|
|
1754
1795
|
this._quoteChangedEvent = new Event(this);
|
|
1755
|
-
this._excludedChangeEvent = new Event(this);
|
|
1756
1796
|
this._newsExistsChangedEvent = new Event(this);
|
|
1797
|
+
this._fundamentalDataChangeEvent = new Event(this);
|
|
1757
1798
|
}
|
|
1758
1799
|
|
|
1759
1800
|
/**
|
|
@@ -1826,10 +1867,6 @@ module.exports = (() => {
|
|
|
1826
1867
|
return this._currentQuote;
|
|
1827
1868
|
}
|
|
1828
1869
|
|
|
1829
|
-
get excluded() {
|
|
1830
|
-
return this._excluded;
|
|
1831
|
-
}
|
|
1832
|
-
|
|
1833
1870
|
/**
|
|
1834
1871
|
* Sets the current quote -- causing position-level data (e.g. market value) to
|
|
1835
1872
|
* be recalculated.
|
|
@@ -1852,12 +1889,16 @@ module.exports = (() => {
|
|
|
1852
1889
|
}
|
|
1853
1890
|
}
|
|
1854
1891
|
|
|
1855
|
-
|
|
1856
|
-
|
|
1892
|
+
/**
|
|
1893
|
+
* Sets fundamental data for the position.
|
|
1894
|
+
*
|
|
1895
|
+
* @public
|
|
1896
|
+
* @param {Object} data
|
|
1897
|
+
*/
|
|
1898
|
+
setPositionFundamentalData(data) {
|
|
1899
|
+
assert.argumentIsRequired(data, 'data', Object);
|
|
1857
1900
|
|
|
1858
|
-
|
|
1859
|
-
this._excludedChangeEvent.fire(this._excluded = value);
|
|
1860
|
-
}
|
|
1901
|
+
this._fundamentalDataChangeEvent(this._data.fundamental = data);
|
|
1861
1902
|
}
|
|
1862
1903
|
|
|
1863
1904
|
/**
|
|
@@ -1886,8 +1927,14 @@ module.exports = (() => {
|
|
|
1886
1927
|
this._quoteChangedEvent.register(handler);
|
|
1887
1928
|
}
|
|
1888
1929
|
|
|
1889
|
-
|
|
1890
|
-
|
|
1930
|
+
/**
|
|
1931
|
+
* Registers an observer for fundamental data changes.
|
|
1932
|
+
*
|
|
1933
|
+
* @public
|
|
1934
|
+
* @param {Function} handler
|
|
1935
|
+
*/
|
|
1936
|
+
registerFundamentalDataChangeHandler(handler) {
|
|
1937
|
+
this._fundamentalDataChangeEvent.register(handler);
|
|
1891
1938
|
}
|
|
1892
1939
|
|
|
1893
1940
|
/**
|
|
@@ -2024,10 +2071,10 @@ module.exports = (() => {
|
|
|
2024
2071
|
data.unrealizedChange = Decimal.ZERO;
|
|
2025
2072
|
}
|
|
2026
2073
|
}
|
|
2027
|
-
|
|
2074
|
+
|
|
2028
2075
|
function calculateSummaryTotal(summary) {
|
|
2029
2076
|
let returnRef;
|
|
2030
|
-
|
|
2077
|
+
|
|
2031
2078
|
if (summary) {
|
|
2032
2079
|
const period = summary.period;
|
|
2033
2080
|
|
|
@@ -2035,7 +2082,7 @@ module.exports = (() => {
|
|
|
2035
2082
|
} else {
|
|
2036
2083
|
returnRef = Decimal.ZERO;
|
|
2037
2084
|
}
|
|
2038
|
-
|
|
2085
|
+
|
|
2039
2086
|
return returnRef;
|
|
2040
2087
|
}
|
|
2041
2088
|
|